예제 #1
0
            private IOperation parseVar()
            {
                Operations.OperationVariableAccess va = new Operations.OperationVariableAccess();

                var  cc        = _reader.Peek();
                bool blockMode = (cc == '{');

                StringBuilder sb = new StringBuilder();

                if (!blockMode)
                {
                    while ((cc = _reader.Peek()) != -1)
                    {
                        var ch = (char)cc;
                        if (!char.IsLetterOrDigit(ch) && _parser._tokenSpecialCharacters.IndexOf(ch) == -1)
                        {
                            break;
                        }

                        sb.Append(ch);
                        _reader.Read();
                    }
                    va.AddName(sb.ToString());
                    return(new Operations.OperationExpression(new IOperation[] { va }));
                }
                _reader.Read();  // Read {
                var v = _parser.ParseMulti(_reader);

                _reader.SkipWhiteSpaceAndComments();
                _reader.ReadAndThrowIfNot('}'); // eat }
                return(v);
            }
예제 #2
0
        /// Parse multi-expression, like ${a|b|=2+3}
        public IOperation ParseMulti(ParsingReader reader)
        {
            Operations.OperationVariableAccess va = new Operations.OperationVariableAccess();
            StringBuilder sb    = new StringBuilder();
            bool          orMet = true;
            int           n;

            while ((n = reader.Peek()) != -1)
            {
                var q = (char)n;
                if (q == '}' || q == ')' || q == ']')
                {
                    break;
                }
                switch (q)
                {
                case '|':
                    reader.Read();
                    va.AddName(sb.ToString());
                    sb.Length = 0;
                    orMet     = true;
                    break;

                case '\'':
                case '\"':
                case '`':
                    orMet = false;
                    if (sb.Length != 0)
                    {
                        reader.ThrowParsingException("Quote must be a first character");
                    }
                    va.AddValue(reader.ReadQuote());
                    reader.SkipWhiteSpaceAndComments();
                    if (reader.Peek() != '}' && reader.Peek() != '|')
                    {
                        reader.ThrowParsingException("Unexpected character '" + (char)reader.Peek() + "'");
                    }
                    sb.Length = 0;
                    break;

                case '=':
                    orMet = false;
                    reader.Read();
                    var v = Parse(reader);
                    if (v != null)
                    {
                        va.AddExpression(v);
                    }
                    else
                    {
                        va.AddValue(null);
                    }
                    break;

                default:
                    orMet = false;
                    sb.Append(q);
                    reader.Read();
                    break;
                }
            }
            if (sb.Length > 0 || orMet)
            {
                va.AddName(sb.ToString());
            }
            return(va);
        }