private static FlowScriptParser.CompilationUnitContext ParseCompilationUnit(AntlrInputStream inputStream, IAntlrErrorListener <IToken> errorListener = null) { var lexer = new FlowScriptLexer(inputStream); var tokenStream = new CommonTokenStream(lexer); // parser var parser = new FlowScriptParser(tokenStream); parser.BuildParseTree = true; //parser.ErrorHandler = new BailErrorStrategy(); parser.ErrorHandler = new DefaultErrorStrategy(); if (errorListener != null) { parser.RemoveErrorListeners(); parser.AddErrorListener(errorListener); } var cst = parser.compilationUnit(); return(cst); }
public static Expression FromText(string source) { var lexer = new FlowScriptLexer(new AntlrInputStream(source)); var tokenStream = new CommonTokenStream(lexer); // parse expression var parser = new FlowScriptParser(tokenStream); parser.BuildParseTree = true; var expressionParseTree = parser.expression(); // parse ast nodes var compilationUnitParser = new CompilationUnitParser(); compilationUnitParser.TryParseExpression(expressionParseTree, out var expression); // resolve types var typeResolver = new TypeResolver(); typeResolver.TryResolveTypesInExpression(expression); return(expression); }