コード例 #1
0
 /// <summary>
 /// Initializes the node after being parsed by the parser.
 /// </summary>
 /// <param name="elements">Collection with literal nodes that compose the elements of the literal array.</param>
 /// <param name="rightParenthesis">Closing right parenthesis of the literal array.</param>
 protected internal void SetContents(IEnumerable <SmallIntegerLiteralNode> elements, SpecialCharacterToken rightBracket)
 {
     if (elements == null)
     {
         throw new ArgumentNullException("elements");
     }
     if ((rightBracket != null) && !VseCompatibleParser.IsClosingByteArrayBracket(rightBracket)) // NB: We allow null value.
     {
         throw new ArgumentException("rightBracket");
     }
     this.RightBracket = rightBracket;
     foreach (SmallIntegerLiteralNode elem in elements)
     {
         this.Elements.Add(elem);
     }
 }
コード例 #2
0
        protected ByteArrayLiteralNode ParseByteArrayLiteral(ILiteralNodeParent parent, SpecialCharacterToken arrayToken, SpecialCharacterToken leftBracket)
        {
            // PARSE: <array literal> ::= '#[' <number literal>* ']'

            List <SmallIntegerLiteralNode> elements = new List <SmallIntegerLiteralNode>();
            ByteArrayLiteralNode           result   = new ByteArrayLiteralNode(parent, arrayToken, leftBracket);

            // Process tokens inside the array ...
            while (true)
            {
                // ... get next token in the array ...
                Token token = this.GetNextTokenxx(Preference.NegativeSign);

                // Is this closing parenthesis?
                if (VseCompatibleParser.IsClosingByteArrayBracket(token))
                {
                    // Closing parenthesis ... done with the array, return litral array node.
                    result.SetContents(elements, (SpecialCharacterToken)token);
                    this.ResidueToken = null;
                    return(result);
                }

                if (token is EofToken)
                {
                    // Unfinished source code ... return
                    result.SetContents(elements, null);
                    this.ReportParserError(parent, "Missing literal byte array closing bracket.", token);
                    this.ResidueToken = token;
                    return(result);
                }

                // PARSE: <numeric liteal>
                if (token is SmallIntegerToken)
                {
                    elements.Add(new SmallIntegerLiteralNode(result, (SmallIntegerToken)token, null));
                }
                else if (token is NegativeSignToken)
                {
                    NegativeSignToken negativeSign = (NegativeSignToken)token;
                    token = this.GetNextTokenxx(Preference.NegativeSign);
                    if (token is SmallIntegerToken)
                    {
                        elements.Add(new SmallIntegerLiteralNode(result, (SmallIntegerToken)token, negativeSign));
                    }
                    else
                    {
                        this.ReportParserError(parent, "Unrecognized literal.", token);
                        this.ResidueToken = token;
                        result.SetContents(elements, null);
                        return(result);
                    }
                }
                else
                {
                    this.ReportParserError(parent, "Unrecognized literal.", token);
                    this.ResidueToken = token;
                    result.SetContents(elements, null);
                    return(result);
                }
            }
        }