You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2022/08/17 12:29:44 UTC
[tinkerpop] 01/03: Fixed bug in grammar for handling empty queries.
This is an automated email from the ASF dual-hosted git repository.
spmallette pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
commit 7b02a28d10ce8568b3d5a5dae05e6679b612ae63
Author: Stephen Mallette <st...@amazon.com>
AuthorDate: Wed Aug 17 08:23:21 2022 -0400
Fixed bug in grammar for handling empty queries.
This worked in 3.5.x, but broke after some refactoring for 3.6.0 CTR
---
CHANGELOG.asciidoc | 2 +-
.../language/grammar/GremlinQueryParserTest.java | 32 ++++++++++++++++++++++
gremlin-language/src/main/antlr4/Gremlin.g4 | 13 ++++-----
3 files changed, 38 insertions(+), 9 deletions(-)
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 5cc05c61c0..88565a0925 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -25,7 +25,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
This release also includes changes from <<release-3-5-5, 3.5.5>>.
-
+* Fixed bug in the Gremlin grammar for parsing of empty queries.
[[release-3-6-1]]
=== TinkerPop 3.6.1 (Release Date: July 18, 2022)
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/GremlinQueryParserTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/GremlinQueryParserTest.java
new file mode 100644
index 0000000000..b9d600dda8
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/GremlinQueryParserTest.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.language.grammar;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class GremlinQueryParserTest {
+
+ @Test
+ public void shouldParseEmpty() {
+ assertEquals("", GremlinQueryParser.parse("\"\""));
+ assertEquals("", GremlinQueryParser.parse("''"));
+ }
+}
diff --git a/gremlin-language/src/main/antlr4/Gremlin.g4 b/gremlin-language/src/main/antlr4/Gremlin.g4
index 495e318e53..33a94d4248 100644
--- a/gremlin-language/src/main/antlr4/Gremlin.g4
+++ b/gremlin-language/src/main/antlr4/Gremlin.g4
@@ -1348,7 +1348,7 @@ genericLiteralExpr
genericLiteralRange
: integerLiteral DOT DOT integerLiteral
- | StringLiteral DOT DOT StringLiteral
+ | stringLiteral DOT DOT stringLiteral
;
genericLiteralCollection
@@ -1400,7 +1400,8 @@ mapEntry
;
stringLiteral
- : StringLiteral
+ : EmptyStringLiteral
+ | NonEmptyStringLiteral
;
integerLiteral
@@ -1421,7 +1422,8 @@ booleanLiteral
;
stringBasedLiteral
- : StringLiteral
+ : EmptyStringLiteral
+ | NonEmptyStringLiteral
| NullLiteral
| gremlinStringConstants
;
@@ -1641,11 +1643,6 @@ InfLiteral
// String Literals
-StringLiteral
- : NonEmptyStringLiteral
- | EmptyStringLiteral
- ;
-
// String literal is customized since Java only allows double quoted strings where Groovy supports single quoted
// literals also. A side effect of this is ANTLR will not be able to parse single character string literals with
// single quoted so we instead remove char literal altogether and only have string literal in lexer tokens.