Skip to content

Commit

Permalink
Remove glr parser
Browse files Browse the repository at this point in the history
small fix

fix tck
  • Loading branch information
czpmango committed Jan 31, 2023
1 parent db7606b commit 3c941d2
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 34 deletions.
5 changes: 3 additions & 2 deletions src/parser/MatchPath.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,13 @@ class MatchNodeLabelList final {

class MatchNode final {
public:
MatchNode(const std::string& alias, MatchNodeLabelList* labels, Expression* props = nullptr) {
MatchNode(const std::string& alias = "",
MatchNodeLabelList* labels = nullptr,
Expression* props = nullptr) {
alias_ = alias;
labels_.reset(labels);
props_ = static_cast<MapExpression*>(props);
}
MatchNode() = default;

void setAlias(const std::string& alias) {
alias_ = alias;
Expand Down
65 changes: 40 additions & 25 deletions src/parser/parser.yy
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Bison options
%language "C++"
%skeleton "glr.cc"
%glr-parser
%no-lines
%skeleton "lalr1.cc"
%no-lines
%locations
%define api.namespace { nebula }
%define api.parser.class { GraphParser }
Expand Down Expand Up @@ -217,10 +216,11 @@ using namespace nebula;
%token KW_MERGE KW_DIVIDE KW_RENAME

/* symbols */
%token L_PAREN R_PAREN L_BRACKET R_BRACKET L_BRACE R_BRACE COMMA
%token PIPE ASSIGN
%token DOT DOT_DOT COLON QM SEMICOLON L_ARROW R_ARROW AT
%token ID_PROP TYPE_PROP SRC_ID_PROP DST_ID_PROP RANK_PROP INPUT_REF DST_REF SRC_REF
%token L_PAREN R_PAREN L_BRACKET R_BRACKET L_BRACE R_BRACE COMMA
MINUS_L_BRACKET R_BRACKET_MINUS L_ARROW_L_BRACKET R_BRACKET_R_ARROW PIPE
MINUS_MINUS MINUS_R_ARROW L_ARROW_MINUS L_ARROW_R_ARROW ASSIGN DOT DOT_DOT
COLON QM SEMICOLON L_ARROW R_ARROW AT ID_PROP TYPE_PROP
SRC_ID_PROP DST_ID_PROP RANK_PROP INPUT_REF DST_REF SRC_REF

/* token type specification */
%token <boolval> BOOL
Expand Down Expand Up @@ -747,10 +747,10 @@ constant_expression
;

compound_expression
: match_path_pattern_expression %dprec 2 {
: match_path_pattern_expression {
$$ = $1;
}
| parenthesized_expression %dprec 1 {
| parenthesized_expression {
$$ = $1;
}
| property_expression {
Expand Down Expand Up @@ -1797,9 +1797,15 @@ match_path_list
}

match_node
: L_PAREN match_alias R_PAREN {
$$ = new MatchNode(*$2, nullptr, nullptr);
delete $2;
: L_PAREN R_PAREN {
$$ = new MatchNode();
}
| parenthesized_expression {
auto& e = $1;
if (e->kind() != Expression::Kind::kLabel) {
throw nebula::GraphParser::syntax_error(@1, "Invalid node pattern");
}
$$ = new MatchNode(static_cast<LabelExpression*>(e)->name(), nullptr, nullptr);
}
| L_PAREN match_alias match_node_label_list R_PAREN {
$$ = new MatchNode(*$2, $3, nullptr);
Expand Down Expand Up @@ -1841,31 +1847,40 @@ match_alias
;

match_edge
: MINUS match_edge_prop MINUS {
: MINUS_MINUS {
$$ = new MatchEdge(nullptr, storage::cpp2::EdgeDirection::BOTH);
}
| MINUS_R_ARROW {
$$ = new MatchEdge(nullptr, storage::cpp2::EdgeDirection::OUT_EDGE);
}
| L_ARROW_MINUS {
$$ = new MatchEdge(nullptr, storage::cpp2::EdgeDirection::IN_EDGE);
}
| L_ARROW_R_ARROW {
$$ = new MatchEdge(nullptr, storage::cpp2::EdgeDirection::BOTH);
}
| MINUS_L_BRACKET match_edge_prop R_BRACKET_MINUS {
$$ = new MatchEdge($2, storage::cpp2::EdgeDirection::BOTH);
}
| MINUS match_edge_prop R_ARROW {
| MINUS_L_BRACKET match_edge_prop R_BRACKET_R_ARROW {
$$ = new MatchEdge($2, storage::cpp2::EdgeDirection::OUT_EDGE);
}
| L_ARROW match_edge_prop MINUS {
| L_ARROW_L_BRACKET match_edge_prop R_BRACKET_MINUS {
$$ = new MatchEdge($2, storage::cpp2::EdgeDirection::IN_EDGE);
}
| L_ARROW match_edge_prop R_ARROW {
| L_ARROW_L_BRACKET match_edge_prop R_BRACKET_R_ARROW {
$$ = new MatchEdge($2, storage::cpp2::EdgeDirection::BOTH);
}
;

match_edge_prop
: %empty {
$$ = nullptr;
}
| L_BRACKET match_alias opt_match_edge_type_list match_step_range R_BRACKET {
$$ = new MatchEdgeProp(*$2, $3, $4, nullptr);
delete $2;
: match_alias opt_match_edge_type_list match_step_range {
$$ = new MatchEdgeProp(*$1, $2, $3, nullptr);
delete $1;
}
| L_BRACKET match_alias opt_match_edge_type_list match_step_range map_expression R_BRACKET {
$$ = new MatchEdgeProp(*$2, $3, $4, $5);
delete $2;
| match_alias opt_match_edge_type_list match_step_range map_expression {
$$ = new MatchEdgeProp(*$1, $2, $3, $4);
delete $1;
}
;

Expand Down
10 changes: 10 additions & 0 deletions src/parser/scanner.lex
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,16 @@ LABEL_FULL_WIDTH {CN_EN_FULL_WIDTH}{CN_EN_NUM_FULL_WIDTH}*

"<-" { return TokenType::L_ARROW; }
"->" { return TokenType::R_ARROW; }

"-[" { return TokenType::MINUS_L_BRACKET; }
"]-" { return TokenType::R_BRACKET_MINUS; }
"<-[" { return TokenType::L_ARROW_L_BRACKET; }
"]->" { return TokenType::R_BRACKET_R_ARROW; }
"--" { return TokenType::MINUS_MINUS; }
"-->" { return TokenType::MINUS_R_ARROW; }
"<--" { return TokenType::L_ARROW_MINUS; }
"<-->" { return TokenType::L_ARROW_R_ARROW; }

"_id" { return TokenType::ID_PROP; }
"_type" { return TokenType::TYPE_PROP; }
"_src" { return TokenType::SRC_ID_PROP; }
Expand Down
2 changes: 1 addition & 1 deletion tests/tck/features/match/Unwind.feature
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ Feature: Unwind clause
Then a SyntaxError should be raised at runtime: syntax error near `WITH'
When executing query:
"""
MATCH (a:player {name:"Tim Duncan"}) - [e:like] -> (b)
MATCH (a:player {name:"Tim Duncan"})-[e:like]->(b)
UNWIND count(b) as num
RETURN num
"""
Expand Down
6 changes: 3 additions & 3 deletions tests/tck/features/yield/yield.IntVid.feature
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ Feature: Yield Sentence
| -9223372036854775808 |
When executing query:
"""
YIELD --9223372036854775808
YIELD - -9223372036854775808
"""
Then a SemanticError should be raised at runtime: result of -(-9223372036854775808) cannot be represented as an integer
When executing query:
Expand Down Expand Up @@ -656,10 +656,10 @@ Feature: Yield Sentence
Scenario: WithComment
When executing query:
"""
YIELD 1--1
YIELD 1- -1
"""
Then the result should be, in any order:
| (1--(1)) |
| (1- -(1)) |
| 2 |

Scenario: deduce typecase
Expand Down
6 changes: 3 additions & 3 deletions tests/tck/features/yield/yield.feature
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ Feature: Yield Sentence
| -9223372036854775808 |
When executing query:
"""
YIELD --9223372036854775808
YIELD - -9223372036854775808
"""
Then a SemanticError should be raised at runtime: result of -(-9223372036854775808) cannot be represented as an integer
When executing query:
Expand Down Expand Up @@ -666,10 +666,10 @@ Feature: Yield Sentence
Scenario: WithComment
When executing query:
"""
YIELD 1--1
YIELD 1- -1
"""
Then the result should be, in any order, with relax comparison:
| (1--(1)) |
| (1- -(1)) |
| 2 |

Scenario: deduce typecase
Expand Down

0 comments on commit 3c941d2

Please sign in to comment.