Cole Greer created TINKERPOP-3126:
-------------------------------------
Summary: GremlinLang Variables subject to name collisions
Key: TINKERPOP-3126
URL: https://issues.apache.org/jira/browse/TINKERPOP-3126
Project: TinkerPop
Issue Type: Improvement
Components: language
Affects Versions: 3.7.3
Reporter: Cole Greer
The antlr grammar is currently unable to parse scripts with variable names
which match existing tokens in the grammar. This includes step names (id,
label, V, map, values...), enum values (key, value, global, list...), and other
miscellaneous names such as WithOptions (ids, labels, keys, values).
Currently a script such as "g.V().hasLabel(labels).count()" will fail to parse
with the following exception:
{noformat}
javax.script.ScriptException:
org.apache.tinkerpop.gremlin.language.grammar.GremlinParserException: Failed to
interpret Gremlin query: Query parsing failed at line 1, character position at
15, error message : no viable alternative at input 'g.V().hasLabel(labels'
at
org.apache.tinkerpop.gremlin.jsr223.GremlinLangScriptEngine.eval(GremlinLangScriptEngine.java:107)
at
java.scripting/javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:233)
at
org.apache.tinkerpop.gremlin.jsr223.GremlinLangScriptEngineTest.shouldEvalGremlinScriptWithParameters(GremlinLangScriptEngineTest.java:75)
at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at
org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at
com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
at
com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
at
com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
at
com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)
Caused by:
org.apache.tinkerpop.gremlin.language.grammar.GremlinParserException: Failed to
interpret Gremlin query: Query parsing failed at line 1, character position at
15, error message : no viable alternative at input 'g.V().hasLabel(labels'
at
org.apache.tinkerpop.gremlin.language.grammar.GremlinQueryParser.parse(GremlinQueryParser.java:80)
at
org.apache.tinkerpop.gremlin.jsr223.GremlinLangScriptEngine.eval(GremlinLangScriptEngine.java:105)
... 29 more
{noformat}
Ideally variables should have a completely distinct namespace and users should
be allowed to use any legal identifier as a variable name.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)