private ExpressionList ParseColumnList() { //match exp [as <string>](, exp [as <string>])* ExpressionList l = new ExpressionList(); while (true) { ParseExpression(); if (_exprs.Count < 1) { throw new Exception("The base expression is missing."); } NamedExpr e = new NamedExpr(null, _exprs.Pop()); if (_tokens.LookAhead().TokenType == TokenType.KW_AS) { _tokens.Read(); Token t = _tokens.LookAhead(); if (t.TokenType == TokenType.LT_STRING || t.TokenType == TokenType.ID) { t = _tokens.Read(); } else { throw new Exception("The alias must be a string literal."); } e.Name = t.Lexeme.ToString(); } l.Add(e); //consumes the , delimiter if (_tokens.LookAhead().TokenType != TokenType.PM_COMMA) { break; } else { _tokens.Read(); } } return l; }
private void ParseCastExpr() { if (_tokens.LookAhead().TokenType != TokenType.PM_LPAREN) { throw new Exception("function call syntax error, missing '('"); } _tokens.Read(); ParseExpression(); if (_exprs.Count < 1) { throw new Exception("missing the source argument"); } NamedExpr e = new NamedExpr(null, _exprs.Pop()); if (_tokens.LookAhead().TokenType == TokenType.KW_AS) { _tokens.Read(); Token t = _tokens.LookAhead(); if (t.TokenType == TokenType.LT_STRING || t.TokenType == TokenType.ID) { t = _tokens.Read(); } else { throw new Exception("The alias must be a string literal."); } e.Name = t.Lexeme.ToString(); } else { throw new Exception("CAST expression syntax error, missing target type"); } FuncExpr f = new CastFunction(); f.Arguments = new ExpressionList(); f.Arguments.Add(e); if (_tokens.LookAhead().TokenType != TokenType.PM_RPAREN) { throw new Exception("function call syntax error, missing ')'"); } _tokens.Read(); _exprs.Push(f); }