Пример #1
0
 public virtual T applyToVerticalBarToken(VerticalBarToken operand)
 {
     return(applyToParseTreeNode(operand));
 }
Пример #2
0
        /// <summary>
        /// Initializes the node after being parsed by the parser.
        /// </summary>
        /// <param name="arguments">Collection of block arguments for this block.</param>
        /// <param name="argumentsBar">The vertical bar after the block arguments.</param>
        /// <param name="leftBar">Left vertical bar "|" token, if temporary variable definition is present.</param>
        /// <param name="temporaries">A collection of temporary variable nodes.</param>
        /// <param name="rightBar">Right vertical bar "|" token, if temporary variable definition is present.</param>
        /// <param name="statements">Executable statements defining the function.</param>
        /// <param name="rightBracket">Token for the right / closing square bracket of the block.</param>
        protected internal void SetContents(IEnumerable <BlockArgumentNode> arguments, VerticalBarToken argumentsBar,
                                            VerticalBarToken leftBar, IEnumerable <TemporaryVariableNode> temporaries, VerticalBarToken rightBar,
                                            StatementNode statements, SpecialCharacterToken rightBracket)
        {
            if (arguments == null)
            {
                throw new ArgumentNullException("arguments");
            }

            this.SetContents(leftBar, temporaries, rightBar, statements);

            this.Arguments.Clear();
            this.Arguments.AddRange(arguments);
            this.ArgumentsBar = argumentsBar; // OK with null if no arguments or illegal source
            this.RightBracket = rightBracket; // OK with null if illegal source
        }
Пример #3
0
        protected virtual BlockNode ParseBlock(IPrimaryParentNode parent, SpecialCharacterToken leftBracket)
        {
            // PARSE: <block constructor> ::= '[' <block body> ']'
            //      <block body> ::= [<block argument>* '|'] [<temporaries>] [<statements>]
            //      <block argument> ::= ':' identifier
            BlockNode result = new BlockNode(parent, leftBracket);

            // PARSE: [<block argument>* '|']
            // ISSUE: It this a bug in X3J20. Shouldn't it be: [<block argument>+ '|']
            // The current definition allows blocks like: [ | ] ... or ... [ | self doStuff ]  ... or ... [ | | temp | temp := self something ]
            // We assume X3J20 bug and expect: [<block argument>+ '|']
            VerticalBarToken         argumentsBar = null;
            List <BlockArgumentNode> arguments    = new List <BlockArgumentNode>();

            Token token = this.GetNextTokenxx(Preference.VerticalBar | Preference.NegativeSign);

            // Check if the block has arguments
            if (Parser.IsBlockArgumentPrefix(token))
            {
                // ... yes arguments ... parse them ...
                while (true)
                {
                    if (Parser.IsBlockArgumentPrefix(token))
                    {
                        // <block argument>
                        arguments.Add(this.ParseBlockArgument(result, (SpecialCharacterToken)token));
                    }
                    else if (token is VerticalBarToken)
                    {
                        // The '|' after the arguments.
                        argumentsBar = (VerticalBarToken)token;
                        token        = this.GetNextTokenxx(Preference.NegativeSign | Preference.VerticalBar);
                        break; // Done with block arguments
                    }
                    else
                    {
                        this.ReportParserError(result, SemanticErrors.MissingBlockClosingArgsBar, token);
                        break;
                    }
                    // Get the next token
                    token = this.GetNextTokenxx(Preference.VerticalBar | Preference.NegativeSign);
                }
            }

            // PARSE: [<temporaries>]
            ParseTemporariesResult ptr = this.ParseTemporaries(result, token);

            // PARSE: <statements>
            token = this.GetNextTokenxx(Preference.NegativeSign);
            StatementNode statements = this.ParseStatement(result, token);

            // Ensure the block is properly closed.
            SpecialCharacterToken rightBracket = null;

            token = this.GetNextTokenxx(Preference.Default);
            if (!Parser.IsBlockEndDelimiter(token))
            {
                this.ReportParserError(result, SemanticErrors.MissingBlockClosingBracket, token);
                this.ResidueToken = token;
            }
            else
            {
                rightBracket = (SpecialCharacterToken)token;
            }

            result.SetContents(arguments, argumentsBar, ptr.LeftBar, ptr.Temporaries, ptr.RightBar, statements, rightBracket);
            return(result);
        }
Пример #4
0
        /// <summary>
        /// Initializes the node after being parsed by the parser.
        /// </summary>
        /// <param name="leftBar">Left vertical bar "|" token, if temporary variable definition is present.</param>
        /// <param name="temporaries">A collection of temporary variable nodes.</param>
        /// <param name="rightBar">Right vertical bar "|" token, if temporary variable definition is present.</param>
        /// <param name="statements">Executable statements defining the function.</param>
        protected internal void SetContents(VerticalBarToken leftBar, IEnumerable <TemporaryVariableNode> temporaries, VerticalBarToken rightBar, StatementNode statements)
        {
            this.Temporaries.Clear();
            if (temporaries != null)
            {
                this.Temporaries.AddRange(temporaries);
            }
            this.LeftBar    = leftBar;    // Null if no temporaries
            this.RightBar   = rightBar;   // Null if no temporaries or illegal source code
            this.Statements = statements; // OK with null

            if ((this.Temporaries.Count != 0) && (this.LeftBar == null))
            {
                throw new ArgumentNullException("leftBar"); // Little late, but OK to throw the exception.
            }
        }