Esempio n. 1
0
        /// <summary>
        /// tuple ==> "{}" | "{" result ( "," result )* "}"
        /// </summary>
        /// <returns>if one tuple found a TupleValue, otherwise a ValueListValue of TupleValues</returns>
        private ResultValue ParseResultTuple(Span input, out Span rest)
        {
            var list = ParseResultList('{', '}', input, out rest);

            if (list == null)
            {
                return(null);
            }
            var        tlist = new List <ResultValue>();
            TupleValue v;

            while (rest.StartsWith(_resultString, ",{"))
            {
                // a tuple list
                v = new TupleValue(list);
                tlist.Add(v);
                list = ParseResultList('{', '}', rest.Advance(1), out rest);
            }
            v = new TupleValue(list);
            if (tlist.Count != 0)
            {
                tlist.Add(v);
                return(new ValueListValue(tlist));
            }
            return(v);
        }
Esempio n. 2
0
        private List <NamedResultValue> ParseResultList(EdgeCondition begin, EdgeCondition end, Span input, out Span rest)
        {
            rest = Span.Empty;
            List <NamedResultValue> list = new List <NamedResultValue>();
            int i = input.Start;

            if (!begin(input, ref i))
            {
                ParseError("Unexpected opening character", input);
                return(null);
            }
            if (end(input, ref i))         // tuple is empty
            {
                rest = input.AdvanceTo(i); // eat through the closing brace
                return(list);
            }
            input = input.AdvanceTo(i);
            var item = ParseResult(input, out rest);

            if (item == null)
            {
                ParseError("Result expected", input);
                return(null);
            }
            list.Add(item);
            input = rest;
            while (!input.IsEmpty && _resultString[input.Start] == ',')
            {
                item = ParseResult(input.Advance(1), out rest);
                if (item == null)
                {
                    ParseError("Result expected", input);
                    return(null);
                }
                list.Add(item);
                input = rest;
            }

            i = input.Start;
            if (!end(input, ref i))    // tuple is not closed
            {
                ParseError("Unexpected list termination", input);
                rest = Span.Empty;
                return(null);
            }
            rest = input.AdvanceTo(i);
            return(list);
        }
Esempio n. 3
0
        /// <summary>
        /// result ==> variable "=" value
        /// </summary>
        /// <param name="resultStr">trimmed input string</param>
        /// <param name="rest">trimmed remainder after result</param>
        private NamedResultValue ParseResult(Span resultStr, out Span rest)
        {
            rest = Span.Empty;
            int equals = resultStr.IndexOf(_resultString, '=');

            if (equals < 1)
            {
                ParseError("variable not found", resultStr);
                return(null);
            }
            string      name  = resultStr.Prefix(equals).Extract(_resultString);
            ResultValue value = ParseResultValue(resultStr.Advance(equals + 1), out rest);

            if (value == null)
            {
                return(null);
            }
            return(new NamedResultValue(name, value));
        }
Esempio n. 4
0
        /// <summary>
        /// list ==>  "[" value ( "," value )* "]"
        /// </summary>
        private ValueListValue ParseValueList(Span input, out Span rest)
        {
            rest = Span.Empty;
            List <ResultValue> list = new List <ResultValue>();

            if (_resultString[input.Start] != '[')
            {
                ParseError("List expected", input);
                return(null);
            }
            input = input.Advance(1);
            var item = ParseValue(input, out rest);

            if (item == null)
            {
                ParseError("Value expected", input);
                return(null);
            }
            list.Add(item);
            input = rest;
            while (!input.IsEmpty && _resultString[input.Start] == ',')
            {
                item = ParseValue(input.Advance(1), out rest);
                if (item == null)
                {
                    ParseError("Value expected", input);
                    return(null);
                }
                list.Add(item);
                input = rest;
            }

            if (input.IsEmpty || _resultString[input.Start] != ']')    // list is not closed
            {
                ParseError("List not terminated", input);
                rest = Span.Empty;
                return(null);
            }
            rest = input.Advance(1);
            return(new ValueListValue(list));
        }
Esempio n. 5
0
 /// <summary>
 /// list ==> "[]" | "[" value ( "," value )* "]" | "[" result ( "," result )* "]"
 /// </summary>
 private ResultValue ParseList(Span input, out Span rest)
 {
     rest = Span.Empty;
     if (_resultString[input.Start] != '[')
     {
         ParseError("List expected", input);
         return(null);
     }
     if (_resultString[input.Start + 1] == ']') // list is empty
     {
         rest = input.Advance(2);               // eat through the closing brace
         return(new ValueListValue(new List <ResultValue>()));
     }
     if (IsValueChar(_resultString[input.Start + 1]))
     {
         return(ParseValueList(input, out rest));
     }
     else
     {
         return(ParseResultList(input, out rest));
     }
 }