示例#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);
     }
 }
示例#2
0
 /// <summary>
 /// Verify a source code and return the Inode
 /// </summary>
 /// <param name="source"></param>
 /// <returns></returns>
 public INode Verifiy(string source)
 {
     RulezParser.MessageListener  aListener = new RulezParser.MessageListener();
     RulezParser.RulezUnitContext aCtx      = null;
     try
     {
         RulezLexer aLexer = new RulezLexer(new Antlr4.Runtime.AntlrInputStream(source));
         // 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.AddErrorListener(aListener);
         aCtx = aParser.rulezUnit();
         if (aCtx != null)
         {
             return(aCtx.XPTreeNode);
         }
         return(null);
     }
     catch (Exception ex)
     {
         if (aCtx != null)
         {
             if (aCtx.XPTreeNode != null)
             {
                 aCtx.XPTreeNode.Messages.Add(new Message(type: MessageType.Error, message: ex.Message));
                 return(aCtx.XPTreeNode);
             }
         }
         return(null);
     }
 }
示例#3
0
        /// <summary>
        /// generate a selection Rule XPT out of a String
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public SelectionRule Generate(string source)
        {
            RulezParser.MessageListener aListener = new RulezParser.MessageListener();
            RulezParser.SelectionRulezContext aCtx = null;

            try
            {
                RulezLexer aLexer = new RulezLexer(new Antlr4.Runtime.AntlrInputStream(source));
                // 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.Engine;
                aParser.AddErrorListener(aListener);
                // parse
                aCtx = aParser.selectionRulez();
                // return
                return (SelectionRule) aCtx.XPTreeNode;
            }
            catch (Exception ex)
            {
                if (aCtx != null) return (SelectionRule) aCtx.XPTreeNode;
                return null;
            }
        }
示例#4
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;
            }
        }
示例#5
0
 /// <summary>
 /// Verify a source code and return the Inode
 /// </summary>
 /// <param name="source"></param>
 /// <returns></returns>
 public INode Verifiy(string source)
 {
     RulezParser.MessageListener aListener = new RulezParser.MessageListener();
     RulezParser.RulezUnitContext aCtx = null;
     try
     {
         RulezLexer aLexer = new RulezLexer(new Antlr4.Runtime.AntlrInputStream(source));
         // 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.AddErrorListener(aListener);
         aCtx = aParser.rulezUnit();
         if (aCtx != null) return aCtx.XPTreeNode;
         return null;
     }
     catch (Exception ex)
     {
         if (aCtx != null)
         {
             if (aCtx.XPTreeNode != null)
             {
                 aCtx.XPTreeNode.Messages.Add(new Message(type: MessageType.Error, message: ex.Message));
                 return aCtx.XPTreeNode;
             }
         }
         return null;
     }
 }