use of com.alibaba.cobar.parser.ast.expression.bit.BitInvertExpression in project cobar by alibaba.
the class MySQLExprParserTest method testUnary.
public void testUnary() throws Exception {
String sql = "!-~ binary a collate latin1_danish_ci";
MySQLExprParser parser = new MySQLExprParser(new MySQLLexer(sql));
Expression expr = parser.expression();
String output = output2MySQL(expr, sql);
Assert.assertEquals("! - ~ BINARY a COLLATE latin1_danish_ci", output);
NegativeValueExpression neg = (NegativeValueExpression) expr;
MinusExpression mi = (MinusExpression) neg.getOperand();
BitInvertExpression bi = (BitInvertExpression) mi.getOperand();
CastBinaryExpression bin = (CastBinaryExpression) bi.getOperand();
CollateExpression col = (CollateExpression) bin.getOperand();
Assert.assertEquals("a", ((Identifier) col.getString()).getIdText());
}
use of com.alibaba.cobar.parser.ast.expression.bit.BitInvertExpression 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);
}
Aggregations