transpiler

This commit is contained in:
2024-08-18 21:02:40 +02:00
parent 9aa33cef96
commit 3d9a147aad
11 changed files with 1047 additions and 35 deletions
+5 -2
View File
@@ -36,7 +36,10 @@ func ConvertAST(node antlr.Tree, wparser *parser.WystParser, lexer *parser.WystL
ast.Text = parseTree.GetText()
}
for i := 0; i < node.GetChildCount(); i++ {
ast.Inner = append(ast.Inner, ConvertAST(node.GetChild(i), wparser, lexer))
l := ConvertAST(node.GetChild(i), wparser, lexer)
if l.Rule != ("'"+l.Text+"'") || l.Text == ";" {
ast.Inner = append(ast.Inner, l)
}
}
}
return ast
@@ -48,6 +51,6 @@ func Parse(code string) ASTNode {
stream := antlr.NewCommonTokenStream(lexer, 0)
p := parser.NewWystParser(stream)
// p.AddErrorListener(antlr.NewDiagnosticErrorListener(true).WithContext(p))
tree := p.Expr()
tree := p.Top()
return ConvertAST(tree, p, lexer)
}