feat: tokenizer accepts braces, line terminator, and equal sign
This commit is contained in:
@@ -20,9 +20,15 @@ type Atom struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
type Clause struct {
|
||||
Statements []Statement
|
||||
Returns Expression
|
||||
}
|
||||
|
||||
func (Abstraction) IsExpression() {}
|
||||
func (Application) IsExpression() {}
|
||||
func (Atom) IsExpression() {}
|
||||
func (Clause) IsExpression() {}
|
||||
|
||||
/** ------------------------------------------------------------------------- */
|
||||
|
||||
@@ -37,3 +43,7 @@ func NewApplication(abstraction Expression, arguments []Expression) *Application
|
||||
func NewAtom(name string) *Atom {
|
||||
return &Atom{Name: name}
|
||||
}
|
||||
|
||||
func NewClause(statements []Statement, returns Expression) *Clause {
|
||||
return &Clause{Statements: statements, Returns: returns}
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package ast
|
||||
|
||||
type Program struct {
|
||||
Statements []Statement
|
||||
}
|
||||
@@ -7,11 +7,6 @@ type Statement interface {
|
||||
/** ------------------------------------------------------------------------- */
|
||||
|
||||
type LetStatement struct {
|
||||
Variable string
|
||||
Value Expression
|
||||
}
|
||||
|
||||
type MethodStatement struct {
|
||||
Name string
|
||||
Parameters []string
|
||||
Body Expression
|
||||
@@ -22,7 +17,6 @@ type DeclareStatement struct {
|
||||
}
|
||||
|
||||
func (LetStatement) IsStatement() {}
|
||||
func (MethodStatement) IsStatement() {}
|
||||
func (DeclareStatement) IsStatement() {}
|
||||
|
||||
/** ------------------------------------------------------------------------- */
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
package ast
|
||||
|
||||
import "fmt"
|
||||
|
||||
type Visitor[T any] interface {
|
||||
VisitAtom(*Atom) T
|
||||
VisitAbstraction(*Abstraction) T
|
||||
VisitApplication(*Application) T
|
||||
}
|
||||
|
||||
func Visit[T any](visitor Visitor[T], node Expression) T {
|
||||
switch node := node.(type) {
|
||||
case *Atom:
|
||||
return visitor.VisitAtom(node)
|
||||
case *Abstraction:
|
||||
return visitor.VisitAbstraction(node)
|
||||
case *Application:
|
||||
return visitor.VisitApplication(node)
|
||||
default:
|
||||
panic(fmt.Sprintf("unknown node %t", node))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user