Skip to content
This repository was archived by the owner on Jul 6, 2023. It is now read-only.

Commit a20f991

Browse files
Add parboiled fallback when parsing parameters
1 parent 7757e22 commit a20f991

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

cypher-shell/build.gradle

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,25 @@ distributions {
3737

3838
dependencies {
3939
compile "net.sourceforge.argparse4j:argparse4j:$argparse4jVersion"
40+
compile("org.neo4j:neo4j-cypher-expression-evaluator:$evaluatorVersion") {
41+
exclude(group: 'org.apache.lucene')
42+
exclude(group: 'org.neo4j', module: 'neo4j-index')
43+
exclude(group: 'org.neo4j', module: 'neo4j-lucene-upgrade')
44+
exclude(group: 'org.neo4j', module: 'neo4j-ssl')
45+
exclude(group: 'org.neo4j', module: 'neo4j-graph-algo')
46+
exclude(group: 'org.neo4j', module: 'neo4j-io')
47+
exclude(group: 'org.neo4j', module: 'neo4j-csv')
48+
exclude(group: 'org.neo4j', module: 'neo4j-configuration')
49+
exclude(group: 'org.neo4j', module: 'neo4j-collections')
50+
exclude(group: 'org.neo4j', module: 'neo4j-diagnostics')
51+
exclude(group: 'org.neo4j', module: 'neo4j-resource')
52+
exclude(group: 'org.neo4j', module: 'neo4j-annotation-processors')
53+
exclude(group: 'org.neo4j', module: 'neo4j-spatial-index')
54+
exclude(group: 'org.neo4j', module: 'neo4j-native')
55+
exclude(group: 'org.neo4j', module: 'neo4j-logging')
56+
exclude(group: 'org.neo4j', module: 'neo4j-procedure-api')
57+
exclude(group: 'org.eclipse.collections')
58+
}
4059
compile("org.neo4j:neo4j-cypher-javacc-parser:$evaluatorVersion")
4160
compile "org.neo4j.driver:neo4j-java-driver:$neo4jJavaDriverVersion"
4261
compileOnly "com.google.code.findbugs:annotations:$findbugsVersion"

cypher-shell/src/main/java/org/neo4j/shell/ShellParameterMap.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import javax.annotation.Nonnull;
88

99
import org.neo4j.cypher.internal.ast.factory.LiteralInterpreter;
10+
import org.neo4j.cypher.internal.evaluator.EvaluationException;
11+
import org.neo4j.cypher.internal.evaluator.Evaluator;
12+
import org.neo4j.cypher.internal.evaluator.ExpressionEvaluator;
1013
import org.neo4j.cypher.internal.parser.javacc.Cypher;
1114
import org.neo4j.cypher.internal.parser.javacc.ParseException;
1215
import org.neo4j.shell.exception.ParameterException;
@@ -20,6 +23,8 @@ public class ShellParameterMap implements ParameterMap
2023
{
2124
private final Map<String, ParamValue> queryParams = new HashMap<>();
2225
private LiteralInterpreter interpreter = new LiteralInterpreter();
26+
private ExpressionEvaluator evaluator = Evaluator.expressionEvaluator();
27+
2328

2429
@Override
2530
public Object setParameter( @Nonnull String name, @Nonnull String valueString ) throws ParameterException
@@ -28,11 +33,17 @@ public Object setParameter( @Nonnull String name, @Nonnull String valueString )
2833
try {
2934
Object value = new Cypher<>( interpreter,
3035
ParameterException.FACTORY,
31-
new StringReader( valueString ) ).Literal();
36+
new StringReader( valueString ) ).Expression();
3237
queryParams.put( parameterName, new ParamValue( valueString, value ) );
3338
return value;
34-
} catch (ParseException e) {
35-
throw new ParameterException(e.getMessage());
39+
} catch (ParseException | UnsupportedOperationException e) {
40+
try {
41+
Object value = evaluator.evaluate( valueString, Object.class );
42+
queryParams.put( parameterName, new ParamValue( valueString, value ) );
43+
return value;
44+
} catch (EvaluationException e1) {
45+
throw new ParameterException( e1.getMessage() );
46+
}
3647
}
3748
}
3849

0 commit comments

Comments
 (0)