Ejemplo n.º 1
0
 /// <summary>
 /// generate from a input string a rule by parsing and compiling and store it
 /// </summary>
 /// <param name="input"></param>
 /// <returns></returns>
 private bool Generate(Antlr4.Runtime.ICharStream input)
 {
     try
     {
         RulezLexer aLexer = new RulezLexer(input);
         // wrap a token-stream around the lexer
         Antlr4.Runtime.CommonTokenStream theTokens = new Antlr4.Runtime.CommonTokenStream(aLexer);
         // create the aParser
         RulezParser aParser = new RulezParser(theTokens);
         aParser.Trace  = true;
         aParser.Engine = this;
         //aParser.RemoveErrorListeners();
         //aParser.AddErrorListener(new ErrorListener());
         RulezParser.RulezUnitContext aTree = aParser.rulezUnit();
         // walk the parse tree -> get the result XPTree
         XPTGenerator aGenerator = new XPTGenerator(aParser);
         Antlr4.Runtime.Tree.ParseTreeWalker.Default.Walk(aGenerator, aTree);
         // result -> Generate and store from the XPTree
         return(Generate((IRule)aGenerator.XPTree));
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// generate from a input string a rule by parsing and compiling and store it
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        private bool Generate(Antlr4.Runtime.ICharStream input)
        {
            try
            {
                RulezLexer aLexer = new RulezLexer(input);
                // wrap a token-stream around the lexer
                Antlr4.Runtime.CommonTokenStream theTokens = new Antlr4.Runtime.CommonTokenStream(aLexer);
                // create the aParser
                RulezParser aParser = new RulezParser(theTokens);
                aParser.Trace = true;
                aParser.Engine = this;
                //aParser.RemoveErrorListeners();
                //aParser.AddErrorListener(new ErrorListener());
                RulezParser.RulezUnitContext  aTree = aParser.rulezUnit();
                // walk the parse tree -> get the result XPTree
                XPTGenerator aGenerator = new XPTGenerator(aParser);
                Antlr4.Runtime.Tree.ParseTreeWalker.Default.Walk(aGenerator, aTree);
                // result -> Generate and store from the XPTree
                return Generate((IRule) aGenerator.XPTree);

            }
            catch (Exception ex)
            {
                return false;
            }
        }