Esempio 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);
     }
 }
Esempio n. 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);
     }
 }
Esempio n. 3
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="parser"></param>
 public XPTGenerator(RulezParser parser, Engine engine = null)
 {
     _parser = parser;
     if (engine == null)
     {
         _engine = parser.Engine;
     }
     else
     {
         _engine = engine;
     }
 }
Esempio n. 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;
            }
        }
Esempio n. 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;
     }
 }
Esempio n. 6
0
 /// <summary>
 /// enter a rule rule
 /// </summary>
 /// <param name="context"></param>
 public override void EnterSelectionRulez(RulezParser.SelectionRulezContext context)
 {
     if (context.XPTreeNode == null) context.XPTreeNode = new SelectionRule(engine: this.Engine);
     // set the _xptree by a new SelectionRule xPTree
     if (this.XPTree == null) this.XPTree = (XPTree)context.XPTreeNode;
 }
Esempio n. 7
0
        private eXPressionTree.XPTree _xptree; // the output tree

        #endregion Fields

        #region Constructors

        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="parser"></param>
        public XPTGenerator(RulezParser parser, Engine engine = null)
        {
            _parser = parser;
            if (engine == null) _engine = parser.Engine;
            else { _engine = engine; }
        }
Esempio n. 8
0
 /// <summary>
 /// exit a rule rule
 /// </summary>
 /// <param name="context"></param>
 public override void ExitSelectionRulez(RulezParser.SelectionRulezContext context)
 {
 }
Esempio n. 9
0
 /// <summary>
 /// exit a parameter definition
 /// </summary>
 /// <param name="context"></param>
 public override void ExitParameterdefinition(RulezParser.ParameterdefinitionContext context)
 {
 }