コード例 #1
0
        public SymPreProcessorWorkerElseIf(SymParserWorkerContext aContext)
            : base(aContext)
        {
            // When the else token is reached, we must work back up the tree
            // looking for the previous (i.e. most recent) conditional expression
            // node.
            SymNodeConditionalExpression condExpNode = SymParserWorkerConditionalExpression.FindMostRecentConditionalExpression(aContext.Document.CurrentNode);

            if (condExpNode == null)
            {
                throw new Exception("Unable to locate most recent condition expression during ELSE IF handling");
            }

            // There must always be a positive condition node and some kind of condition
            if (condExpNode.ChildTypeExists(typeof(SymNodeCondition)) == false)
            {
                throw new Exception("No child condition node found during ELSE IF handling");
            }

            // Make the conditional expression the current node
            aContext.Document.CurrentNode = condExpNode;

            // Make a new condition worker. The condition worker creates a new condition node
            // which becomes the new current node.
            SymParserWorkerContext   context         = new SymParserWorkerContext(aContext.Document.Context, this);
            SymParserWorkerCondition conditionWorker = new SymParserWorkerCondition(context, new SymNodePreProcessorCondition(aContext.CurrentToken.Value));

            AddChild(conditionWorker);
        }
コード例 #2
0
        public SymPreProcessorWorkerEndif(SymParserWorkerContext aContext)
            : base(aContext)
        {
            // When the endif token is reached, we must work back up the tree
            // looking for the previous (i.e. most recent) conditional expression
            // node.
            SymNodeConditionalExpression condExpNode = SymParserWorkerConditionalExpression.FindMostRecentConditionalExpression(aContext.Document.CurrentNode);

            if (condExpNode == null)
            {
                throw new Exception("Unable to locate most recent condition expression during ENDIF handling");
            }

            // There must always be a positive condition node and some kind of condition
            if (condExpNode.ChildTypeExists(typeof(SymNodeCondition)) == false)
            {
                throw new Exception("No child condition node found during ENDIF handling");
            }

            // We change the current node to be the parent of the conditional expression.
            // Any new tokens will appear as siblings
            aContext.Document.CurrentNode = condExpNode.Parent;

            // Make sure we tell the parser that it can pop off this conditional expression node.
            SymPreProcessorParser        parser           = (SymPreProcessorParser)aContext.Parser;
            SymNodeConditionalExpression poppedExpression = parser.ConditionalExpressionPop();

            System.Diagnostics.Debug.Assert(poppedExpression == condExpNode);

            // Job done - dequeue
            RemoveSelf();
        }
コード例 #3
0
        public SymNodeConditionalExpression ConditionalExpressionPop()
        {
            System.Diagnostics.Debug.Assert(iCondExpResultStack.Count > 0);
            //
            SymNodeConditionalExpression top = ConditionalExpressionPeek();

            iCondExpResultStack.Pop();
            return(top);
        }
コード例 #4
0
        public SymParserWorkerConditionalExpression(SymParserWorkerContext aContext)
            : base(aContext)
        {
            SymNode node = new SymNodeConditionalExpression(aContext.CurrentToken);

            aContext.Document.CurrentNode.Add(node);

            // Make this child node the new parent
            aContext.Document.CurrentNode = node;
        }
コード例 #5
0
        public SymNodeConditionalExpression ConditionalExpressionPeek()
        {
            SymNodeConditionalExpression top = null;

            //
            if (iCondExpResultStack.Count > 0)
            {
                top = (SymNodeConditionalExpression)iCondExpResultStack.Peek();
            }
            //
            return(top);
        }
コード例 #6
0
        public void ConditionalExpressionPush(SymNodeConditionalExpression aConditionalExpression)
        {
            bool inheritedValue = true;
            //
            SymNodeConditionalExpression top = ConditionalExpressionPeek();

            if (top != null)
            {
                inheritedValue = top.InheritedValue;
            }
            //
            aConditionalExpression.InheritedValue = inheritedValue;
            iCondExpResultStack.Push(aConditionalExpression);
        }
コード例 #7
0
        protected override void HandleTerminatingConditionMatch(SymToken aToken)
        {
            // Give the condition node ownership of the raw parsed tokens
            iConditionNode.AssignArgumentTokens(iTokenBalancer.DocumentTree);

            // We only need to evaluate the conditional arguments if we have not yet
            // found a positive branch.
            SymNodeConditionalExpression condExpNode = (SymNodeConditionalExpression)iConditionNode.Parent;

            if (condExpNode.HasPositiveBranch == false)
            {
                iConditionNode.Evaluate(WorkerContext);
            }

            // We remain as the current node, even after we die. This allows
            // the body of the condition to be added as our child.
        }
コード例 #8
0
        public static SymNodeConditionalExpression FindMostRecentConditionalExpression(SymNode aCurrentNode)
        {
            SymNodeConditionalExpression ret = null;
            //
            SymNodeEnumeratorUpTreeSiblingsFirst iterator = new SymNodeEnumeratorUpTreeSiblingsFirst(aCurrentNode);

            //
            foreach (SymNode node in iterator)
            {
                if (node is SymNodeConditionalExpression)
                {
                    ret = (SymNodeConditionalExpression)node;
                    break;
                }
            }
            //
            return(ret);
        }