Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove glr parser #5290

Merged
merged 4 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
66 changes: 41 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,16 @@ 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) {
delete $1;
throw nebula::GraphParser::syntax_error(@1, "Invalid node pattern");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete $1 before throw exception

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The expression memory is managed by ObjectPool, and there is no need for delete, which would result in double free.

}
$$ = 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 +1848,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
22 changes: 22 additions & 0 deletions tests/tck/features/match/Base.feature
Original file line number Diff line number Diff line change
Expand Up @@ -1285,3 +1285,25 @@ Feature: Basic match
| ("Tony Parker") |
| ("Tracy McGrady") |
| ("Marco Belinelli") |
When executing query:
"""
MATCH (v:player{name: 'Tim Duncan'})-[e:like*0..2]-(v2)
WHERE size([ii in e WHERE (v)-[ii]-(v2) | ii])>1
RETURN count(*) AS cnt
"""
# FIXME(czp): Fix this case after https://github.com/vesoft-inc/nebula/issues/5289 closed
Then a SemanticError should be raised at runtime: PatternExpression are not allowed to introduce new variables: `ii'.

# Then the result should be, in any order:
# | cnt |
# | 0 |
# When executing query:
# """
# MATCH (v:player{name: 'Tim Duncan'})-[e:like*0..2]-(v2)-[i]-(v3)
# WHERE size([i in e WHERE (v)-[i]-(v2) | i])>1
# RETURN count(*) AS cnt
# """
# FIXME(czp): Fix this case after https://github.com/vesoft-inc/nebula/issues/5289 closed
# Then the result should be, in any order:
# | cnt |
# | 0 |
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)
czpmango marked this conversation as resolved.
Show resolved Hide resolved
UNWIND count(b) as num
RETURN num
"""
Expand Down
34 changes: 34 additions & 0 deletions tests/tck/features/yield/return.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,40 @@ Feature: Return. A standalone return sentence is actually a yield sentence
Then the result should be, in any order:
| sum |
| 2 |
When executing query:
"""
RETURN 1- -1 AS sub
"""
Then the result should be, in any order:
| sub |
| 2 |
When executing query:
"""
RETURN 1--1 AS sub
"""
Then a SyntaxError should be raised at runtime: syntax error near `--'
When executing query:
"""
RETURN [2,3 ] - [3] AS sub
"""
Then a SemanticError should be raised at runtime: `([2,3]-[3])' is not a valid expression, can not apply `-' to `LIST' and `LIST'.
When executing query:
"""
RETURN [2,3 ]-[3] AS sub
"""
Then a SyntaxError should be raised at runtime: syntax error near `]-'
# When executing query:
# """
# WITH [2,3] AS a, 3 AS b, [2] AS c return (a)-[b]-(c)
# """
# FIXME(czp): Fix this after https://github.com/vesoft-inc/nebula/issues/5288 closed
# Then a semanticError should be raised at runtime: `a' is defined with type Runtime, but referenced with type Node
# When executing query:
# """
# WITH [2,3] AS a, 3 AS b, [2] AS c return (a)- [b] -(c)
# """
# FIXME(czp): Fix this after https://github.com/vesoft-inc/nebula/issues/5288 closed
# Then a semanticError should be raised at runtime: `(a)- [b]' is not a valid expression, can not apply `-' to `LIST' and `LIST'.
When executing query:
"""
RETURN DISTINCT 1+1, '1+1', (int)3.14, (string)(1+1), (string)true
Expand Down
4 changes: 2 additions & 2 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,7 +656,7 @@ Feature: Yield Sentence
Scenario: WithComment
When executing query:
"""
YIELD 1--1
YIELD 1- -1
"""
Then the result should be, in any order:
| (1--(1)) |
Expand Down
4 changes: 2 additions & 2 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,7 +666,7 @@ 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)) |
Expand Down