示例#1
0
        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, "Expected integer.");
                    }

                    r.SkipWhitespace();

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

                        r.SkipWhitespace();
                    }
                }

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

            return null;
        }
示例#2
0
        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, "Expected integer.");
                    }

                    r.SkipWhitespace();

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

                        r.SkipWhitespace();
                    }
                }

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

            return(null);
        }
示例#3
0
        public static string Parse(Reader r)
        {
            if (IsValidIdentifierStart(r.Peek))
            {
                var result = new StringBuilder();

                while (!r.End && IsValidIdentifierChar(r.Peek))
                {
                    result.Append(r.Take());
                }

                return(result.ToString());
            }
            else
            {
                return(null);
            }
        }
示例#4
0
        public static string Parse(Reader r)
        {
            if (IsValidIdentifierStart(r.Peek))
            {
                var result = new StringBuilder();

                while (!r.End && IsValidIdentifierChar(r.Peek))
                {
                    result.Append(r.Take());
                }

                return result.ToString();
            }
            else
            {
                return null;
            }
        }
示例#5
0
        public static object Parse(Reader r)
        {
            if (char.IsDigit(r.Peek))
            {
                StringBuilder result = new StringBuilder();

                while (!r.End)
                {
                    if (char.IsDigit(r.Peek))
                    {
                        result.Append(r.Take());
                    }
                    else
                    {
                        break;
                    }
                }

                return(int.Parse(result.ToString(), CultureInfo.InvariantCulture));
            }

            return(null);
        }
示例#6
0
        public static object Parse(Reader r)
        {
            if (char.IsDigit(r.Peek))
            {
                StringBuilder result = new StringBuilder();

                while (!r.End)
                {
                    if (char.IsDigit(r.Peek))
                    {
                        result.Append(r.Take());
                    }
                    else
                    {
                        break;
                    }
                }

                return int.Parse(result.ToString(), CultureInfo.InvariantCulture);
            }

            return null;
        }