Ejemplo n.º 1
0
        public bool Execute(DataContext context)
        {
            QLLexer lexer = new QLLexer(context.AntlrInput);
            lexer.AddErrorListener(new LexerErrorHandler(context.ASTHandlerExceptions));

            CommonTokenStream tokens = new CommonTokenStream(lexer);
            QLParser parser = new QLParser(tokens);
            parser.AddErrorListener(new ParserErrorHandler(context.ASTHandlerExceptions));

            QLListener listener = new QLListener(context.ASTHandlerExceptions);
            parser.AddParseListener(listener);

            // commence parsing the input as a formBlock since it's supposed to be the entry point of the input file
            parser.formBlock();
            context.RootNode = listener.GetAstRootNode();
            return !context.ASTHandlerExceptions.Any();
        }
Ejemplo n.º 2
0
        public bool Execute(DataContext context)
        {
            QLLexer lexer = new QLLexer(context.AntlrInput);

            lexer.AddErrorListener(new LexerErrorHandler(context.ASTHandlerExceptions));

            CommonTokenStream tokens = new CommonTokenStream(lexer);
            QLParser          parser = new QLParser(tokens);

            parser.AddErrorListener(new ParserErrorHandler(context.ASTHandlerExceptions));

            QLListener listener = new QLListener(context.ASTHandlerExceptions);

            parser.AddParseListener(listener);

            // commence parsing the input as a formBlock since it's supposed to be the entry point of the input file
            parser.formBlock();
            context.RootNode = listener.GetAstRootNode();
            return(!context.ASTHandlerExceptions.Any());
        }
Ejemplo n.º 3
0
        private Reference <T> BuildAstTree <T>(string definition) where T : IAstNode
        {
            var stream = new AntlrInputStream(definition);
            var lexer  = new QLLexer(stream);

            lexer.RemoveErrorListeners();
            lexer.AddErrorListener(new QlErrorListener());

            var tokens = new CommonTokenStream(lexer);

            var parser = new QLParser(tokens);

            parser.RemoveErrorListeners();
            parser.AddErrorListener(new QlErrorListener());

            var tree = parser.questionnaire();

            var qlVisitor = new BuildAstVisitor(m_astFactory, m_domainItemLocator);

            return(qlVisitor.Visit(tree).To <T>(m_domainItemLocator));
        }
Ejemplo n.º 4
0
        public ParsingTask Process(ParsingTask input)
        {
            if (string.IsNullOrEmpty(input.ParsingInput))
            {
                input.Errors.Add("Input string is empty");
                _canContinue = false;
                return(input);
            }

            QLParser parser        = SetupParser(input.ParsingInput);
            var      errorListener = new ErrorListener();

            parser.AddErrorListener(errorListener);

            var visitor = new ParseTreeVisitor(new OperatorFactory(new ValueFactory()));

            input.Ast = visitor.Visit(parser.form());
            errorListener.Errors.ForEach(x => input.Errors.Add(x));
            _canContinue = !errorListener.Errors.Any();

            return(input);
        }
Ejemplo n.º 5
0
 private void AddErrorListener(QLParser parser)
 {
     parser.RemoveErrorListeners();
     parser.AddErrorListener(new AntlrErrorListener(Messages));
 }