diff options
author | Tor Brede Vekterli <vekterli@verizonmedia.com> | 2020-06-17 09:43:42 +0000 |
---|---|---|
committer | Tor Brede Vekterli <vekterli@verizonmedia.com> | 2020-06-17 09:43:42 +0000 |
commit | 0f4829d8436397fbdef454a0028c9f72e9b4ea0e (patch) | |
tree | 2164c2baa679eff3c5b2d1d1286b1bbfc20e4a05 /document | |
parent | 544ba2e3d8cc1e4f1766ead5651712401d98a86f (diff) |
Support "user" and "group" as identifiers in C++ selection parser
These were not included in the explicit list of allowed tokens
and would therefore cause parse failures if e.g. a document type
was called "user".
Diffstat (limited to 'document')
-rw-r--r-- | document/src/tests/documentselectparsertest.cpp | 25 | ||||
-rw-r--r-- | document/src/vespa/document/select/grammar/parser.yy | 3 |
2 files changed, 24 insertions, 4 deletions
diff --git a/document/src/tests/documentselectparsertest.cpp b/document/src/tests/documentselectparsertest.cpp index 9ac402f56ef..b75d094459b 100644 --- a/document/src/tests/documentselectparsertest.cpp +++ b/document/src/tests/documentselectparsertest.cpp @@ -76,6 +76,12 @@ namespace { void DocumentSelectParserTest::SetUp() { DocumenttypesConfigBuilderHelper builder(TestDocRepo::getDefaultConfig()); + builder.document(1234567, "with_imported", + Struct("with_imported.header"), + Struct("with_imported.body")) + .imported_field("my_imported_field"); + // Additional document types with names that are (or include) identifiers + // that lex to specific tokens. builder.document(535424777, "notandor", Struct("notandor.header"), Struct("notandor.body")); builder.document(1348665801, "ornotand", @@ -87,10 +93,10 @@ void DocumentSelectParserTest::SetUp() builder.document(-1673092522, "usergroup", Struct("usergroup.header"), Struct("usergroup.body")); - builder.document(1234567, "with_imported", - Struct("with_imported.header"), - Struct("with_imported.body")) - .imported_field("my_imported_field"); + builder.document(875463456, "user", + Struct("user.header"), Struct("user.body")); + builder.document(567463442, "group", + Struct("group.header"), Struct("group.body")); _repo = std::make_unique<DocumentTypeRepo>(builder.config()); _parser = std::make_unique<select::Parser>(*_repo, _bucketIdFactory); @@ -442,6 +448,8 @@ TEST_F(DocumentSelectParserTest, testParseTerminals) verifyParse("andornot"); verifyParse("idid"); verifyParse("usergroup"); + verifyParse("user"); + verifyParse("group"); } TEST_F(DocumentSelectParserTest, testParseBranches) @@ -463,6 +471,7 @@ TEST_F(DocumentSelectParserTest, testParseBranches) verifyParse("not andornot"); verifyParse("idid or not usergroup"); verifyParse("not(andornot or idid)", "not (andornot or idid)"); + verifyParse("not user or not group"); } template <typename ContainsType> @@ -1440,6 +1449,14 @@ TEST_F(DocumentSelectParserTest, test_ambiguous_field_spec_expression_is_handled parse_to_tree("(testdoctype1.foo) AND (testdoctype1.bar)")); } +TEST_F(DocumentSelectParserTest, special_tokens_are_allowed_as_freestanding_identifier_names) { + createDocs(); + EXPECT_EQ("(NOT (DOCTYPE user))", parse_to_tree("not user")); + EXPECT_EQ("(== (ID id.user) (FIELD user user))", parse_to_tree("id.user == user.user")); + EXPECT_EQ("(NOT (DOCTYPE group))", parse_to_tree("not group")); + EXPECT_EQ("(== (ID id.group) (FIELD group group))", parse_to_tree("id.group == group.group")); +} + TEST_F(DocumentSelectParserTest, test_can_build_field_value_from_field_expr_node) { using select::FieldExprNode; diff --git a/document/src/vespa/document/select/grammar/parser.yy b/document/src/vespa/document/select/grammar/parser.yy index 76b7cb7eeba..9d5b5825330 100644 --- a/document/src/vespa/document/select/grammar/parser.yy +++ b/document/src/vespa/document/select/grammar/parser.yy @@ -219,8 +219,11 @@ doc_type } ; + /* We allow most otherwise reserved tokens to be used as identifiers. */ ident : IDENTIFIER { $$ = $1; } + | USER { $$ = $1; } + | GROUP { $$ = $1; } | SCHEME { $$ = $1; } | TYPE { $$ = $1; } | NAMESPACE { $$ = $1; } |