Beispiel #1
0
        private GrammarParseResult Parse(string text)
        {
            AntlrInputStream  inputStream       = new AntlrInputStream(text);
            GrammarLexer      grammarLexer      = new GrammarLexer(inputStream);
            CommonTokenStream commonTokenStream = new CommonTokenStream(grammarLexer);
            GrammarParser     grammarParser     = new GrammarParser(commonTokenStream);

            GrammarParser.StatementsContext context = grammarParser.statements();
            StatementsVisitor  visitor = new StatementsVisitor(new TestRuleSet());
            GrammarParseResult result  = visitor.Visit(context);

            return(result);
        }
Beispiel #2
0
        public static GrammarParseResult Evaluate(string text, IRuleSet ruleSet)
        {
            if (String.IsNullOrEmpty(text?.Trim()))
            {
                return(GrammarParseResult.Unsuccessful(text));
            }
            AntlrInputStream  inputStream       = new AntlrInputStream(text);
            GrammarLexer      grammarLexer      = new GrammarLexer(inputStream);
            CommonTokenStream commonTokenStream = new CommonTokenStream(grammarLexer);
            GrammarParser     grammarParser     = new GrammarParser(commonTokenStream);

            GrammarParser.StatementsContext context = grammarParser.statements();
            StatementsVisitor  visitor = new StatementsVisitor(ruleSet);
            GrammarParseResult result  = visitor.Visit(context);

            return(result);
        }