Beispiel #1
0
        internal TagToken NextToken()
        {
            if (_tokenEnumerator == null)
            {
                _tokenEnumerator = Lexer.WalkTokens(this).GetEnumerator();
            }

            if (_peekToken != null)
            {
                _currentToken = _peekToken;
                _peekToken    = null;
            }
            else
            {
                if (_tokenEnumerator.MoveNext())
                {
                    _currentToken = _tokenEnumerator.Current;
                }
                else
                {
                    _currentToken = null;
                }
            }

            return(_currentToken);
        }
Beispiel #2
0
        internal static TagExpression ArgValue(ParserState state)
        {
            TagToken tk = state.PeekToken();

            if (tk == null)
            {
                return(null);
            }

            switch (tk.TokenType)
            {
            case TagTokenType.String:
                state.NextToken();
                return(DynamicStringExpression.IsDynamic(tk) ? new DynamicStringExpression(tk) : new StringExpression(tk));

            case TagTokenType.Number:
                state.NextToken();
                return(new NumberExpression(tk));

            case TagTokenType.Property:
            case TagTokenType.Item:
            case TagTokenType.Tag:
                state.NextToken();
                return(new DynamicStringExpression(tk));

            default:
                return(null);
            }
        }
Beispiel #3
0
 public UnaryExpression(TagToken token, TagExpression inner)
     : base(token)
 {
     if (inner == null)
     {
         throw new ArgumentNullException("inner");
     }
     _inner = inner;
 }
        public FunctionExpression(TagToken token, IList <TagExpression> args)
            : base(token)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            _args = args;
        }
Beispiel #5
0
        internal TagTokenType PeekTokenType()
        {
            TagToken peekToken = PeekToken();

            if (peekToken != null)
            {
                return(peekToken.TokenType);
            }
            else
            {
                return(TagTokenType.AtEof);
            }
        }
        protected BinaryExpression(TagToken token, TagExpression lhs, TagExpression rhs)
            : base(token)
        {
            if (lhs == null)
            {
                throw new ArgumentNullException("lhs");
            }
            else if (rhs == null)
            {
                throw new ArgumentNullException("rhs");
            }

            _lhs = lhs;
            _rhs = rhs;
        }
Beispiel #7
0
        internal TagToken PeekToken()
        {
            if (_tokenEnumerator == null)
            {
                _tokenEnumerator = Lexer.WalkTokens(this).GetEnumerator();
            }

            if (_peekToken == null)
            {
                if (_tokenEnumerator.MoveNext())
                {
                    _peekToken = _tokenEnumerator.Current;
                }
            }

            return(_peekToken);
        }
        public NumberExpression(TagToken token)
            : base(token)
        {
            string tv = token.Value;

            if (tv.IndexOfAny(new char[] { '.', 'E', 'e' }) >= 0)
            {
                _value = new ExValue(double.Parse(tv));
            }
            else if (tv.StartsWith("0x", StringComparison.Ordinal))
            {
                _value = new ExValue(int.Parse(tv, System.Globalization.NumberStyles.AllowHexSpecifier));
            }
            else
            {
                _value = new ExValue(int.Parse(tv, System.Globalization.NumberStyles.AllowLeadingSign));
            }
        }
Beispiel #9
0
        internal void ForceExpression(TagToken token, TagExpression lhs, TagExpression rhs)
        {
            switch (token.TokenType)
            {
            case TagTokenType.And:
                _isAnd = true;
                break;

            case TagTokenType.Or:
                break;

            default:
                throw new ArgumentException("Only AND and OR are allowed");
            }
            _token = token;
            SetEditable(true);
            LeftHand  = lhs;
            RightHand = rhs;
            SetEditable(false);
        }
