Beispiel #1
0
        /// <summary>
        /// Provides the parse tree according to the statement provided
        /// </summary>
        /// <param name="root">the element for which this statemennt should be parsed</param>
        /// <param name="expression"></param>
        /// <returns></returns>
        public Statement.Statement Statement(ModelElement root, string expression)
        {
            Statement.Statement retVal = null;

            try
            {
                Generated.ControllersManager.NamableController.DesactivateNotification();

                Root   = root;
                Buffer = expression.ToCharArray();
                retVal = Statement(root);

                skipWhiteSpaces();
                if (Index != Buffer.Length)
                {
                    if (Index < Buffer.Length)
                    {
                        throw new ParseErrorException("End of statement expected at " + Index + ", but found " + Buffer[Index]);
                    }
                }

                if (retVal != null)
                {
                    retVal.SemanticAnalysis();
                }
            }
            finally
            {
                Generated.ControllersManager.NamableController.ActivateNotification();
            }

            return(retVal);
        }
Beispiel #2
0
 /// <summary>
 ///     Visits a statement
 /// </summary>
 /// <param name="statement"></param>
 protected virtual void VisitStatement(Statement.Statement statement)
 {
     if (statement != null)
     {
         // ReSharper disable CanBeReplacedWithTryCastAndCheckForNull
         if (statement is ApplyStatement)
         {
             VisitApplyStatement((ApplyStatement)statement);
         }
         else if (statement is InsertStatement)
         {
             VisitInsertStatement((InsertStatement)statement);
         }
         else if (statement is ProcedureCallStatement)
         {
             VisitProcedureCallStatement((ProcedureCallStatement)statement);
         }
         else if (statement is RemoveStatement)
         {
             VisitRemoveStatement((RemoveStatement)statement);
         }
         else if (statement is ReplaceStatement)
         {
             VisitReplaceStatement((ReplaceStatement)statement);
         }
         else if (statement is VariableUpdateStatement)
         {
             VisitVariableUpdateStatement((VariableUpdateStatement)statement);
         }
         // ReSharper restore CanBeReplacedWithTryCastAndCheckForNull
     }
 }
 /// <summary>
 /// Don't visit statements which do not cover the position given
 /// </summary>
 /// <param name="statement"></param>
 protected override void VisitStatement(Statement.Statement statement)
 {
     if (ShouldCheck(statement))
     {
         base.VisitStatement(statement);
     }
 }
Beispiel #4
0
        /// <summary>
        ///     Visits a tree node
        /// </summary>
        /// <param name="interpreterTreeNode"></param>
        protected virtual void visitInterpreterTreeNode(InterpreterTreeNode interpreterTreeNode)
        {
            Designator designator = interpreterTreeNode as Designator;

            if (designator != null)
            {
                VisitDesignator(designator);
            }

            Term term = interpreterTreeNode as Term;

            if (term != null)
            {
                VisitTerm(term);
            }

            Expression expression = interpreterTreeNode as Expression;

            if (expression != null)
            {
                VisitExpression(expression);
            }

            Statement.Statement statement = interpreterTreeNode as Statement.Statement;
            if (statement != null)
            {
                VisitStatement(statement);
            }
        }
        /// <summary>
        ///     Constructor
        /// </summary>
        /// <param name="root">The root element for which this element is built</param>
        /// <param name="log"></param>
        /// <param name="appliedStatement">The statement to be applied when the condition is satisfied</param>
        /// <param name="listExpression">The list to work on</param>
        /// <param name="conditionExpression">The condition to apply on the list elements</param>
        /// <param name="parsingData">Additional information about the parsing process</param>
        public ApplyStatement(ModelElement root, ModelElement log, Statement appliedStatement, Expression listExpression,
            Expression conditionExpression, ParsingData parsingData)
            : base(root, log, parsingData)
        {
            DeclaredElements = new Dictionary<string, List<INamable>>();

            AppliedStatement = SetEnclosed(appliedStatement);
            ListExpression = SetEnclosed(listExpression);
            ConditionExpression = SetEnclosed(conditionExpression);

            IteratorVariable = CreateBoundVariable("X", null);
            InitDeclaredElements();
        }
        /// <summary>
        /// Checks a statement associated to a model element
        /// </summary>
        /// <param name="model">The model element on which the expression is defined</param>
        /// <param name="expression">The expression to check</param>
        /// <returns>the expression parse tree</returns>
        private Interpreter.Statement.Statement checkStatement(ModelElement model, string expression)
        {
            Interpreter.Statement.Statement retVal = null;

            Interpreter.Parser parser = model.EFSSystem.Parser;
            try
            {
                retVal = parser.Statement(model, expression);
                retVal.CheckStatement();
            }
            catch (Exception exception)
            {
                model.AddException(exception);
            }
            return(retVal);
        }
        /// <summary>
        ///     Constructor
        /// </summary>
        /// <param name="root">The root element for which this element is built</param>
        /// <param name="log"></param>
        /// <param name="appliedStatement">The statement to be applied when the condition is satisfied</param>
        /// <param name="listExpression">The list to work on</param>
        /// <param name="conditionExpression">The condition to apply on the list elements</param>
        /// <param name="start">The start character for this expression in the original string</param>
        /// <param name="end">The end character for this expression in the original string</param>
        public ApplyStatement(ModelElement root, ModelElement log, Statement appliedStatement, Expression listExpression,
            Expression conditionExpression, int start, int end)
            : base(root, log, start, end)
        {
            DeclaredElements = new Dictionary<string, List<INamable>>();

            AppliedStatement = appliedStatement;
            AppliedStatement.Enclosing = this;

            ListExpression = listExpression;
            ListExpression.Enclosing = this;

            ConditionExpression = conditionExpression;
            if (ConditionExpression != null)
            {
                ConditionExpression.Enclosing = this;
            }

            IteratorVariable = CreateBoundVariable("X", null);
            InitDeclaredElements();
        }
        public override void visit(Generated.Action obj, bool subNodes)
        {
            Rules.Action action = obj as Rules.Action;

            if (action != null)
            {
                try
                {
                    action.Messages.Clear();
                    if (!action.Expression.Contains('%'))
                    {
                        Interpreter.Statement.Statement statement = checkStatement(action, action.Expression);
                    }
                }
                catch (Exception exception)
                {
                    action.AddException(exception);
                }
            }

            base.visit(obj, subNodes);
        }
