Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
210360228
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2021
210360228
Commits
4b061d3a
Commit
4b061d3a
authored
5 years ago
by
boshengchen
Committed by
dutor
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Support unreserved keywords (#396)
* Support unreserved keywords * Reserve keyword TAG, VERTEX and EDGE
parent
305d822f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/parser/parser.yy
+72
-48
72 additions, 48 deletions
src/parser/parser.yy
src/parser/test/ParserTest.cpp
+10
-0
10 additions, 0 deletions
src/parser/test/ParserTest.cpp
with
82 additions
and
48 deletions
src/parser/parser.yy
+
72
−
48
View file @
4b061d3a
...
...
@@ -99,6 +99,7 @@ class GraphScanner;
%token <doubleval> DOUBLE
%token <strval> STRING VARIABLE LABEL
%type <strval> name_label unreserved_keyword
%type <expr> expression logic_or_expression logic_and_expression
%type <expr> relational_expression multiplicative_expression additive_expression
%type <expr> unary_expression primary_expression equality_expression
...
...
@@ -167,6 +168,29 @@ class GraphScanner;
%%
name_label
: LABEL { $$ = $1; }
| unreserved_keyword { $$ = $1; }
;
unreserved_keyword
: KW_SPACE { $$ = new std::string("SPACE"); }
| KW_HOSTS { $$ = new std::string("HOSTS"); }
| KW_SPACES { $$ = new std::string("SPACES"); }
| KW_FIRSTNAME { $$ = new std::string("FIRSTNAME"); }
| KW_LASTNAME { $$ = new std::string("LASTNAME"); }
| KW_EMAIL { $$ = new std::string("EMAIL"); }
| KW_PHONE { $$ = new std::string("PHONE"); }
| KW_USER { $$ = new std::string("USER"); }
| KW_USERS { $$ = new std::string("USERS"); }
| KW_PASSWORD { $$ = new std::string("PASSWORD"); }
| KW_ROLE { $$ = new std::string("ROLE"); }
| KW_ROLES { $$ = new std::string("ROLES"); }
| KW_GOD { $$ = new std::string("GOD"); }
| KW_ADMIN { $$ = new std::string("ADMIN"); }
| KW_GUEST { $$ = new std::string("GUEST"); }
;
primary_expression
: INTEGER {
$$ = new PrimaryExpression($1);
...
...
@@ -251,7 +275,7 @@ alias_ref_expression
;
function_call_expression
:
LABEL
L_PAREN argument_list R_PAREN {
:
name_label
L_PAREN argument_list R_PAREN {
$$ = new FunctionCallExpression($1, $3);
}
;
...
...
@@ -421,16 +445,16 @@ id_list
;
over_clause
: KW_OVER
LABEL
{
: KW_OVER
name_label
{
$$ = new OverClause($2);
}
| KW_OVER
LABEL
KW_REVERSELY {
| KW_OVER
name_label
KW_REVERSELY {
$$ = new OverClause($2, nullptr, true);
}
| KW_OVER
LABEL KW_AS LABEL
{
| KW_OVER
name_label KW_AS name_label
{
$$ = new OverClause($2, $4);
}
| KW_OVER
LABEL KW_AS LABEL
KW_REVERSELY {
| KW_OVER
name_label KW_AS name_label
KW_REVERSELY {
$$ = new OverClause($2, $4, true);
}
;
...
...
@@ -461,7 +485,7 @@ yield_column
: expression {
$$ = new YieldColumn($1);
}
| expression KW_AS
LABEL
{
| expression KW_AS
name_label
{
$$ = new YieldColumn($1, $3);
}
;
...
...
@@ -477,7 +501,7 @@ match_sentence
;
find_sentence
: KW_FIND prop_list KW_FROM
LABEL
where_clause {
: KW_FIND prop_list KW_FROM
name_label
where_clause {
auto sentence = new FindSentence($4, $2);
sentence->setWhereClause($5);
$$ = sentence;
...
...
@@ -485,23 +509,23 @@ find_sentence
;
use_sentence
: KW_USE
LABEL
{ $$ = new UseSentence($2); }
: KW_USE
name_label
{ $$ = new UseSentence($2); }
;
create_tag_sentence
: KW_CREATE KW_TAG
LABEL
L_PAREN R_PAREN {
: KW_CREATE KW_TAG
name_label
L_PAREN R_PAREN {
$$ = new CreateTagSentence($3, new ColumnSpecificationList());
}
| KW_CREATE KW_TAG
LABEL
L_PAREN column_spec_list R_PAREN {
| KW_CREATE KW_TAG
name_label
L_PAREN column_spec_list R_PAREN {
$$ = new CreateTagSentence($3, $5);
}
| KW_CREATE KW_TAG
LABEL
L_PAREN column_spec_list COMMA R_PAREN {
| KW_CREATE KW_TAG
name_label
L_PAREN column_spec_list COMMA R_PAREN {
$$ = new CreateTagSentence($3, $5);
}
;
alter_tag_sentence
: KW_ALTER KW_TAG
LABEL
alter_schema_opt_list {
: KW_ALTER KW_TAG
name_label
alter_schema_opt_list {
$$ = new AlterTagSentence($3, $4);
}
;
...
...
@@ -530,19 +554,19 @@ alter_schema_opt_item
;
create_edge_sentence
: KW_CREATE KW_EDGE
LABEL
L_PAREN R_PAREN {
: KW_CREATE KW_EDGE
name_label
L_PAREN R_PAREN {
$$ = new CreateEdgeSentence($3, new ColumnSpecificationList());
}
| KW_CREATE KW_EDGE
LABEL
L_PAREN column_spec_list R_PAREN {
| KW_CREATE KW_EDGE
name_label
L_PAREN column_spec_list R_PAREN {
$$ = new CreateEdgeSentence($3, $5);
}
| KW_CREATE KW_EDGE
LABEL
L_PAREN column_spec_list COMMA R_PAREN {
| KW_CREATE KW_EDGE
name_label
L_PAREN column_spec_list COMMA R_PAREN {
$$ = new CreateEdgeSentence($3, $5);
}
;
alter_edge_sentence
: KW_ALTER KW_EDGE
LABEL
alter_schema_opt_list {
: KW_ALTER KW_EDGE
name_label
alter_schema_opt_list {
$$ = new AlterEdgeSentence($3, $4);
}
;
...
...
@@ -559,9 +583,9 @@ column_spec_list
;
column_spec
:
LABEL
{ $$ = new ColumnSpecification($1); }
|
LABEL
type_spec { $$ = new ColumnSpecification($2, $1); }
|
LABEL
type_spec ttl_spec { $$ = new ColumnSpecification($2, $1, $3); }
:
name_label
{ $$ = new ColumnSpecification($1); }
|
name_label
type_spec { $$ = new ColumnSpecification($2, $1); }
|
name_label
type_spec ttl_spec { $$ = new ColumnSpecification($2, $1, $3); }
;
ttl_spec
...
...
@@ -569,25 +593,25 @@ ttl_spec
;
describe_tag_sentence
: KW_DESCRIBE KW_TAG
LABEL
{
: KW_DESCRIBE KW_TAG
name_label
{
$$ = new DescribeTagSentence($3);
}
;
describe_edge_sentence
: KW_DESCRIBE KW_EDGE
LABEL
{
: KW_DESCRIBE KW_EDGE
name_label
{
$$ = new DescribeEdgeSentence($3);
}
;
remove_tag_sentence
: KW_REMOVE KW_TAG
LABEL
{
: KW_REMOVE KW_TAG
name_label
{
$$ = new RemoveTagSentence($3);
}
;
remove_edge_sentence
: KW_REMOVE KW_EDGE
LABEL
{
: KW_REMOVE KW_EDGE
name_label
{
$$ = new RemoveEdgeSentence($3);
}
;
...
...
@@ -638,20 +662,20 @@ vertex_tag_list
;
vertex_tag_item
:
LABEL
{
:
name_label
{
$$ = new VertexTagItem($1);
}
|
LABEL
L_PAREN prop_list R_PAREN {
|
name_label
L_PAREN prop_list R_PAREN {
$$ = new VertexTagItem($1, $3);
}
;
prop_list
:
LABEL
{
:
name_label
{
$$ = new PropertyList();
$$->addProp($1);
}
| prop_list COMMA
LABEL
{
| prop_list COMMA
name_label
{
$$ = $1;
$$->addProp($3);
}
...
...
@@ -692,14 +716,14 @@ value_list
;
insert_edge_sentence
: KW_INSERT KW_EDGE
LABEL
L_PAREN prop_list R_PAREN KW_VALUES edge_row_list {
: KW_INSERT KW_EDGE
name_label
L_PAREN prop_list R_PAREN KW_VALUES edge_row_list {
auto sentence = new InsertEdgeSentence();
sentence->setEdge($3);
sentence->setProps($5);
sentence->setRows($8);
$$ = sentence;
}
| KW_INSERT KW_EDGE KW_NO KW_OVERWRITE
LABEL
L_PAREN prop_list R_PAREN KW_VALUES edge_row_list {
| KW_INSERT KW_EDGE KW_NO KW_OVERWRITE
name_label
L_PAREN prop_list R_PAREN KW_VALUES edge_row_list {
auto sentence = new InsertEdgeSentence();
sentence->setOverwrite(false);
sentence->setEdge($5);
...
...
@@ -761,7 +785,7 @@ update_list
;
update_item
:
LABEL
ASSIGN expression {
:
name_label
ASSIGN expression {
$$ = new UpdateItem($1, $3);
}
;
...
...
@@ -856,10 +880,10 @@ show_sentence
| KW_SHOW KW_USERS {
$$ = new ShowSentence(ShowSentence::ShowType::kShowUsers);
}
| KW_SHOW KW_USER
LABEL
{
| KW_SHOW KW_USER
name_label
{
$$ = new ShowSentence(ShowSentence::ShowType::kShowUser, $3);
}
| KW_SHOW KW_ROLES KW_IN
LABEL
{
| KW_SHOW KW_ROLES KW_IN
name_label
{
$$ = new ShowSentence(ShowSentence::ShowType::kShowRoles, $4);
}
;
...
...
@@ -906,7 +930,7 @@ host_item
port : INTEGER { $$ = $1; }
create_space_sentence
: KW_CREATE KW_SPACE
LABEL
L_PAREN space_opt_list R_PAREN {
: KW_CREATE KW_SPACE
name_label
L_PAREN space_opt_list R_PAREN {
auto sentence = new CreateSpaceSentence($3);
sentence->setOpts($5);
$$ = sentence;
...
...
@@ -935,11 +959,11 @@ space_opt_list
$$ = new SpaceOptItem(SpaceOptItem::REPLICA_FACTOR, $3);
}
// TODO(YT) Create Spaces for different engines
// KW_ENGINE_TYPE ASSIGN
LABEL
// KW_ENGINE_TYPE ASSIGN
name_label
;
drop_space_sentence
: KW_DROP KW_SPACE
LABEL
{
: KW_DROP KW_SPACE
name_label
{
$$ = new DropSpaceSentence($3);
}
;
...
...
@@ -973,20 +997,20 @@ with_user_opt_list
;
create_user_sentence
: KW_CREATE KW_USER
LABEL
KW_WITH KW_PASSWORD STRING {
: KW_CREATE KW_USER
name_label
KW_WITH KW_PASSWORD STRING {
$$ = new CreateUserSentence($3, $6);
}
| KW_CREATE KW_USER KW_IF KW_NOT KW_EXISTS
LABEL
KW_WITH KW_PASSWORD STRING {
| KW_CREATE KW_USER KW_IF KW_NOT KW_EXISTS
name_label
KW_WITH KW_PASSWORD STRING {
auto sentence = new CreateUserSentence($6, $9);
sentence->setMissingOk(true);
$$ = sentence;
}
| KW_CREATE KW_USER
LABEL
KW_WITH KW_PASSWORD STRING COMMA with_user_opt_list {
| KW_CREATE KW_USER
name_label
KW_WITH KW_PASSWORD STRING COMMA with_user_opt_list {
auto sentence = new CreateUserSentence($3, $6);
sentence->setOpts($8);
$$ = sentence;
}
| KW_CREATE KW_USER KW_IF KW_NOT KW_EXISTS
LABEL
KW_WITH KW_PASSWORD STRING COMMA with_user_opt_list {
| KW_CREATE KW_USER KW_IF KW_NOT KW_EXISTS
name_label
KW_WITH KW_PASSWORD STRING COMMA with_user_opt_list {
auto sentence = new CreateUserSentence($6, $9);
sentence->setMissingOk(true);
sentence->setOpts($11);
...
...
@@ -994,7 +1018,7 @@ create_user_sentence
}
alter_user_sentence
: KW_ALTER KW_USER
LABEL
KW_WITH with_user_opt_list {
: KW_ALTER KW_USER
name_label
KW_WITH with_user_opt_list {
auto sentence = new AlterUserSentence($3);
sentence->setOpts($5);
$$ = sentence;
...
...
@@ -1002,10 +1026,10 @@ alter_user_sentence
;
drop_user_sentence
: KW_DROP KW_USER
LABEL
{
: KW_DROP KW_USER
name_label
{
$$ = new DropUserSentence($3);
}
| KW_DROP KW_USER KW_IF KW_EXISTS
LABEL
{
| KW_DROP KW_USER KW_IF KW_EXISTS
name_label
{
auto sentence = new DropUserSentence($5);
sentence->setMissingOk(true);
$$ = sentence;
...
...
@@ -1013,11 +1037,11 @@ drop_user_sentence
;
change_password_sentence
: KW_CHANGE KW_PASSWORD
LABEL
KW_TO STRING {
: KW_CHANGE KW_PASSWORD
name_label
KW_TO STRING {
auto sentence = new ChangePasswordSentence($3, $5);
$$ = sentence;
}
| KW_CHANGE KW_PASSWORD
LABEL
KW_FROM STRING KW_TO STRING {
| KW_CHANGE KW_PASSWORD
name_label
KW_FROM STRING KW_TO STRING {
auto sentence = new ChangePasswordSentence($3, $5, $7);
$$ = sentence;
}
...
...
@@ -1031,12 +1055,12 @@ role_type_clause
;
acl_item_clause
: KW_ROLE role_type_clause KW_ON
LABEL
{
: KW_ROLE role_type_clause KW_ON
name_label
{
auto sentence = new AclItemClause(true, $4);
sentence->setRoleTypeClause($2);
$$ = sentence;
}
| role_type_clause KW_ON
LABEL
{
| role_type_clause KW_ON
name_label
{
auto sentence = new AclItemClause(false, $3);
sentence->setRoleTypeClause($1);
$$ = sentence;
...
...
@@ -1044,7 +1068,7 @@ acl_item_clause
;
grant_sentence
: KW_GRANT acl_item_clause KW_TO
LABEL
{
: KW_GRANT acl_item_clause KW_TO
name_label
{
auto sentence = new GrantSentence($4);
sentence->setAclItemClause($2);
$$ = sentence;
...
...
@@ -1052,7 +1076,7 @@ grant_sentence
;
revoke_sentence
: KW_REVOKE acl_item_clause KW_FROM
LABEL
{
: KW_REVOKE acl_item_clause KW_FROM
name_label
{
auto sentence = new RevokeSentence($4);
sentence->setAclItemClause($2);
$$ = sentence;
...
...
This diff is collapsed.
Click to expand it.
src/parser/test/ParserTest.cpp
+
10
−
0
View file @
4b061d3a
...
...
@@ -531,4 +531,14 @@ TEST(Parser, UserOperation) {
}
}
TEST
(
Parser
,
UnreservedKeywords
)
{
{
GQLParser
parser
;
std
::
string
query
=
"CREATE TAG TAG1(space string, spaces string, "
"email string, password string, roles string)"
;
auto
result
=
parser
.
parse
(
query
);
ASSERT_TRUE
(
result
.
ok
())
<<
result
.
status
();
}
}
}
// namespace nebula
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment