Пример #1
0
        public Item ParseValue(string instring)
        {
            // number
            if (char.IsDigit(instring[0]))
            {
                return(new ValueItem(ItemType.Number, double.Parse(instring)));
            }

            // string
            if (instring[0] == '"')
            {
                return(new ValueItem(
                           ItemType.String,
                           instring.Substring(1, instring.Length - 2)));
            }

            // Type
            if (instring[0] == ':')
            {
                var type = (ItemType)Enum.Parse(typeof(ItemType), instring.Substring(1), true);
                return(new TypeItem(type));
            }

            // symbol
            var current = instring;
            var quote   = false;

            if (instring[0] == '\'')
            {
                current = current.Substring(1);
                quote   = true;
            }

            if (char.IsDigit(current.First()))
            {
                throw new FormatException();
            }

            var symbol = new SymbolItem(current);

            if (quote)
            {
                symbol.Quote();
            }

            return(symbol);
        }