Exemple #1
0
        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>());
        }
Exemple #2
0
        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));
        }
Exemple #3
0
        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()));
        }