public Expression <Func <object> > ParseExpression(string expression) { var inputStream = new AntlrInputStream(expression); var lexer = new NespGrammarLexer(inputStream); var commonTokenStream = new CommonTokenStream(lexer); var grammarParser = new NespGrammarParser(commonTokenStream); // Take from body rule. var context = (IParseTree)grammarParser.body(); NespExpression expr; lock (parser) { expr = parser.Visit(context); } return(null); //var valueType = typeof(object); //var strictExpr = (expr.Type == valueType) // ? expr // : Expression.Convert(expr, valueType); //return Expression.Lambda<Func<object>>( // strictExpr, false, Enumerable.Empty<ParameterExpression>()); }
private static string Parse(string text, Func <NespGrammarParser, ParserRuleContext> parseToContext) { var inputStream = new AntlrInputStream(text); var lexer = new NespGrammarLexer(inputStream); var commonTokenStream = new CommonTokenStream(lexer); var grammarParser = new NespGrammarParser(commonTokenStream); var graphContext = parseToContext(grammarParser); return(graphContext.ToStringTree(grammarParser.RuleNames)); }
private NespAbstractListExpression ParseAndVisit(string replLine) { var inputStream = new AntlrInputStream(replLine); var lexer = new NespGrammarLexer(inputStream); var commonTokenStream = new CommonTokenStream(lexer); var grammarParser = new NespGrammarParser(commonTokenStream); var parser = new NespParser(new MemberBinder()); parser.AddMembers(NespBaseExtension.CreateMemberProducer()); parser.AddMembers(NespStandardExtension.CreateMemberProducer()); return((NespAbstractListExpression)parser.Visit(grammarParser.body())); }