Fix bug in parenthesized expression

Reviewers: buda

Reviewed By: buda

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D249
This commit is contained in:
Mislav Bradac 2017-04-07 18:32:40 +02:00
parent db740fb9fc
commit 7a58ec5afb
3 changed files with 34 additions and 12 deletions

View File

@ -360,7 +360,7 @@ antlrcpp::Any CypherMainVisitor::visitRangeLiteral(
antlrcpp::Any CypherMainVisitor::visitExpression(
CypherParser::ExpressionContext *ctx) {
return visitChildren(ctx);
return static_cast<Expression *>(ctx->expression12()->accept(this));
}
// OR.
@ -499,7 +499,7 @@ antlrcpp::Any CypherMainVisitor::visitExpression3(
if (ctx->children.size() > 1u) {
throw NotYetImplemented();
}
return visitChildren(ctx);
return static_cast<Expression *>(visitChildren(ctx));
}
antlrcpp::Any CypherMainVisitor::visitExpression2(
@ -525,11 +525,12 @@ antlrcpp::Any CypherMainVisitor::visitAtom(CypherParser::AtomContext *ctx) {
// TODO: implement other clauses.
throw NotYetImplemented();
} else if (ctx->parenthesizedExpression()) {
return ctx->parenthesizedExpression()->accept(this);
return static_cast<Expression *>(
ctx->parenthesizedExpression()->accept(this));
} else if (ctx->variable()) {
std::string variable = ctx->variable()->accept(this);
users_identifiers.insert(variable);
return (Expression *)storage_.Create<Identifier>(variable);
return static_cast<Expression *>(storage_.Create<Identifier>(variable));
}
// TODO: Implement this. We don't support comprehensions, functions,
// filtering... at the moment.
@ -556,6 +557,11 @@ antlrcpp::Any CypherMainVisitor::visitLiteral(
return visitChildren(ctx);
}
antlrcpp::Any CypherMainVisitor::visitParenthesizedExpression(
CypherParser::ParenthesizedExpressionContext *ctx) {
return static_cast<Expression *>(ctx->expression()->accept(this));
}
antlrcpp::Any CypherMainVisitor::visitNumberLiteral(
CypherParser::NumberLiteralContext *ctx) {
if (ctx->integerLiteral()) {

View File

@ -350,20 +350,26 @@ class CypherMainVisitor : public antlropencypher::CypherBaseVisitor {
CypherParser::Expression3Context *ctx) override;
/**
* Property lookup, test for node labels existence...
*
* @return Expression*
*/
* Property lookup, test for node labels existence...
*
* @return Expression*
*/
antlrcpp::Any visitExpression2(
CypherParser::Expression2Context *ctx) override;
/**
* Literals, params, list comprehension...
*
* @return Expression*
*/
* Literals, params, list comprehension...
*
* @return Expression*
*/
antlrcpp::Any visitAtom(CypherParser::AtomContext *ctx) override;
/**
* @return Expression*
*/
antlrcpp::Any visitParenthesizedExpression(
CypherParser::ParenthesizedExpressionContext *ctx) override;
/**
* @return Literal*
*/

View File

@ -121,6 +121,16 @@ TEST(CypherMainVisitorTest, NullLiteral) {
ASSERT_EQ(literal->value_.type(), TypedValue::Type::Null);
}
TEST(CypherMainVisitorTest, ParenthesizedExpression) {
AstGenerator ast_generator("RETURN (2)");
auto *query = ast_generator.query_;
auto *return_clause = dynamic_cast<Return *>(query->clauses_[0]);
auto *literal = dynamic_cast<Literal *>(
return_clause->named_expressions_[0]->expression_);
ASSERT_TRUE(literal);
ASSERT_EQ(literal->value_.Value<int64_t>(), 2);
}
TEST(CypherMainVisitorTest, OrOperator) {
AstGenerator ast_generator("RETURN true Or false oR n");
auto *query = ast_generator.query_;