public TreeDoc ParseEntry(ref int i)
        {
            SkipWhiteSpace(ref i);
            if (GetChar(i) == '(')
            {
                i++;
                TreeDoc result = TreeDoc.CreateListRange(ParseList(ref i));
                if (GetChar(i) != ')')
                {
                    throw new InvalidDataException("Unexpected char " + GetChar(i) + " at " + i + " expected )");
                }
                i++;
                return(result);
            }
            else
            {
                string text = ParseString(ref i);
                SkipWhiteSpace(ref i);
                switch (GetChar(i))
                {
                case null:
                case ',':
                case ')':
                    return(TreeDoc.CreateLeaf(text));

                case ':':
                    i++;
                    string value = ParseString(ref i);
                    return(TreeDoc.CreateLeaf(text, value));

                case '(':
                    i++;
                    TreeDoc entry = TreeDoc.CreateListRange(text, ParseList(ref i));
                    SkipWhiteSpace(ref i);
                    if (GetChar(i) != ')')
                    {
                        throw new InvalidDataException("Unexpected char " + GetChar(i) + " at " + i + " expected )");
                    }
                    i++;
                    return(entry);

                default:
                    throw new InvalidDataException("Unexpected char " + GetChar(i) + " at " + i + "expected ,):(");
                }
            }
        }
Esempio n. 2
0
        public static TreeDoc Parse(string s)
        {
            IEnumerable <TreeDoc> docs = InternalTreeDocParser.ParseDocument(s);

            return(TreeDoc.CreateListRange(docs));
        }