public static IList<object> Parse(Reader r, char open, char close)
        {
            if (r.Peek == open)
            {
                var result = new List<object>();

                r.Take();

                while (!r.End)
                {
                    var literal = LiteralParser.Parse(r);

                    if (literal != null)
                    {
                        result.Add(literal);
                    }
                    else
                    {
                        throw new ExpressionParseException(r.Position, "Expected integer.");
                    }

                    r.SkipWhitespace();

                    if (r.End)
                    {
                        throw new ExpressionParseException(r.Position, "Expected ','.");
                    }
                    else if (r.TakeIf(close))
                    {
                        return result;
                    }
                    else
                    {
                        if (r.Take() != ',')
                        {
                            throw new ExpressionParseException(r.Position, "Expected ','.");
                        }

                        r.SkipWhitespace();
                    }
                }

                if (!r.End)
                {
                    r.Take();
                    return result;
                }
                else
                {
                    throw new ExpressionParseException(r.Position, "Expected ']'.");
                }
            }

            return null;
        }
        public static IList<string> Parse(Reader r, char open, char close)
        {
            if (r.Peek == open)
            {
                var result = new List<string>();

                r.Take();

                while (!r.End)
                {
                    var builder = new StringBuilder();
                    while (!r.End && r.Peek != ',' && r.Peek != close && !char.IsWhiteSpace(r.Peek))
                    {
                        builder.Append(r.Take());
                    }
                    if (builder.Length == 0)
                    {
                        throw new ExpressionParseException(r.Position, "Expected indexer argument.");
                    }
                    result.Add(builder.ToString());

                    r.SkipWhitespace();

                    if (r.End)
                    {
                        throw new ExpressionParseException(r.Position, "Expected ','.");
                    }
                    else if (r.TakeIf(close))
                    {
                        return result;
                    }
                    else
                    {
                        if (r.Take() != ',')
                        {
                            throw new ExpressionParseException(r.Position, "Expected ','.");
                        }

                        r.SkipWhitespace();
                    }
                }

                if (!r.End)
                {
                    r.Take();
                    return result;
                }
                else
                {
                    throw new ExpressionParseException(r.Position, "Expected ']'.");
                }
            }

            return null;
        }
Exemple #3
0
 private static bool ParseMemberAccessor(Reader r)
 {
     return !r.End && r.TakeIf('.');
 }
Exemple #4
0
 private static bool ParseNot(Reader r)
 {
     return !r.End && r.TakeIf('!');
 }