Beispiel #10
0
        internal static TagExpression CompleteExpression(ParserState state)
        {
            TagExpression expr = Expr(state);

            while (state.PeekTokenType() != TagTokenType.AtEof)
            {
                TagToken tk = state.NextToken();
                switch (tk.TokenType)
                {
                case TagTokenType.Or:
                    expr = new AndOrExpression(tk, expr, BooleanExpression(state));
                    break;

                case TagTokenType.And:
                    expr = new AndOrExpression(tk, expr, BooleanExpression(state));
                    break;

                default:
                    throw new ParserException(string.Format("Unexpected token {0}", tk), tk, state);
                }
            }

            return(expr);
        }
 public CompareExpression(TagToken token, TagExpression lhs, TagExpression rhs)
     : base(token, lhs, rhs)
 {
 }
Beispiel #12
0
 public StringExpression(TagToken token)
     : base(token)
 {
     _value = token.Value;
     _value = _value.Substring(1, _value.Length - 2);
 }
Beispiel #13
0
 public NotExpression(TagToken token, TagExpression inner)
     : base(token, inner)
 {
 }
Beispiel #14
0
        internal static TagExpression Part(ParserState state)
        {
            TagExpression expression = ArgValue(state);

            if (expression != null)
            {
                return(expression);
            }

            TagToken tk = state.NextToken();
            TagToken next;

            if (tk == null)
            {
                return(null);
            }

            switch (tk.TokenType)
            {
            case TagTokenType.Function:
                next = state.NextToken();
                if (next == null)
                {
                    throw new ParserException("Expected '('", tk, state);
                }
                else if (next.TokenType != TagTokenType.ParenOpen)
                {
                    throw new ParserException(string.Format("Expected '(' instead of '{0}')", next), state);
                }

                List <TagExpression> functionArgs = ArgList(state);

                next = state.NextToken();

                if (next == null)
                {
                    throw new ParserException(string.Format("Expected ')' before end of expression", state.PeekToken()), state);
                }
                else if (next.TokenType != TagTokenType.ParenClose)
                {
                    throw new ParserException(string.Format("Expected ')' instead of '{0}'", next), state);
                }

                expression = new FunctionExpression(tk, functionArgs.AsReadOnly());
                break;

            case TagTokenType.ParenOpen:
                expression = new ParenExpression(tk, Expr(state));

                next = state.NextToken();
                if (next == null)
                {
                    throw new ParserException(string.Format("Expected ')' before end of expression", state.PeekToken()), state);
                }
                else if (next.TokenType != TagTokenType.ParenClose)
                {
                    throw new ParserException(string.Format("Expected ')' instead of '{0}'", next), state);
                }

                break;

            case TagTokenType.Not:
                expression = new NotExpression(tk, Expr(state));
                break;

            default:
                throw new ParserException(string.Format("Unexpected token '{0}'", tk), state);
            }

            return(expression);
        }
Beispiel #15
0
 public DynamicStringExpression(TagToken token)
     : base(token)
 {
 }
Beispiel #16
0
 public ParenExpression(TagToken token, TagExpression inner)
     : base(token, inner)
 {
 }
Beispiel #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LexerException"/> class.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="token">The token.</param>
 /// <param name="state">The state.</param>
 internal PriorityException(string message, TagToken token, ParserState state)
     : base(message, token, state)
 {
 }
Beispiel #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LexerException"/> class.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="token">The token.</param>
 /// <param name="state">The state.</param>
 internal ParserException(string message, TagToken token, ParserState state)
     : base(string.Format("{0} while parsing '{1}'", message, token))
 {
 }
Beispiel #19
0
        /// <summary>
        /// Determines whether the specified token is a dynamic string
        /// </summary>
        /// <param name="tk">The tk.</param>
        /// <returns>
        ///     <c>true</c> if the specified tk is dynamic; otherwise, <c>false</c>.
        /// </returns>
        internal static bool IsDynamic(TagToken tk)
        {
            string value = tk.Value;

            return(value.StartsWith("\'") && value.EndsWith("\'") && TagExpander.ItemKeyOrPropertyRegex.Match(value).Success);
        }
Beispiel #20
0
 public AndOrExpression(TagToken token, TagExpression lhs, TagExpression rhs)
     : base(token, lhs, rhs)
 {
     ForceExpression(token, lhs, rhs);
 }