Skip to content

Commit

Permalink
address Shylock's comment
Browse files Browse the repository at this point in the history
  • Loading branch information
laura-ding committed Mar 26, 2020
1 parent fe00fe5 commit ac0b324
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,12 @@ static constexpr size_t MAX_ABS_INTEGER = 9223372036854775808ULL;

name_label
: LABEL { $$ = $1; }
| STRING { $$ = $1; }
| STRING {
if ($1->empty()) {
throw nebula::GraphParser::syntax_error(@1, "Empty string:");
}
$$ = $1;
}
| unreserved_keyword { $$ = $1; }
;

Expand Down Expand Up @@ -348,13 +353,20 @@ base_expression
: DOUBLE {
$$ = new PrimaryExpression($1);
}
| STRING {
$$ = new PrimaryExpression(*$1);
delete $1;
}
| BOOL {
$$ = new PrimaryExpression($1);
}
| name_label {
| LABEL {
$$ = new PrimaryExpression(*$1);
delete $1;
}
| unreserved_keyword {
$$ = new PrimaryExpression(*$1);;
}
| input_ref_expression {
$$ = $1;
}
Expand Down Expand Up @@ -1024,7 +1036,7 @@ create_schema_prop_item
}
$$ = new SchemaPropItem(SchemaPropItem::TTL_DURATION, $3);
}
| KW_TTL_COL ASSIGN name_label {
| KW_TTL_COL ASSIGN STRING {
$$ = new SchemaPropItem(SchemaPropItem::TTL_COL, *$3);
delete $3;
}
Expand Down Expand Up @@ -1105,7 +1117,7 @@ alter_schema_prop_item
}
$$ = new SchemaPropItem(SchemaPropItem::TTL_DURATION, $3);
}
| KW_TTL_COL ASSIGN name_label {
| KW_TTL_COL ASSIGN STRING {
$$ = new SchemaPropItem(SchemaPropItem::TTL_COL, *$3);
delete $3;
}
Expand Down
9 changes: 9 additions & 0 deletions src/parser/test/ParserTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1969,5 +1969,14 @@ TEST(Parser, UseReservedKeyword) {
auto result = parser.parse(query);
ASSERT_TRUE(result.ok());
}
// Test empty name_label
{
GQLParser parser;
std::string query = "CREATE TAG 'person'(\"\" string)";
auto result = parser.parse(query);
ASSERT_FALSE(result.ok());
auto error = "SyntaxError: Empty string: near `\" string'";
ASSERT_EQ(error, result.status().toString());
}
}
} // namespace nebula

0 comments on commit ac0b324

Please sign in to comment.