Beispiel #1
0
        private static ValueExpression ParseValue(ExpressionReader reader)
        {
            var c = reader.PeekChar();

            switch (c)
            {
            case '$':
                return(VariableParser.ParseVariable(reader));

            case '\'':
                return(ParseConstant(reader));

            default:
                throw reader.UnexpectedCharacterException();
            }
        }
Beispiel #2
0
        public static VariableString Parse(string text)
        {
            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }

            var result      = new List <object>();
            var basicString = new StringBuilder();

            using (var reader = new ExpressionReader(text))
            {
                while (reader.Peek() != -1)
                {
                    switch (reader.PeekChar())
                    {
                    case '$':
                        FlushString();
                        result.Add(VariableParser.ParseVariable(reader));
                        break;

                    default:
                        var c = reader.ReadChar();
                        basicString.Append(c);
                        break;
                    }
                }
            }

            FlushString();

            return(new VariableString(result));

            void FlushString()
            {
                if (basicString.Length <= 0)
                {
                    return;
                }

                result.Add(basicString.ToString());
                basicString.Clear();
            }
        }