[
https://issues.apache.org/jira/browse/TINKERPOP-2999?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17778864#comment-17778864
]
ASF GitHub Bot commented on TINKERPOP-2999:
-------------------------------------------
ryn5 commented on code in PR #2297:
URL: https://github.com/apache/tinkerpop/pull/2297#discussion_r1369404179
##########
gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/GremlinGroovysh.groovy:
##########
@@ -140,4 +171,48 @@ class GremlinGroovysh extends Groovysh {
maybeRecordResult(result)
}
+
+ private Object evaluateWithStoredBoundVars(String importsSpec,
List<String> current) {
+ Object result
+ String variableBlocks = null
+ // To make groovysh behave more like an interpreter, we need to
retrieve all bound
+ // vars at the end of script execution, and then update them into the
groovysh Binding context.
+ Set<String> boundVars =
ScriptVariableAnalyzer.getBoundVars(importsSpec + Parser.NEWLINE +
current.join(Parser.NEWLINE), interp.classLoader)
+ if (boundVars) {
+ variableBlocks = "$COLLECTED_BOUND_VARS_MAP_VARNAME = new
HashMap();"
+ boundVars.each({ String varname ->
+ // bound vars can be in global or some local scope.
+ // We discard locally scoped vars by ignoring
MissingPropertyException
+ variableBlocks += """
+try {$COLLECTED_BOUND_VARS_MAP_VARNAME[\"$varname\"] = $varname;
+} catch (MissingPropertyException e){}"""
+ })
+ }
+ // Evaluate the current buffer w/imports and dummy statement
+ List<String> buff
+ if (variableBlocks) {
+ buff = [importsSpec] + ['try {', 'true'] + current + ['} finally
{' + variableBlocks + '}']
+ } else {
+ buff = [importsSpec] + ['true'] + current
+ }
+ setLastResult(result = interp.evaluate(buff))
Review Comment:
Confirmed that multiline queries are fixed for both interpreter modes
> 3.7.0 Remote Console Sends Incomplete Queries
> ---------------------------------------------
>
> Key: TINKERPOP-2999
> URL: https://issues.apache.org/jira/browse/TINKERPOP-2999
> Project: TinkerPop
> Issue Type: Bug
> Components: console
> Affects Versions: 3.7.0
> Reporter: Ken Hu
> Priority: Critical
>
> As reported by user "pdsway" on gremlin-users.
> In remote console mode the 3.7.0 Gremlin Console will send incomplete queries
> to the server causing a parsing error.
> This is caused by the upgrade to Groovy 4. That version of Groovy uses the
> newer antlr4 parser which throws errors later in execution. So even if the
> parser says the the line is COMPLETE, it could still be incomplete. We need
> to add the same try catch to the remote console's execution to make the
> handling the same as groovysh.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)