You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by "spmallette (via GitHub)" <gi...@apache.org> on 2025/07/20 15:17:04 UTC
[PR] TINKERPOP-3040 Fixed limitation in multi-line parsing. [tinkerpop]
spmallette opened a new pull request, #3162:
URL: https://github.com/apache/tinkerpop/pull/3162
https://issues.apache.org/jira/browse/TINKERPOP-3040
Added a custom parser to help better detect multi-line inputs that does not involve actual evaluation of the input string which can result in scenarios where the script is not sent to the server.
VOTE +1
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tinkerpop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] TINKERPOP-3040 Fixed limitation in multi-line parsing. [tinkerpop]
Posted by "andreachild (via GitHub)" <gi...@apache.org>.
andreachild commented on code in PR #3162:
URL: https://github.com/apache/tinkerpop/pull/3162#discussion_r2220264073
##########
gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/RemoteParser.groovy:
##########
@@ -0,0 +1,146 @@
+/*
+ * 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.console
+
+import org.apache.groovy.groovysh.ParseCode
+import org.apache.groovy.groovysh.ParseStatus
+import org.apache.groovy.groovysh.Parsing
+import org.codehaus.groovy.control.CompilerConfiguration
+import org.codehaus.groovy.control.MultipleCompilationErrorsException
+import org.codehaus.groovy.control.messages.Message
+import org.codehaus.groovy.control.messages.SyntaxErrorMessage
+
+/**
+ * A {@link Parsing} implementation that detects if a Groovy script is complete or incomplete. This implementation uses
+ * the Groovy compiler to try to compile the script and analyzes any compilation errors to determine if the script is
+ * incomplete. It does not evaluate the script, which prevents local execution and potential local failure.
+ */
+class RemoteParser implements Parsing {
+
+ // Try to compile the script
+ def config = new CompilerConfiguration()
+
+ // Create a custom GroovyClassLoader that doesn't write class files
+ def gcl = new GroovyClassLoader(this.class.classLoader, config) {
Review Comment:
Nit: just for consistency
```suggestion
private final GroovyClassLoader gcl = new GroovyClassLoader(this.class.classLoader, config) {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tinkerpop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] TINKERPOP-3040 Fixed limitation in multi-line parsing. [tinkerpop]
Posted by "xiazcy (via GitHub)" <gi...@apache.org>.
xiazcy commented on PR #3162:
URL: https://github.com/apache/tinkerpop/pull/3162#issuecomment-3119514053
VOTE +1
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tinkerpop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] TINKERPOP-3040 Fixed limitation in multi-line parsing. [tinkerpop]
Posted by "Cole-Greer (via GitHub)" <gi...@apache.org>.
Cole-Greer merged PR #3162:
URL: https://github.com/apache/tinkerpop/pull/3162
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tinkerpop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] TINKERPOP-3040 Fixed limitation in multi-line parsing. [tinkerpop]
Posted by "andreachild (via GitHub)" <gi...@apache.org>.
andreachild commented on code in PR #3162:
URL: https://github.com/apache/tinkerpop/pull/3162#discussion_r2220263138
##########
gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/RemoteParser.groovy:
##########
@@ -0,0 +1,146 @@
+/*
+ * 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.console
+
+import org.apache.groovy.groovysh.ParseCode
+import org.apache.groovy.groovysh.ParseStatus
+import org.apache.groovy.groovysh.Parsing
+import org.codehaus.groovy.control.CompilerConfiguration
+import org.codehaus.groovy.control.MultipleCompilationErrorsException
+import org.codehaus.groovy.control.messages.Message
+import org.codehaus.groovy.control.messages.SyntaxErrorMessage
+
+/**
+ * A {@link Parsing} implementation that detects if a Groovy script is complete or incomplete. This implementation uses
+ * the Groovy compiler to try to compile the script and analyzes any compilation errors to determine if the script is
+ * incomplete. It does not evaluate the script, which prevents local execution and potential local failure.
+ */
+class RemoteParser implements Parsing {
+
+ // Try to compile the script
+ def config = new CompilerConfiguration()
Review Comment:
Nit: just for consistency
```suggestion
private final CompilerConfiguration config = new CompilerConfiguration();
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tinkerpop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] TINKERPOP-3040 Fixed limitation in multi-line parsing. [tinkerpop]
Posted by "andreachild (via GitHub)" <gi...@apache.org>.
andreachild commented on code in PR #3162:
URL: https://github.com/apache/tinkerpop/pull/3162#discussion_r2220403240
##########
gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/GremlinGroovysh.groovy:
##########
@@ -107,41 +109,10 @@ class GremlinGroovysh extends Groovysh {
String importsSpec = this.getImportStatements()
// determine if this script is complete or not - if not it's a multiline script
- def status = parser.parse([importsSpec] + current)
+ def status = remoteParser.parse([importsSpec] + current)
switch (status.code) {
case ParseCode.COMPLETE:
- if (!Boolean.valueOf(getPreference(INTERPRETER_MODE_PREFERENCE_KEY, 'false')) || isTypeOrMethodDeclaration(current)) {
- // Evaluate the current buffer w/imports and dummy statement
- List buff = [importsSpec] + [ 'true' ] + current
- try {
- interp.evaluate(buff)
- } catch(MultipleCompilationErrorsException t) {
- if (isIncompleteCaseOfAntlr4(t)) {
- // treat like INCOMPLETE case
- buffers.updateSelected(current)
- break
- }
- throw t
- } catch (MissingPropertyException mpe) {
Review Comment:
This `MissingPropertyException` handling was not ported into the new `RemoteParser`, was that intentional?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tinkerpop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] TINKERPOP-3040 Fixed limitation in multi-line parsing. [tinkerpop]
Posted by "spmallette (via GitHub)" <gi...@apache.org>.
spmallette commented on code in PR #3162:
URL: https://github.com/apache/tinkerpop/pull/3162#discussion_r2223051034
##########
gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/GremlinGroovysh.groovy:
##########
@@ -107,41 +109,10 @@ class GremlinGroovysh extends Groovysh {
String importsSpec = this.getImportStatements()
// determine if this script is complete or not - if not it's a multiline script
- def status = parser.parse([importsSpec] + current)
+ def status = remoteParser.parse([importsSpec] + current)
switch (status.code) {
case ParseCode.COMPLETE:
- if (!Boolean.valueOf(getPreference(INTERPRETER_MODE_PREFERENCE_KEY, 'false')) || isTypeOrMethodDeclaration(current)) {
Review Comment:
I sense this whole section of code i removed was all unnecessary. Note the `interpreterMode` tests are still passing so I think it's ok.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tinkerpop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] TINKERPOP-3040 Fixed limitation in multi-line parsing. [tinkerpop]
Posted by "andreachild (via GitHub)" <gi...@apache.org>.
andreachild commented on code in PR #3162:
URL: https://github.com/apache/tinkerpop/pull/3162#discussion_r2220273471
##########
gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/RemoteParser.groovy:
##########
@@ -0,0 +1,146 @@
+/*
+ * 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.console
+
+import org.apache.groovy.groovysh.ParseCode
+import org.apache.groovy.groovysh.ParseStatus
+import org.apache.groovy.groovysh.Parsing
+import org.codehaus.groovy.control.CompilerConfiguration
+import org.codehaus.groovy.control.MultipleCompilationErrorsException
+import org.codehaus.groovy.control.messages.Message
+import org.codehaus.groovy.control.messages.SyntaxErrorMessage
+
+/**
+ * A {@link Parsing} implementation that detects if a Groovy script is complete or incomplete. This implementation uses
+ * the Groovy compiler to try to compile the script and analyzes any compilation errors to determine if the script is
+ * incomplete. It does not evaluate the script, which prevents local execution and potential local failure.
+ */
+class RemoteParser implements Parsing {
Review Comment:
Nit: `RemoteParser` name to me indicates that parsing is happening remotely but the reality is the opposite. How about something like `LocalSafeParser`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tinkerpop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] TINKERPOP-3040 Fixed limitation in multi-line parsing. [tinkerpop]
Posted by "andreachild (via GitHub)" <gi...@apache.org>.
andreachild commented on code in PR #3162:
URL: https://github.com/apache/tinkerpop/pull/3162#discussion_r2220497885
##########
gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/GremlinGroovysh.groovy:
##########
@@ -107,41 +109,10 @@ class GremlinGroovysh extends Groovysh {
String importsSpec = this.getImportStatements()
// determine if this script is complete or not - if not it's a multiline script
- def status = parser.parse([importsSpec] + current)
+ def status = remoteParser.parse([importsSpec] + current)
switch (status.code) {
case ParseCode.COMPLETE:
- if (!Boolean.valueOf(getPreference(INTERPRETER_MODE_PREFERENCE_KEY, 'false')) || isTypeOrMethodDeclaration(current)) {
Review Comment:
Does `interpretorMode` no longer need to be specifically handled with the new `RemoteParser`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tinkerpop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] TINKERPOP-3040 Fixed limitation in multi-line parsing. [tinkerpop]
Posted by "spmallette (via GitHub)" <gi...@apache.org>.
spmallette commented on code in PR #3162:
URL: https://github.com/apache/tinkerpop/pull/3162#discussion_r2220548643
##########
gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/GremlinGroovysh.groovy:
##########
@@ -107,41 +109,10 @@ class GremlinGroovysh extends Groovysh {
String importsSpec = this.getImportStatements()
// determine if this script is complete or not - if not it's a multiline script
- def status = parser.parse([importsSpec] + current)
+ def status = remoteParser.parse([importsSpec] + current)
switch (status.code) {
case ParseCode.COMPLETE:
- if (!Boolean.valueOf(getPreference(INTERPRETER_MODE_PREFERENCE_KEY, 'false')) || isTypeOrMethodDeclaration(current)) {
- // Evaluate the current buffer w/imports and dummy statement
- List buff = [importsSpec] + [ 'true' ] + current
- try {
- interp.evaluate(buff)
- } catch(MultipleCompilationErrorsException t) {
- if (isIncompleteCaseOfAntlr4(t)) {
- // treat like INCOMPLETE case
- buffers.updateSelected(current)
- break
- }
- throw t
- } catch (MissingPropertyException mpe) {
Review Comment:
you can't have a `MissingPropertyException` anymore because this change stops doing a local evaluation of the code in the interpreter. now it just parses for correctness in the script itself.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tinkerpop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org