feat: parse saccharine, conversion incoming
This commit is contained in:
@@ -25,6 +25,35 @@ func stringifyApplication(n *ast.Application) string {
|
||||
return "(" + strings.Join(arguments, " ") + ")"
|
||||
}
|
||||
|
||||
func stringifyLet(s *ast.LetStatement) string {
|
||||
return s.Name + " " + strings.Join(s.Parameters, " ") + " := " + Stringify(s.Body)
|
||||
}
|
||||
|
||||
func stringifyDeclare(s *ast.DeclareStatement) string {
|
||||
return Stringify(s.Value)
|
||||
}
|
||||
|
||||
func stringifyStatement(s ast.Statement) string {
|
||||
switch s := s.(type) {
|
||||
case *ast.DeclareStatement:
|
||||
return stringifyDeclare(s)
|
||||
case *ast.LetStatement:
|
||||
return stringifyLet(s)
|
||||
default:
|
||||
panic(fmt.Errorf("unknown statement type: %v", s))
|
||||
}
|
||||
}
|
||||
|
||||
func stringifyClause(n *ast.Clause) string {
|
||||
stmts := ""
|
||||
|
||||
for _, statement := range n.Statements {
|
||||
stmts += stringifyStatement(statement) + "; "
|
||||
}
|
||||
|
||||
return "{ " + stmts + Stringify(n.Returns) + " }"
|
||||
}
|
||||
|
||||
func Stringify(n ast.Expression) string {
|
||||
switch n := n.(type) {
|
||||
case *ast.Atom:
|
||||
@@ -33,7 +62,9 @@ func Stringify(n ast.Expression) string {
|
||||
return stringifyAbstraction(n)
|
||||
case *ast.Application:
|
||||
return stringifyApplication(n)
|
||||
case *ast.Clause:
|
||||
return stringifyClause(n)
|
||||
default:
|
||||
panic(fmt.Errorf("unknown expression type: %v", n))
|
||||
panic(fmt.Errorf("unknown expression type: %T", n))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user