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
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]