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); }
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); } }
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; }
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; }
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)); } }
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); }
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) { }
public StringExpression(TagToken token) : base(token) { _value = token.Value; _value = _value.Substring(1, _value.Length - 2); }
public NotExpression(TagToken token, TagExpression inner) : base(token, inner) { }
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); }
public DynamicStringExpression(TagToken token) : base(token) { }
public ParenExpression(TagToken token, TagExpression inner) : base(token, inner) { }
/// <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) { }
/// <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)) { }
/// <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); }
public AndOrExpression(TagToken token, TagExpression lhs, TagExpression rhs) : base(token, lhs, rhs) { ForceExpression(token, lhs, rhs); }