Fix bug in parenthesized expression
Reviewers: buda Reviewed By: buda Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D249
This commit is contained in:
parent
db740fb9fc
commit
7a58ec5afb
@ -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()) {
|
||||
|
@ -364,6 +364,12 @@ class CypherMainVisitor : public antlropencypher::CypherBaseVisitor {
|
||||
*/
|
||||
antlrcpp::Any visitAtom(CypherParser::AtomContext *ctx) override;
|
||||
|
||||
/**
|
||||
* @return Expression*
|
||||
*/
|
||||
antlrcpp::Any visitParenthesizedExpression(
|
||||
CypherParser::ParenthesizedExpressionContext *ctx) override;
|
||||
|
||||
/**
|
||||
* @return Literal*
|
||||
*/
|
||||
|
@ -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_;
|
||||
|
Loading…
Reference in New Issue
Block a user