/// <summary>
        ///     Evaluates the current input as a list
        /// </summary>
        /// <returns></returns>
        public ListExpression EvaluateList()
        {
            ListExpression retVal = null;

            SkipWhiteSpaces();
            int start = Index;
            if (LookAhead("["))
            {
                Match("[");
                List<Expression> list = new List<Expression>();

                if (LookAhead("]"))
                {
                    Match("]");
                    retVal = new ListExpression(Root, RootLog, list, start, Index);
                }
                else
                {
                    bool findListEntries = true;
                    while (findListEntries)
                    {
                        Expression expression = Expression(0);
                        if (expression != null)
                        {
                            list.Add(expression);

                            if (LookAhead(","))
                            {
                                Match(",");
                                continue;
                            }

                            if (LookAhead("]"))
                            {
                                Match("]");

                                retVal = new ListExpression(Root, RootLog, list, start, Index);
                                findListEntries = false;
                            }
                            else
                            {
                                RootLog.AddError("] expected");
                                findListEntries = false;
                            }
                        }
                        else
                        {
                            RootLog.AddError("Cannot parse expression");
                            findListEntries = false;
                        }
                    }
                }
            }

            if (retVal == null)
            {
                Index = start;
            }

            return retVal;
        }
Example #2
0
 /// <summary>
 ///     Visits a List expression
 /// </summary>
 /// <param name="listExpression"></param>
 protected virtual void VisitListExpression(ListExpression listExpression)
 {
     foreach (Expression expression in listExpression.ListElements)
     {
         if (expression != null)
         {
             VisitExpression(expression);
         }
     }
 }
        /// <summary>
        /// Evaluates the current input as a list
        /// </summary>
        /// <param name="root">the root element for which this list is built</param>
        /// <returns></returns>
        public ListExpression EvaluateList()
        {
            ListExpression retVal = null;

            int backup = Index;
            if (LookAhead("["))
            {
                Match("[");
                List<Expression> list = new List<Expression>();
                Types.Type elementType = null;

                if (LookAhead("]"))
                {
                    Match("]");
                    retVal = new ListExpression(Root, list);
                }
                else
                {
                    bool cont = true;
                    while (cont)
                    {
                        Expression expression = Expression(0);
                        if (expression != null)
                        {
                            list.Add(expression);

                            if (LookAhead(","))
                            {
                                Match(",");
                                continue;
                            }
                            else if (LookAhead("]"))
                            {
                                Match("]");

                                retVal = new ListExpression(Root, list);
                                break;
                            }
                            else
                            {
                                Root.AddError("] expected");
                                break;
                            }
                        }
                        else
                        {
                            Root.AddError("Cannot parse expression");
                            break;
                        }
                    }
                }
            }

            if (retVal == null)
            {
                Index = backup;
            }

            return retVal;
        }