Beispiel #9
0
        /// <summary>
        ///     Visits an interpreter tree node
        /// </summary>
        /// <param name="interpreterTreeNode"></param>
        protected virtual void VisitInterpreterTreeNode(InterpreterTreeNode interpreterTreeNode)
        {
            Expression expression = interpreterTreeNode as Expression;

            if (expression != null)
            {
                VisitExpression(expression);
            }
            else
            {
                Statement.Statement statement = interpreterTreeNode as Statement.Statement;
                if (statement != null)
                {
                    VisitStatement(statement);
                }
                else
                {
                    Term term = interpreterTreeNode as Term;
                    if (term != null)
                    {
                        VisitTerm(term);
                    }
                    else
                    {
                        Designator designator = interpreterTreeNode as Designator;
                        if (designator != null)
                        {
                            VisitDesignator(designator);
                        }
                        else
                        {
                            throw new NotImplementedException();
                        }
                    }
                }
            }
        }
        /// <summary>
        ///     Browses through the statement to find the structures to edit
        /// </summary>
        /// <param name="statement"></param>
        private Statement VisitStatement(Statement statement)
        {
            Statement retVal = statement;

            VariableUpdateStatement variableUpdateStatement = statement as VariableUpdateStatement;
            if (variableUpdateStatement != null)
            {
                variableUpdateStatement.Expression = VisitExpression(variableUpdateStatement.Expression);
            }

            return retVal;
        }
