Skip to content

Commit

Permalink
add minus/factorial order
Browse files Browse the repository at this point in the history
  • Loading branch information
aziz-mu committed Dec 20, 2022
1 parent ad02275 commit dcfe3e1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/antlr4/Cypher.g4
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ oC_PowerOfExpression
: oC_UnaryAddSubtractOrFactorialExpression ( SP? '^' SP? oC_UnaryAddSubtractOrFactorialExpression )* ;

oC_UnaryAddSubtractOrFactorialExpression
: ( MINUS SP? )? oC_StringListNullOperatorExpression SP? FACTORIAL? ;
: ( MINUS SP? )? oC_StringListNullOperatorExpression (SP? FACTORIAL)? ;

MINUS : '-' ;

Expand Down
8 changes: 7 additions & 1 deletion src/parser/transformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,13 @@ unique_ptr<ParsedExpression> Transformer::transformPowerOfExpression(

unique_ptr<ParsedExpression> Transformer::transformUnaryAddSubtractOrFactorialExpression(
CypherParser::OC_UnaryAddSubtractOrFactorialExpressionContext& ctx) {
if (ctx.MINUS()) {
if (ctx.MINUS() && ctx.FACTORIAL()) {
auto exp1 = make_unique<ParsedFunctionExpression>(FACTORIAL_FUNC_NAME,
transformStringListNullOperatorExpression(*ctx.oC_StringListNullOperatorExpression()),
ctx.getText());
return make_unique<ParsedFunctionExpression>(
NEGATE_FUNC_NAME, std::move(exp1), ctx.getText());
} else if (ctx.MINUS()) {
return make_unique<ParsedFunctionExpression>(NEGATE_FUNC_NAME,
transformStringListNullOperatorExpression(*ctx.oC_StringListNullOperatorExpression()),
ctx.getText());
Expand Down
38 changes: 19 additions & 19 deletions third_party/antlr4_cypher/cypher_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6887,6 +6887,10 @@ tree::TerminalNode* CypherParser::OC_UnaryAddSubtractOrFactorialExpressionContex
return getToken(CypherParser::MINUS, 0);
}

tree::TerminalNode* CypherParser::OC_UnaryAddSubtractOrFactorialExpressionContext::FACTORIAL() {
return getToken(CypherParser::FACTORIAL, 0);
}

std::vector<tree::TerminalNode *> CypherParser::OC_UnaryAddSubtractOrFactorialExpressionContext::SP() {
return getTokens(CypherParser::SP);
}
Expand All @@ -6895,10 +6899,6 @@ tree::TerminalNode* CypherParser::OC_UnaryAddSubtractOrFactorialExpressionContex
return getToken(CypherParser::SP, i);
}

tree::TerminalNode* CypherParser::OC_UnaryAddSubtractOrFactorialExpressionContext::FACTORIAL() {
return getToken(CypherParser::FACTORIAL, 0);
}


size_t CypherParser::OC_UnaryAddSubtractOrFactorialExpressionContext::getRuleIndex() const {
return CypherParser::RuleOC_UnaryAddSubtractOrFactorialExpression;
Expand Down Expand Up @@ -6937,27 +6937,27 @@ CypherParser::OC_UnaryAddSubtractOrFactorialExpressionContext* CypherParser::oC_
}
setState(1235);
oC_StringListNullOperatorExpression();
setState(1237);
setState(1240);
_errHandler->sync(this);

switch (getInterpreter<atn::ParserATNSimulator>()->adaptivePredict(_input, 214, _ctx)) {
switch (getInterpreter<atn::ParserATNSimulator>()->adaptivePredict(_input, 215, _ctx)) {
case 1: {
setState(1236);
match(CypherParser::SP);
setState(1237);
_errHandler->sync(this);

_la = _input->LA(1);
if (_la == CypherParser::SP) {
setState(1236);
match(CypherParser::SP);
}
setState(1239);
match(CypherParser::FACTORIAL);
break;
}

default:
break;
}
setState(1240);
_errHandler->sync(this);

_la = _input->LA(1);
if (_la == CypherParser::FACTORIAL) {
setState(1239);
match(CypherParser::FACTORIAL);
}

}
catch (RecognitionException &e) {
Expand Down Expand Up @@ -10123,10 +10123,10 @@ CypherParser::Initializer::Initializer() {
0x2, 0x2, 0x4d1, 0x4d0, 0x3, 0x2, 0x2, 0x2, 0x4d1, 0x4d2, 0x3, 0x2,
0x2, 0x2, 0x4d2, 0x4d4, 0x3, 0x2, 0x2, 0x2, 0x4d3, 0x4cf, 0x3, 0x2,
0x2, 0x2, 0x4d3, 0x4d4, 0x3, 0x2, 0x2, 0x2, 0x4d4, 0x4d5, 0x3, 0x2,
0x2, 0x2, 0x4d5, 0x4d7, 0x5, 0x9e, 0x50, 0x2, 0x4d6, 0x4d8, 0x7, 0x6e,
0x2, 0x2, 0x4d5, 0x4da, 0x5, 0x9e, 0x50, 0x2, 0x4d6, 0x4d8, 0x7, 0x6e,
0x2, 0x2, 0x4d7, 0x4d6, 0x3, 0x2, 0x2, 0x2, 0x4d7, 0x4d8, 0x3, 0x2,
0x2, 0x2, 0x4d8, 0x4da, 0x3, 0x2, 0x2, 0x2, 0x4d9, 0x4db, 0x7, 0x57,
0x2, 0x2, 0x4da, 0x4d9, 0x3, 0x2, 0x2, 0x2, 0x4da, 0x4db, 0x3, 0x2,
0x2, 0x2, 0x4d8, 0x4d9, 0x3, 0x2, 0x2, 0x2, 0x4d9, 0x4db, 0x7, 0x57,
0x2, 0x2, 0x4da, 0x4d7, 0x3, 0x2, 0x2, 0x2, 0x4da, 0x4db, 0x3, 0x2,
0x2, 0x2, 0x4db, 0x9d, 0x3, 0x2, 0x2, 0x2, 0x4dc, 0x4e0, 0x5, 0xaa,
0x56, 0x2, 0x4dd, 0x4e1, 0x5, 0xa6, 0x54, 0x2, 0x4de, 0x4e1, 0x5, 0xa0,
0x51, 0x2, 0x4df, 0x4e1, 0x5, 0xa8, 0x55, 0x2, 0x4e0, 0x4dd, 0x3, 0x2,
Expand Down
2 changes: 1 addition & 1 deletion third_party/antlr4_cypher/include/cypher_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -1279,9 +1279,9 @@ class CypherParser : public antlr4::Parser {
virtual size_t getRuleIndex() const override;
OC_StringListNullOperatorExpressionContext *oC_StringListNullOperatorExpression();
antlr4::tree::TerminalNode *MINUS();
antlr4::tree::TerminalNode *FACTORIAL();
std::vector<antlr4::tree::TerminalNode *> SP();
antlr4::tree::TerminalNode* SP(size_t i);
antlr4::tree::TerminalNode *FACTORIAL();


};
Expand Down

0 comments on commit dcfe3e1

Please sign in to comment.