public RqlConstantExpression(RqlToken token) : base(RqlExpressionType.Constant) { if (!token.IsConstant) throw new RqlParseException(token); this.Token = token; }
public RqlIdentifierExpression(RqlToken token) : base(RqlExpressionType.Identifier) { if (!token.IsIdentifier) { throw new RqlParseException(token); } this.Token = token; }
public RqlConstantExpression(RqlToken token) : base(RqlExpressionType.Constant) { if (!token.IsConstant) { throw new RqlParseException(token); } this.Token = token; }
public RqlTupleExpression(RqlToken token, IList <RqlConstantExpression> constants) : base(RqlExpressionType.Tuple) { if (!token.IsLeftParen) { throw new RqlParseException(token); } this.Token = token; this.Constants = new ReadOnlyCollection <RqlConstantExpression>(constants); }
public RqlFunctionCallExpression(RqlToken token, IList <RqlExpression> arguments) : base(RqlExpressionType.FunctionCall) { if (!token.IsIdentifier) { throw new RqlParseException(token); } this.Token = token; this.Arguments = new ReadOnlyCollection <RqlExpression>(arguments); }
public RqlExpression Parse(string input) { tokenizer = new RqlTokenizer(input); RqlToken token = tokenizer.Next(); if (!token.IsIdentifier) { throw new RqlParseException(token); } return(ParseExpression(token)); }
public RqlToken PeekNext() { if (stopToken != null) { return(stopToken); } if (nextToken == null) { nextToken = Next(); } return(nextToken); }
private RqlExpression ParseExpression(RqlToken functionToken) { RqlToken token = tokenizer.Next(); if (!token.IsLeftParen) throw new RqlParseException(token); var arguments = new List<RqlExpression>(); while (true) { token = tokenizer.Next(); RqlExpression argument = null; if (token.IsIdentifier) { if (tokenizer.PeekNext().IsLeftParen) argument = ParseExpression(token); else argument = RqlExpression.Identifier(token); } else if (token.IsConstant) { argument = RqlExpression.Constant(token); } else if (token.IsLeftParen) { argument = ParseTuple(token); } else throw new RqlParseException(token); arguments.Add(argument); token = tokenizer.Next(); if (token.IsComma) continue; else if (token.IsRightParen) break; else throw new RqlParseException(token); } return RqlExpression.FunctionCall(functionToken, arguments); }
private RqlTupleExpression ParseTuple(RqlToken leftParenToken) { var constants = new List <RqlConstantExpression>(); Type itemType = null; while (true) { RqlToken token = tokenizer.Next(); if (token.IsConstant) { if (itemType == null) { itemType = token.Data.GetType(); } else if (token.Data.GetType() != itemType) { throw new RqlParseException(token, "Tuple items must all be of the same type"); } constants.Add(RqlExpression.Constant(token)); } else { throw new RqlParseException(token); } token = tokenizer.Next(); if (token.IsComma) { continue; } else if (token.IsRightParen) { break; } else { throw new RqlParseException(token); } } return(RqlExpression.Tuple(leftParenToken, constants)); }
public RqlToken PeekNext() { if (stopToken != null) return stopToken; if (nextToken == null) { nextToken = Next(); } return nextToken; }
private RqlExpression ParseExpression(RqlToken functionToken) { RqlToken token = tokenizer.Next(); if (!token.IsLeftParen) { throw new RqlParseException(token); } var arguments = new List <RqlExpression>(); while (true) { token = tokenizer.Next(); RqlExpression argument = null; if (token.IsIdentifier) { if (tokenizer.PeekNext().IsLeftParen) { argument = ParseExpression(token); } else { argument = RqlExpression.Identifier(token); } } else if (token.IsConstant) { argument = RqlExpression.Constant(token); } else if (token.IsLeftParen) { argument = ParseTuple(token); } else { throw new RqlParseException(token); } arguments.Add(argument); token = tokenizer.Next(); if (token.IsComma) { continue; } else if (token.IsRightParen) { break; } else { throw new RqlParseException(token); } } return(RqlExpression.FunctionCall(functionToken, arguments)); }
public RqlToken Next() { if (stopToken != null) return stopToken; if (nextToken != null) { RqlToken token = nextToken; nextToken = null; return token; } char c = ReadChar(); while (c != '\0' && Char.IsWhiteSpace(c)) c = ReadChar(); int tokenOffset = this.offset - 1; if (c == '\0') return (stopToken = RqlToken.End(offset)); if (Char.IsLetter(c)) { sb.Clear(); sb.Append(c); c = ReadChar(); bool lastCharWasDot = false; while (c != 0 && (Char.IsLetterOrDigit(c)) || c == '.') { sb.Append(c); if (c == '.') { if (lastCharWasDot) goto Error; lastCharWasDot = true; } else lastCharWasDot = false; c = ReadChar(); } UnreadChar(); string s = sb.ToString(); if (s == "true") return RqlToken.Constant(tokenOffset, (object)true); else if (s == "false") return RqlToken.Constant(tokenOffset, (object)false); else if (s == "null") return RqlToken.Constant(tokenOffset, null); else return RqlToken.Identifier(tokenOffset, s); } else if (Char.IsDigit(c) || c == '-') { sb.Clear(); sb.Append(c); c = ReadChar(); if (sb[0] == '-' && !Char.IsDigit(c)) goto Error; while (Char.IsDigit(c)) { sb.Append(c); c = ReadChar(); } if (c == '.') { sb.Append(c); c = ReadChar(); while (Char.IsDigit(c) ) { sb.Append(c); c = ReadChar(); } UnreadChar(); Double n; if (Double.TryParse(sb.ToString(), out n)) return RqlToken.Constant(tokenOffset, n); } else { UnreadChar(); Int32 n; if (Int32.TryParse(sb.ToString(), out n)) return RqlToken.Constant(tokenOffset, n); } } else if (c == '$') { sb.Clear(); sb.Append(c); c = ReadChar(); while (Char.IsLetterOrDigit(c)) { sb.Append(c); c = ReadChar(); } UnreadChar(); if (sb.Length > 0) return RqlToken.Constant(tokenOffset, new RqlId(sb.ToString())); } else if (c == '@') { sb.Clear(); sb.Append(c); c = ReadChar(); while (c != 'Z') { sb.Append(c); c = ReadChar(); } sb.Append(c); RqlDateTime dateTime; if (RqlDateTime.TryParse(sb.ToString(), out dateTime)) return RqlToken.Constant(tokenOffset, dateTime); } else if (c == '~') { sb.Clear(); sb.Append(c); c = ReadChar(); while (c != 'S') { sb.Append(c); c = ReadChar(); } sb.Append(c); RqlTimeSpan timeSpan; if (RqlTimeSpan.TryParse(sb.ToString(), out timeSpan)) return RqlToken.Constant(tokenOffset, timeSpan); } else if (c == '\'') { sb.Clear(); c = ReadChar(); while (c != '\0' && c != '\'') { sb.Append(c); c = ReadChar(); } if (c == '\'') return RqlToken.Constant(tokenOffset, sb.ToString()); } else { switch ((char)c) { case ',': return RqlToken.Comma(tokenOffset); case '(': return RqlToken.LeftParen(tokenOffset); case ')': return RqlToken.RightParen(tokenOffset); } } Error: return (stopToken = RqlToken.Error(tokenOffset)); }
public RqlTupleExpression(RqlToken token) : this(token, new RqlConstantExpression[0]) { }
public RqlFunctionCallExpression(RqlToken token, IList<RqlExpression> arguments) : base(RqlExpressionType.FunctionCall) { if (!token.IsIdentifier) throw new RqlParseException(token); this.Token = token; this.Arguments = new ReadOnlyCollection<RqlExpression>(arguments); }
private RqlTupleExpression ParseTuple(RqlToken leftParenToken) { var constants = new List<RqlConstantExpression>(); Type itemType = null; while (true) { RqlToken token = tokenizer.Next(); if (token.IsConstant) { if (itemType == null) itemType = token.Data.GetType(); else if (token.Data.GetType() != itemType) throw new RqlParseException(token, "Tuple items must all be of the same type"); constants.Add(RqlExpression.Constant(token)); } else throw new RqlParseException(token); token = tokenizer.Next(); if (token.IsComma) continue; else if (token.IsRightParen) break; else throw new RqlParseException(token); } return RqlExpression.Tuple(leftParenToken, constants); }
public static RqlConstantExpression Constant(RqlToken token) { return new RqlConstantExpression(token); }
public static RqlConstantExpression Constant(RqlToken token) { return(new RqlConstantExpression(token)); }
public static RqlTupleExpression Tuple(RqlToken token, IList <RqlConstantExpression> constants) { return(new RqlTupleExpression(token, constants)); }
public RqlParseException(RqlToken token) { this.ErrorOffset = token.Offset; }
public static RqlTupleExpression Tuple(RqlToken token, IList<RqlConstantExpression> constants) { return new RqlTupleExpression(token, constants); }
public static RqlIdentifierExpression Identifier(RqlToken token) { return new RqlIdentifierExpression(token); }
public static RqlFunctionCallExpression FunctionCall(RqlToken token, IList<RqlExpression> arguments) { return new RqlFunctionCallExpression(token, arguments); }
public RqlToken Next() { if (stopToken != null) { return(stopToken); } if (nextToken != null) { RqlToken token = nextToken; nextToken = null; return(token); } char c = ReadChar(); while (c != '\0' && Char.IsWhiteSpace(c)) { c = ReadChar(); } int tokenOffset = this.offset - 1; if (c == '\0') { return(stopToken = RqlToken.End(offset)); } if (Char.IsLetter(c)) { sb.Clear(); sb.Append(c); c = ReadChar(); bool lastCharWasDot = false; while (c != 0 && (Char.IsLetterOrDigit(c)) || c == '.') { sb.Append(c); if (c == '.') { if (lastCharWasDot) { goto Error; } lastCharWasDot = true; } else { lastCharWasDot = false; } c = ReadChar(); } UnreadChar(); string s = sb.ToString(); if (s == "true") { return(RqlToken.Constant(tokenOffset, (object)true)); } else if (s == "false") { return(RqlToken.Constant(tokenOffset, (object)false)); } else if (s == "null") { return(RqlToken.Constant(tokenOffset, null)); } else { return(RqlToken.Identifier(tokenOffset, s)); } } else if (Char.IsDigit(c) || c == '-') { sb.Clear(); sb.Append(c); c = ReadChar(); if (sb[0] == '-' && !Char.IsDigit(c)) { goto Error; } while (Char.IsDigit(c)) { sb.Append(c); c = ReadChar(); } if (c == '.') { sb.Append(c); c = ReadChar(); while (Char.IsDigit(c)) { sb.Append(c); c = ReadChar(); } UnreadChar(); Double n; if (Double.TryParse(sb.ToString(), out n)) { return(RqlToken.Constant(tokenOffset, n)); } } else { UnreadChar(); Int32 n; if (Int32.TryParse(sb.ToString(), out n)) { return(RqlToken.Constant(tokenOffset, n)); } } } else if (c == '$') { sb.Clear(); sb.Append(c); c = ReadChar(); while (Char.IsLetterOrDigit(c)) { sb.Append(c); c = ReadChar(); } UnreadChar(); if (sb.Length > 0) { return(RqlToken.Constant(tokenOffset, new RqlId(sb.ToString()))); } } else if (c == '@') { sb.Clear(); sb.Append(c); c = ReadChar(); while (c != 'Z') { sb.Append(c); c = ReadChar(); } sb.Append(c); RqlDateTime dateTime; if (RqlDateTime.TryParse(sb.ToString(), out dateTime)) { return(RqlToken.Constant(tokenOffset, dateTime)); } } else if (c == '~') { sb.Clear(); sb.Append(c); c = ReadChar(); while (c != 'S') { sb.Append(c); c = ReadChar(); } sb.Append(c); RqlTimeSpan timeSpan; if (RqlTimeSpan.TryParse(sb.ToString(), out timeSpan)) { return(RqlToken.Constant(tokenOffset, timeSpan)); } } else if (c == '\'') { sb.Clear(); c = ReadChar(); while (c != '\0' && c != '\'') { sb.Append(c); c = ReadChar(); } if (c == '\'') { return(RqlToken.Constant(tokenOffset, sb.ToString())); } } else { switch ((char)c) { case ',': return(RqlToken.Comma(tokenOffset)); case '(': return(RqlToken.LeftParen(tokenOffset)); case ')': return(RqlToken.RightParen(tokenOffset)); } } Error: return(stopToken = RqlToken.Error(tokenOffset)); }
public static RqlFunctionCallExpression FunctionCall(RqlToken token, IList <RqlExpression> arguments) { return(new RqlFunctionCallExpression(token, arguments)); }
public RqlParseException(RqlToken token, string message) : base(message) { this.ErrorOffset = token.Offset; }
public RqlIdentifierExpression(RqlToken token) : base(RqlExpressionType.Identifier) { if (!token.IsIdentifier) throw new RqlParseException(token); this.Token = token; }
public RqlTupleExpression(RqlToken token, IList<RqlConstantExpression> constants) : base(RqlExpressionType.Tuple) { if (!token.IsLeftParen) throw new RqlParseException(token); this.Token = token; this.Constants = new ReadOnlyCollection<RqlConstantExpression>(constants); }
public static RqlIdentifierExpression Identifier(RqlToken token) { return(new RqlIdentifierExpression(token)); }