Beispiel #11
0
        /// <summary>
        /// Provides the Term at position Index of the Buffer.
        /// </summary>
        /// <param name="root">The root element for which this term is built</param>
        /// <returns></returns>
        private Statement.Statement Statement(ModelElement root)
        {
            Statement.Statement retVal = null;

            Root = root;
            if (LookAhead("APPLY"))
            {
                Match("APPLY");
                Call callExpression = Expression(0) as Call;
                if (callExpression != null)
                {
                    Statement.ProcedureCallStatement call = new Statement.ProcedureCallStatement(root, callExpression);
                    Match("ON");
                    Expression listExpression = Expression(0);
                    Expression condition      = null;
                    if (LookAhead("|"))
                    {
                        Match("|");
                        condition = Expression(0);
                    }
                    retVal = new Statement.ApplyStatement(root, call, listExpression, condition);
                }
                else
                {
                    Root.AddError("Cannot parse call expression");
                }
            }
            else if (LookAhead("INSERT"))
            {
                Match("INSERT");
                Expression value = Expression(0);
                if (value != null)
                {
                    Match("IN");
                    Expression list           = Expression(0);
                    Expression replaceElement = null;
                    if (LookAhead("WHEN"))
                    {
                        Match("WHEN");
                        Match("FULL");
                        Match("REPLACE");

                        replaceElement = Expression(0);
                    }
                    retVal = new Statement.InsertStatement(root, value, list, replaceElement);
                }
            }
            else if (LookAhead("REMOVE"))
            {
                Match("REMOVE");

                Statement.RemoveStatement.PositionEnum position = Interpreter.Statement.RemoveStatement.PositionEnum.First;
                if (LookAhead("FIRST"))
                {
                    Match("FIRST");
                }
                else if (LookAhead("LAST"))
                {
                    Match("LAST");
                    position = Interpreter.Statement.RemoveStatement.PositionEnum.Last;
                }
                else if (LookAhead("ALL"))
                {
                    Match("ALL");
                    position = Interpreter.Statement.RemoveStatement.PositionEnum.All;
                }

                Expression condition = null;
                if (!LookAhead("IN"))
                {
                    condition = Expression(0);
                }
                Match("IN");
                Expression list = Expression(0);
                retVal = new Statement.RemoveStatement(root, condition, position, list);
            }
            else if (LookAhead("REPLACE"))
            {
                Match("REPLACE");
                Expression condition = Expression(0);
                Match("IN");
                Expression list = Expression(0);
                Match("BY");
                Expression value = Expression(0);

                retVal = new Statement.ReplaceStatement(root, value, list, condition);
            }
            else
            {
                Expression expression = Expression(0);
                if (expression != null)
                {
                    if (LookAhead("<-"))
                    {
                        // This is a variable update
                        Match("<-");
                        if (LookAhead("%"))
                        {
                            Match("%");
                        }
                        Expression expression2 = Expression(0);

                        if (expression2 != null)
                        {
                            retVal = new Statement.VariableUpdateStatement(root, expression, expression2);
                        }
                        else
                        {
                            Root.AddError("Invalid <- right side");
                        }
                        expression.Enclosing = retVal;
                    }
                    else
                    {
                        // This is a procedure call
                        Call call = expression as Call;
                        if (call != null)
                        {
                            retVal = new Statement.ProcedureCallStatement(root, call);
                        }
                        else
                        {
                            Root.AddError("Cannot parse call expression");
                        }
                    }
                }
                else
                {
                    Root.AddError("Cannot parse expression");
                }
            }

            return(retVal);
        }
 /// <summary>
 ///     Visits a statement
 /// </summary>
 /// <param name="statement"></param>
 protected virtual void VisitStatement(Statement.Statement statement)
 {
     if (statement != null)
     {
         // ReSharper disable CanBeReplacedWithTryCastAndCheckForNull
         if (statement is ApplyStatement)
         {
             VisitApplyStatement((ApplyStatement) statement);
         }
         else if (statement is InsertStatement)
         {
             VisitInsertStatement((InsertStatement) statement);
         }
         else if (statement is ProcedureCallStatement)
         {
             VisitProcedureCallStatement((ProcedureCallStatement) statement);
         }
         else if (statement is RemoveStatement)
         {
             VisitRemoveStatement((RemoveStatement) statement);
         }
         else if (statement is ReplaceStatement)
         {
             VisitReplaceStatement((ReplaceStatement) statement);
         }
         else if (statement is VariableUpdateStatement)
         {
             VisitVariableUpdateStatement((VariableUpdateStatement) statement);
         }
         // ReSharper restore CanBeReplacedWithTryCastAndCheckForNull
     }
 }
Beispiel #13
0
 /// <summary>
 ///     Visits a statement
 /// </summary>
 /// <param name="?"></param>
 protected virtual void VisitStatement(Statement.Statement statement)
 {
     if (statement != null)
     {
         if (statement is ApplyStatement)
         {
             VisitApplyStatement((ApplyStatement) statement);
         }
         else if (statement is InsertStatement)
         {
             VisitInsertStatement((InsertStatement) statement);
         }
         else if (statement is ProcedureCallStatement)
         {
             VisitProcedureCallStatement((ProcedureCallStatement) statement);
         }
         else if (statement is RemoveStatement)
         {
             VisitRemoveStatement((RemoveStatement) statement);
         }
         else if (statement is ReplaceStatement)
         {
             VisitReplaceStatement((ReplaceStatement) statement);
         }
         else if (statement is VariableUpdateStatement)
         {
             VisitVariableUpdateStatement((VariableUpdateStatement) statement);
         }
     }
 }