use of com.alibaba.cobar.parser.ast.expression.Expression in project cobar by alibaba.
the class MySQLExprParser method unaryOpExpression.
/**
* <code>('+'|'-'|'~'|'!'|'BINARY')* higherExpr</code><br/>
* '!' has higher precedence
*/
private Expression unaryOpExpression(String consumed, String consumedUp) throws SQLSyntaxErrorException {
if (consumed == null) {
Expression expr;
switch(lexer.token()) {
case OP_EXCLAMATION:
lexer.nextToken();
expr = unaryOpExpression(null, null);
return new NegativeValueExpression(expr).setCacheEvalRst(cacheEvalRst);
case OP_PLUS:
lexer.nextToken();
return unaryOpExpression(null, null);
case OP_MINUS:
lexer.nextToken();
expr = unaryOpExpression(null, null);
return new MinusExpression(expr).setCacheEvalRst(cacheEvalRst);
case OP_TILDE:
lexer.nextToken();
expr = unaryOpExpression(null, null);
return new BitInvertExpression(expr).setCacheEvalRst(cacheEvalRst);
case KW_BINARY:
lexer.nextToken();
expr = unaryOpExpression(null, null);
return new CastBinaryExpression(expr).setCacheEvalRst(cacheEvalRst);
}
}
return collateExpression(consumed, consumedUp);
}
use of com.alibaba.cobar.parser.ast.expression.Expression in project cobar by alibaba.
the class MySQLExprParser method logicalAndExpression.
/**
* <code>higherPRJExpr ( ('AND'|'&&') higherPRJExpr )*</code>
*
* @throws SQLSyntaxErrorException
*/
private Expression logicalAndExpression() throws SQLSyntaxErrorException {
LogicalAndExpression and = null;
for (Expression expr = logicalNotExpression(); ; ) {
switch(lexer.token()) {
case OP_LOGICAL_AND:
case KW_AND:
lexer.nextToken();
if (and == null) {
and = new LogicalAndExpression();
and.setCacheEvalRst(cacheEvalRst);
and.appendOperand(expr);
expr = and;
}
Expression newExpr = logicalNotExpression();
and.appendOperand(newExpr);
break;
default:
return expr;
}
}
}
use of com.alibaba.cobar.parser.ast.expression.Expression in project cobar by alibaba.
the class MySQLExprParser method type4specialFunc.
/**
* @return never null
*/
private Pair<String, Pair<Expression, Expression>> type4specialFunc() throws SQLSyntaxErrorException {
Expression exp1 = null;
Expression exp2 = null;
// DATE
// DATETIME
// SIGNED [INTEGER]
// TIME
String typeName;
switch(lexer.token()) {
case KW_BINARY:
case KW_CHAR:
typeName = MySQLToken.keyWordToString(lexer.token());
if (lexer.nextToken() == PUNC_LEFT_PAREN) {
lexer.nextToken();
exp1 = expression();
match(PUNC_RIGHT_PAREN);
}
return constructTypePair(typeName, exp1, exp2);
case KW_DECIMAL:
typeName = MySQLToken.keyWordToString(lexer.token());
if (lexer.nextToken() == PUNC_LEFT_PAREN) {
lexer.nextToken();
exp1 = expression();
if (lexer.token() == PUNC_COMMA) {
lexer.nextToken();
exp2 = expression();
}
match(PUNC_RIGHT_PAREN);
}
return constructTypePair(typeName, exp1, exp2);
case KW_UNSIGNED:
typeName = MySQLToken.keyWordToString(lexer.token());
if (lexer.nextToken() == KW_INTEGER) {
lexer.nextToken();
}
return constructTypePair(typeName, null, null);
case IDENTIFIER:
typeName = lexer.stringValueUppercase();
lexer.nextToken();
if ("SIGNED".equals(typeName)) {
if (lexer.token() == KW_INTEGER) {
lexer.nextToken();
}
} else if (!"DATE".equals(typeName) && !"DATETIME".equals(typeName) && !"TIME".equals(typeName)) {
throw err("invalide type name: " + typeName);
}
return constructTypePair(typeName, null, null);
default:
throw err("invalide type name: " + lexer.stringValueUppercase());
}
}
use of com.alibaba.cobar.parser.ast.expression.Expression in project cobar by alibaba.
the class MySQLExprParser method bitShiftExpression.
/**
* <code>higherExpr ( ('<<'|'>>') higherExpr)+</code>
*/
private Expression bitShiftExpression(String consumed, String consumedUp) throws SQLSyntaxErrorException {
Expression temp;
for (Expression expr = arithmeticTermOperatorExpression(consumed, consumedUp); ; ) {
switch(lexer.token()) {
case OP_LEFT_SHIFT:
lexer.nextToken();
temp = arithmeticTermOperatorExpression(null, null);
expr = new BitShiftExpression(false, expr, temp).setCacheEvalRst(cacheEvalRst);
break;
case OP_RIGHT_SHIFT:
lexer.nextToken();
temp = arithmeticTermOperatorExpression(null, null);
expr = new BitShiftExpression(true, expr, temp).setCacheEvalRst(cacheEvalRst);
break;
default:
return expr;
}
}
}
use of com.alibaba.cobar.parser.ast.expression.Expression in project cobar by alibaba.
the class MySQLExprParser method functionConvert.
/**
* first '(' has been consumed
*/
private Convert functionConvert() throws SQLSyntaxErrorException {
Expression expr = expression();
match(KW_USING);
String tempStr = lexer.stringValue();
match(IDENTIFIER);
match(PUNC_RIGHT_PAREN);
Convert cvt = new Convert(expr, tempStr);
cvt.setCacheEvalRst(cacheEvalRst);
return cvt;
}
Aggregations