feat: tokenizer accepts braces, line terminator, and equal sign
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
package convert
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.maximhutz.com/max/lambda/pkg/lambda"
|
||||
"git.maximhutz.com/max/lambda/pkg/saccharine/ast"
|
||||
)
|
||||
|
||||
type compileVisitor struct{}
|
||||
|
||||
func (v compileVisitor) VisitAtom(n *ast.Atom) lambda.Expression {
|
||||
func convertAtom(n *ast.Atom) lambda.Expression {
|
||||
return lambda.NewVariable(n.Name)
|
||||
}
|
||||
|
||||
func (v compileVisitor) VisitAbstraction(n *ast.Abstraction) lambda.Expression {
|
||||
result := ast.Visit(v, n.Body)
|
||||
func convertAbstraction(n *ast.Abstraction) lambda.Expression {
|
||||
result := SaccharineToLambda(n.Body)
|
||||
|
||||
parameters := n.Parameters
|
||||
|
||||
@@ -31,12 +31,12 @@ func (v compileVisitor) VisitAbstraction(n *ast.Abstraction) lambda.Expression {
|
||||
return result
|
||||
}
|
||||
|
||||
func (v compileVisitor) VisitApplication(n *ast.Application) lambda.Expression {
|
||||
result := ast.Visit(v, n.Abstraction)
|
||||
func convertApplication(n *ast.Application) lambda.Expression {
|
||||
result := SaccharineToLambda(n.Abstraction)
|
||||
|
||||
arguments := []lambda.Expression{}
|
||||
for _, argument := range n.Arguments {
|
||||
convertedArgument := ast.Visit(v, argument)
|
||||
convertedArgument := SaccharineToLambda(argument)
|
||||
arguments = append(arguments, convertedArgument)
|
||||
}
|
||||
|
||||
@@ -48,5 +48,14 @@ func (v compileVisitor) VisitApplication(n *ast.Application) lambda.Expression {
|
||||
}
|
||||
|
||||
func SaccharineToLambda(n ast.Expression) lambda.Expression {
|
||||
return ast.Visit(&compileVisitor{}, n)
|
||||
switch n := n.(type) {
|
||||
case *ast.Atom:
|
||||
return convertAtom(n)
|
||||
case *ast.Abstraction:
|
||||
return convertAbstraction(n)
|
||||
case *ast.Application:
|
||||
return convertApplication(n)
|
||||
default:
|
||||
panic(fmt.Errorf("unknown expression type: %v", n))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user