示例#1
0
 public void Visit(ArrayLiteralNode arrayLiteral)
 {
     foreach (var element in arrayLiteral.Elements)
     {
         element.Parent = arrayLiteral;
         element.Accept(this);
     }
 }
示例#2
0
 public override object VisitArrayLiteral(ArrayLiteralNode node)
 {
     object[] result = new object[node.Elements.Count];
     for (int i = 0; i < result.Length; i++)
     {
         result[i] = node.Elements[i].Accept(this);
     }
     return(result);
 }
示例#3
0
        /// <summary>
        /// Visits the Array Literal node.
        /// </summary>
        /// <param name="node">The node to visit.</param>
        public virtual TResult VisitArrayLiteral(ArrayLiteralNode node)
        {
            foreach (LiteralNode item in node.Elements)
            {
                item.Accept(this);
            }

            return(default(TResult));            // The default naive implementation
        }
示例#4
0
        private object EvaluateNode(ArrayLiteralNode expression, Context context)
        {
            var result = new List <object>();

            foreach (var exp in expression.values)
            {
                result.Add(EvaluateNode(exp, context));
            }
            return(result);
        }
示例#5
0
        /// <summary>
        /// Visits the Array Literal node.
        /// </summary>
        /// <param name="node">The node to visit.</param>
        public override bool VisitArrayLiteral(ArrayLiteralNode node)
        {
            if (node.Parent == null)
            {
                return(false);
            }
            if ((node.ArrayToken == null) || (node.LeftParenthesis == null) || (node.RightParenthesis == null))
            {
                return(false);
            }

            foreach (LiteralNode item in node.Elements)
            {
                if (!item.Accept(this))
                {
                    return(false);
                }
            }

            return(true);
        }
示例#6
0
 /// <summary>
 /// Visits the Array Literal node.
 /// </summary>
 /// <param name="node">The node to visit.</param>
 public virtual TResult VisitArrayLiteral(ArrayLiteralNode node)
 {
     throw new NotImplementedException();
 }
 public override Expression VisitArrayLiteral(ArrayLiteralNode node)
 {
     return(this.Context.Compiler.LiteralEncodingStrategy.Array(this, node.Elements));
 }
示例#8
0
        protected virtual ArrayLiteralNode ParseArrayLiteral(ILiteralNodeParent parent, SpecialCharacterToken arrayToken)
        {
            // PARSE: <array literal> ::= '#(' <array element>* ')'
            // <array element> ::= <literal> | identifier

            Token token = this.GetNextTokenxx(Preference.Default);

            if (!Parser.IsOpeningParenthesis(token))
            {
                this.ReportParserError(parent, SemanticErrors.MissingLiteralArrayOpeningParenthesis, token);
                // The hash token is thrown away and lost :-/   ... only the current token is passed on.
                this.ResidueToken = token;
                return(null);
            }
            List <LiteralNode> elements = new List <LiteralNode>();
            ArrayLiteralNode   result   = new ArrayLiteralNode(parent, arrayToken, (SpecialCharacterToken)token);

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

                // Is this closing parenthesis?
                if (Parser.IsClosingParenthesis(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, SemanticErrors.MissingLiteralArrayClosingParenthesis, token);
                    this.ResidueToken = token;
                    return(result);
                }

                // PARSE: <array element> ::= <literal> | identifier
                if (token is ILiteralArrayIdentifierToken)
                {
                    // identifier ... special case only inside arrays.
                    elements.Add(new IdentifierLiteralNode(result, (ILiteralArrayIdentifierToken)token));
                }
                else
                {
                    // ... it's not identifier, so it must be an literal
                    LiteralNode element = this.ParseLiteral(result, token);
                    if (element == null)
                    {
                        // Report error in source code ... here, it must be a literal
                        this.ReportParserError(result, SemanticErrors.UnrecognizedLiteral, token);
                        result.SetContents(elements, null);
                        return(result);
                    }
                    else
                    {
                        // ... add the child element to the array elements.
                        elements.Add(element);
                    }
                }
            }
        }
示例#9
0
 internal override void Visit(ArrayLiteralNode node)
 {
 }