You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2021/07/20 18:57:35 UTC
[tinkerpop] 01/01: TINKERPOP-2582 wip
This is an automated email from the ASF dual-hosted git repository.
spmallette pushed a commit to branch TINKERPOP-2582
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
commit 041afc7119d82c370fec9b48160ebe9f8527d47d
Author: Stephen Mallette <st...@amazon.com>
AuthorDate: Tue Jul 20 14:56:57 2021 -0400
TINKERPOP-2582 wip
---
gremlin-core/pom.xml | 5 +
.../language/grammar/GenericLiteralVisitor.java | 494 ++++++
.../grammar/GraphTraversalSourceVisitor.java | 61 +
.../language/grammar/GremlinAntlrToJava.java | 147 ++
.../language/grammar/GremlinBaseVisitor.java | 1410 ++++++++++++++++
.../language/grammar/GremlinErrorListener.java | 36 +
.../language/grammar/GremlinParserException.java | 45 +
.../language/grammar/GremlinQueryParser.java | 85 +
.../grammar/GremlinStringConstantsVisitor.java | 172 ++
.../grammar/NestedTraversalSourceListVisitor.java | 67 +
.../language/grammar/NoOpTerminalVisitor.java | 79 +
.../grammar/ParseTreeContextCastHelper.java | 47 +
.../grammar/TerminalMethodToBytecodeVisitor.java | 141 ++
.../language/grammar/TraversalEnumParser.java | 57 +
.../language/grammar/TraversalFunctionVisitor.java | 66 +
.../language/grammar/TraversalMethodVisitor.java | 1695 ++++++++++++++++++++
.../grammar/TraversalPredicateVisitor.java | 256 +++
.../language/grammar/TraversalRootVisitor.java | 139 ++
.../grammar/TraversalSourceSelfMethodVisitor.java | 152 ++
.../grammar/TraversalSourceSpawnMethodVisitor.java | 124 ++
.../language/grammar/TraversalStrategyVisitor.java | 146 ++
.../grammar/TraversalTerminalMethodVisitor.java | 140 ++
.../grammar/ComplexTraversalMethodVisitorTest.java | 150 ++
.../grammar/GeneralLiteralVisitorTest.java | 561 +++++++
.../grammar/GraphTraversalSourceVisitorTest.java | 74 +
.../language/grammar/TraversalEnumParserTest.java | 113 ++
.../grammar/TraversalMethodVisitorTest.java | 1099 +++++++++++++
.../grammar/TraversalPredicateVisitorTest.java | 101 ++
.../language/grammar/TraversalRootVisitorTest.java | 59 +
.../TraversalSourceSelfMethodVisitorTest.java | 84 +
.../grammar/TraversalSourceSpawnVisitorTest.java | 61 +
.../grammar/TraversalStrategyVisitorTest.java | 87 +
.../gremlin-javascript/package-lock.json | 22 +-
33 files changed, 7964 insertions(+), 11 deletions(-)
diff --git a/gremlin-core/pom.xml b/gremlin-core/pom.xml
index 0c359f6..b4e76ad 100644
--- a/gremlin-core/pom.xml
+++ b/gremlin-core/pom.xml
@@ -31,6 +31,11 @@ limitations under the License.
<version>${project.version}</version>
</dependency>
<dependency>
+ <groupId>org.apache.tinkerpop</groupId>
+ <artifactId>gremlin-language</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-configuration2</artifactId>
</dependency>
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/GenericLiteralVisitor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/GenericLiteralVisitor.java
new file mode 100644
index 0000000..07ba642
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/GenericLiteralVisitor.java
@@ -0,0 +1,494 @@
+/*
+ * 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.language.grammar;
+
+import org.antlr.v4.runtime.tree.ParseTree;
+import org.apache.commons.text.StringEscapeUtils;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalOptionParent;
+import org.apache.tinkerpop.gremlin.structure.Direction;
+import org.apache.tinkerpop.gremlin.structure.T;
+import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Visitor class to handle generic literal. All visitor methods return type is Object. It maybe used as a singleton
+ * in cases where a {@link Traversal} object is not expected, otherwise a new instance must be constructed.
+ */
+public class GenericLiteralVisitor extends GremlinBaseVisitor<Object> {
+ /**
+ * Limit for integer range result count. It is used to avoid OOM in JVM.
+ */
+ public static final int TOTAL_INTEGER_RANGE_RESULT_COUNT_LIMIT = 1_000_000;
+ protected final GremlinAntlrToJava antlr;
+ protected GremlinBaseVisitor<TraversalStrategy> traversalStrategyVisitor;
+
+ private static GenericLiteralVisitor instance;
+
+ private GenericLiteralVisitor() {
+ this.antlr = null;
+ }
+
+ public GenericLiteralVisitor(final GremlinAntlrToJava antlr) {
+ this.antlr = antlr;
+ }
+
+ public static GenericLiteralVisitor getInstance() {
+ if (instance == null) {
+ instance = new GenericLiteralVisitor();
+ }
+
+ return instance;
+ }
+
+ /**
+ * Parse a string literal context and return the string literal
+ */
+ public static String getStringLiteral(final GremlinParser.StringLiteralContext stringLiteral) {
+ return (String) (getInstance().visitStringLiteral(stringLiteral));
+ }
+
+ /**
+ * Parse a boolean literal context and return the boolean literal
+ */
+ public static boolean getBooleanLiteral(final GremlinParser.BooleanLiteralContext booleanLiteral) {
+ return (boolean) (getInstance().visitBooleanLiteral(booleanLiteral));
+ }
+
+ /**
+ * Parse a String literal list context and return a string array
+ */
+ public static String[] getStringLiteralList(final GremlinParser.StringLiteralListContext stringLiteralList) {
+ if (stringLiteralList == null || stringLiteralList.stringLiteralExpr() == null) {
+ return new String[0];
+ }
+ return stringLiteralList.stringLiteralExpr().stringLiteral()
+ .stream()
+ .filter(Objects::nonNull)
+ .map(stringLiteral -> getInstance().visitStringLiteral(stringLiteral))
+ .toArray(String[]::new);
+ }
+
+ /**
+ * Parse a generic literal list, and return an object array
+ */
+ public static Object[] getGenericLiteralList(final GremlinParser.GenericLiteralListContext objectLiteralList) {
+ if (objectLiteralList == null || objectLiteralList.genericLiteralExpr() == null) {
+ return new Object[0];
+ }
+ return objectLiteralList.genericLiteralExpr().genericLiteral()
+ .stream()
+ .filter(Objects::nonNull)
+ .map(genericLiteral -> getInstance().visitGenericLiteral(genericLiteral))
+ .toArray(Object[]::new);
+ }
+
+ /**
+ * Parse a TraversalStrategy literal list context and return a string array
+ */
+ public static TraversalStrategy[] getTraversalStrategyList(final GremlinParser.TraversalStrategyListContext traversalStrategyListContext,
+ final GremlinBaseVisitor<TraversalStrategy> traversalStrategyVisitor) {
+ if (traversalStrategyListContext == null || traversalStrategyListContext.traversalStrategyExpr() == null) {
+ return new TraversalStrategy[0];
+ }
+ return traversalStrategyListContext.traversalStrategyExpr().traversalStrategy()
+ .stream()
+ .filter(Objects::nonNull)
+ .map(tstrat -> traversalStrategyVisitor.visitTraversalStrategy(tstrat))
+ .toArray(TraversalStrategy[]::new);
+ }
+
+ /**
+ * Remove single/double quotes around String literal
+ *
+ * @param quotedString : quoted string
+ * @return quotes stripped string
+ */
+ private static String stripQuotes(final String quotedString) {
+ return quotedString.substring(1, quotedString.length() - 1);
+ }
+
+ /**
+ * create an integer range from start to end, based on groovy syntax
+ * http://groovy-lang.org/operators.html#_range_operator
+ *
+ * @param start : start of range
+ * @param end : end of range
+ * @param range : original range string, for error message
+ * @return : return an object which is type of array of object, and each object is a Integer inside the range.
+ */
+ private static Object createIntegerRange(final int start, final int end, final String range) {
+ final List<Object> results = new ArrayList<>();
+ int total_result_count = Math.abs(start - end);
+
+ // validate result count not exceeding limit
+ if (total_result_count > TOTAL_INTEGER_RANGE_RESULT_COUNT_LIMIT) {
+ throw new IllegalArgumentException("Range " + range + " is too wide. Current limit is " + TOTAL_INTEGER_RANGE_RESULT_COUNT_LIMIT + " items");
+ }
+
+ if (start <= end) {
+ // handle start <= end
+ int cur = start;
+ while (cur <= end) {
+ results.add(cur);
+ cur++;
+ }
+ } else {
+ // handle start > end
+ int cur = start;
+ while (cur >= end) {
+ results.add(cur);
+ cur--;
+ }
+ }
+
+ return results;
+ }
+
+ /**
+ * create a string range from start to end, based on groovy syntax
+ * http://groovy-lang.org/operators.html#_range_operator
+ * The start and end needs to have same length and share same prefix except the last character.
+ *
+ * @param start : start of range
+ * @param end : end of range
+ * @param range : original range string, for error message
+ * @return : return an object which is type of array of object, and each object is a String inside the range.
+ */
+ private static Object createStringRange(final String start, final String end, final String range) {
+ final List<Object> results = new ArrayList<>();
+
+ // verify lengths of start and end are same.
+ if (start.length() != end.length()) {
+ throw new IllegalArgumentException("The start and end of Range " + range + " does not have same number of characters");
+ }
+
+ if (start.isEmpty()) {
+ // return empty result for empty string ranges
+ return results;
+ }
+
+ // verify start and end share same prefix
+ final String commonPrefix = start.substring(0, start.length() - 1);
+ if (!end.startsWith(commonPrefix)) {
+ throw new IllegalArgumentException("The start and end of Range " + range +
+ " does not share same prefix until the last character");
+ }
+
+ final char startLastCharacter = start.charAt(start.length() - 1);
+ final char endLastCharacter = end.charAt(end.length() - 1);
+
+ if (startLastCharacter <= endLastCharacter) {
+ // handle start <= end
+ char cur = startLastCharacter;
+ while (cur <= endLastCharacter) {
+ results.add(commonPrefix + cur);
+ cur++;
+ }
+ } else {
+ // handle start > end
+ char cur = startLastCharacter;
+ while (cur >= endLastCharacter) {
+ results.add(commonPrefix + cur);
+ cur--;
+ }
+ }
+
+ return results;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object visitGenericLiteralList(final GremlinParser.GenericLiteralListContext ctx) {
+ return visitChildren(ctx);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object visitGenericLiteralExpr(final GremlinParser.GenericLiteralExprContext ctx) {
+ final int childCount = ctx.getChildCount();
+ switch (childCount) {
+ case 0:
+ // handle empty expression
+ return new Object[0];
+ case 1:
+ // handle single generic literal
+ return visitGenericLiteral((GremlinParser.GenericLiteralContext) ctx.getChild(0));
+ default:
+ // handle multiple generic literal separated by comma
+ final List<Object> genericLiterals = new ArrayList<>();
+ int childIndex = 0;
+ while (childIndex < ctx.getChildCount()) {
+ genericLiterals.add(visitGenericLiteral(
+ (GremlinParser.GenericLiteralContext) ctx.getChild(childIndex)));
+ // skip comma
+ childIndex += 2;
+ }
+ return genericLiterals.toArray();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object visitGenericLiteral(final GremlinParser.GenericLiteralContext ctx) {
+ return visitChildren(ctx);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object visitGenericLiteralMap(final GremlinParser.GenericLiteralMapContext ctx) {
+ final HashMap<Object, Object> literalMap = new HashMap<>();
+ int childIndex = 1;
+ while (childIndex < ctx.getChildCount() && ctx.getChildCount() > 3) {
+ Object key = visitGenericLiteral((GremlinParser.GenericLiteralContext) ctx.getChild(childIndex));
+ // skip colon
+ childIndex += 2;
+ Object value = visitGenericLiteral((GremlinParser.GenericLiteralContext) ctx.getChild(childIndex));
+ literalMap.put(key, value);
+ // skip comma
+ childIndex += 2;
+ }
+ return literalMap;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object visitNestedTraversal(final GremlinParser.NestedTraversalContext ctx) {
+ return antlr.tvisitor.visitNestedTraversal(ctx);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object visitTerminatedTraversal(final GremlinParser.TerminatedTraversalContext ctx) {
+ final Traversal traversal = antlr.tvisitor.visitRootTraversal(
+ (GremlinParser.RootTraversalContext) ctx.getChild(0));
+ return new TraversalTerminalMethodVisitor(traversal).visitTraversalTerminalMethod(
+ (GremlinParser.TraversalTerminalMethodContext) ctx.getChild(2));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object visitIntegerLiteral(final GremlinParser.IntegerLiteralContext ctx) {
+ String integerLiteral = ctx.getText().toLowerCase().replace("_", "");
+ // handle suffix: L/l
+ final int lastCharIndex = integerLiteral.length() - 1;
+ if (integerLiteral.charAt(lastCharIndex) == 'l') {
+ integerLiteral = integerLiteral.substring(0, lastCharIndex);
+
+ return Long.decode(integerLiteral);
+ }
+
+ try {
+ // try to parse it as integer first
+ return Integer.decode(integerLiteral);
+ } catch (NumberFormatException ignoredExpection1) {
+ try {
+ // If range exceeds integer limit, try to parse it as long
+ return Long.decode(integerLiteral);
+ } catch (NumberFormatException ignoredExpection2) {
+ // If range exceeds Long limit, parse it as BigInteger
+ // as the literal range is longer than long, the number of character should be much more than 3,
+ // so we skip boundary check below.
+
+ // parse sign character
+ int startIndex = 0;
+ final char firstChar = integerLiteral.charAt(0);
+ final boolean negative = (firstChar == '-');
+ if ((firstChar == '-') || (firstChar == '+')) {
+ startIndex++;
+ }
+
+ // parse radix based on format
+ int radix = 10;
+ if (integerLiteral.charAt(startIndex + 1) == 'x') {
+ radix = 16;
+ startIndex += 2;
+ integerLiteral = integerLiteral.substring(startIndex);
+ if (negative) {
+ integerLiteral = '-' + integerLiteral;
+ }
+ } else if (integerLiteral.charAt(startIndex) == '0') {
+ radix = 8;
+ }
+
+ // create big integer
+ return new BigInteger(integerLiteral, radix);
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object visitFloatLiteral(final GremlinParser.FloatLiteralContext ctx) {
+ final String floatLiteral = ctx.getText().toLowerCase();
+
+ // check suffix
+ final char lastCharacter = floatLiteral.charAt(floatLiteral.length() - 1);
+ if (Character.isDigit(lastCharacter)) {
+ // if there is no suffix, parse it as BigDecimal
+ return new BigDecimal(floatLiteral);
+ }
+
+ if (lastCharacter == 'f') {
+ // parse F/f suffix as Float
+ return new Float(ctx.getText());
+ } else {
+ // parse D/d suffix as Double
+ return new Double(floatLiteral);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object visitBooleanLiteral(final GremlinParser.BooleanLiteralContext ctx) {
+ return Boolean.valueOf(ctx.getText());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object visitStringLiteral(final GremlinParser.StringLiteralContext ctx) {
+ // Using Java string unescaping because it coincides with the Groovy rules:
+ // https://docs.oracle.com/javase/tutorial/java/data/characters.html
+ // http://groovy-lang.org/syntax.html#_escaping_special_characters
+ if (ctx.gremlinStringConstants() != null) {
+ return GremlinStringConstantsVisitor.getInstance().visitChildren(ctx);
+ }
+ return StringEscapeUtils.unescapeJava(stripQuotes(ctx.getText()));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object visitTraversalToken(final GremlinParser.TraversalTokenContext ctx) {
+ return TraversalEnumParser.parseTraversalEnumFromContext(T.class, ctx);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object visitTraversalCardinality(final GremlinParser.TraversalCardinalityContext ctx) {
+ return TraversalEnumParser.parseTraversalEnumFromContext(VertexProperty.Cardinality.class, ctx);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object visitTraversalDirection(final GremlinParser.TraversalDirectionContext ctx) {
+ return TraversalEnumParser.parseTraversalEnumFromContext(Direction.class, ctx);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object visitTraversalOptionParent(final GremlinParser.TraversalOptionParentContext ctx) {
+ return TraversalEnumParser.parseTraversalEnumFromContext(TraversalOptionParent.Pick.class, ctx);
+ }
+
+ @Override
+ public Object visitTraversalStrategy(final GremlinParser.TraversalStrategyContext ctx) {
+ if (null == traversalStrategyVisitor)
+ traversalStrategyVisitor = new TraversalStrategyVisitor((GremlinBaseVisitor) antlr.tvisitor);
+
+ return traversalStrategyVisitor.visitTraversalStrategy(ctx);
+ }
+
+ /**
+ * Groovy range operator syntax is defined in http://groovy-lang.org/operators.html#_range_operator
+ * {@inheritDoc}
+ */
+ @Override
+ public Object visitGenericLiteralRange(final GremlinParser.GenericLiteralRangeContext ctx) {
+ final int childIndexOfParameterStart = 0;
+ final int childIndexOfParameterEnd = 3;
+ final ParseTree startContext = ctx.getChild(childIndexOfParameterStart);
+ final ParseTree endContext = ctx.getChild(childIndexOfParameterEnd);
+
+ if (startContext instanceof GremlinParser.IntegerLiteralContext) {
+ // handle integer ranges.
+ final int start = Integer.valueOf(startContext.getText());
+ final int end = Integer.valueOf(endContext.getText());
+ return createIntegerRange(start, end, ctx.getText());
+ } else {
+ // handle string ranges.
+ final String start = stripQuotes(startContext.getText());
+ final String end = stripQuotes(endContext.getText());
+ return createStringRange(start, end, ctx.getText());
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object visitNullLiteral(final GremlinParser.NullLiteralContext ctx) {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ * Generic literal collection returns a list of Object
+ */
+ @Override
+ public Object visitGenericLiteralCollection(final GremlinParser.GenericLiteralCollectionContext ctx) {
+ final List<Object> result = new ArrayList<>(ctx.getChildCount() / 2);
+ // first child is "[", so start from 2nd child
+ int childIndex = 1;
+ final int childCount = ctx.getChildCount();
+ if (childCount > 2) {
+ while (childIndex < childCount) {
+ result.add(visitGenericLiteral((GremlinParser.GenericLiteralContext) ctx.getChild(childIndex)));
+ // comma is also child, so we need skip it.
+ childIndex += 2;
+ }
+ }
+ return result;
+ }
+
+}
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/GraphTraversalSourceVisitor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/GraphTraversalSourceVisitor.java
new file mode 100644
index 0000000..be36136
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/GraphTraversalSourceVisitor.java
@@ -0,0 +1,61 @@
+/*
+ * 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.language.grammar;
+
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+
+/**
+ * This class implements the GraphTraversalSource producing methods of Gremlin grammar.
+ */
+public class GraphTraversalSourceVisitor extends GremlinBaseVisitor<GraphTraversalSource> {
+ public static final String TRAVERSAL_ROOT = "g";
+ private final Graph graph;
+ private final GremlinAntlrToJava antlr;
+
+ public GraphTraversalSourceVisitor(final GremlinAntlrToJava antlr) {
+ this.graph = antlr.graph;
+ this.antlr = antlr;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversalSource visitTraversalSource(final GremlinParser.TraversalSourceContext ctx) {
+ if (ctx.getChildCount() == 1) {
+ // handle source method only
+ return graph.traversal();
+ } else {
+ final int childIndexOfSelfMethod = 2;
+ GraphTraversalSource source;
+ if (ctx.getChild(0).getText().equals(TRAVERSAL_ROOT)) {
+ // handle single traversal source
+ source = graph.traversal();
+ } else {
+ // handle chained self method
+ final int childIndexOfTraversalSource = 0;
+ source = visitTraversalSource(
+ (GremlinParser.TraversalSourceContext) ctx.getChild(childIndexOfTraversalSource));
+ }
+ return new TraversalSourceSelfMethodVisitor(source, antlr).visitTraversalSourceSelfMethod(
+ (GremlinParser.TraversalSourceSelfMethodContext) (ctx.getChild(childIndexOfSelfMethod)));
+ }
+ }
+}
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/GremlinAntlrToJava.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/GremlinAntlrToJava.java
new file mode 100644
index 0000000..7629a41
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/GremlinAntlrToJava.java
@@ -0,0 +1,147 @@
+/*
+ * 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.language.grammar;
+
+import org.antlr.v4.runtime.tree.ParseTree;
+import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph;
+
+import java.util.function.Supplier;
+
+/**
+ * This is the entry point for converting the Gremlin Antlr grammar into Java. It is bound to a {@link Graph} instance
+ * as that instance may spawn specific {@link Traversal} or {@link TraversalSource} types. A new instance should be
+ * created for each parse execution.
+ */
+public class GremlinAntlrToJava extends GremlinBaseVisitor<Object> {
+
+ /**
+ * The {@link Graph} instance to which this instance is bound.
+ */
+ final Graph graph;
+
+ /**
+ * A {@link GremlinBaseVisitor} that processes {@link TraversalSource} methods.
+ */
+ final GremlinBaseVisitor<GraphTraversalSource> gvisitor;
+
+ /**
+ * A {@link GremlinBaseVisitor} that processes {@link Traversal} methods and is meant to construct traversals
+ * anonymously.
+ */
+ final GremlinBaseVisitor<GraphTraversal> tvisitor;
+
+ final GremlinBaseVisitor<Traversal[]> anonymousListVisitor;
+
+ final Supplier<GraphTraversal> createAnonymous;
+
+ /**
+ * Constructs a new instance and is bound to an {@link EmptyGraph}. This form of construction is helpful for
+ * generating {@link Bytecode} or for various forms of testing. {@link Traversal} instances constructed from this
+ * form will not be capable of iterating.
+ */
+ public GremlinAntlrToJava() {
+ this(EmptyGraph.instance());
+ }
+
+ /**
+ * Constructs a new instance that is bound to the specified {@link Graph} instance.
+ */
+ public GremlinAntlrToJava(final Graph graph) {
+ this(graph, __::start);
+ }
+
+ /**
+ * Constructs a new instance that is bound to the specified {@link Graph} instance with an override to using
+ * {@link __} for constructing anonymous {@link Traversal} instances.
+ */
+ protected GremlinAntlrToJava(final Graph graph, final Supplier<GraphTraversal> createAnonymous) {
+ this.graph = graph;
+ this.gvisitor = new GraphTraversalSourceVisitor(this);
+ this.tvisitor = new TraversalRootVisitor(this);
+ this.anonymousListVisitor = new NestedTraversalSourceListVisitor(this);
+ this.createAnonymous = createAnonymous;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object visitQuery(final GremlinParser.QueryContext ctx) {
+ final int childCount = ctx.getChildCount();
+ if (childCount <= 3) {
+ final ParseTree firstChild = ctx.getChild(0);
+ if (firstChild instanceof GremlinParser.TraversalSourceContext) {
+ if (childCount == 1) {
+ // handle traversalSource
+ return gvisitor.visitTraversalSource((GremlinParser.TraversalSourceContext) firstChild);
+ } else {
+ // handle traversalSource DOT transactionPart
+ throw new GremlinParserException("Transaction operation is not supported yet");
+ }
+ } else if (firstChild instanceof GremlinParser.EmptyQueryContext) {
+ // handle empty query
+ return "";
+ } else {
+ if (childCount == 1) {
+ // handle rootTraversal
+ return tvisitor.visitRootTraversal(
+ (GremlinParser.RootTraversalContext) firstChild);
+ } else {
+ // handle rootTraversal DOT traversalTerminalMethod
+ return new TraversalTerminalMethodVisitor(tvisitor.visitRootTraversal(
+ (GremlinParser.RootTraversalContext) firstChild)).visitTraversalTerminalMethod(
+ (GremlinParser.TraversalTerminalMethodContext)ctx.getChild(2));
+ }
+ }
+ } else {
+ // handle toString
+ return String.valueOf(visitChildren(ctx));
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public Object visitQueryList(final GremlinParser.QueryListContext ctx) {
+ return visitChildren(ctx);
+ }
+
+ /**
+ * Override the aggregate result behavior.
+ * If the next Result is null, return the current result.
+ * This is used to handle child EOF, which is the last child of the QueryList context.
+ * If the next Result is not null, return the next result.
+ * This is used to handle multiple queries, and return only the last query result logic.
+ */
+ @Override
+ protected Object aggregateResult(final Object result, final Object nextResult) {
+ if (nextResult == null) {
+ return result;
+ } else {
+ return nextResult;
+ }
+ }
+}
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/GremlinBaseVisitor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/GremlinBaseVisitor.java
new file mode 100644
index 0000000..3324142
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/GremlinBaseVisitor.java
@@ -0,0 +1,1410 @@
+/*
+ * 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.language.grammar;
+
+import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
+import org.antlr.v4.runtime.tree.ParseTree;
+
+/**
+ * This class provides implementation of {@link GremlinVisitor}, where each method will throw
+ * {@code UnsupportedOperationException}. All the visitor class will extends this class, so that if there is method
+ * that are not manually implemented, and called, an exception will be thrown to help us catch bugs.
+ *
+ * @param <T> The return type of the visit operation. Use {@link Void} for
+ * operations with no return type.
+ */
+public class GremlinBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements GremlinVisitor<T> {
+ private void notImplemented(ParseTree ctx) {
+ final String className = (ctx != null)? ctx.getClass().getName() : "";
+ throw new UnsupportedOperationException("Method not implemented for context class " + className);
+ }
+
+ @Override public T visitQueryList(final GremlinParser.QueryListContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitQuery(final GremlinParser.QueryContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitEmptyQuery(final GremlinParser.EmptyQueryContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalSource(final GremlinParser.TraversalSourceContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTransactionPart(final GremlinParser.TransactionPartContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitRootTraversal(final GremlinParser.RootTraversalContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalSourceSelfMethod(final GremlinParser.TraversalSourceSelfMethodContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalSourceSelfMethod_withBulk(final GremlinParser.TraversalSourceSelfMethod_withBulkContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalSourceSelfMethod_withPath(final GremlinParser.TraversalSourceSelfMethod_withPathContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalSourceSelfMethod_withSack(final GremlinParser.TraversalSourceSelfMethod_withSackContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalSourceSelfMethod_withSideEffect(final GremlinParser.TraversalSourceSelfMethod_withSideEffectContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalSourceSelfMethod_withStrategies(final GremlinParser.TraversalSourceSelfMethod_withStrategiesContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalSourceSelfMethod_with(final GremlinParser.TraversalSourceSelfMethod_withContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalSourceSpawnMethod(final GremlinParser.TraversalSourceSpawnMethodContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalSourceSpawnMethod_addE(final GremlinParser.TraversalSourceSpawnMethod_addEContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalSourceSpawnMethod_addV(final GremlinParser.TraversalSourceSpawnMethod_addVContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalSourceSpawnMethod_E(final GremlinParser.TraversalSourceSpawnMethod_EContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalSourceSpawnMethod_V(final GremlinParser.TraversalSourceSpawnMethod_VContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitTraversalSourceSpawnMethod_inject(final GremlinParser.TraversalSourceSpawnMethod_injectContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitTraversalSourceSpawnMethod_io(final GremlinParser.TraversalSourceSpawnMethod_ioContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitChainedTraversal(final GremlinParser.ChainedTraversalContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitChainedParentOfGraphTraversal(final GremlinParser.ChainedParentOfGraphTraversalContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitNestedTraversal(final GremlinParser.NestedTraversalContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTerminatedTraversal(final GremlinParser.TerminatedTraversalContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod(final GremlinParser.TraversalMethodContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_V(final GremlinParser.TraversalMethod_VContext ctx) { notImplemented(ctx); return null; }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitTraversalMethod_addE_String(final GremlinParser.TraversalMethod_addE_StringContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitTraversalMethod_addE_Traversal(final GremlinParser.TraversalMethod_addE_TraversalContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_addV_Empty(final GremlinParser.TraversalMethod_addV_EmptyContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_addV_String(final GremlinParser.TraversalMethod_addV_StringContext ctx) { notImplemented(ctx); return null; }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitTraversalMethod_addV_Traversal(final GremlinParser.TraversalMethod_addV_TraversalContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_aggregate_String(final GremlinParser.TraversalMethod_aggregate_StringContext ctx) { notImplemented(ctx); return null; }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_aggregate_Scope_String(final GremlinParser.TraversalMethod_aggregate_Scope_StringContext ctx) { notImplemented(ctx); return null; }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_and(final GremlinParser.TraversalMethod_andContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_as(final GremlinParser.TraversalMethod_asContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_barrier_Consumer(final GremlinParser.TraversalMethod_barrier_ConsumerContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_barrier_Empty(final GremlinParser.TraversalMethod_barrier_EmptyContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_barrier_int(final GremlinParser.TraversalMethod_barrier_intContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_both(final GremlinParser.TraversalMethod_bothContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_bothE(final GremlinParser.TraversalMethod_bothEContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_bothV(final GremlinParser.TraversalMethod_bothVContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_branch(final GremlinParser.TraversalMethod_branchContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_by_Comparator(final GremlinParser.TraversalMethod_by_ComparatorContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_by_Empty(final GremlinParser.TraversalMethod_by_EmptyContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_by_Function(final GremlinParser.TraversalMethod_by_FunctionContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_by_Function_Comparator(final GremlinParser.TraversalMethod_by_Function_ComparatorContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_by_Order(final GremlinParser.TraversalMethod_by_OrderContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_by_String(final GremlinParser.TraversalMethod_by_StringContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_by_String_Comparator(final GremlinParser.TraversalMethod_by_String_ComparatorContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_by_T(final GremlinParser.TraversalMethod_by_TContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_by_Traversal(final GremlinParser.TraversalMethod_by_TraversalContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_by_Traversal_Comparator(final GremlinParser.TraversalMethod_by_Traversal_ComparatorContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_cap(final GremlinParser.TraversalMethod_capContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_choose_Function(final GremlinParser.TraversalMethod_choose_FunctionContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_choose_Predicate_Traversal(final GremlinParser.TraversalMethod_choose_Predicate_TraversalContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_choose_Predicate_Traversal_Traversal(final GremlinParser.TraversalMethod_choose_Predicate_Traversal_TraversalContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_choose_Traversal(final GremlinParser.TraversalMethod_choose_TraversalContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_choose_Traversal_Traversal(final GremlinParser.TraversalMethod_choose_Traversal_TraversalContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_choose_Traversal_Traversal_Traversal(final GremlinParser.TraversalMethod_choose_Traversal_Traversal_TraversalContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_coalesce(final GremlinParser.TraversalMethod_coalesceContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_coin(final GremlinParser.TraversalMethod_coinContext ctx) { notImplemented(ctx); return null; }
+
+ @Override
+ public T visitTraversalMethod_connectedComponent(final GremlinParser.TraversalMethod_connectedComponentContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_constant(final GremlinParser.TraversalMethod_constantContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_count_Empty(final GremlinParser.TraversalMethod_count_EmptyContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_count_Scope(final GremlinParser.TraversalMethod_count_ScopeContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_cyclicPath(final GremlinParser.TraversalMethod_cyclicPathContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_dedup_Scope_String(final GremlinParser.TraversalMethod_dedup_Scope_StringContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_dedup_String(final GremlinParser.TraversalMethod_dedup_StringContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_drop(final GremlinParser.TraversalMethod_dropContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitTraversalMethod_elementMap(final GremlinParser.TraversalMethod_elementMapContext ctx) {
+ return null;
+ }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_emit_Empty(final GremlinParser.TraversalMethod_emit_EmptyContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_emit_Predicate(final GremlinParser.TraversalMethod_emit_PredicateContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_emit_Traversal(final GremlinParser.TraversalMethod_emit_TraversalContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_filter_Predicate(final GremlinParser.TraversalMethod_filter_PredicateContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_filter_Traversal(final GremlinParser.TraversalMethod_filter_TraversalContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_flatMap(final GremlinParser.TraversalMethod_flatMapContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_fold_Empty(final GremlinParser.TraversalMethod_fold_EmptyContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_fold_Object_BiFunction(final GremlinParser.TraversalMethod_fold_Object_BiFunctionContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_from_String(final GremlinParser.TraversalMethod_from_StringContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_from_Traversal(final GremlinParser.TraversalMethod_from_TraversalContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_group_Empty(final GremlinParser.TraversalMethod_group_EmptyContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_group_String(final GremlinParser.TraversalMethod_group_StringContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_groupCount_Empty(final GremlinParser.TraversalMethod_groupCount_EmptyContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_groupCount_String(final GremlinParser.TraversalMethod_groupCount_StringContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_has_String(final GremlinParser.TraversalMethod_has_StringContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_has_String_Object(final GremlinParser.TraversalMethod_has_String_ObjectContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_has_String_P(final GremlinParser.TraversalMethod_has_String_PContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_has_String_String_Object(final GremlinParser.TraversalMethod_has_String_String_ObjectContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_has_String_String_P(final GremlinParser.TraversalMethod_has_String_String_PContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_has_String_Traversal(final GremlinParser.TraversalMethod_has_String_TraversalContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_has_T_Object(final GremlinParser.TraversalMethod_has_T_ObjectContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_has_T_P(final GremlinParser.TraversalMethod_has_T_PContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_has_T_Traversal(final GremlinParser.TraversalMethod_has_T_TraversalContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_hasId_Object_Object(final GremlinParser.TraversalMethod_hasId_Object_ObjectContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_hasId_P(final GremlinParser.TraversalMethod_hasId_PContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_hasKey_P(final GremlinParser.TraversalMethod_hasKey_PContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_hasKey_String_String(final GremlinParser.TraversalMethod_hasKey_String_StringContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_hasLabel_P(final GremlinParser.TraversalMethod_hasLabel_PContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_hasLabel_String_String(final GremlinParser.TraversalMethod_hasLabel_String_StringContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_hasNot(final GremlinParser.TraversalMethod_hasNotContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_hasValue_Object_Object(final GremlinParser.TraversalMethod_hasValue_Object_ObjectContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_hasValue_P(final GremlinParser.TraversalMethod_hasValue_PContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_id(final GremlinParser.TraversalMethod_idContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_identity(final GremlinParser.TraversalMethod_identityContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_in(final GremlinParser.TraversalMethod_inContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_inE(final GremlinParser.TraversalMethod_inEContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_inV(final GremlinParser.TraversalMethod_inVContext ctx) { notImplemented(ctx); return null; }
+
+ @Override
+ public T visitTraversalMethod_index(final GremlinParser.TraversalMethod_indexContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_inject(final GremlinParser.TraversalMethod_injectContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_is_Object(final GremlinParser.TraversalMethod_is_ObjectContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_is_P(final GremlinParser.TraversalMethod_is_PContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_key(final GremlinParser.TraversalMethod_keyContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_label(final GremlinParser.TraversalMethod_labelContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_limit_Scope_long(final GremlinParser.TraversalMethod_limit_Scope_longContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_limit_long(final GremlinParser.TraversalMethod_limit_longContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_local(final GremlinParser.TraversalMethod_localContext ctx) { notImplemented(ctx); return null; }
+
+ @Override
+ public T visitTraversalMethod_loops_Empty(final GremlinParser.TraversalMethod_loops_EmptyContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ @Override
+ public T visitTraversalMethod_loops_String(final GremlinParser.TraversalMethod_loops_StringContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_map(final GremlinParser.TraversalMethod_mapContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_match(final GremlinParser.TraversalMethod_matchContext ctx) { notImplemented(ctx); return null; }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitTraversalMethod_math(final GremlinParser.TraversalMethod_mathContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_max_Empty(final GremlinParser.TraversalMethod_max_EmptyContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_max_Scope(final GremlinParser.TraversalMethod_max_ScopeContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_mean_Empty(final GremlinParser.TraversalMethod_mean_EmptyContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_mean_Scope(final GremlinParser.TraversalMethod_mean_ScopeContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_min_Empty(final GremlinParser.TraversalMethod_min_EmptyContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_min_Scope(final GremlinParser.TraversalMethod_min_ScopeContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_not(final GremlinParser.TraversalMethod_notContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_option_Object_Traversal(final GremlinParser.TraversalMethod_option_Object_TraversalContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_option_Traversal(final GremlinParser.TraversalMethod_option_TraversalContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_optional(final GremlinParser.TraversalMethod_optionalContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_or(final GremlinParser.TraversalMethod_orContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_order_Empty(final GremlinParser.TraversalMethod_order_EmptyContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_order_Scope(final GremlinParser.TraversalMethod_order_ScopeContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_otherV(final GremlinParser.TraversalMethod_otherVContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_out(final GremlinParser.TraversalMethod_outContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_outE(final GremlinParser.TraversalMethod_outEContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_outV(final GremlinParser.TraversalMethod_outVContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_pageRank_Empty(final GremlinParser.TraversalMethod_pageRank_EmptyContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_pageRank_double(final GremlinParser.TraversalMethod_pageRank_doubleContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_path(final GremlinParser.TraversalMethod_pathContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_peerPressure(final GremlinParser.TraversalMethod_peerPressureContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_profile_Empty(final GremlinParser.TraversalMethod_profile_EmptyContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_profile_String(final GremlinParser.TraversalMethod_profile_StringContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_project(final GremlinParser.TraversalMethod_projectContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_properties(final GremlinParser.TraversalMethod_propertiesContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_property_Cardinality_Object_Object_Object(final GremlinParser.TraversalMethod_property_Cardinality_Object_Object_ObjectContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_property_Object_Object_Object(final GremlinParser.TraversalMethod_property_Object_Object_ObjectContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_propertyMap(final GremlinParser.TraversalMethod_propertyMapContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_range_Scope_long_long(final GremlinParser.TraversalMethod_range_Scope_long_longContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_range_long_long(final GremlinParser.TraversalMethod_range_long_longContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitTraversalMethod_read(final GremlinParser.TraversalMethod_readContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitTraversalMethod_repeat_String_Traversal(final GremlinParser.TraversalMethod_repeat_String_TraversalContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitTraversalMethod_repeat_Traversal(final GremlinParser.TraversalMethod_repeat_TraversalContext ctx) {
+ notImplemented(ctx); return null;
+ }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_sack_BiFunction(final GremlinParser.TraversalMethod_sack_BiFunctionContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_sack_Empty(final GremlinParser.TraversalMethod_sack_EmptyContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_sample_Scope_int(final GremlinParser.TraversalMethod_sample_Scope_intContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_sample_int(final GremlinParser.TraversalMethod_sample_intContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_select_Column(final GremlinParser.TraversalMethod_select_ColumnContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_select_Pop_String(final GremlinParser.TraversalMethod_select_Pop_StringContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_select_Pop_String_String_String(final GremlinParser.TraversalMethod_select_Pop_String_String_StringContext ctx) { notImplemented(ctx); return null; }
+
+ @Override
+ public T visitTraversalMethod_select_Pop_Traversal(final GremlinParser.TraversalMethod_select_Pop_TraversalContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_select_String(final GremlinParser.TraversalMethod_select_StringContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_select_String_String_String(final GremlinParser.TraversalMethod_select_String_String_StringContext ctx) { notImplemented(ctx); return null; }
+
+ @Override
+ public T visitTraversalMethod_select_Traversal(final GremlinParser.TraversalMethod_select_TraversalContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ @Override
+ public T visitTraversalMethod_shortestPath(final GremlinParser.TraversalMethod_shortestPathContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_sideEffect(final GremlinParser.TraversalMethod_sideEffectContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_simplePath(final GremlinParser.TraversalMethod_simplePathContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_skip_Scope_long(final GremlinParser.TraversalMethod_skip_Scope_longContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_skip_long(final GremlinParser.TraversalMethod_skip_longContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_store(final GremlinParser.TraversalMethod_storeContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_subgraph(final GremlinParser.TraversalMethod_subgraphContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_sum_Empty(final GremlinParser.TraversalMethod_sum_EmptyContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_sum_Scope(final GremlinParser.TraversalMethod_sum_ScopeContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_tail_Empty(final GremlinParser.TraversalMethod_tail_EmptyContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_tail_Scope(final GremlinParser.TraversalMethod_tail_ScopeContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_tail_Scope_long(final GremlinParser.TraversalMethod_tail_Scope_longContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_tail_long(final GremlinParser.TraversalMethod_tail_longContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_timeLimit(final GremlinParser.TraversalMethod_timeLimitContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_times(final GremlinParser.TraversalMethod_timesContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_to_Direction_String(final GremlinParser.TraversalMethod_to_Direction_StringContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_to_String(final GremlinParser.TraversalMethod_to_StringContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_to_Traversal(final GremlinParser.TraversalMethod_to_TraversalContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_toE(final GremlinParser.TraversalMethod_toEContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_toV(final GremlinParser.TraversalMethod_toVContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_tree_Empty(final GremlinParser.TraversalMethod_tree_EmptyContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_tree_String(final GremlinParser.TraversalMethod_tree_StringContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_unfold(final GremlinParser.TraversalMethod_unfoldContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_union(final GremlinParser.TraversalMethod_unionContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_until_Predicate(final GremlinParser.TraversalMethod_until_PredicateContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_until_Traversal(final GremlinParser.TraversalMethod_until_TraversalContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_value(final GremlinParser.TraversalMethod_valueContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_valueMap_String(final GremlinParser.TraversalMethod_valueMap_StringContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_valueMap_boolean_String(final GremlinParser.TraversalMethod_valueMap_boolean_StringContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_values(final GremlinParser.TraversalMethod_valuesContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_where_P(final GremlinParser.TraversalMethod_where_PContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_where_String_P(final GremlinParser.TraversalMethod_where_String_PContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalMethod_where_Traversal(final GremlinParser.TraversalMethod_where_TraversalContext ctx) { notImplemented(ctx); return null; }
+
+ @Override
+ public T visitTraversalMethod_with_String(final GremlinParser.TraversalMethod_with_StringContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ @Override
+ public T visitTraversalMethod_with_String_Object(final GremlinParser.TraversalMethod_with_String_ObjectContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ @Override
+ public T visitTraversalMethod_write(final GremlinParser.TraversalMethod_writeContext ctx) {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalScope(final GremlinParser.TraversalScopeContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalToken(final GremlinParser.TraversalTokenContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalOrder(final GremlinParser.TraversalOrderContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalDirection(final GremlinParser.TraversalDirectionContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalCardinality(final GremlinParser.TraversalCardinalityContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalColumn(final GremlinParser.TraversalColumnContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalPop(final GremlinParser.TraversalPopContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalOperator(final GremlinParser.TraversalOperatorContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalOptionParent(final GremlinParser.TraversalOptionParentContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalPredicate(final GremlinParser.TraversalPredicateContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalTerminalMethod(final GremlinParser.TraversalTerminalMethodContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalSackMethod(final GremlinParser.TraversalSackMethodContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitTraversalSelfMethod(final GremlinParser.TraversalSelfMethodContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalComparator(final GremlinParser.TraversalComparatorContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalFunction(final GremlinParser.TraversalFunctionContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalBiFunction(final GremlinParser.TraversalBiFunctionContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalPredicate_eq(final GremlinParser.TraversalPredicate_eqContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalPredicate_neq(final GremlinParser.TraversalPredicate_neqContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalPredicate_lt(final GremlinParser.TraversalPredicate_ltContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalPredicate_lte(final GremlinParser.TraversalPredicate_lteContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalPredicate_gt(final GremlinParser.TraversalPredicate_gtContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalPredicate_gte(final GremlinParser.TraversalPredicate_gteContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalPredicate_inside(final GremlinParser.TraversalPredicate_insideContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalPredicate_outside(final GremlinParser.TraversalPredicate_outsideContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalPredicate_between(final GremlinParser.TraversalPredicate_betweenContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalPredicate_within(final GremlinParser.TraversalPredicate_withinContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalPredicate_without(final GremlinParser.TraversalPredicate_withoutContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalPredicate_not(final GremlinParser.TraversalPredicate_notContext ctx) { notImplemented(ctx); return null; }
+
+ @Override
+ public T visitTraversalPredicate_containing(final GremlinParser.TraversalPredicate_containingContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ @Override
+ public T visitTraversalPredicate_notContaining(final GremlinParser.TraversalPredicate_notContainingContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ @Override
+ public T visitTraversalPredicate_startingWith(final GremlinParser.TraversalPredicate_startingWithContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ @Override
+ public T visitTraversalPredicate_notStartingWith(final GremlinParser.TraversalPredicate_notStartingWithContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ @Override
+ public T visitTraversalPredicate_endingWith(final GremlinParser.TraversalPredicate_endingWithContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ @Override
+ public T visitTraversalPredicate_notEndingWith(final GremlinParser.TraversalPredicate_notEndingWithContext ctx) {
+ notImplemented(ctx); return null;
+ }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalTerminalMethod_iterate(final GremlinParser.TraversalTerminalMethod_iterateContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalTerminalMethod_explain(final GremlinParser.TraversalTerminalMethod_explainContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalTerminalMethod_hasNext(final GremlinParser.TraversalTerminalMethod_hasNextContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalTerminalMethod_tryNext(final GremlinParser.TraversalTerminalMethod_tryNextContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalTerminalMethod_next(final GremlinParser.TraversalTerminalMethod_nextContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalTerminalMethod_toList(final GremlinParser.TraversalTerminalMethod_toListContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalTerminalMethod_toSet(final GremlinParser.TraversalTerminalMethod_toSetContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalTerminalMethod_toBulkSet(final GremlinParser.TraversalTerminalMethod_toBulkSetContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalSelfMethod_none(final GremlinParser.TraversalSelfMethod_noneContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalStrategy(final GremlinParser.TraversalStrategyContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalStrategyList(final GremlinParser.TraversalStrategyListContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitTraversalStrategyExpr(final GremlinParser.TraversalStrategyExprContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitTraversalStrategyArgs_PartitionStrategy(final GremlinParser.TraversalStrategyArgs_PartitionStrategyContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitTraversalStrategyArgs_EdgeLabelVerificationStrategy(final GremlinParser.TraversalStrategyArgs_EdgeLabelVerificationStrategyContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitTraversalStrategyArgs_ReservedKeysVerificationStrategy(final GremlinParser.TraversalStrategyArgs_ReservedKeysVerificationStrategyContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitTraversalStrategyArgs_SubgraphStrategy(final GremlinParser.TraversalStrategyArgs_SubgraphStrategyContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitNestedTraversalList(final GremlinParser.NestedTraversalListContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitNestedTraversalExpr(final GremlinParser.NestedTraversalExprContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitGenericLiteralList(final GremlinParser.GenericLiteralListContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitGenericLiteralExpr(final GremlinParser.GenericLiteralExprContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitGenericLiteralRange(final GremlinParser.GenericLiteralRangeContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitGenericLiteralCollection(final GremlinParser.GenericLiteralCollectionContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitStringLiteralList(final GremlinParser.StringLiteralListContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitStringLiteralExpr(final GremlinParser.StringLiteralExprContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitGenericLiteral(final GremlinParser.GenericLiteralContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitGenericLiteralMap(final GremlinParser.GenericLiteralMapContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitIntegerLiteral(final GremlinParser.IntegerLiteralContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitFloatLiteral(final GremlinParser.FloatLiteralContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitBooleanLiteral(final GremlinParser.BooleanLiteralContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitStringLiteral(final GremlinParser.StringLiteralContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitDateLiteral(final GremlinParser.DateLiteralContext ctx) { notImplemented(ctx); return null; }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public T visitNullLiteral(final GremlinParser.NullLiteralContext ctx) { notImplemented(ctx); return null; }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitGremlinStringConstants(final GremlinParser.GremlinStringConstantsContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitPageRankStringConstants(final GremlinParser.PageRankStringConstantsContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitPeerPressureStringConstants(final GremlinParser.PeerPressureStringConstantsContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitShortestPathStringConstants(final GremlinParser.ShortestPathStringConstantsContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitWithOptionsStringConstants(final GremlinParser.WithOptionsStringConstantsContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitGremlinStringConstants_pageRankStringConstants_edges(final GremlinParser.GremlinStringConstants_pageRankStringConstants_edgesContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitGremlinStringConstants_pageRankStringConstants_times(final GremlinParser.GremlinStringConstants_pageRankStringConstants_timesContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitGremlinStringConstants_pageRankStringConstants_propertyName(final GremlinParser.GremlinStringConstants_pageRankStringConstants_propertyNameContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitGremlinStringConstants_peerPressureStringConstants_edges(final GremlinParser.GremlinStringConstants_peerPressureStringConstants_edgesContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitGremlinStringConstants_peerPressureStringConstants_times(final GremlinParser.GremlinStringConstants_peerPressureStringConstants_timesContext ctx) {
+ notImplemented(ctx);return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitGremlinStringConstants_peerPressureStringConstants_propertyName(final GremlinParser.GremlinStringConstants_peerPressureStringConstants_propertyNameContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitGremlinStringConstants_shortestPathStringConstants_target(final GremlinParser.GremlinStringConstants_shortestPathStringConstants_targetContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitGremlinStringConstants_shortestPathStringConstants_edges(final GremlinParser.GremlinStringConstants_shortestPathStringConstants_edgesContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitGremlinStringConstants_shortestPathStringConstants_distance(final GremlinParser.GremlinStringConstants_shortestPathStringConstants_distanceContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitGremlinStringConstants_shortestPathStringConstants_maxDistance(final GremlinParser.GremlinStringConstants_shortestPathStringConstants_maxDistanceContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitGremlinStringConstants_shortestPathStringConstants_includeEdges(final GremlinParser.GremlinStringConstants_shortestPathStringConstants_includeEdgesContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitGremlinStringConstants_withOptionsStringConstants_tokens(final GremlinParser.GremlinStringConstants_withOptionsStringConstants_tokensContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitGremlinStringConstants_withOptionsStringConstants_none(final GremlinParser.GremlinStringConstants_withOptionsStringConstants_noneContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitGremlinStringConstants_withOptionsStringConstants_ids(final GremlinParser.GremlinStringConstants_withOptionsStringConstants_idsContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitGremlinStringConstants_withOptionsStringConstants_labels(final GremlinParser.GremlinStringConstants_withOptionsStringConstants_labelsContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitGremlinStringConstants_withOptionsStringConstants_keys(final GremlinParser.GremlinStringConstants_withOptionsStringConstants_keysContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitGremlinStringConstants_withOptionsStringConstants_values(final GremlinParser.GremlinStringConstants_withOptionsStringConstants_valuesContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitGremlinStringConstants_withOptionsStringConstants_all(final GremlinParser.GremlinStringConstants_withOptionsStringConstants_allContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitGremlinStringConstants_withOptionsStringConstants_indexer(final GremlinParser.GremlinStringConstants_withOptionsStringConstants_indexerContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitGremlinStringConstants_withOptionsStringConstants_list(final GremlinParser.GremlinStringConstants_withOptionsStringConstants_listContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitGremlinStringConstants_withOptionsStringConstants_map(final GremlinParser.GremlinStringConstants_withOptionsStringConstants_mapContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitPageRankStringConstant(final GremlinParser.PageRankStringConstantContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitPeerPressureStringConstant(final GremlinParser.PeerPressureStringConstantContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitShortestPathStringConstant(final GremlinParser.ShortestPathStringConstantContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitWithOptionsStringConstant(final GremlinParser.WithOptionsStringConstantContext ctx) {
+ notImplemented(ctx); return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T visitTraversalMethod_option_Predicate_Traversal(final GremlinParser.TraversalMethod_option_Predicate_TraversalContext ctx) {
+ notImplemented(ctx); return null;
+ }
+}
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/GremlinErrorListener.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/GremlinErrorListener.java
new file mode 100644
index 0000000..53007a9
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/GremlinErrorListener.java
@@ -0,0 +1,36 @@
+/*
+ * 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.language.grammar;
+
+import org.antlr.v4.runtime.BaseErrorListener;
+import org.antlr.v4.runtime.RecognitionException;
+import org.antlr.v4.runtime.Recognizer;
+
+/**
+ * Gremlin error listener class which throw GremlinParserException on syntax error
+ */
+public class GremlinErrorListener extends BaseErrorListener {
+
+ @Override
+ public void syntaxError(final Recognizer<?, ?> recognizer, final Object offendingSymbol, final int line,
+ final int charPositionInLine, final String msg, final RecognitionException e) {
+ throw new GremlinParserException(line, charPositionInLine, msg);
+ }
+
+}
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/GremlinParserException.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/GremlinParserException.java
new file mode 100644
index 0000000..047c4b9
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/GremlinParserException.java
@@ -0,0 +1,45 @@
+/*
+ * 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.language.grammar;
+
+/**
+ * Gremlin Parser Exception is thrown when a parser error is encountered.
+ */
+public class GremlinParserException extends RuntimeException {
+
+ private static final long serialVersionUID = 13748205730257427L;
+
+ public GremlinParserException(final String message, final Throwable cause) {
+ super(message, cause);
+ }
+
+ public GremlinParserException(final String message) {
+ super(message);
+ }
+
+ public GremlinParserException(final int line_number, final int charPositionInLine, final String message) {
+ super(new StringBuilder()
+ .append("Query parsing failed at line ")
+ .append(line_number)
+ .append(", character position at ")
+ .append(charPositionInLine)
+ .append(", error message : ")
+ .append(message).toString());
+ }
+}
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/GremlinQueryParser.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/GremlinQueryParser.java
new file mode 100644
index 0000000..eb7397f
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/GremlinQueryParser.java
@@ -0,0 +1,85 @@
+/*
+ * 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.language.grammar;
+
+import org.antlr.v4.runtime.CharStream;
+import org.antlr.v4.runtime.CharStreams;
+import org.antlr.v4.runtime.CommonTokenStream;
+import org.antlr.v4.runtime.atn.PredictionMode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class GremlinQueryParser {
+ private static final Logger log = LoggerFactory.getLogger(GremlinQueryParser.class);
+ private static final GremlinErrorListener errorListener = new GremlinErrorListener();
+
+ // todo: cleanup exception
+ public static Object parse(final String query) throws Exception {
+ return parse(query, new GremlinAntlrToJava());
+ }
+
+ public static Object parse(final String query, final GremlinVisitor<Object> visitor) throws Exception {
+ final CharStream in = CharStreams.fromString(query);
+ final GremlinLexer lexer = new GremlinLexer(in);
+ lexer.removeErrorListeners();
+ lexer.addErrorListener(errorListener);
+
+ final CommonTokenStream tokens = new CommonTokenStream(lexer);
+
+ // Setup error handler on parser
+ final GremlinParser parser = new GremlinParser(tokens);
+ // SLL prediction mode is faster than the LL prediction mode when parsing the grammar,
+ // but it does not cover parsing all types of input. We use the SLL by default, and fallback
+ // to LL mode if fails to parse the query.
+ parser.getInterpreter().setPredictionMode(PredictionMode.SLL);
+ parser.removeErrorListeners();
+ parser.addErrorListener(errorListener);
+
+ GremlinParser.QueryListContext queryContext;
+ try {
+ queryContext = parser.queryList();
+ } catch (Exception ex) {
+ // Retry parsing the query again with using LL prediction mode. LL parsing mode is more powerful
+ // so retrying the parsing would help parsing the rare edge cases.
+ try {
+ tokens.seek(0); // rewind input stream
+ lexer.reset();
+ parser.reset();
+ parser.getInterpreter().setPredictionMode(PredictionMode.LL);
+ log.debug("Query parsed with using LL prediction mode: {}", query);
+ queryContext = parser.queryList();
+ } catch (Exception e) {
+ log.debug("Query parsing failed in retry with exception" + e);
+ throw new GremlinParserException("Failed to interpret Gremlin query: " + e.getMessage());
+ }
+ }
+
+ try {
+ return visitor.visit(queryContext);
+ } catch (ClassCastException ex) {
+ // Special case that can be interpreted as a (semantic) parse error.
+ // Do not include ex as the cause - org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor.eval()
+ // in Tinkerpop v 3.3.0, strips root causes off their outer exception objects.
+ // We just log ex here for debugging purposes.
+ log.debug("Converting a java.lang.ClassCastException to GremlinParserException," +
+ " assuming that it indicates a semantic parse error.", ex);
+ throw new GremlinParserException("Failed to interpret Gremlin query: " + ex.getMessage());
+ }
+ }
+}
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/GremlinStringConstantsVisitor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/GremlinStringConstantsVisitor.java
new file mode 100644
index 0000000..95a35e9
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/GremlinStringConstantsVisitor.java
@@ -0,0 +1,172 @@
+/*
+ * 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.language.grammar;
+
+import org.apache.tinkerpop.gremlin.process.computer.traversal.step.map.PageRank;
+import org.apache.tinkerpop.gremlin.process.computer.traversal.step.map.PeerPressure;
+import org.apache.tinkerpop.gremlin.process.computer.traversal.step.map.ShortestPath;
+import org.apache.tinkerpop.gremlin.process.traversal.step.util.WithOptions;
+
+/**
+ * Gremlin String Constant Visitor handles parsing the new constant types Gremlin introduced by version 3.4.0.
+ */
+public class GremlinStringConstantsVisitor extends GremlinBaseVisitor<Object> {
+
+ private GremlinStringConstantsVisitor() {}
+
+ private static GremlinStringConstantsVisitor instance;
+
+ public static GremlinStringConstantsVisitor getInstance() {
+ if (instance == null) {
+ instance = new GremlinStringConstantsVisitor();
+ }
+ return instance;
+ }
+
+ @Override
+ public Object visitGremlinStringConstants(final GremlinParser.GremlinStringConstantsContext ctx) {
+ return visitChildren(ctx);
+ }
+
+ @Override
+ public Object visitPageRankStringConstants(final GremlinParser.PageRankStringConstantsContext ctx) {
+ return visitChildren(ctx);
+ }
+
+ @Override
+ public Object visitPeerPressureStringConstants(final GremlinParser.PeerPressureStringConstantsContext ctx) {
+ return visitChildren(ctx);
+ }
+
+ @Override
+ public Object visitShortestPathStringConstants(final GremlinParser.ShortestPathStringConstantsContext ctx) {
+ return visitChildren(ctx);
+ }
+
+ @Override
+ public Object visitWithOptionsStringConstants(final GremlinParser.WithOptionsStringConstantsContext ctx) {
+ return visitChildren(ctx);
+ }
+
+ @Override
+ public Object visitGremlinStringConstants_pageRankStringConstants_edges(final GremlinParser.GremlinStringConstants_pageRankStringConstants_edgesContext ctx) {
+ return PageRank.edges;
+ }
+
+ @Override
+ public Object visitGremlinStringConstants_pageRankStringConstants_times(final GremlinParser.GremlinStringConstants_pageRankStringConstants_timesContext ctx) {
+ return PageRank.times;
+ }
+
+ @Override
+ public Object visitGremlinStringConstants_pageRankStringConstants_propertyName(final GremlinParser.GremlinStringConstants_pageRankStringConstants_propertyNameContext ctx) {
+ return PageRank.propertyName;
+ }
+
+ @Override
+ public Object visitGremlinStringConstants_peerPressureStringConstants_edges(final GremlinParser.GremlinStringConstants_peerPressureStringConstants_edgesContext ctx) {
+ return PeerPressure.edges;
+ }
+
+ @Override
+ public Object visitGremlinStringConstants_peerPressureStringConstants_times(final GremlinParser.GremlinStringConstants_peerPressureStringConstants_timesContext ctx) {
+ return PeerPressure.times;
+ }
+
+ @Override
+ public Object visitGremlinStringConstants_peerPressureStringConstants_propertyName(final GremlinParser.GremlinStringConstants_peerPressureStringConstants_propertyNameContext ctx) {
+ return PeerPressure.propertyName;
+ }
+
+ @Override
+ public Object visitGremlinStringConstants_shortestPathStringConstants_target(final GremlinParser.GremlinStringConstants_shortestPathStringConstants_targetContext ctx) {
+ return ShortestPath.target;
+ }
+
+ @Override
+ public Object visitGremlinStringConstants_shortestPathStringConstants_edges(final GremlinParser.GremlinStringConstants_shortestPathStringConstants_edgesContext ctx) {
+ return ShortestPath.edges;
+ }
+
+ @Override
+ public Object visitGremlinStringConstants_shortestPathStringConstants_distance(final GremlinParser.GremlinStringConstants_shortestPathStringConstants_distanceContext ctx) {
+ return ShortestPath.distance;
+ }
+
+ @Override
+ public Object visitGremlinStringConstants_shortestPathStringConstants_maxDistance(final GremlinParser.GremlinStringConstants_shortestPathStringConstants_maxDistanceContext ctx) {
+ return ShortestPath.maxDistance;
+ }
+
+ @Override
+ public Object visitGremlinStringConstants_shortestPathStringConstants_includeEdges(final GremlinParser.GremlinStringConstants_shortestPathStringConstants_includeEdgesContext ctx) {
+ return ShortestPath.includeEdges;
+ }
+
+ @Override
+ public Object visitGremlinStringConstants_withOptionsStringConstants_tokens(final GremlinParser.GremlinStringConstants_withOptionsStringConstants_tokensContext ctx) {
+ return WithOptions.tokens;
+ }
+
+ @Override
+ public Object visitGremlinStringConstants_withOptionsStringConstants_none(final GremlinParser.GremlinStringConstants_withOptionsStringConstants_noneContext ctx) {
+ return WithOptions.none;
+ }
+
+ @Override
+ public Object visitGremlinStringConstants_withOptionsStringConstants_ids(final GremlinParser.GremlinStringConstants_withOptionsStringConstants_idsContext ctx) {
+ return WithOptions.ids;
+ }
+
+ @Override
+ public Object visitGremlinStringConstants_withOptionsStringConstants_labels(final GremlinParser.GremlinStringConstants_withOptionsStringConstants_labelsContext ctx) {
+ return WithOptions.labels;
+ }
+
+ @Override
+ public Object visitGremlinStringConstants_withOptionsStringConstants_keys(final GremlinParser.GremlinStringConstants_withOptionsStringConstants_keysContext ctx) {
+ return WithOptions.keys;
+ }
+
+ @Override
+ public Object visitGremlinStringConstants_withOptionsStringConstants_values(final GremlinParser.GremlinStringConstants_withOptionsStringConstants_valuesContext ctx) {
+ return WithOptions.values;
+ }
+
+ @Override
+ public Object visitGremlinStringConstants_withOptionsStringConstants_all(final GremlinParser.GremlinStringConstants_withOptionsStringConstants_allContext ctx) {
+ return WithOptions.all;
+ }
+
+ @Override
+ public Object visitGremlinStringConstants_withOptionsStringConstants_indexer(final GremlinParser.GremlinStringConstants_withOptionsStringConstants_indexerContext ctx) {
+ return WithOptions.indexer;
+ }
+
+ @Override
+ public Object visitGremlinStringConstants_withOptionsStringConstants_list(final GremlinParser.GremlinStringConstants_withOptionsStringConstants_listContext ctx) {
+ return WithOptions.list;
+ }
+
+ @Override
+ public Object visitGremlinStringConstants_withOptionsStringConstants_map(final GremlinParser.GremlinStringConstants_withOptionsStringConstants_mapContext ctx) {
+ return WithOptions.map;
+ }
+
+}
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/NestedTraversalSourceListVisitor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/NestedTraversalSourceListVisitor.java
new file mode 100644
index 0000000..41d44e8
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/NestedTraversalSourceListVisitor.java
@@ -0,0 +1,67 @@
+/*
+ * 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.language.grammar;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+
+/**
+ * This class implements gremlin grammar's nested-traversal-list methods
+ * that returns a Traversal [] to the callers. It doesn't depend on a GraphTraversal and hence a singleton class.
+ * As it is stateless, we use singleton to avoid object creation/deletion
+ */
+public class NestedTraversalSourceListVisitor extends GremlinBaseVisitor<Traversal[]> {
+
+ protected final GremlinAntlrToJava context;
+
+ public NestedTraversalSourceListVisitor(final GremlinAntlrToJava context) {
+ this.context = context;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Traversal[] visitNestedTraversalList(final GremlinParser.NestedTraversalListContext ctx) {
+ if (ctx.children == null) {
+ return new Traversal[0];
+ }
+
+ return this.visitChildren(ctx);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Traversal[] visitNestedTraversalExpr(final GremlinParser.NestedTraversalExprContext ctx) {
+ final int childCount = ctx.getChildCount();
+
+ // handle arbitrary number of traversals that are separated by comma
+ final Traversal[] results = new Traversal[(childCount + 1) / 2];
+ int childIndex = 0;
+ while (childIndex < ctx.getChildCount()) {
+ results[childIndex / 2] = context.tvisitor.visitNestedTraversal(
+ (GremlinParser.NestedTraversalContext)ctx.getChild(childIndex));
+ // skip comma child
+ childIndex += 2;
+ }
+
+ return results;
+ }
+}
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/NoOpTerminalVisitor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/NoOpTerminalVisitor.java
new file mode 100644
index 0000000..ed9062b
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/NoOpTerminalVisitor.java
@@ -0,0 +1,79 @@
+/*
+ * 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.language.grammar;
+
+import org.antlr.v4.runtime.tree.ParseTree;
+
+/**
+ * {@inheritDoc}
+ *
+ * The same as parent visitor {@link GremlinAntlrToJava} but returns bytecode instead of a Traversal or TraversalSource,
+ * and uses an overridden terminal step visitor
+ */
+public class NoOpTerminalVisitor extends GremlinAntlrToJava {
+
+ public NoOpTerminalVisitor() throws Exception {
+ super();
+ }
+
+ /**
+ * Returns bytecode of traversal or traversal source, overriding any terminal step operations to prevent them from
+ * being executed using the {@link TraversalTerminalMethodVisitor} to append terminal operations to bytecode.
+ *
+ * @param ctx - the parse tree
+ * @return - bytecode from the traversal or traversal source
+ */
+ @Override
+ public Object visitQuery(final GremlinParser.QueryContext ctx){
+ final int childCount = ctx.getChildCount();
+ if (childCount <= 3) {
+ final ParseTree firstChild = ctx.getChild(0);
+ if (firstChild instanceof GremlinParser.TraversalSourceContext) {
+ if (childCount == 1) {
+ // handle traversalSource
+ return gvisitor.visitTraversalSource((GremlinParser.TraversalSourceContext)firstChild).getBytecode();
+ } else {
+ // handle traversalSource DOT transactionPart
+ throw new GremlinParserException("Transaction operation is not supported yet");
+ }
+ } else if (firstChild instanceof GremlinParser.EmptyQueryContext) {
+ // handle empty query
+ return "";
+ } else {
+ if (childCount == 1) {
+ // handle rootTraversal
+ return tvisitor.visitRootTraversal(
+ (GremlinParser.RootTraversalContext)firstChild).asAdmin().getBytecode();
+ } else {
+ // handle rootTraversal DOT traversalTerminalMethod
+ // could not keep all of these methods in one visitor due to the need of the terminal visitor to have a traversal,
+ return new TerminalMethodToBytecodeVisitor(tvisitor
+ .visitRootTraversal((GremlinParser.RootTraversalContext)firstChild))
+ .visitTraversalTerminalMethod((GremlinParser.TraversalTerminalMethodContext)ctx.getChild(2));
+ }
+ }
+ } else {
+ // TODO: what queries hit this path?
+ return String.valueOf(visitChildren(ctx));
+ }
+ }
+
+
+}
+
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/ParseTreeContextCastHelper.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/ParseTreeContextCastHelper.java
new file mode 100644
index 0000000..18bbe0f
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/ParseTreeContextCastHelper.java
@@ -0,0 +1,47 @@
+/*
+ * 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.language.grammar;
+
+import org.antlr.v4.runtime.tree.ParseTree;
+
+/**
+ * Antlr parse tree context cast helper.
+ */
+public class ParseTreeContextCastHelper {
+
+ /**
+ * Cast ParseTree node child into GenericLiteralContext
+ * @param ctx : ParseTree node
+ * @param childIndex : child index
+ * @return casted GenericLiteralContext
+ */
+ public static GremlinParser.GenericLiteralContext castChildToGenericLiteral(final ParseTree ctx, final int childIndex) {
+ return (GremlinParser.GenericLiteralContext)(ctx.getChild(childIndex));
+ }
+
+ /**
+ * Cast ParseTree node child into GenericLiteralListContext
+ * @param ctx : ParseTree node
+ * @param childIndex : child index
+ * @return casted GenericLiteralListContext
+ */
+ public static GremlinParser.GenericLiteralListContext castChildToGenericLiteralList(final ParseTree ctx, final int childIndex) {
+ return (GremlinParser.GenericLiteralListContext)(ctx.getChild(childIndex));
+ }
+}
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TerminalMethodToBytecodeVisitor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TerminalMethodToBytecodeVisitor.java
new file mode 100644
index 0000000..5936601
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TerminalMethodToBytecodeVisitor.java
@@ -0,0 +1,141 @@
+/*
+ * 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.language.grammar;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+
+public class TerminalMethodToBytecodeVisitor extends TraversalTerminalMethodVisitor {
+
+ public TerminalMethodToBytecodeVisitor(final Traversal traversal) {
+ super(traversal);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object visitTraversalTerminalMethod(final GremlinParser.TraversalTerminalMethodContext ctx) {
+ return visitChildren(ctx);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Traversal terminal method explain step
+ */
+ @Override
+ public Object visitTraversalTerminalMethod_explain(final GremlinParser.TraversalTerminalMethod_explainContext ctx) {
+ final Bytecode bc = this.traversal.asAdmin().getBytecode();
+ bc.addStep("explain");
+ return bc;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Traversal terminal method iterate step
+ */
+ @Override
+ public Object visitTraversalTerminalMethod_iterate(final GremlinParser.TraversalTerminalMethod_iterateContext ctx) {
+ final Bytecode bc = this.traversal.asAdmin().getBytecode();
+ bc.addStep("iterate");
+ return bc;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Traversal terminal method has next step
+ */
+ @Override
+ public Object visitTraversalTerminalMethod_hasNext(final GremlinParser.TraversalTerminalMethod_hasNextContext ctx) {
+ final Bytecode bc = this.traversal.asAdmin().getBytecode();
+ bc.addStep("hasNext");
+ return bc;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Traversal terminal method try next step
+ */
+ @Override
+ public Object visitTraversalTerminalMethod_tryNext(final GremlinParser.TraversalTerminalMethod_tryNextContext ctx) {
+ final Bytecode bc = this.traversal.asAdmin().getBytecode();
+ bc.addStep("tryNext");
+ return bc;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Traversal terminal method next step
+ */
+ @Override
+ public Object visitTraversalTerminalMethod_next(final GremlinParser.TraversalTerminalMethod_nextContext ctx) {
+ final Bytecode bc = this.traversal.asAdmin().getBytecode();
+ if (ctx.getChildCount() == 3) {
+ bc.addStep("next");
+ } else {
+ // the 3rd child is integer value
+ final int childIndexOfParamaterAmount = 2;
+ bc.addStep("next", Integer.decode(ctx.getChild(childIndexOfParamaterAmount).getText()));
+ }
+
+ return bc;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Traversal terminal method to list step
+ */
+ @Override
+ public Object visitTraversalTerminalMethod_toList(final GremlinParser.TraversalTerminalMethod_toListContext ctx) {
+ final Bytecode bc = this.traversal.asAdmin().getBytecode();
+ bc.addStep("toList");
+ return bc;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Traversal terminal method to set step
+ */
+ @Override
+ public Object visitTraversalTerminalMethod_toSet(final GremlinParser.TraversalTerminalMethod_toSetContext ctx) {
+ final Bytecode bc = this.traversal.asAdmin().getBytecode();
+ bc.addStep("toSet");
+ return bc;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Traversal terminal method to bulk set step
+ */
+ @Override
+ public Object visitTraversalTerminalMethod_toBulkSet(final GremlinParser.TraversalTerminalMethod_toBulkSetContext ctx) {
+ final Bytecode bc = this.traversal.asAdmin().getBytecode();
+ bc.addStep("toBulkSet");
+ return bc;
+ }
+}
+
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalEnumParser.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalEnumParser.java
new file mode 100644
index 0000000..b79666a
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalEnumParser.java
@@ -0,0 +1,57 @@
+/*
+ * 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.language.grammar;
+
+import org.antlr.v4.runtime.tree.ParseTree;
+
+/**
+ * Traversal enum parser parses all the enums in graph traversal.
+ * These include:
+ * org.apache.tinkerpop.gremlin.process.traversal.Scope
+ * org.apache.tinkerpop.gremlin.process.traversal.Order
+ * org.apache.tinkerpop.gremlin.process.traversal.Pop
+ * org.apache.tinkerpop.gremlin.process.traversal.SackFunctions$Barrier
+ * org.apache.tinkerpop.gremlin.process.traversal.Operator
+ * org.apache.tinkerpop.gremlin.structure.T
+ * org.apache.tinkerpop.gremlin.structure.Column
+ * org.apache.tinkerpop.gremlin.structure.Direction
+ * org.apache.tinkerpop.gremlin.structure.VertexProperty$Cardinality
+ * org.apache.tinkerpop.gremlin.process.traversal.step.TraversalOptionParent$Pick
+ */
+public class TraversalEnumParser {
+
+ /**
+ * Parse enum text from a parse tree context into a enum object
+ * @param enumType : class of enum
+ * @param context : parse tree context
+ * @return enum object
+ */
+ public static <E extends Enum<E>, C extends ParseTree> E parseTraversalEnumFromContext(final Class<E> enumType, final C context) {
+ final String text = context.getText();
+ final String className = enumType.getSimpleName();
+
+ // Support qualified class names like (ex: T.id or Scope.local)
+ if (text.startsWith(className)) {
+ final String strippedText = text.substring(className.length() + 1);
+ return E.valueOf(enumType, strippedText);
+ } else {
+ return E.valueOf(enumType, text);
+ }
+ }
+}
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalFunctionVisitor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalFunctionVisitor.java
new file mode 100644
index 0000000..a286da8
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalFunctionVisitor.java
@@ -0,0 +1,66 @@
+/*
+ * 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.language.grammar;
+
+import org.apache.tinkerpop.gremlin.structure.Column;
+import org.apache.tinkerpop.gremlin.structure.T;
+
+import java.util.function.Function;
+
+/**
+ * Traversal Function parser parses Function enums.
+ * As it is stateless, we use singleton to avoid object creation/deletion
+ */
+public class TraversalFunctionVisitor extends GremlinBaseVisitor<Function> {
+
+ private TraversalFunctionVisitor() {}
+
+ private static TraversalFunctionVisitor instance;
+
+ public static TraversalFunctionVisitor getInstance() {
+ if (instance == null) {
+ instance = new TraversalFunctionVisitor();
+ }
+ return instance;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Function visitTraversalFunction(final GremlinParser.TraversalFunctionContext ctx) {
+ return this.visitChildren(ctx);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Function visitTraversalToken(final GremlinParser.TraversalTokenContext ctx) {
+ return TraversalEnumParser.parseTraversalEnumFromContext(T.class, ctx);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Function visitTraversalColumn(final GremlinParser.TraversalColumnContext ctx) {
+ return TraversalEnumParser.parseTraversalEnumFromContext(Column.class, ctx);
+ }
+}
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalMethodVisitor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalMethodVisitor.java
new file mode 100644
index 0000000..026ea84
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalMethodVisitor.java
@@ -0,0 +1,1695 @@
+/*
+ * 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.language.grammar;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Operator;
+import org.apache.tinkerpop.gremlin.process.traversal.Order;
+import org.apache.tinkerpop.gremlin.process.traversal.Pop;
+import org.apache.tinkerpop.gremlin.process.traversal.Scope;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
+import org.apache.tinkerpop.gremlin.structure.Column;
+import org.apache.tinkerpop.gremlin.structure.Direction;
+import org.apache.tinkerpop.gremlin.structure.T;
+import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+
+import static org.apache.tinkerpop.gremlin.process.traversal.SackFunctions.Barrier.normSack;
+
+/**
+ * Specific case of TraversalRootVisitor where all TraversalMethods returns
+ * a GraphTraversal object.
+ */
+public class TraversalMethodVisitor extends TraversalRootVisitor<GraphTraversal> {
+ // This object is used to append the traversal methods.
+ private GraphTraversal graphTraversal;
+
+ public TraversalMethodVisitor(final GremlinAntlrToJava antlr, GraphTraversal graphTraversal) {
+ super(antlr, graphTraversal);
+ this.graphTraversal = graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Traversal visitTraversalMethod(final GremlinParser.TraversalMethodContext ctx) {
+ return visitChildren(ctx);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_V(final GremlinParser.TraversalMethod_VContext ctx) {
+ if (ctx.genericLiteralList().getChildCount() != 0) {
+ this.graphTraversal = this.graphTraversal.V(GenericLiteralVisitor.getGenericLiteralList(ctx.genericLiteralList()));
+ } else {
+ this.graphTraversal = this.graphTraversal.V();
+ }
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_addV_Empty(final GremlinParser.TraversalMethod_addV_EmptyContext ctx) {
+ this.graphTraversal = this.graphTraversal.addV();
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_addV_String(final GremlinParser.TraversalMethod_addV_StringContext ctx) {
+ this.graphTraversal = this.graphTraversal.addV(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()));
+ return this.graphTraversal;
+ }
+
+ @Override
+ public GraphTraversal visitTraversalMethod_addE_Traversal(final GremlinParser.TraversalMethod_addE_TraversalContext ctx) {
+ this.graphTraversal = this.graphTraversal.addE(antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal()));
+ return this.graphTraversal;
+ }
+
+ @Override
+ public GraphTraversal visitTraversalMethod_addV_Traversal(final GremlinParser.TraversalMethod_addV_TraversalContext ctx) {
+ this.graphTraversal = this.graphTraversal.addV(antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal()));
+ return this.graphTraversal;
+ }
+
+ @Override
+ public GraphTraversal visitTraversalMethod_addE_String(final GremlinParser.TraversalMethod_addE_StringContext ctx) {
+ final int childIndexOfParameterEdgeLabel = 2;
+ final GremlinParser.StringLiteralContext stringLiteralContext =
+ (GremlinParser.StringLiteralContext) (ctx.getChild(childIndexOfParameterEdgeLabel));
+ this.graphTraversal = this.graphTraversal.addE(GenericLiteralVisitor.getStringLiteral(stringLiteralContext));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_aggregate_String(final GremlinParser.TraversalMethod_aggregate_StringContext ctx) {
+ this.graphTraversal = graphTraversal.aggregate(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_aggregate_Scope_String(final GremlinParser.TraversalMethod_aggregate_Scope_StringContext ctx) {
+ this.graphTraversal = graphTraversal.aggregate(
+ TraversalEnumParser.parseTraversalEnumFromContext(Scope.class, ctx.getChild(2)),
+ GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_and(final GremlinParser.TraversalMethod_andContext ctx) {
+ this.graphTraversal = this.graphTraversal.and(
+ antlr.anonymousListVisitor.visitNestedTraversalList(ctx.nestedTraversalList()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_as(final GremlinParser.TraversalMethod_asContext ctx) {
+ if (ctx.getChildCount() == 4) {
+ this.graphTraversal = graphTraversal.as(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()));
+ } else {
+ this.graphTraversal = graphTraversal.as(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()),
+ GenericLiteralVisitor.getStringLiteralList(ctx.stringLiteralList()));
+ }
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_barrier_Consumer(final GremlinParser.TraversalMethod_barrier_ConsumerContext ctx) {
+ // normSack is a special consumer enum type defined in org.apache.tinkerpop.gremlin.process.traversal.SackFunctions.Barrier
+ // it is not used in any other traversal methods.
+ this.graphTraversal = this.graphTraversal.barrier(normSack);
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_barrier_Empty(final GremlinParser.TraversalMethod_barrier_EmptyContext ctx) {
+ this.graphTraversal = graphTraversal.barrier();
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_barrier_int(final GremlinParser.TraversalMethod_barrier_intContext ctx) {
+ this.graphTraversal = graphTraversal.barrier(Integer.valueOf(ctx.integerLiteral().getText()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_both(final GremlinParser.TraversalMethod_bothContext ctx) {
+ graphTraversal.both(GenericLiteralVisitor.getStringLiteralList(ctx.stringLiteralList()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_bothE(final GremlinParser.TraversalMethod_bothEContext ctx) {
+ this.graphTraversal = graphTraversal.bothE(GenericLiteralVisitor.getStringLiteralList(ctx.stringLiteralList()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_bothV(final GremlinParser.TraversalMethod_bothVContext ctx) {
+ this.graphTraversal = graphTraversal.bothV();
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_branch(final GremlinParser.TraversalMethod_branchContext ctx) {
+ this.graphTraversal = this.graphTraversal.branch(antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_by_Comparator(final GremlinParser.TraversalMethod_by_ComparatorContext ctx) {
+ this.graphTraversal = graphTraversal.by(TraversalEnumParser.parseTraversalEnumFromContext(Order.class, ctx.getChild(2)));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_by_Empty(final GremlinParser.TraversalMethod_by_EmptyContext ctx) {
+ this.graphTraversal = graphTraversal.by();
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_by_Function(final GremlinParser.TraversalMethod_by_FunctionContext ctx) {
+ this.graphTraversal = graphTraversal.by(TraversalFunctionVisitor.getInstance().visitTraversalFunction(ctx.traversalFunction()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_by_Function_Comparator(final GremlinParser.TraversalMethod_by_Function_ComparatorContext ctx) {
+ this.graphTraversal = graphTraversal.by(TraversalFunctionVisitor.getInstance().visitTraversalFunction(ctx.traversalFunction()),
+ TraversalEnumParser.parseTraversalEnumFromContext(Order.class, ctx.getChild(4)));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_by_Order(final GremlinParser.TraversalMethod_by_OrderContext ctx) {
+ this.graphTraversal = graphTraversal.by(TraversalEnumParser.parseTraversalEnumFromContext(Order.class, ctx.getChild(2)));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_by_String(final GremlinParser.TraversalMethod_by_StringContext ctx) {
+ this.graphTraversal = graphTraversal.by(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_by_String_Comparator(final GremlinParser.TraversalMethod_by_String_ComparatorContext ctx) {
+ this.graphTraversal = graphTraversal.by(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()),
+ TraversalEnumParser.parseTraversalEnumFromContext(Order.class, ctx.getChild(4)));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_by_T(final GremlinParser.TraversalMethod_by_TContext ctx) {
+ this.graphTraversal = graphTraversal.by(TraversalEnumParser.parseTraversalEnumFromContext(T.class, ctx.getChild(2)));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_by_Traversal(final GremlinParser.TraversalMethod_by_TraversalContext ctx) {
+ this.graphTraversal =
+ this.graphTraversal.by(antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_by_Traversal_Comparator(final GremlinParser.TraversalMethod_by_Traversal_ComparatorContext ctx) {
+ this.graphTraversal =
+ this.graphTraversal.by(antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal()),
+ TraversalEnumParser.parseTraversalEnumFromContext(Order.class, ctx.getChild(4)));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_cap(final GremlinParser.TraversalMethod_capContext ctx) {
+ if (ctx.getChildCount() == 4) {
+ this.graphTraversal = graphTraversal.cap(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()));
+ } else {
+ this.graphTraversal = graphTraversal.cap(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()),
+ GenericLiteralVisitor.getStringLiteralList(ctx.stringLiteralList()));
+ }
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_choose_Function(final GremlinParser.TraversalMethod_choose_FunctionContext ctx) {
+ graphTraversal.choose(TraversalFunctionVisitor.getInstance().visitTraversalFunction(ctx.traversalFunction()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_choose_Predicate_Traversal(final GremlinParser.TraversalMethod_choose_Predicate_TraversalContext ctx) {
+ this.graphTraversal = graphTraversal.choose(TraversalPredicateVisitor.getInstance().visitTraversalPredicate(ctx.traversalPredicate()),
+ antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_choose_Predicate_Traversal_Traversal(final GremlinParser.TraversalMethod_choose_Predicate_Traversal_TraversalContext ctx) {
+ this.graphTraversal = graphTraversal.choose(TraversalPredicateVisitor.getInstance().visitTraversalPredicate(ctx.traversalPredicate()),
+ antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal(0)),
+ antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal(1)));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_choose_Traversal(final GremlinParser.TraversalMethod_choose_TraversalContext ctx) {
+ this.graphTraversal = this.graphTraversal.choose(antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_choose_Traversal_Traversal(final GremlinParser.TraversalMethod_choose_Traversal_TraversalContext ctx) {
+ this.graphTraversal = this.graphTraversal.choose(antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal(0)),
+ antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal(1)));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_choose_Traversal_Traversal_Traversal(final GremlinParser.TraversalMethod_choose_Traversal_Traversal_TraversalContext ctx) {
+ this.graphTraversal = this.graphTraversal.choose(antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal(0)),
+ antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal(1)),
+ antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal(2)));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_coalesce(final GremlinParser.TraversalMethod_coalesceContext ctx) {
+ this.graphTraversal = this.graphTraversal.coalesce(
+ antlr.anonymousListVisitor.visitNestedTraversalList(ctx.nestedTraversalList()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_coin(final GremlinParser.TraversalMethod_coinContext ctx) {
+ this.graphTraversal = graphTraversal.coin(Double.valueOf(ctx.floatLiteral().getText()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_constant(final GremlinParser.TraversalMethod_constantContext ctx) {
+ this.graphTraversal = graphTraversal
+ .constant(GenericLiteralVisitor.getInstance().visitGenericLiteral(ctx.genericLiteral()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_count_Empty(final GremlinParser.TraversalMethod_count_EmptyContext ctx) {
+ this.graphTraversal = graphTraversal.count();
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_count_Scope(final GremlinParser.TraversalMethod_count_ScopeContext ctx) {
+ this.graphTraversal = graphTraversal.count(TraversalEnumParser.parseTraversalEnumFromContext(Scope.class, ctx.getChild(2)));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_cyclicPath(final GremlinParser.TraversalMethod_cyclicPathContext ctx) {
+ this.graphTraversal = graphTraversal.cyclicPath();
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_dedup_Scope_String(final GremlinParser.TraversalMethod_dedup_Scope_StringContext ctx) {
+ this.graphTraversal = graphTraversal.dedup(TraversalEnumParser.parseTraversalEnumFromContext(Scope.class, ctx.getChild(2)),
+ GenericLiteralVisitor.getStringLiteralList(ctx.stringLiteralList()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_dedup_String(final GremlinParser.TraversalMethod_dedup_StringContext ctx) {
+ this.graphTraversal = graphTraversal.dedup(GenericLiteralVisitor.getStringLiteralList(ctx.stringLiteralList()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_drop(final GremlinParser.TraversalMethod_dropContext ctx) {
+ this.graphTraversal = graphTraversal.drop();
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_emit_Empty(final GremlinParser.TraversalMethod_emit_EmptyContext ctx) {
+ this.graphTraversal = graphTraversal.emit();
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_emit_Predicate(final GremlinParser.TraversalMethod_emit_PredicateContext ctx) {
+ this.graphTraversal = graphTraversal.emit(TraversalPredicateVisitor.getInstance().visitTraversalPredicate(ctx.traversalPredicate()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_emit_Traversal(final GremlinParser.TraversalMethod_emit_TraversalContext ctx) {
+ this.graphTraversal =
+ this.graphTraversal.emit(antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_filter_Predicate(final GremlinParser.TraversalMethod_filter_PredicateContext ctx) {
+ this.graphTraversal = graphTraversal.filter(TraversalPredicateVisitor.getInstance().visitTraversalPredicate(ctx.traversalPredicate()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_filter_Traversal(final GremlinParser.TraversalMethod_filter_TraversalContext ctx) {
+ this.graphTraversal =
+ this.graphTraversal.filter(antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_flatMap(final GremlinParser.TraversalMethod_flatMapContext ctx) {
+ this.graphTraversal =
+ this.graphTraversal.flatMap(antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_fold_Empty(final GremlinParser.TraversalMethod_fold_EmptyContext ctx) {
+ this.graphTraversal = graphTraversal.fold();
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_fold_Object_BiFunction(final GremlinParser.TraversalMethod_fold_Object_BiFunctionContext ctx) {
+ graphTraversal.fold(GenericLiteralVisitor.getInstance().visitGenericLiteral(ctx.genericLiteral()),
+ TraversalEnumParser.parseTraversalEnumFromContext(Operator.class, ctx.getChild(4)));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_from_String(final GremlinParser.TraversalMethod_from_StringContext ctx) {
+ this.graphTraversal = graphTraversal.from(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_from_Traversal(final GremlinParser.TraversalMethod_from_TraversalContext ctx) {
+ this.graphTraversal =
+ this.graphTraversal.from(antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_groupCount_Empty(final GremlinParser.TraversalMethod_groupCount_EmptyContext ctx) {
+ this.graphTraversal = graphTraversal.groupCount();
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_groupCount_String(final GremlinParser.TraversalMethod_groupCount_StringContext ctx) {
+ this.graphTraversal = graphTraversal.groupCount(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_group_Empty(final GremlinParser.TraversalMethod_group_EmptyContext ctx) {
+ this.graphTraversal = graphTraversal.group();
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_group_String(final GremlinParser.TraversalMethod_group_StringContext ctx) {
+ this.graphTraversal = graphTraversal.group(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_hasId_Object_Object(final GremlinParser.TraversalMethod_hasId_Object_ObjectContext ctx) {
+ this.graphTraversal = graphTraversal.hasId(GenericLiteralVisitor.getInstance().visitGenericLiteral(ctx.genericLiteral()),
+ GenericLiteralVisitor.getGenericLiteralList(ctx.genericLiteralList()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_hasId_P(final GremlinParser.TraversalMethod_hasId_PContext ctx) {
+ this.graphTraversal = graphTraversal.hasId(TraversalPredicateVisitor.getInstance().visitTraversalPredicate(ctx.traversalPredicate()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_hasKey_P(final GremlinParser.TraversalMethod_hasKey_PContext ctx) {
+ this.graphTraversal = graphTraversal.hasKey(TraversalPredicateVisitor.getInstance().visitTraversalPredicate(ctx.traversalPredicate()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_hasKey_String_String(final GremlinParser.TraversalMethod_hasKey_String_StringContext ctx) {
+ if (ctx.getChildCount() == 4) {
+ this.graphTraversal = graphTraversal.hasKey(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()));
+ } else {
+ this.graphTraversal = graphTraversal.hasKey(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()),
+ GenericLiteralVisitor.getStringLiteralList(ctx.stringLiteralList()));
+ }
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_hasLabel_P(final GremlinParser.TraversalMethod_hasLabel_PContext ctx) {
+ this.graphTraversal = graphTraversal.hasLabel(TraversalPredicateVisitor.getInstance().visitTraversalPredicate(ctx.traversalPredicate()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_hasLabel_String_String(final GremlinParser.TraversalMethod_hasLabel_String_StringContext ctx) {
+ if (ctx.getChildCount() == 4) {
+ this.graphTraversal = graphTraversal.hasLabel(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()));
+ } else {
+ this.graphTraversal = graphTraversal.hasLabel(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()),
+ GenericLiteralVisitor.getStringLiteralList(ctx.stringLiteralList()));
+ }
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_hasNot(final GremlinParser.TraversalMethod_hasNotContext ctx) {
+ this.graphTraversal = graphTraversal.hasNot(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_hasValue_Object_Object(final GremlinParser.TraversalMethod_hasValue_Object_ObjectContext ctx) {
+ this.graphTraversal = graphTraversal.hasValue(GenericLiteralVisitor.getInstance().visitGenericLiteral(ctx.genericLiteral()),
+ GenericLiteralVisitor.getGenericLiteralList(ctx.genericLiteralList()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_hasValue_P(final GremlinParser.TraversalMethod_hasValue_PContext ctx) {
+ this.graphTraversal = graphTraversal.hasValue(TraversalPredicateVisitor.getInstance().visitTraversalPredicate(ctx.traversalPredicate()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_has_String(final GremlinParser.TraversalMethod_has_StringContext ctx) {
+ this.graphTraversal = graphTraversal.has(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_has_String_Object(final GremlinParser.TraversalMethod_has_String_ObjectContext ctx) {
+ this.graphTraversal = graphTraversal.has(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()),
+ new GenericLiteralVisitor(antlr).visitGenericLiteral(ctx.genericLiteral()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_has_String_P(final GremlinParser.TraversalMethod_has_String_PContext ctx) {
+ this.graphTraversal = graphTraversal.has(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()),
+ TraversalPredicateVisitor.getInstance().visitTraversalPredicate(ctx.traversalPredicate()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_has_String_String_Object(final GremlinParser.TraversalMethod_has_String_String_ObjectContext ctx) {
+ this.graphTraversal = graphTraversal.has(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral(0)),
+ GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral(1)),
+ GenericLiteralVisitor.getInstance().visitGenericLiteral(ctx.genericLiteral()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_has_String_String_P(final GremlinParser.TraversalMethod_has_String_String_PContext ctx) {
+ this.graphTraversal = graphTraversal.has(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral(0)),
+ GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral(1)),
+ TraversalPredicateVisitor.getInstance().visitTraversalPredicate(ctx.traversalPredicate()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_has_String_Traversal(final GremlinParser.TraversalMethod_has_String_TraversalContext ctx) {
+ this.graphTraversal = graphTraversal.has(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()),
+ antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_has_T_Object(final GremlinParser.TraversalMethod_has_T_ObjectContext ctx) {
+ this.graphTraversal = graphTraversal.has(TraversalEnumParser.parseTraversalEnumFromContext(T.class, ctx.getChild(2)),
+ new GenericLiteralVisitor(antlr).visitGenericLiteral(ctx.genericLiteral()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_has_T_P(final GremlinParser.TraversalMethod_has_T_PContext ctx) {
+ this.graphTraversal = graphTraversal.has(TraversalEnumParser.parseTraversalEnumFromContext(T.class, ctx.getChild(2)),
+ TraversalPredicateVisitor.getInstance().visitTraversalPredicate(ctx.traversalPredicate()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_has_T_Traversal(final GremlinParser.TraversalMethod_has_T_TraversalContext ctx) {
+ this.graphTraversal = graphTraversal.has(TraversalEnumParser.parseTraversalEnumFromContext(T.class, ctx.getChild(2)),
+ antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_id(final GremlinParser.TraversalMethod_idContext ctx) {
+ this.graphTraversal = graphTraversal.id();
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_identity(final GremlinParser.TraversalMethod_identityContext ctx) {
+ this.graphTraversal = graphTraversal.identity();
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_in(final GremlinParser.TraversalMethod_inContext ctx) {
+ this.graphTraversal = graphTraversal.in(GenericLiteralVisitor.getStringLiteralList(ctx.stringLiteralList()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_inE(final GremlinParser.TraversalMethod_inEContext ctx) {
+ this.graphTraversal = graphTraversal.inE(GenericLiteralVisitor.getStringLiteralList(ctx.stringLiteralList()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_inV(final GremlinParser.TraversalMethod_inVContext ctx) {
+ this.graphTraversal = graphTraversal.inV();
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_inject(final GremlinParser.TraversalMethod_injectContext ctx) {
+ this.graphTraversal = graphTraversal.inject(GenericLiteralVisitor.getGenericLiteralList(ctx.genericLiteralList()));
+ return this.graphTraversal;
+ }
+
+ @Override
+ public GraphTraversal visitTraversalMethod_index(final GremlinParser.TraversalMethod_indexContext ctx) {
+ this.graphTraversal = graphTraversal.index();
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_is_Object(final GremlinParser.TraversalMethod_is_ObjectContext ctx) {
+ this.graphTraversal = graphTraversal.is(GenericLiteralVisitor.getInstance().visitGenericLiteral(ctx.genericLiteral()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_is_P(final GremlinParser.TraversalMethod_is_PContext ctx) {
+ this.graphTraversal = graphTraversal.is(TraversalPredicateVisitor.getInstance().visitTraversalPredicate(ctx.traversalPredicate()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_key(final GremlinParser.TraversalMethod_keyContext ctx) {
+ this.graphTraversal = graphTraversal.key();
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_label(final GremlinParser.TraversalMethod_labelContext ctx) {
+ this.graphTraversal = graphTraversal.label();
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_limit_Scope_long(final GremlinParser.TraversalMethod_limit_Scope_longContext ctx) {
+ this.graphTraversal = graphTraversal.limit(TraversalEnumParser.parseTraversalEnumFromContext(Scope.class, ctx.getChild(2)),
+ Integer.valueOf(ctx.integerLiteral().getText()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_limit_long(final GremlinParser.TraversalMethod_limit_longContext ctx) {
+ this.graphTraversal = graphTraversal.limit(Integer.valueOf(ctx.integerLiteral().getText()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_local(final GremlinParser.TraversalMethod_localContext ctx) {
+ this.graphTraversal = graphTraversal.local(antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal()));
+ return this.graphTraversal;
+ }
+
+ @Override
+ public GraphTraversal visitTraversalMethod_loops_Empty(final GremlinParser.TraversalMethod_loops_EmptyContext ctx) {
+ this.graphTraversal = graphTraversal.loops();
+ return this.graphTraversal;
+ }
+
+ @Override
+ public GraphTraversal visitTraversalMethod_loops_String(final GremlinParser.TraversalMethod_loops_StringContext ctx) {
+ this.graphTraversal = graphTraversal.loops(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()));
+ return this.graphTraversal;
+ }
+
+ @Override
+ public GraphTraversal visitTraversalMethod_repeat_String_Traversal(final GremlinParser.TraversalMethod_repeat_String_TraversalContext ctx) {
+ this.graphTraversal = graphTraversal.repeat((GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral())),
+ antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal()));
+ return this.graphTraversal;
+ }
+
+ @Override
+ public GraphTraversal visitTraversalMethod_repeat_Traversal(final GremlinParser.TraversalMethod_repeat_TraversalContext ctx) {
+ this.graphTraversal = this.graphTraversal.repeat(antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal()));
+ return this.graphTraversal;
+ }
+
+ @Override
+ public GraphTraversal visitTraversalMethod_read(final GremlinParser.TraversalMethod_readContext ctx) {
+ this.graphTraversal = graphTraversal.read();
+ return this.graphTraversal;
+ }
+
+ @Override
+ public GraphTraversal visitTraversalMethod_write(final GremlinParser.TraversalMethod_writeContext ctx) {
+ this.graphTraversal = graphTraversal.write();
+ return this.graphTraversal;
+ }
+
+ @Override
+ public GraphTraversal visitTraversalMethod_with_String(final GremlinParser.TraversalMethod_with_StringContext ctx) {
+ this.graphTraversal = graphTraversal.with(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()));
+ return this.graphTraversal;
+ }
+
+ @Override
+ public GraphTraversal visitTraversalMethod_with_String_Object(final GremlinParser.TraversalMethod_with_String_ObjectContext ctx) {
+ this.graphTraversal = graphTraversal.with(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()),
+ new GenericLiteralVisitor(antlr).visitGenericLiteral(ctx.genericLiteral()));
+ return this.graphTraversal;
+ }
+
+ @Override
+ public GraphTraversal visitTraversalMethod_shortestPath(final GremlinParser.TraversalMethod_shortestPathContext ctx) {
+ this.graphTraversal = graphTraversal.shortestPath();
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_map(final GremlinParser.TraversalMethod_mapContext ctx) {
+ this.graphTraversal = this.graphTraversal.map(antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_match(final GremlinParser.TraversalMethod_matchContext ctx) {
+ this.graphTraversal = this.graphTraversal.match(
+ antlr.anonymousListVisitor.visitNestedTraversalList(ctx.nestedTraversalList()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_max_Empty(final GremlinParser.TraversalMethod_max_EmptyContext ctx) {
+ this.graphTraversal = graphTraversal.max();
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_max_Scope(final GremlinParser.TraversalMethod_max_ScopeContext ctx) {
+ this.graphTraversal = graphTraversal.max(TraversalEnumParser.parseTraversalEnumFromContext(Scope.class, ctx.getChild(2)));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_mean_Empty(final GremlinParser.TraversalMethod_mean_EmptyContext ctx) {
+ this.graphTraversal = graphTraversal.mean();
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_mean_Scope(final GremlinParser.TraversalMethod_mean_ScopeContext ctx) {
+ this.graphTraversal = graphTraversal.mean(TraversalEnumParser.parseTraversalEnumFromContext(Scope.class, ctx.getChild(2)));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_min_Empty(final GremlinParser.TraversalMethod_min_EmptyContext ctx) {
+ this.graphTraversal = graphTraversal.min();
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_min_Scope(final GremlinParser.TraversalMethod_min_ScopeContext ctx) {
+ this.graphTraversal = graphTraversal.min(TraversalEnumParser.parseTraversalEnumFromContext(Scope.class, ctx.getChild(2)));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_not(final GremlinParser.TraversalMethod_notContext ctx) {
+ this.graphTraversal = this.graphTraversal.not(antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_option_Object_Traversal(final GremlinParser.TraversalMethod_option_Object_TraversalContext ctx) {
+ this.graphTraversal = graphTraversal.option(GenericLiteralVisitor.getInstance().visitGenericLiteral(ctx.genericLiteral()),
+ antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_option_Traversal(final GremlinParser.TraversalMethod_option_TraversalContext ctx) {
+ this.graphTraversal =
+ this.graphTraversal.option(antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_optional(final GremlinParser.TraversalMethod_optionalContext ctx) {
+ this.graphTraversal =
+ this.graphTraversal.optional(antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_or(final GremlinParser.TraversalMethod_orContext ctx) {
+ this.graphTraversal = this.graphTraversal.or(
+ antlr.anonymousListVisitor.visitNestedTraversalList(ctx.nestedTraversalList()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_order_Empty(final GremlinParser.TraversalMethod_order_EmptyContext ctx) {
+ this.graphTraversal = graphTraversal.order();
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_order_Scope(final GremlinParser.TraversalMethod_order_ScopeContext ctx) {
+ this.graphTraversal = graphTraversal.order(TraversalEnumParser.parseTraversalEnumFromContext(Scope.class, ctx.getChild(2)));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_otherV(final GremlinParser.TraversalMethod_otherVContext ctx) {
+ this.graphTraversal = graphTraversal.otherV();
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_out(final GremlinParser.TraversalMethod_outContext ctx) {
+ this.graphTraversal = graphTraversal.out(GenericLiteralVisitor.getStringLiteralList(ctx.stringLiteralList()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_outE(final GremlinParser.TraversalMethod_outEContext ctx) {
+ this.graphTraversal = graphTraversal.outE(GenericLiteralVisitor.getStringLiteralList(ctx.stringLiteralList()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_outV(final GremlinParser.TraversalMethod_outVContext ctx) {
+ this.graphTraversal = graphTraversal.outV();
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_pageRank_Empty(final GremlinParser.TraversalMethod_pageRank_EmptyContext ctx) {
+ this.graphTraversal = graphTraversal.pageRank();
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_pageRank_double(final GremlinParser.TraversalMethod_pageRank_doubleContext ctx) {
+ this.graphTraversal = graphTraversal.pageRank(Double.valueOf(ctx.floatLiteral().getText()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_path(final GremlinParser.TraversalMethod_pathContext ctx) {
+ this.graphTraversal = graphTraversal.path();
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_peerPressure(final GremlinParser.TraversalMethod_peerPressureContext ctx) {
+ this.graphTraversal = graphTraversal.peerPressure();
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_profile_Empty(final GremlinParser.TraversalMethod_profile_EmptyContext ctx) {
+ this.graphTraversal = graphTraversal.profile();
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_profile_String(final GremlinParser.TraversalMethod_profile_StringContext ctx) {
+ this.graphTraversal = graphTraversal.profile(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_project(final GremlinParser.TraversalMethod_projectContext ctx) {
+ if (ctx.getChildCount() == 4) {
+ this.graphTraversal = graphTraversal.project(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()));
+ } else {
+ this.graphTraversal = graphTraversal.project(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()),
+ GenericLiteralVisitor.getStringLiteralList(ctx.stringLiteralList()));
+ }
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_properties(final GremlinParser.TraversalMethod_propertiesContext ctx) {
+ this.graphTraversal = graphTraversal.properties(GenericLiteralVisitor.getStringLiteralList(ctx.stringLiteralList()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_elementMap(final GremlinParser.TraversalMethod_elementMapContext ctx) {
+ this.graphTraversal = graphTraversal.elementMap(GenericLiteralVisitor.getStringLiteralList(ctx.stringLiteralList()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_propertyMap(final GremlinParser.TraversalMethod_propertyMapContext ctx) {
+ this.graphTraversal = graphTraversal.propertyMap(GenericLiteralVisitor.getStringLiteralList(ctx.stringLiteralList()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_property_Cardinality_Object_Object_Object(final GremlinParser.TraversalMethod_property_Cardinality_Object_Object_ObjectContext ctx) {
+ this.graphTraversal = graphTraversal.property(TraversalEnumParser.parseTraversalEnumFromContext(VertexProperty.Cardinality.class, ctx.getChild(2)),
+ GenericLiteralVisitor.getInstance().visitGenericLiteral(ctx.genericLiteral(0)),
+ GenericLiteralVisitor.getInstance().visitGenericLiteral(ctx.genericLiteral(1)),
+ GenericLiteralVisitor.getGenericLiteralList(ctx.genericLiteralList()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_property_Object_Object_Object(final GremlinParser.TraversalMethod_property_Object_Object_ObjectContext ctx) {
+ this.graphTraversal = graphTraversal.property(GenericLiteralVisitor.getInstance().visitGenericLiteral(ctx.genericLiteral(0)),
+ GenericLiteralVisitor.getInstance().visitGenericLiteral(ctx.genericLiteral(1)),
+ GenericLiteralVisitor.getGenericLiteralList(ctx.genericLiteralList()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_range_Scope_long_long(final GremlinParser.TraversalMethod_range_Scope_long_longContext ctx) {
+ this.graphTraversal = graphTraversal.range(TraversalEnumParser.parseTraversalEnumFromContext(Scope.class, ctx.getChild(2)),
+ Integer.valueOf(ctx.integerLiteral(0).getText()),
+ Integer.valueOf(ctx.integerLiteral(1).getText()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_range_long_long(final GremlinParser.TraversalMethod_range_long_longContext ctx) {
+ this.graphTraversal = graphTraversal.range(Integer.valueOf(ctx.integerLiteral(0).getText()),
+ Integer.valueOf(ctx.integerLiteral(1).getText()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_sack_BiFunction(final GremlinParser.TraversalMethod_sack_BiFunctionContext ctx) {
+ graphTraversal.sack(TraversalEnumParser.parseTraversalEnumFromContext(Operator.class, ctx.getChild(2)));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_sack_Empty(final GremlinParser.TraversalMethod_sack_EmptyContext ctx) {
+ this.graphTraversal = graphTraversal.sack();
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_sample_Scope_int(final GremlinParser.TraversalMethod_sample_Scope_intContext ctx) {
+ this.graphTraversal = graphTraversal.sample(TraversalEnumParser.parseTraversalEnumFromContext(Scope.class, ctx.getChild(2)),
+ Integer.valueOf(ctx.integerLiteral().getText()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_sample_int(final GremlinParser.TraversalMethod_sample_intContext ctx) {
+ this.graphTraversal = graphTraversal.sample(Integer.valueOf(ctx.integerLiteral().getText()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_select_Column(final GremlinParser.TraversalMethod_select_ColumnContext ctx) {
+ this.graphTraversal = graphTraversal.select(TraversalEnumParser.parseTraversalEnumFromContext(Column.class, ctx.getChild(2)));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_select_Pop_String(final GremlinParser.TraversalMethod_select_Pop_StringContext ctx) {
+ this.graphTraversal = graphTraversal.select(TraversalEnumParser.parseTraversalEnumFromContext(Pop.class, ctx.getChild(2)),
+ GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_select_Pop_String_String_String(final GremlinParser.TraversalMethod_select_Pop_String_String_StringContext ctx) {
+ this.graphTraversal = graphTraversal.select(TraversalEnumParser.parseTraversalEnumFromContext(Pop.class, ctx.getChild(2)),
+ GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral(0)),
+ GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral(1)),
+ GenericLiteralVisitor.getStringLiteralList(ctx.stringLiteralList()));
+ return this.graphTraversal;
+ }
+
+ @Override
+ public GraphTraversal visitTraversalMethod_select_Pop_Traversal(final GremlinParser.TraversalMethod_select_Pop_TraversalContext ctx) {
+ this.graphTraversal = graphTraversal.select(TraversalEnumParser.parseTraversalEnumFromContext(Pop.class, ctx.getChild(2)),
+ antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_select_String(final GremlinParser.TraversalMethod_select_StringContext ctx) {
+ this.graphTraversal = graphTraversal.select(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_select_String_String_String(final GremlinParser.TraversalMethod_select_String_String_StringContext ctx) {
+ this.graphTraversal = graphTraversal.select(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral(0)),
+ GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral(1)),
+ GenericLiteralVisitor.getStringLiteralList(ctx.stringLiteralList()));
+ return this.graphTraversal;
+ }
+
+ @Override
+ public GraphTraversal visitTraversalMethod_select_Traversal(final GremlinParser.TraversalMethod_select_TraversalContext ctx) {
+ this.graphTraversal = graphTraversal.select(antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_sideEffect(final GremlinParser.TraversalMethod_sideEffectContext ctx) {
+ this.graphTraversal =
+ this.graphTraversal.sideEffect(antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_simplePath(final GremlinParser.TraversalMethod_simplePathContext ctx) {
+ this.graphTraversal = graphTraversal.simplePath();
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_skip_Scope_long(final GremlinParser.TraversalMethod_skip_Scope_longContext ctx) {
+ this.graphTraversal = graphTraversal.skip(TraversalEnumParser.parseTraversalEnumFromContext(Scope.class, ctx.getChild(2)),
+ Integer.valueOf(ctx.integerLiteral().getText()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_skip_long(final GremlinParser.TraversalMethod_skip_longContext ctx) {
+ this.graphTraversal = graphTraversal.skip(Integer.valueOf(ctx.integerLiteral().getText()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_store(final GremlinParser.TraversalMethod_storeContext ctx) {
+ this.graphTraversal = graphTraversal.store(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_subgraph(final GremlinParser.TraversalMethod_subgraphContext ctx) {
+ this.graphTraversal = graphTraversal.subgraph(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_sum_Empty(final GremlinParser.TraversalMethod_sum_EmptyContext ctx) {
+ this.graphTraversal = graphTraversal.sum();
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_sum_Scope(final GremlinParser.TraversalMethod_sum_ScopeContext ctx) {
+ this.graphTraversal = graphTraversal.sum(TraversalEnumParser.parseTraversalEnumFromContext(Scope.class, ctx.getChild(2)));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_tail_Empty(final GremlinParser.TraversalMethod_tail_EmptyContext ctx) {
+ this.graphTraversal = graphTraversal.tail();
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_tail_Scope(final GremlinParser.TraversalMethod_tail_ScopeContext ctx) {
+ this.graphTraversal = graphTraversal.tail(TraversalEnumParser.parseTraversalEnumFromContext(Scope.class, ctx.getChild(2)));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_tail_Scope_long(final GremlinParser.TraversalMethod_tail_Scope_longContext ctx) {
+ this.graphTraversal = graphTraversal.tail(TraversalEnumParser.parseTraversalEnumFromContext(Scope.class, ctx.getChild(2)),
+ Integer.valueOf(ctx.integerLiteral().getText()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_tail_long(final GremlinParser.TraversalMethod_tail_longContext ctx) {
+ this.graphTraversal = graphTraversal.tail(Integer.valueOf(ctx.integerLiteral().getText()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_timeLimit(final GremlinParser.TraversalMethod_timeLimitContext ctx) {
+ this.graphTraversal = graphTraversal.timeLimit(Integer.valueOf(ctx.integerLiteral().getText()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_times(final GremlinParser.TraversalMethod_timesContext ctx) {
+ this.graphTraversal = graphTraversal.times(Integer.valueOf(ctx.integerLiteral().getText()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_toE(final GremlinParser.TraversalMethod_toEContext ctx) {
+ this.graphTraversal = graphTraversal.toE(TraversalEnumParser.parseTraversalEnumFromContext(Direction.class, ctx.getChild(2)),
+ GenericLiteralVisitor.getStringLiteralList(ctx.stringLiteralList()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_toV(final GremlinParser.TraversalMethod_toVContext ctx) {
+ this.graphTraversal = graphTraversal.toV(TraversalEnumParser.parseTraversalEnumFromContext(Direction.class, ctx.getChild(2)));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_to_Direction_String(final GremlinParser.TraversalMethod_to_Direction_StringContext ctx) {
+ this.graphTraversal = graphTraversal.to(TraversalEnumParser.parseTraversalEnumFromContext(Direction.class, ctx.getChild(2)),
+ GenericLiteralVisitor.getStringLiteralList(ctx.stringLiteralList()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_to_String(final GremlinParser.TraversalMethod_to_StringContext ctx) {
+ this.graphTraversal = graphTraversal.to(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_to_Traversal(final GremlinParser.TraversalMethod_to_TraversalContext ctx) {
+ this.graphTraversal =
+ this.graphTraversal.to(antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_tree_Empty(final GremlinParser.TraversalMethod_tree_EmptyContext ctx) {
+ this.graphTraversal = graphTraversal.tree();
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_tree_String(final GremlinParser.TraversalMethod_tree_StringContext ctx) {
+ this.graphTraversal = graphTraversal.tree(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_unfold(final GremlinParser.TraversalMethod_unfoldContext ctx) {
+ this.graphTraversal = graphTraversal.unfold();
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_union(final GremlinParser.TraversalMethod_unionContext ctx) {
+ this.graphTraversal = this.graphTraversal.union(
+ antlr.anonymousListVisitor.visitNestedTraversalList(ctx.nestedTraversalList()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_until_Predicate(final GremlinParser.TraversalMethod_until_PredicateContext ctx) {
+ this.graphTraversal = graphTraversal.until(TraversalPredicateVisitor.getInstance().visitTraversalPredicate(ctx.traversalPredicate()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_until_Traversal(final GremlinParser.TraversalMethod_until_TraversalContext ctx) {
+ this.graphTraversal =
+ this.graphTraversal.until(antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_value(final GremlinParser.TraversalMethod_valueContext ctx) {
+ this.graphTraversal = graphTraversal.value();
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_valueMap_String(final GremlinParser.TraversalMethod_valueMap_StringContext ctx) {
+ this.graphTraversal = graphTraversal.valueMap(GenericLiteralVisitor.getStringLiteralList(ctx.stringLiteralList()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_valueMap_boolean_String(final GremlinParser.TraversalMethod_valueMap_boolean_StringContext ctx) {
+ if (ctx.getChildCount() == 4) {
+ this.graphTraversal = graphTraversal.valueMap(Boolean.valueOf(ctx.booleanLiteral().getText()));
+ } else {
+ this.graphTraversal = graphTraversal.valueMap(Boolean.valueOf(ctx.booleanLiteral().getText()),
+ GenericLiteralVisitor.getStringLiteralList(ctx.stringLiteralList()));
+ }
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_values(final GremlinParser.TraversalMethod_valuesContext ctx) {
+ this.graphTraversal = graphTraversal.values(GenericLiteralVisitor.getStringLiteralList(ctx.stringLiteralList()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_where_P(final GremlinParser.TraversalMethod_where_PContext ctx) {
+ this.graphTraversal = graphTraversal.where(TraversalPredicateVisitor.getInstance().visitTraversalPredicate(ctx.traversalPredicate()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_where_String_P(final GremlinParser.TraversalMethod_where_String_PContext ctx) {
+ this.graphTraversal = graphTraversal.where(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()),
+ TraversalPredicateVisitor.getInstance().visitTraversalPredicate(ctx.traversalPredicate()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalMethod_where_Traversal(final GremlinParser.TraversalMethod_where_TraversalContext ctx) {
+ this.graphTraversal =
+ this.graphTraversal.where(antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal()));
+ return this.graphTraversal;
+ }
+
+ @Override
+ public GraphTraversal visitTraversalMethod_math(final GremlinParser.TraversalMethod_mathContext ctx) {
+ this.graphTraversal = graphTraversal.math(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()));
+ return this.graphTraversal;
+ }
+
+ public GraphTraversal[] getNestedTraversalList(final GremlinParser.NestedTraversalListContext ctx) {
+ return ctx.nestedTraversalExpr().nestedTraversal()
+ .stream()
+ .map(this::visitNestedTraversal)
+ .toArray(GraphTraversal[]::new);
+ }
+}
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalPredicateVisitor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalPredicateVisitor.java
new file mode 100644
index 0000000..6be27b2
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalPredicateVisitor.java
@@ -0,0 +1,256 @@
+/*
+ * 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.language.grammar;
+
+import org.antlr.v4.runtime.tree.ParseTree;
+import org.apache.tinkerpop.gremlin.process.traversal.P;
+import org.apache.tinkerpop.gremlin.process.traversal.TextP;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * As this class does not need any status, use singleton pattern to avoid object creation and GC overhead.
+ */
+public class TraversalPredicateVisitor extends GremlinBaseVisitor<P> {
+ private static TraversalPredicateVisitor instance;
+
+ public static TraversalPredicateVisitor getInstance() {
+ if (instance == null) {
+ instance = new TraversalPredicateVisitor();
+ }
+ return instance;
+ }
+
+ private TraversalPredicateVisitor() {}
+
+ /**
+ * Cast ParseTree node child into TraversalPredicateContext
+ * @param ctx : ParseTree node
+ * @param childIndex : child index
+ * @return casted TraversalPredicateContext
+ */
+ private GremlinParser.TraversalPredicateContext castChildToTraversalPredicate(final ParseTree ctx, final int childIndex) {
+ return (GremlinParser.TraversalPredicateContext)(ctx.getChild(childIndex));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public P visitTraversalPredicate(final GremlinParser.TraversalPredicateContext ctx) {
+ switch(ctx.getChildCount()) {
+ case 1:
+ // handle simple predicate
+ return visitChildren(ctx);
+ case 5:
+ // handle negate
+ return visit(ctx.getChild(0)).negate();
+ case 6:
+ final int childIndexOfParameterOperator = 2;
+ final int childIndexOfCaller = 0;
+ final int childIndexOfArgument = 4;
+
+ if (ctx.getChild(childIndexOfParameterOperator).getText().equals("or")) {
+ // handle or
+ return visit(ctx.getChild(childIndexOfCaller)).or(visit(ctx.getChild(childIndexOfArgument)));
+ } else {
+ // handle and
+ return visit(ctx.getChild(childIndexOfCaller)).and(visit(ctx.getChild(childIndexOfArgument)));
+ }
+ default:
+ throw new RuntimeException("unexpected number of children in TraversalPredicateContext " + ctx.getChildCount());
+ }
+ }
+
+ /**
+ * get 1 generic literal argument from the antlr parse tree context,
+ * where the arguments has the child index of 2
+ */
+ private Object getSingleGenericLiteralArgument(final ParseTree ctx) {
+ final int childIndexOfParameterValue = 2;
+
+ return GenericLiteralVisitor.getInstance().visitGenericLiteral(
+ ParseTreeContextCastHelper.castChildToGenericLiteral(ctx, childIndexOfParameterValue));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public P visitTraversalPredicate_eq(final GremlinParser.TraversalPredicate_eqContext ctx) {
+ return P.eq(getSingleGenericLiteralArgument(ctx));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public P visitTraversalPredicate_neq(final GremlinParser.TraversalPredicate_neqContext ctx) {
+ return P.neq(getSingleGenericLiteralArgument(ctx));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public P visitTraversalPredicate_lt(final GremlinParser.TraversalPredicate_ltContext ctx) {
+ return P.lt(getSingleGenericLiteralArgument(ctx));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public P visitTraversalPredicate_lte(final GremlinParser.TraversalPredicate_lteContext ctx) {
+ return P.lte(getSingleGenericLiteralArgument(ctx));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public P visitTraversalPredicate_gt(final GremlinParser.TraversalPredicate_gtContext ctx) {
+ return P.gt(getSingleGenericLiteralArgument(ctx));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public P visitTraversalPredicate_gte(final GremlinParser.TraversalPredicate_gteContext ctx) {
+ return P.gte(getSingleGenericLiteralArgument(ctx));
+ }
+
+ /**
+ * get 2 generic literal arguments from the antlr parse tree context,
+ * where the arguments has the child index of 2 and 4
+ */
+ private Object[] getDoubleGenericLiteralArgument(ParseTree ctx) {
+ final int childIndexOfParameterFirst = 2;
+ final int childIndexOfParameterSecond = 4;
+
+ final Object first = GenericLiteralVisitor.getInstance().visitGenericLiteral(
+ ParseTreeContextCastHelper.castChildToGenericLiteral(ctx, childIndexOfParameterFirst));
+ final Object second = GenericLiteralVisitor.getInstance().visitGenericLiteral(
+ ParseTreeContextCastHelper.castChildToGenericLiteral(ctx, childIndexOfParameterSecond));
+
+ return new Object[]{first, second};
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public P visitTraversalPredicate_inside(final GremlinParser.TraversalPredicate_insideContext ctx) {
+ final Object[] arguments = getDoubleGenericLiteralArgument(ctx);
+ return P.inside(arguments[0], arguments[1]);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public P visitTraversalPredicate_outside(final GremlinParser.TraversalPredicate_outsideContext ctx) {
+ final Object[] arguments = getDoubleGenericLiteralArgument(ctx);
+ return P.outside(arguments[0], arguments[1]);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public P visitTraversalPredicate_between(final GremlinParser.TraversalPredicate_betweenContext ctx) {
+ final Object[] arguments = getDoubleGenericLiteralArgument(ctx);
+ return P.between(arguments[0], arguments[1]);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public P visitTraversalPredicate_within(final GremlinParser.TraversalPredicate_withinContext ctx) {
+ final int childIndexOfParameterValues = 2;
+
+ final Object arguments = GenericLiteralVisitor.getInstance().visitGenericLiteralList(
+ ParseTreeContextCastHelper.castChildToGenericLiteralList(ctx, childIndexOfParameterValues));
+
+ if (arguments instanceof Object[]) {
+ // when generic literal list is consist of a comma separated generic literals
+ return P.within((Object [])arguments);
+ } else if (arguments instanceof List || arguments instanceof Set) {
+ // when generic literal list is consist of a collection of generic literals, E.g. range
+ return P.within((Collection) arguments);
+ } else {
+ // when generic literal list is consist of a single generic literal
+ return P.within(arguments);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public P visitTraversalPredicate_without(final GremlinParser.TraversalPredicate_withoutContext ctx) {
+ final int childIndexOfParameterValues = 2;
+
+ final Object arguments = GenericLiteralVisitor.getInstance().visitGenericLiteralList(
+ ParseTreeContextCastHelper.castChildToGenericLiteralList(ctx, childIndexOfParameterValues));
+
+ if (arguments instanceof Object[]) {
+ // when generic literal list is consist of a comma separated generic literals
+ return P.without((Object [])arguments);
+ } else if (arguments instanceof List) {
+ // when generic literal list is consist of a collection of generic literals, E.g. range
+ return P.without((List)arguments);
+ } else {
+ // when generic literal list is consist of a single generic literal
+ return P.without(arguments);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public P visitTraversalPredicate_not(final GremlinParser.TraversalPredicate_notContext ctx) {
+ final int childIndexOfParameterPredicate = 2;
+
+ return P.not(visitTraversalPredicate(castChildToTraversalPredicate(ctx, childIndexOfParameterPredicate)));
+ }
+
+ @Override
+ public P visitTraversalPredicate_containing(final GremlinParser.TraversalPredicate_containingContext ctx) {
+ return TextP.containing(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()));
+ }
+
+ @Override
+ public P visitTraversalPredicate_notContaining(final GremlinParser.TraversalPredicate_notContainingContext ctx) {
+ return TextP.notContaining(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()));
+ }
+
+ @Override
+ public P visitTraversalPredicate_notEndingWith(final GremlinParser.TraversalPredicate_notEndingWithContext ctx) {
+ return TextP.notEndingWith(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()));
+ }
+
+ @Override
+ public P visitTraversalPredicate_endingWith(final GremlinParser.TraversalPredicate_endingWithContext ctx) {
+ return TextP.endingWith(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()));
+ }
+
+ @Override
+ public P visitTraversalPredicate_startingWith(final GremlinParser.TraversalPredicate_startingWithContext ctx) {
+ return TextP.startingWith(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()));
+ }
+
+ @Override
+ public P visitTraversalPredicate_notStartingWith(final GremlinParser.TraversalPredicate_notStartingWithContext ctx) {
+ return TextP.notStartingWith(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()));
+ }
+}
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalRootVisitor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalRootVisitor.java
new file mode 100644
index 0000000..239c87e
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalRootVisitor.java
@@ -0,0 +1,139 @@
+/*
+ * 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.language.grammar;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
+
+/**
+ * This visitor handles the cases when a new traversal is getting started. It could either be a nested traversal
+ * or a root traversal, but in either case should be anonymous.
+ */
+public class TraversalRootVisitor<G extends Traversal> extends GremlinBaseVisitor<Traversal> {
+ private Traversal traversal;
+ protected final GremlinAntlrToJava antlr;
+
+ /**
+ * Constructor to produce an anonymous traversal.
+ */
+ public TraversalRootVisitor(final GremlinAntlrToJava antlr) {
+ this(antlr, null);
+ }
+
+ /**
+ * Constructor to build on an existing traversal.
+ */
+ public TraversalRootVisitor(final Traversal traversal) {
+ this(null, traversal);
+ }
+
+ public TraversalRootVisitor(final GremlinAntlrToJava antlr, final Traversal traversal) {
+ this.traversal = traversal;
+ this.antlr = antlr;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Traversal visitNestedTraversal(final GremlinParser.NestedTraversalContext ctx) {
+ if (ctx.getChild(0) instanceof GremlinParser.RootTraversalContext) {
+ return visitChildren(ctx);
+ } else if (ctx.getChild(2) instanceof GremlinParser.ChainedParentOfGraphTraversalContext) {
+ return new TraversalRootVisitor<Traversal>(antlr.createAnonymous.get()).visitChainedParentOfGraphTraversal(ctx.chainedTraversal().chainedParentOfGraphTraversal());
+ } else {
+ return new TraversalMethodVisitor(antlr, antlr.createAnonymous.get()).visitChainedTraversal(ctx.chainedTraversal());
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Traversal visitRootTraversal(final GremlinParser.RootTraversalContext ctx) {
+ // create traversal source
+ final int childIndexOfTraversalSource = 0;
+ final GraphTraversalSource source = antlr.gvisitor.visitTraversalSource(
+ (GremlinParser.TraversalSourceContext) ctx.getChild(childIndexOfTraversalSource));
+ // call traversal source spawn method
+ final int childIndexOfTraversalSourceSpawnMethod = 2;
+ final GraphTraversal traversal = new TraversalSourceSpawnMethodVisitor(source, this).visitTraversalSourceSpawnMethod(
+ (GremlinParser.TraversalSourceSpawnMethodContext) ctx.getChild(childIndexOfTraversalSourceSpawnMethod));
+
+ if (ctx.getChildCount() == 5) {
+ // handle chained traversal
+ final int childIndexOfChainedTraversal = 4;
+
+ if (ctx.getChild(childIndexOfChainedTraversal) instanceof GremlinParser.ChainedParentOfGraphTraversalContext) {
+ final TraversalRootVisitor traversalRootVisitor = new TraversalRootVisitor(traversal);
+ return traversalRootVisitor.visitChainedParentOfGraphTraversal((GremlinParser.ChainedParentOfGraphTraversalContext) ctx.getChild(childIndexOfChainedTraversal));
+ } else {
+ final TraversalMethodVisitor traversalMethodVisitor = new TraversalMethodVisitor(antlr, traversal);
+ return traversalMethodVisitor.visitChainedTraversal((GremlinParser.ChainedTraversalContext) ctx.getChild(childIndexOfChainedTraversal));
+ }
+ } else {
+ return traversal;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Traversal visitTraversalSelfMethod(final GremlinParser.TraversalSelfMethodContext ctx) {
+ return visitChildren(ctx);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Traversal visitTraversalSelfMethod_none(final GremlinParser.TraversalSelfMethod_noneContext ctx) {
+ this.traversal = traversal.none();
+ return this.traversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Traversal visitChainedParentOfGraphTraversal(final GremlinParser.ChainedParentOfGraphTraversalContext ctx) {
+ if (ctx.getChildCount() == 1) {
+ return visitChildren(ctx);
+ } else {
+ visit(ctx.getChild(0));
+ return visit(ctx.getChild(2));
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Traversal visitChainedTraversal(final GremlinParser.ChainedTraversalContext ctx) {
+ if (ctx.getChildCount() == 1) {
+ return visitChildren(ctx);
+ } else {
+ visit(ctx.getChild(0));
+ return visit(ctx.getChild(2));
+ }
+ }
+}
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalSourceSelfMethodVisitor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalSourceSelfMethodVisitor.java
new file mode 100644
index 0000000..916999e
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalSourceSelfMethodVisitor.java
@@ -0,0 +1,152 @@
+/*
+ * 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.language.grammar;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Operator;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Graph Traversal source self method visitor
+ */
+public class TraversalSourceSelfMethodVisitor extends GremlinBaseVisitor<GraphTraversalSource> {
+
+ private GremlinBaseVisitor<TraversalStrategy> traversalStrategyVisitor;
+ private GraphTraversalSource source;
+ private final GremlinAntlrToJava antlr;
+
+ public TraversalSourceSelfMethodVisitor(final GraphTraversalSource source, final GremlinAntlrToJava antlr) {
+ this.source = source;
+ this.antlr = antlr;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversalSource visitTraversalSourceSelfMethod(final GremlinParser.TraversalSourceSelfMethodContext ctx) {
+ return visitChildren(ctx);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversalSource visitTraversalSourceSelfMethod_withBulk(final GremlinParser.TraversalSourceSelfMethod_withBulkContext ctx)
+ {
+ final int childIndexOfParameterUseBulk = 2;
+
+ final Boolean useBulk = (Boolean)(GenericLiteralVisitor.getInstance().visitBooleanLiteral(
+ (GremlinParser.BooleanLiteralContext)(ctx.getChild(childIndexOfParameterUseBulk))));
+
+ return source.withBulk(useBulk);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversalSource visitTraversalSourceSelfMethod_withPath(final GremlinParser.TraversalSourceSelfMethod_withPathContext ctx)
+ {
+ return source.withPath();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversalSource visitTraversalSourceSelfMethod_withSack(final GremlinParser.TraversalSourceSelfMethod_withSackContext ctx)
+ {
+ final int childIndexOfParameterInitialValue = 2;
+
+ if (ctx.getChildCount() == 4) {
+ return source.withSack(GenericLiteralVisitor.getInstance().visitGenericLiteral(
+ ParseTreeContextCastHelper.castChildToGenericLiteral(ctx, childIndexOfParameterInitialValue)));
+ } else {
+ final int childIndexOfParameterMergeOperator = 4;
+
+ return source.withSack(GenericLiteralVisitor.getInstance().visitGenericLiteral(
+ ParseTreeContextCastHelper.castChildToGenericLiteral(ctx, childIndexOfParameterInitialValue)),
+ TraversalEnumParser.parseTraversalEnumFromContext(Operator.class, ctx.getChild(childIndexOfParameterMergeOperator)));
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversalSource visitTraversalSourceSelfMethod_withSideEffect(final GremlinParser.TraversalSourceSelfMethod_withSideEffectContext ctx)
+ {
+ final int childIndexOfParameterKey = 2;
+ final int childIndexOfParameterInitialValue = 4;
+
+ final String argument1 = (String)(GenericLiteralVisitor.getInstance().visitStringLiteral(
+ (GremlinParser.StringLiteralContext)(ctx.getChild(childIndexOfParameterKey))));
+ final Object argument2 = GenericLiteralVisitor.getInstance().visitGenericLiteral(
+ (GremlinParser.GenericLiteralContext)(ctx.getChild(childIndexOfParameterInitialValue)));
+
+ return source.withSideEffect(argument1, argument2);
+ }
+
+ @Override
+ public GraphTraversalSource visitTraversalSourceSelfMethod_withStrategies(final GremlinParser.TraversalSourceSelfMethod_withStrategiesContext ctx) {
+
+ if (null == traversalStrategyVisitor)
+ traversalStrategyVisitor = new TraversalStrategyVisitor((GremlinBaseVisitor) antlr.tvisitor);
+
+ // with 4 children withStrategies() was called with a single TraversalStrategy, otherwise multiple were
+ // specified.
+ if (ctx.getChildCount() < 5) {
+ return source.withStrategies(traversalStrategyVisitor.visitTraversalStrategy((GremlinParser.TraversalStrategyContext) ctx.getChild(2)));
+ } else {
+ final Object[] vargs = GenericLiteralVisitor.getTraversalStrategyList(
+ (GremlinParser.TraversalStrategyListContext) ctx.getChild(4), traversalStrategyVisitor);
+ final List<TraversalStrategy> strats = new ArrayList<>(Arrays.asList(Arrays.copyOf(vargs, vargs.length, TraversalStrategy[].class)));
+ strats.add(0, traversalStrategyVisitor.visitTraversalStrategy((GremlinParser.TraversalStrategyContext) ctx.getChild(2)));
+ return source.withStrategies(strats.toArray(new TraversalStrategy[strats.size()]));
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversalSource visitTraversalSourceSelfMethod_with(final GremlinParser.TraversalSourceSelfMethod_withContext ctx)
+ {
+ final int childIndexOfParameterKey = 2;
+
+ if (ctx.getChildCount() == 4) {
+ final String argument1 = (String)(GenericLiteralVisitor.getInstance().visitStringLiteral(
+ (GremlinParser.StringLiteralContext)(ctx.getChild(childIndexOfParameterKey))));
+ return source.with(argument1);
+ } else {
+ final int childIndexOfParameterInitialValue = 4;
+
+ final String argument1 = (String)(GenericLiteralVisitor.getInstance().visitStringLiteral(
+ (GremlinParser.StringLiteralContext)(ctx.getChild(childIndexOfParameterKey))));
+ final Object argument2 = GenericLiteralVisitor.getInstance().visitGenericLiteral(
+ (GremlinParser.GenericLiteralContext)(ctx.getChild(childIndexOfParameterInitialValue)));
+ return source.with(argument1, argument2);
+ }
+ }
+}
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalSourceSpawnMethodVisitor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalSourceSpawnMethodVisitor.java
new file mode 100644
index 0000000..2f8dbf9
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalSourceSpawnMethodVisitor.java
@@ -0,0 +1,124 @@
+/*
+ * 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.language.grammar;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+
+/**
+ * This class implements gremlin grammar's source-spawn methods which uses a
+ * GraphTraversalSource as the source and returns a GraphTraversal object.
+ */
+public class TraversalSourceSpawnMethodVisitor extends GremlinBaseVisitor<GraphTraversal> {
+
+ protected GraphTraversalSource traversalSource;
+ protected GraphTraversal graphTraversal;
+ protected final GremlinBaseVisitor<Traversal> anonymousVisitor;
+
+ public TraversalSourceSpawnMethodVisitor(final GraphTraversalSource traversalSource,
+ final GremlinBaseVisitor<Traversal> anonymousVisitor) {
+ this.traversalSource = traversalSource;
+ this.anonymousVisitor = anonymousVisitor;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalSourceSpawnMethod(final GremlinParser.TraversalSourceSpawnMethodContext ctx) {
+ return visitChildren(ctx);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalSourceSpawnMethod_addE(final GremlinParser.TraversalSourceSpawnMethod_addEContext ctx) {
+ if (ctx.stringLiteral() != null) {
+ this.graphTraversal = this.traversalSource.addE(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()));
+ } else if (ctx.nestedTraversal() != null) {
+ this.graphTraversal = this.traversalSource.addE(anonymousVisitor.visitNestedTraversal(ctx.nestedTraversal()));
+ } else {
+ throw new IllegalArgumentException("addE with empty arguments is not valid.");
+ }
+
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalSourceSpawnMethod_addV(final GremlinParser.TraversalSourceSpawnMethod_addVContext ctx) {
+ if (ctx.stringLiteral() != null) {
+ this.graphTraversal = this.traversalSource.addV(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()));
+ } else if (ctx.nestedTraversal() != null) {
+ this.graphTraversal = this.traversalSource.addV(anonymousVisitor.visitNestedTraversal(ctx.nestedTraversal()));
+ } else {
+ this.graphTraversal = this.traversalSource.addV();
+ }
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalSourceSpawnMethod_E(final GremlinParser.TraversalSourceSpawnMethod_EContext ctx) {
+ if (ctx.genericLiteralList().getChildCount() > 0) {
+ this.graphTraversal = this.traversalSource.E(GenericLiteralVisitor.getGenericLiteralList(ctx.genericLiteralList()));
+ } else {
+ this.graphTraversal = this.traversalSource.E();
+ }
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalSourceSpawnMethod_V(final GremlinParser.TraversalSourceSpawnMethod_VContext ctx) {
+ if (ctx.genericLiteralList().getChildCount() > 0) {
+ this.graphTraversal = this.traversalSource.V(GenericLiteralVisitor.getGenericLiteralList(ctx.genericLiteralList()));
+ } else {
+ this.graphTraversal = this.traversalSource.V();
+ }
+ return this.graphTraversal;
+ }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalSourceSpawnMethod_inject(final GremlinParser.TraversalSourceSpawnMethod_injectContext ctx) {
+ this.graphTraversal = this.traversalSource.inject(GenericLiteralVisitor.getGenericLiteralList(ctx.genericLiteralList()));
+ return this.graphTraversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GraphTraversal visitTraversalSourceSpawnMethod_io(final GremlinParser.TraversalSourceSpawnMethod_ioContext ctx) {
+ if (ctx.getChildCount() > 2) {
+ this.graphTraversal = this.traversalSource.io(ctx.getChild(2).getText());
+ }
+ return graphTraversal;
+ }
+}
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalStrategyVisitor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalStrategyVisitor.java
new file mode 100644
index 0000000..b8e5f50
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalStrategyVisitor.java
@@ -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.language.grammar;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.PartitionStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SubgraphStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.EdgeLabelVerificationStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReadOnlyStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReservedKeysVerificationStrategy;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+
+public class TraversalStrategyVisitor extends GremlinBaseVisitor<TraversalStrategy> {
+ protected final GremlinBaseVisitor<Traversal> tvisitor;
+
+ public TraversalStrategyVisitor(final GremlinBaseVisitor<Traversal> tvisitor) {
+ this.tvisitor = tvisitor;
+ }
+
+ @Override
+ public TraversalStrategy visitTraversalStrategy(final GremlinParser.TraversalStrategyContext ctx) {
+ // child count of one implies init syntax for the singleton constructed strategies. otherwise, it will
+ // fall back to the Builder methods for construction
+ if (ctx.getChildCount() == 1) {
+ final String strategyName = ctx.getChild(0).getText();
+ if (strategyName.equals(ReadOnlyStrategy.class.getSimpleName()))
+ return ReadOnlyStrategy.instance();
+ } else if (ctx.getChild(0).getText().equals("new")) {
+ final String strategyName = ctx.getChild(1).getText();
+ if (strategyName.equals(PartitionStrategy.class.getSimpleName()))
+ return getPartitionStrategy(ctx.traversalStrategyArgs_PartitionStrategy());
+ else if (strategyName.equals(ReservedKeysVerificationStrategy.class.getSimpleName()))
+ return getReservedKeysVerificationStrategy(ctx.traversalStrategyArgs_ReservedKeysVerificationStrategy());
+ else if (strategyName.equals(EdgeLabelVerificationStrategy.class.getSimpleName()))
+ return getEdgeLabelVerificationStrategy(ctx.traversalStrategyArgs_EdgeLabelVerificationStrategy());
+ else if (strategyName.equals(SubgraphStrategy.class.getSimpleName()))
+ return getSubgraphStrategy(ctx.traversalStrategyArgs_SubgraphStrategy());
+ }
+ throw new IllegalStateException("Unexpected TraversalStrategy specification - " + ctx.getText());
+ }
+
+ private static EdgeLabelVerificationStrategy getEdgeLabelVerificationStrategy(final List<GremlinParser.TraversalStrategyArgs_EdgeLabelVerificationStrategyContext> ctxs) {
+ if (null == ctxs || ctxs.isEmpty())
+ return EdgeLabelVerificationStrategy.build().create();
+
+ final EdgeLabelVerificationStrategy.Builder builder = EdgeLabelVerificationStrategy.build();
+ ctxs.forEach(ctx -> {
+ switch (ctx.getChild(0).getText()) {
+ case "logWarning":
+ builder.logWarning(GenericLiteralVisitor.getBooleanLiteral(ctx.booleanLiteral()));
+ break;
+ case "throwException":
+ builder.throwException(GenericLiteralVisitor.getBooleanLiteral(ctx.booleanLiteral()));
+ break;
+ }
+ });
+
+ return builder.create();
+ }
+
+ private static ReservedKeysVerificationStrategy getReservedKeysVerificationStrategy(final List<GremlinParser.TraversalStrategyArgs_ReservedKeysVerificationStrategyContext> ctxs) {
+ if (null == ctxs || ctxs.isEmpty())
+ return ReservedKeysVerificationStrategy.build().create();
+
+ final ReservedKeysVerificationStrategy.Builder builder = ReservedKeysVerificationStrategy.build();
+ ctxs.forEach(ctx -> {
+ switch (ctx.getChild(0).getText()) {
+ case "logWarning":
+ builder.logWarning(GenericLiteralVisitor.getBooleanLiteral(ctx.booleanLiteral()));
+ break;
+ case "throwException":
+ builder.throwException(GenericLiteralVisitor.getBooleanLiteral(ctx.booleanLiteral()));
+ break;
+ case "keys":
+ builder.reservedKeys(new HashSet<>(Arrays.asList(GenericLiteralVisitor.getStringLiteralList(ctx.stringLiteralList()))));
+ break;
+ }
+ });
+
+ return builder.create();
+ }
+
+ private static PartitionStrategy getPartitionStrategy(final List<GremlinParser.TraversalStrategyArgs_PartitionStrategyContext> ctxs) {
+ final PartitionStrategy.Builder builder = PartitionStrategy.build();
+ ctxs.forEach(ctx -> {
+ switch (ctx.getChild(0).getText()) {
+ case PartitionStrategy.INCLUDE_META_PROPERTIES:
+ builder.includeMetaProperties(GenericLiteralVisitor.getBooleanLiteral(ctx.booleanLiteral()));
+ break;
+ case PartitionStrategy.READ_PARTITIONS:
+ builder.readPartitions(Arrays.asList(GenericLiteralVisitor.getStringLiteralList(ctx.stringLiteralList())));
+ break;
+ case PartitionStrategy.WRITE_PARTITION:
+ builder.writePartition(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()));
+ break;
+ case PartitionStrategy.PARTITION_KEY:
+ builder.partitionKey(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()));
+ break;
+ }
+ });
+
+ return builder.create();
+ }
+
+ private SubgraphStrategy getSubgraphStrategy(final List<GremlinParser.TraversalStrategyArgs_SubgraphStrategyContext> ctxs) {
+ final SubgraphStrategy.Builder builder = SubgraphStrategy.build();
+ ctxs.forEach(ctx -> {
+ switch (ctx.getChild(0).getText()) {
+ case SubgraphStrategy.VERTICES:
+ builder.vertices(tvisitor.visitNestedTraversal(ctx.nestedTraversal()));
+ break;
+ case SubgraphStrategy.EDGES:
+ builder.edges(tvisitor.visitNestedTraversal(ctx.nestedTraversal()));
+ break;
+ case SubgraphStrategy.VERTEX_PROPERTIES:
+ builder.vertexProperties(tvisitor.visitNestedTraversal(ctx.nestedTraversal()));
+ break;
+ case SubgraphStrategy.CHECK_ADJACENT_VERTICES:
+ builder.checkAdjacentVertices(GenericLiteralVisitor.getBooleanLiteral(ctx.booleanLiteral()));
+ break;
+ }
+ });
+
+ return builder.create();
+ }
+}
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalTerminalMethodVisitor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalTerminalMethodVisitor.java
new file mode 100644
index 0000000..2a3e985
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalTerminalMethodVisitor.java
@@ -0,0 +1,140 @@
+/*
+ * 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.language.grammar;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.structure.util.CloseableIterator;
+
+/**
+ * Traversal terminal method visitor
+ */
+public class TraversalTerminalMethodVisitor extends GremlinBaseVisitor<Object> {
+
+ protected final Traversal<?,?> traversal;
+
+ public TraversalTerminalMethodVisitor(final Traversal<?,?> traversal) {
+ this.traversal = traversal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object visitTraversalTerminalMethod(final GremlinParser.TraversalTerminalMethodContext ctx) {
+ return visitChildren(ctx);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Traversal terminal method explain step
+ */
+ @Override
+ public Object visitTraversalTerminalMethod_explain(final GremlinParser.TraversalTerminalMethod_explainContext ctx) {
+ return traversal.explain();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Traversal terminal method has next step
+ */
+ @Override
+ public Object visitTraversalTerminalMethod_hasNext(final GremlinParser.TraversalTerminalMethod_hasNextContext ctx) {
+ try {
+ return traversal.hasNext();
+ } finally {
+ CloseableIterator.closeIterator(traversal);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Traversal terminal method iterate step
+ */
+ @Override
+ public Object visitTraversalTerminalMethod_iterate(final GremlinParser.TraversalTerminalMethod_iterateContext ctx) {
+ return traversal.iterate();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Traversal terminal method try next step
+ */
+ @Override
+ public Object visitTraversalTerminalMethod_tryNext(final GremlinParser.TraversalTerminalMethod_tryNextContext ctx) {
+ try {
+ return traversal.tryNext();
+ } finally {
+ CloseableIterator.closeIterator(traversal);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Traversal terminal method next step
+ */
+ @Override
+ public Object visitTraversalTerminalMethod_next(final GremlinParser.TraversalTerminalMethod_nextContext ctx) {
+ try {
+ if (ctx.getChildCount() == 3) {
+ return traversal.next();
+ } else {
+ // the 3rd child is integer value
+ final int childIndexOfParamaterAmount = 2;
+ return traversal.next(Integer.decode(ctx.getChild(childIndexOfParamaterAmount).getText()));
+ }
+ } finally {
+ CloseableIterator.closeIterator(traversal);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Traversal terminal method to list step
+ */
+ @Override
+ public Object visitTraversalTerminalMethod_toList(final GremlinParser.TraversalTerminalMethod_toListContext ctx) {
+ return traversal.toList();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Traversal terminal method to set step
+ */
+ @Override
+ public Object visitTraversalTerminalMethod_toSet(final GremlinParser.TraversalTerminalMethod_toSetContext ctx) {
+ return traversal.toSet();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Traversal terminal method to bulk set step
+ */
+ @Override
+ public Object visitTraversalTerminalMethod_toBulkSet(final GremlinParser.TraversalTerminalMethod_toBulkSetContext ctx) {
+ return traversal.toBulkSet();
+ }
+}
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/ComplexTraversalMethodVisitorTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/ComplexTraversalMethodVisitorTest.java
new file mode 100644
index 0000000..32ba811
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/ComplexTraversalMethodVisitorTest.java
@@ -0,0 +1,150 @@
+/*
+ * 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.language.grammar;
+
+import org.antlr.v4.runtime.CharStreams;
+import org.antlr.v4.runtime.CommonTokenStream;
+import org.apache.tinkerpop.gremlin.process.traversal.P;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
+import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.experimental.runners.Enclosed;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.Arrays;
+
+import static org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.both;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.where;
+import static org.junit.Assert.assertEquals;
+
+@RunWith(Enclosed.class)
+public class ComplexTraversalMethodVisitorTest {
+
+ private static GraphTraversalSource g = traversal().withEmbedded(EmptyGraph.instance());
+
+ /**
+ * Test multiple level of nested graph traversal step
+ */
+ @RunWith(Parameterized.class)
+ public static class NestedTest {
+
+ @Parameterized.Parameter(value = 0)
+ public String script;
+
+ @Parameterized.Parameter(value = 1)
+ public GraphTraversal expected;
+
+ @Parameterized.Parameters()
+ public static Iterable<Object[]> generateTestParameters() {
+ return Arrays.asList(new Object[][]{
+ {"g.V().where(both())", g.V().where(both())},
+ {"g.V().where(where(both()))", g.V().where(where(both()))},
+ {"g.V().where(where(where(both())))", g.V().where(where(where(both())))},
+ {"g.V().where(where(where(where(both()))))", g.V().where(where(where(where(both()))))},
+ {"g.V().where(__.where(both()))", g.V().where(__.where(both()))},
+ {"g.V().where(__.where(where(both())))", g.V().where(__.where(where(both())))},
+ {"g.V().where(__.where(where(__.where(both()))))", g.V().where(__.where(where(__.where(both()))))},
+ {"g.V().where(__.where(where(__.where(where(both())))))", g.V().where(__.where(where(__.where(where(both())))))},
+ {"g.V().where(__.where(__.where(__.where(where(both())))))", g.V().where(__.where(__.where(__.where(where(both())))))},
+ });
+ }
+
+ @Test
+ public void testNestedGraphTraversal() {
+ final GremlinLexer lexer = new GremlinLexer(CharStreams.fromString(script));
+ final GremlinParser parser = new GremlinParser(new CommonTokenStream(lexer));
+ final GremlinParser.QueryContext ctx = parser.query();
+ final Object result = new GremlinAntlrToJava().visitQuery(ctx);
+
+ assertEquals(expected.toString(), result.toString());
+ }
+ }
+
+ /**
+ * Test multiple chains of chained graph traversal step
+ */
+ @RunWith(Parameterized.class)
+ public static class ChainedTest {
+
+ @Parameterized.Parameter(value = 0)
+ public String script;
+
+ @Parameterized.Parameter(value = 1)
+ public GraphTraversal expected;
+
+ @Parameterized.Parameters()
+ public static Iterable<Object[]> generateTestParameters() {
+ return Arrays.asList(new Object[][]{
+ {"g.V().out()", g.V().out()},
+ {"g.V().out().out()", g.V().out().out()},
+ {"g.V().out().out().out()", g.V().out().out().out()},
+ {"g.V().out().out().out().out()", g.V().out().out().out().out()}
+ });
+ }
+
+ @Test
+ public void testChainedGraphTraversal() {
+ final GremlinLexer lexer = new GremlinLexer(CharStreams.fromString(script));
+ final GremlinParser parser = new GremlinParser(new CommonTokenStream(lexer));
+ final GremlinParser.QueryContext ctx = parser.query();
+ final Object result = new GremlinAntlrToJava().visitQuery(ctx);
+
+ assertEquals(expected.toString(), result.toString());
+ }
+ }
+
+ /**
+ * Test multiple terminated graph traversals
+ */
+ @RunWith(Parameterized.class)
+ @Ignore("do we want to let gremlin-language handle terminators like this in a single script or are terminators external to the language?")
+ public static class TerminatedTest {
+
+ @Parameterized.Parameter(value = 0)
+ public String script;
+
+ @Parameterized.Parameter(value = 1)
+ public GraphTraversal expected;
+
+ @Parameterized.Parameters()
+ public static Iterable<Object[]> generateTestParameters() {
+ return Arrays.asList(new Object[][]{
+ {"g.V().values('a').toSet()", g.V().values("a").toSet()},
+ {"g.V().addV().property('d', g.V().values('a').count().next())", g.V().addV().property("d", g.V().values("a").count().next())},
+ {"g.V().where(__.values('a').is(within(g.V().values('a').toSet())))", g.V().where(__.values("a").is(P.within(g.V().values("a").toSet())))}
+ });
+ }
+
+ @Test
+ public void testTerminatedGraphTraversal() {
+ final GremlinLexer lexer = new GremlinLexer(CharStreams.fromString(script));
+ final GremlinParser parser = new GremlinParser(new CommonTokenStream(lexer));
+ final GremlinParser.QueryContext ctx = parser.query();
+ final Object result = new GremlinAntlrToJava().visitQuery(ctx);
+
+ assertEquals(expected.toString(), result.toString());
+ }
+ }
+}
+
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/GeneralLiteralVisitorTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/GeneralLiteralVisitorTest.java
new file mode 100644
index 0000000..3dd36f3
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/GeneralLiteralVisitorTest.java
@@ -0,0 +1,561 @@
+/*
+ * 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.language.grammar;
+
+import org.antlr.v4.runtime.CharStreams;
+import org.antlr.v4.runtime.CommonTokenStream;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.experimental.runners.Enclosed;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.lang.reflect.Constructor;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.IsInstanceOf.instanceOf;
+import static org.hamcrest.number.OrderingComparison.greaterThanOrEqualTo;
+import static org.hamcrest.number.OrderingComparison.lessThan;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Generic Literal visitor test
+ */
+@RunWith(Enclosed.class)
+public class GeneralLiteralVisitorTest {
+
+ static Object parseGenericLiteralRange(final String query) {
+ final GremlinLexer lexer = new GremlinLexer(CharStreams.fromString(query));
+ final GremlinParser parser = new GremlinParser(new CommonTokenStream(lexer));
+ final GremlinParser.GenericLiteralRangeContext ctx = parser.genericLiteralRange();
+ return GenericLiteralVisitor.getInstance().visitGenericLiteralRange(ctx);
+ }
+
+ @RunWith(Parameterized.class)
+ public static class ValidIntegerRangeTest {
+
+ @Parameterized.Parameter(value = 0)
+ public int start;
+
+ @Parameterized.Parameter(value = 1)
+ public int end;
+
+ @Parameterized.Parameters()
+ public static Iterable<Object[]> generateTestParameters() {
+ return Arrays.asList(new Object[][]{
+ {1, 1000000},
+ {1, 1},
+ {1000000, 1},
+ });
+ }
+
+ @Test
+ public void shouldParse() {
+ assertThat(Math.abs(end - start), lessThan(GenericLiteralVisitor.TOTAL_INTEGER_RANGE_RESULT_COUNT_LIMIT));
+
+ final Object result = parseGenericLiteralRange(String.format("%d..%d", start, end));
+ assertThat(result, instanceOf(List.class));
+ int expectedValue = start;
+ final List<Object> results = (List<Object>) result;
+
+ // iterate the result and check they are as expected
+ for (Object actualValue : results) {
+ assertThat(actualValue, instanceOf(Integer.class));
+ assertEquals(expectedValue, actualValue);
+ if (start <= end) {
+ expectedValue++;
+ } else {
+ expectedValue--;
+ }
+ }
+ assertEquals(Math.abs(end - start) + 1, results.size());
+ }
+ }
+
+ @RunWith(Parameterized.class)
+ public static class InvalidIntegerRangeTest {
+ @Parameterized.Parameter(value = 0)
+ public int start;
+
+ @Parameterized.Parameter(value = 1)
+ public int end;
+
+ @Parameterized.Parameters()
+ public static Iterable<Object[]> generateTestParameters() {
+ return Arrays.asList(new Object[][]{
+ {0, 10000000},
+ {10000000, 1},
+ });
+ }
+
+ /**
+ * test integer range exceed limit
+ */
+ @Test(expected = IllegalArgumentException.class)
+ public void shouldNotParse() {
+ assertThat(Math.abs(end - start), greaterThanOrEqualTo(GenericLiteralVisitor.TOTAL_INTEGER_RANGE_RESULT_COUNT_LIMIT));
+ parseGenericLiteralRange(String.format("%d..%d", start, end));
+ }
+ }
+
+ @RunWith(Parameterized.class)
+ public static class ValidStringRangeTest {
+ @Parameterized.Parameter(value = 0)
+ public String start;
+
+ @Parameterized.Parameter(value = 1)
+ public String end;
+
+ @Parameterized.Parameter(value = 2)
+ public String expected;
+
+ @Parameterized.Parameters(name = "{0}")
+ public static Iterable<Object[]> generateTestParameters() {
+ return Arrays.asList(new Object[][]{
+ {"'abc1'", "'abc3'", "abc1_abc2_abc3"},
+ {"\"abc1\"", "'abc3'", "abc1_abc2_abc3"},
+ {"\"abc1\"", "\"abc3\"", "abc1_abc2_abc3"},
+ {"'abc1'", "\"abc3\"", "abc1_abc2_abc3"},
+ {"'a11a'", "'a11d'", "a11a_a11b_a11c_a11d"},
+ {"'a11N'", "'a11L'", "a11N_a11M_a11L"},
+ {"'a113'", "'a111'", "a113_a112_a111"},
+ {"'a111'", "'a111'", "a111"},
+ {"'a'", "'c'", "a_b_c"},
+ {"'6'", "'3'", "6_5_4_3"},
+ {"'1'", "'1'", "1"},
+ {"'N'", "'N'", "N"},
+ {"''", "''", "_"},
+ });
+ }
+
+ @Test
+ public void shouldParse() {
+ final Object result = parseGenericLiteralRange(String.format("%s..%s", start, end));
+ assertThat(result, instanceOf(List.class));
+
+ final List<Object> results = (List<Object>) result;
+ if (expected.equals("_")) {
+ // handle special case for empty range
+ assertEquals(0, results.size());
+ return;
+ }
+
+ final String[] expectedResults = expected.split("_");
+ assertEquals(expectedResults.length, results.size());
+
+ // iterate the result and check they are as expected
+ for (int i = 0; i < expectedResults.length; i++) {
+ assertEquals(expectedResults[i], results.get(i));
+ }
+ }
+ }
+
+ @RunWith(Parameterized.class)
+ public static class InvalidStringRangeTest {
+ @Parameterized.Parameter(value = 0)
+ public String start;
+
+ @Parameterized.Parameter(value = 1)
+ public String end;
+
+ @Parameterized.Parameters(name = "{0}")
+ public static Iterable<Object[]> generateTestParameters() {
+ return Arrays.asList(new Object[][]{
+ {"'abc1'", "'abc23'"}, // start and end string length is different
+ {"a11", "'a22'"}, // start and end string does not share the same prefix except last character
+ {"''", "'1'"}, // start and end string length is different
+ {"'1'", "''"}, // start and end string length is different
+ });
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void shouldNotParse() {
+ parseGenericLiteralRange(String.format("%s..%s", start, end));
+ }
+ }
+
+ @RunWith(Parameterized.class)
+ public static class ValidStringLiteralTest {
+ @Parameterized.Parameter(value = 0)
+ public String script;
+
+ @Parameterized.Parameter(value = 1)
+ public String expected;
+
+ @Parameterized.Parameters(name = "{0}")
+ public static Iterable<Object[]> generateTestParameters() {
+ return Arrays.asList(new Object[][]{
+ {"'a'", "a"},
+ {"'A1'", "A1"},
+ {"'1'", "1"},
+ {"''", "Empty"},
+ {"'10_000'", "10_000"},
+ {"\"a\"", "a"},
+ {"\"A1\"", "A1"},
+ {"\"1\"", "1"},
+ {"\"\"", "Empty"},
+ {"\"10_000\"", "10_000"},
+ // escaped characters according to http://groovy-lang.org/syntax.html#_escaping_special_characters
+ // {} are there just for readability
+ {"'{\\t} {\\b} {\\n} {\\r} {\\f} {\\'} {\\\"} {\\\\}'", "{\t} {\b} {\n} {\r} {\f} {'} {\"} {\\}"},
+ {"\"{\\t} {\\b} {\\n} {\\r} {\\f} {\\'} {\\\"} {\\\\}\"", "{\t} {\b} {\n} {\r} {\f} {'} {\"} {\\}"},
+ // unicode escape
+ {"'\\u2300'", "\u2300"},
+ {"'abc\\u2300def'", "abc\u2300def"},
+ {"'\u2300'", "\u2300"},
+ {"'abc\u2300def'", "abc\u2300def"},
+ });
+ }
+
+ @Test
+ public void shouldParse() {
+ final GremlinLexer lexer = new GremlinLexer(CharStreams.fromString(script));
+ final GremlinParser parser = new GremlinParser(new CommonTokenStream(lexer));
+ final GremlinParser.StringLiteralContext ctx = parser.stringLiteral();
+ if (expected.equals("Empty")) {
+ // handle special case for Empty string
+ assertEquals("", GenericLiteralVisitor.getInstance().visitStringLiteral(ctx));
+ } else {
+ assertEquals(expected, GenericLiteralVisitor.getInstance().visitStringLiteral(ctx));
+ }
+ }
+ }
+
+ @RunWith(Parameterized.class)
+ public static class AllPrintableAsciiCharactersTest {
+ @Parameterized.Parameter(value = 0)
+ public String quoteCharacter;
+
+ @Parameterized.Parameters()
+ public static Iterable<Object[]> generateTestParameters() {
+ return Arrays.asList(new Object[][]{
+ {"\""},
+ {"'"},
+ });
+ }
+
+ @Test
+ public void shouldParse() {
+ final StringBuilder inputBuilder = new StringBuilder();
+ final StringBuilder expectedOutputBuilder = new StringBuilder();
+
+ // build a string which contains all the ASCII printable characters
+ // ASCII printable character start from 32 to 126
+ for (Character c = 32; c < 127; c++) {
+ if ((quoteCharacter.equals(String.valueOf(c))) || (c == '\\')) {
+ // escape this character in the input
+ inputBuilder.append("\\");
+ }
+ inputBuilder.append(c);
+ expectedOutputBuilder.append(c);
+ }
+ final String inputChars = inputBuilder.toString();
+ final String expectedOutputChars = expectedOutputBuilder.toString();
+
+ final String stringLiteral = quoteCharacter + inputChars + quoteCharacter;
+ final GremlinLexer lexer = new GremlinLexer(CharStreams.fromString(stringLiteral));
+ final GremlinParser parser = new GremlinParser(new CommonTokenStream(lexer));
+ final GremlinParser.StringLiteralContext ctx = parser.stringLiteral();
+ assertEquals(expectedOutputChars, GenericLiteralVisitor.getInstance().visitStringLiteral(ctx));
+ }
+ }
+
+ @RunWith(Parameterized.class)
+ public static class ValidIntegerLiteralTest {
+ @Parameterized.Parameter(value = 0)
+ public String script;
+
+ @Parameterized.Parameter(value = 1)
+ public String expected;
+
+ @Parameterized.Parameters(name = "{0}")
+ public static Iterable<Object[]> generateTestParameters() {
+ return Arrays.asList(new Object[][]{
+ // decimal format
+ {"1", "1"},
+ {"-11", "-11"},
+ {"0", "0"},
+ {"1L", "1L"},
+ {"-1l", "-1l"},
+ {"1_2_3", "123"},
+ {"-1_2_3L", "-123L"},
+ {"9223372036854775807", "9223372036854775807"},
+ {"-9223372036854775808", "-9223372036854775808"},
+ {"9223372036854775807L", "9223372036854775807"},
+ {"-9223372036854775808l", "-9223372036854775808"},
+ // hex format
+ {"0xA", "10"},
+ {"-0xA", "-10"},
+ {"0xaL", "10l"},
+ {"-0xal", "-10l"},
+ {"-0xA_0L", "-160l"},
+ {"0x10", "16"},
+ {"-0x10", "-16"},
+ {"0x10", "16"},
+ {"-0x10l", "-16l"},
+ {"-0x1_0L", "-16l"},
+ // oct format
+ {"01", "1"},
+ {"-01", "-1"},
+ {"01L", "1l"},
+ {"-01l", "-1l"},
+ {"010", "8"},
+ {"-010", "-8"},
+ {"010L", "8l"},
+ {"-010l", "-8l"},
+ {"-01_0L", "-8l"},
+ });
+ }
+
+ @Test
+ public void shouldParse() {
+ final GremlinLexer lexer = new GremlinLexer(CharStreams.fromString(script));
+ final GremlinParser parser = new GremlinParser(new CommonTokenStream(lexer));
+ final GremlinParser.IntegerLiteralContext ctx = parser.integerLiteral();
+
+ final Object actualValue = GenericLiteralVisitor.getInstance().visitIntegerLiteral(ctx);
+
+ // verify suffix L/l
+ if (expected.toUpperCase().charAt(expected.length() - 1) == 'L') {
+ assertEquals(Long.valueOf(expected.substring(0, expected.length() - 1)), actualValue);
+ return;
+ }
+
+ // based on value range verify the value is parsed in correct type
+ try {
+ assertEquals(Integer.valueOf(expected), actualValue);
+ } catch (NumberFormatException ignoredException) {
+ assertEquals(Long.valueOf(expected), actualValue);
+ }
+ }
+ }
+
+ @RunWith(Parameterized.class)
+ public static class ValidBigIntegerLiteralTest {
+ @Parameterized.Parameter(value = 0)
+ public String script;
+
+ @Parameterized.Parameter(value = 1)
+ public String expected;
+
+ @Parameterized.Parameter(value = 2)
+ public int radix;
+
+ @Parameterized.Parameters()
+ public static Iterable<Object[]> generateTestParameters() {
+ return Arrays.asList(new Object[][]{
+ {"+0xfffffffffffffffffffffffffffffffffffffffffffffff", "fffffffffffffffffffffffffffffffffffffffffffffff", 16},
+ {"0xfffffffffffffffffffffffffffffffffffffffffffffff", "fffffffffffffffffffffffffffffffffffffffffffffff", 16},
+ {"-0xfffffffffffffffffffffffffffffffffffffffffffffff", "-fffffffffffffffffffffffffffffffffffffffffffffff", 16},
+ {"+9999999999999999999999999999999999999999999999999", "9999999999999999999999999999999999999999999999999", 10},
+ {"9999999999999999999999999999999999999999999999999", "9999999999999999999999999999999999999999999999999", 10},
+ {"-9999999999999999999999999999999999999999999999999", "-9999999999999999999999999999999999999999999999999", 10},
+ {"+0777777777777777777777777777777777777777777777777", "0777777777777777777777777777777777777777777777777", 8},
+ {"0777777777777777777777777777777777777777777777777", "0777777777777777777777777777777777777777777777777", 8},
+ {"-0777777777777777777777777777777777777777777777777", "-0777777777777777777777777777777777777777777777777", 8}
+ });
+ }
+
+ @Test
+ public void shouldParse() {
+ final GremlinLexer lexer = new GremlinLexer(CharStreams.fromString(script));
+ final GremlinParser parser = new GremlinParser(new CommonTokenStream(lexer));
+ final GremlinParser.IntegerLiteralContext ctx = parser.integerLiteral();
+
+ assertEquals(new BigInteger(expected, radix), GenericLiteralVisitor.getInstance().visitIntegerLiteral(ctx));
+ }
+ }
+
+ @RunWith(Parameterized.class)
+ public static class ValidFloatLiteralTest {
+ @Parameterized.Parameter(value = 0)
+ public String script;
+
+ @Parameterized.Parameter(value = 1)
+ public String expected;
+
+ @Parameterized.Parameter(value = 2)
+ public String type;
+
+ @Parameterized.Parameters()
+ public static Iterable<Object[]> generateTestParameters() {
+ return Arrays.asList(new Object[][]{
+ {"1.1", "1.1", "java.math.BigDecimal"},
+ {"-0.1", "-0.1", "java.math.BigDecimal"},
+ {"1.0E+12", "1.0E12", "java.math.BigDecimal"},
+ {"-0.1E-12", "-0.1E-12", "java.math.BigDecimal"},
+ {"1E12", "1E12", "java.math.BigDecimal"},
+ // float
+ {"1.1f", "1.1", "java.lang.Float"},
+ {"-0.1F", "-0.1", "java.lang.Float"},
+ {"1.0E+12f", "1.0E12", "java.lang.Float"},
+ {"-0.1E-12F", "-0.1E-12", "java.lang.Float"},
+ {"1E12f", "1E12", "java.lang.Float"},
+ {"1F", "1", "java.lang.Float"},
+
+ // double
+ {"1.1d", "1.1", "java.lang.Double"},
+ {"-0.1D", "-0.1", "java.lang.Double"},
+ {"1.0E+12d", "1.0E12", "java.lang.Double"},
+ {"-0.1E-12D", "-0.1E-12", "java.lang.Double"},
+ {"1E12d", "1E12", "java.lang.Double"},
+ {"1D", "1", "java.lang.Double"}
+ });
+ }
+
+ @Test
+ public void shouldParse() throws Exception {
+ final GremlinLexer lexer = new GremlinLexer(CharStreams.fromString(script));
+ final GremlinParser parser = new GremlinParser(new CommonTokenStream(lexer));
+ final GremlinParser.FloatLiteralContext ctx = parser.floatLiteral();
+
+ final Class<?> clazz = Class.forName(type);
+ final Constructor<?> ctor = clazz.getConstructor(String.class);
+ final Object expectedValue = ctor.newInstance(expected);
+
+ assertEquals(expectedValue, GenericLiteralVisitor.getInstance().visitFloatLiteral(ctx));
+ }
+ }
+
+ @RunWith(Parameterized.class)
+ public static class ValidBooleanLiteralTest {
+ @Parameterized.Parameter(value = 0)
+ public String script;
+
+ @Parameterized.Parameter(value = 1)
+ public boolean expected;
+
+ @Parameterized.Parameters()
+ public static Iterable<Object[]> generateTestParameters() {
+ return Arrays.asList(new Object[][]{
+ {"true", true},
+ {"false", false}
+ });
+ }
+
+ @Test
+ public void shouldParse() {
+ final GremlinLexer lexer = new GremlinLexer(CharStreams.fromString(script));
+ final GremlinParser parser = new GremlinParser(new CommonTokenStream(lexer));
+ final GremlinParser.BooleanLiteralContext ctx = parser.booleanLiteral();
+
+ assertEquals(expected, GenericLiteralVisitor.getInstance().visitBooleanLiteral(ctx));
+ }
+ }
+
+ @RunWith(Parameterized.class)
+ public static class ValidMapLiteralTest {
+ @Parameterized.Parameter(value = 0)
+ public String script;
+
+ @Parameterized.Parameter(value = 1)
+ public int expectedNumKeysInMap;
+
+ @Parameterized.Parameters()
+ public static Iterable<Object[]> generateTestParameters() {
+ return Arrays.asList(new Object[][]{
+ {"[\"name\":\"simba\"]", 1},
+ {"[:]", 0},
+ {"[\"name\":\"simba\",\"age\":32]", 2},
+ {"[\"name\":\"simba\",\"age\":[2,3]]", 2}
+ });
+ }
+
+ @Test
+ public void shouldParse() {
+ final GremlinLexer lexer = new GremlinLexer(CharStreams.fromString(script));
+ final GremlinParser parser = new GremlinParser(new CommonTokenStream(lexer));
+ final GremlinParser.GenericLiteralContext ctx = parser.genericLiteral();
+ final Object genericLiteral = GenericLiteralVisitor.getInstance().visitGenericLiteral(ctx);
+
+ // verify type is Map
+ assertThat(genericLiteral, instanceOf(Map.class));
+
+ // verify total number of elements
+ final Map<Object, Object> genericLiterals = (Map<Object, Object>) genericLiteral;
+ assertEquals(expectedNumKeysInMap, genericLiterals.size());
+ }
+ }
+
+ public static class ValidListLiteralTest {
+
+ @Test
+ public void testGenericLiteralCollection() {
+ final GremlinLexer lexer = new GremlinLexer(CharStreams.fromString("['world', 165, [12L, 0xA, 14.5, \"hello\"]]"));
+ final GremlinParser parser = new GremlinParser(new CommonTokenStream(lexer));
+ final GremlinParser.GenericLiteralContext ctx = parser.genericLiteral();
+ final Object genericLiteral = GenericLiteralVisitor.getInstance().visitGenericLiteral(ctx);
+
+ // verify type is Object[]
+ assertThat(genericLiteral, instanceOf(List.class));
+
+ // verify total number of elements
+ List<Object> genericLiterals = (List<Object>) genericLiteral;
+ assertEquals(genericLiterals.size(), 3);
+
+ // verify first element
+ assertEquals("world", genericLiterals.get(0));
+
+ // verify second element
+ assertEquals(165, genericLiterals.get(1));
+
+ // verify 3rd element
+ assertThat(genericLiterals.get(2), instanceOf(List.class));
+
+ // verify total number of elements
+ genericLiterals = (List<Object>) genericLiterals.get(2);
+ assertEquals(genericLiterals.size(), 4);
+
+ // verify first element
+ assertEquals(12L, genericLiterals.get(0));
+
+ // verify second element
+ assertEquals(10, genericLiterals.get(1));
+
+ // verify 3rd element
+ assertEquals(new BigDecimal(14.5), genericLiterals.get(2));
+
+ // verify 4th element
+ assertEquals("hello", genericLiterals.get(3));
+ }
+
+ /**
+ * Generic literal collection test
+ */
+ @Test
+ public void testEmptyGenericLiteralCollection() {
+ final GremlinLexer lexer = new GremlinLexer(CharStreams.fromString("[]"));
+ final GremlinParser parser = new GremlinParser(new CommonTokenStream(lexer));
+ final GremlinParser.GenericLiteralContext ctx = parser.genericLiteral();
+ final Object genericLiteral = GenericLiteralVisitor.getInstance().visitGenericLiteral(ctx);
+
+ // verify type is Object[]
+ assertThat(genericLiteral, instanceOf(List.class));
+
+ // verify total number of elements
+ final List<Object> genericLiterals = (List<Object>) genericLiteral;
+ Assert.assertTrue(genericLiterals.isEmpty());
+ }
+ }
+}
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/GraphTraversalSourceVisitorTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/GraphTraversalSourceVisitorTest.java
new file mode 100644
index 0000000..1407f31
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/GraphTraversalSourceVisitorTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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.language.grammar;
+
+import org.antlr.v4.runtime.CharStreams;
+import org.antlr.v4.runtime.CommonTokenStream;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.Arrays;
+
+import static org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal;
+import static org.junit.Assert.assertEquals;
+
+@RunWith(Parameterized.class)
+public class GraphTraversalSourceVisitorTest {
+
+ private static final GraphTraversalSource g = traversal().withEmbedded(EmptyGraph.instance());
+ private GremlinAntlrToJava antlrToLanguage;
+
+ @Parameterized.Parameter(value = 0)
+ public String script;
+
+ @Parameterized.Parameter(value = 1)
+ public GraphTraversalSource traversalSource;
+
+ @Parameterized.Parameters(name = "{0}")
+ public static Iterable<Object[]> generateTestParameters() {
+ return Arrays.asList(new Object[][]{
+ {"g", g},
+ {"g.withBulk(false)", g.withBulk(false)},
+ {"g.withBulk(false).withPath()", g.withBulk(false).withPath()},
+ });
+ }
+
+ @Before
+ public void setup() throws Exception {
+ antlrToLanguage = new GremlinAntlrToJava();
+ }
+
+ /**
+ * Test Graph traversal source visitor
+ */
+ @Test
+ public void shouldHandleGraphTraversalSourceVisitor() {
+ final GremlinLexer lexer = new GremlinLexer(CharStreams.fromString(script));
+ final GremlinParser parser = new GremlinParser(new CommonTokenStream(lexer));
+ final GremlinParser.TraversalSourceContext ctx = parser.traversalSource();
+ final GraphTraversalSource result = new GraphTraversalSourceVisitor(antlrToLanguage).visitTraversalSource(ctx);
+
+ assertEquals(traversalSource.getBytecode(), result.getBytecode());
+ }
+}
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalEnumParserTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalEnumParserTest.java
new file mode 100644
index 0000000..0d490df
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalEnumParserTest.java
@@ -0,0 +1,113 @@
+/*
+ * 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.language.grammar;
+
+import org.antlr.v4.runtime.CharStreams;
+import org.antlr.v4.runtime.CommonTokenStream;
+import org.antlr.v4.runtime.tree.ParseTree;
+import org.junit.Test;
+import org.junit.experimental.runners.Enclosed;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Test for parse Graph traversal enums
+ */
+@RunWith(Enclosed.class)
+public class TraversalEnumParserTest {
+
+ @RunWith(Parameterized.class)
+ public static class EnumTest {
+
+ @Parameterized.Parameter(value = 0)
+ public String className;
+
+ @Parameterized.Parameter(value = 1)
+ public String parseMethodName;
+
+ @Parameterized.Parameters()
+ public static Iterable<Object[]> generateTestParameters() {
+ return Arrays.asList(new Object[][]{
+ {"org.apache.tinkerpop.gremlin.process.traversal.Scope", "traversalScope"},
+ {"org.apache.tinkerpop.gremlin.process.traversal.Order", "traversalOrder"},
+ {"org.apache.tinkerpop.gremlin.process.traversal.Pop", "traversalPop"},
+ {"org.apache.tinkerpop.gremlin.process.traversal.SackFunctions$Barrier", "traversalSackMethod"},
+ {"org.apache.tinkerpop.gremlin.process.traversal.Operator", "traversalOperator"},
+ {"org.apache.tinkerpop.gremlin.structure.T", "traversalToken"},
+ {"org.apache.tinkerpop.gremlin.structure.Column", "traversalColumn"},
+ {"org.apache.tinkerpop.gremlin.structure.Direction", "traversalDirection"},
+ {"org.apache.tinkerpop.gremlin.structure.VertexProperty$Cardinality", "traversalCardinality"},
+ {"org.apache.tinkerpop.gremlin.process.traversal.step.TraversalOptionParent$Pick", "traversalOptionParent"},
+ });
+ }
+
+ @Test
+ public void testAllEnumTypes() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
+ final Class<? extends Enum> enumType = (Class<? extends Enum>) (Class.forName(className));
+ for (Enum enumConstant : enumType.getEnumConstants()) {
+ final GremlinLexer lexer = new GremlinLexer(CharStreams.fromString(enumConstant.name()));
+ final GremlinParser parser = new GremlinParser(new CommonTokenStream(lexer));
+
+ final Method method = parser.getClass().getMethod(parseMethodName);
+ final ParseTree ctx = (ParseTree) (method.invoke(parser));
+ assertEquals(enumConstant, TraversalEnumParser.parseTraversalEnumFromContext(enumType, ctx));
+ }
+ }
+ }
+
+ @RunWith(Parameterized.class)
+ public static class QualifiedEnumTest {
+
+ @Parameterized.Parameter(value = 0)
+ public String className;
+
+ @Parameterized.Parameter(value = 1)
+ public String parseMethodName;
+
+ @Parameterized.Parameters()
+ public static Iterable<Object[]> generateTestParameters() {
+ return Arrays.asList(new Object[][]{
+ {"org.apache.tinkerpop.gremlin.process.traversal.Scope", "traversalScope"},
+ {"org.apache.tinkerpop.gremlin.process.traversal.Order", "traversalOrder"},
+ {"org.apache.tinkerpop.gremlin.structure.T", "traversalToken"}
+ });
+ }
+
+ @Test
+ public void testAllQualifiedEnumTypes() throws
+ ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
+ Class<? extends Enum> enumType = (Class<? extends Enum>) (Class.forName(className));
+ for (Enum enumConstant : enumType.getEnumConstants()) {
+ String testExpr = enumType.getSimpleName() + "." + enumConstant.name();
+ GremlinLexer lexer = new GremlinLexer(CharStreams.fromString(testExpr));
+ GremlinParser parser = new GremlinParser(new CommonTokenStream(lexer));
+
+ Method method = parser.getClass().getMethod(parseMethodName);
+ ParseTree ctx = (ParseTree) (method.invoke(parser));
+ assertEquals(enumConstant, TraversalEnumParser.parseTraversalEnumFromContext(enumType, ctx));
+ }
+ }
+ }
+}
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalMethodVisitorTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalMethodVisitorTest.java
new file mode 100644
index 0000000..6bad0e9
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalMethodVisitorTest.java
@@ -0,0 +1,1099 @@
+/*
+ * 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.language.grammar;
+
+import org.antlr.v4.runtime.CharStreams;
+import org.antlr.v4.runtime.CommonTokenStream;
+import org.apache.tinkerpop.gremlin.process.computer.traversal.step.map.PageRank;
+import org.apache.tinkerpop.gremlin.process.computer.traversal.step.map.PeerPressure;
+import org.apache.tinkerpop.gremlin.process.computer.traversal.step.map.ShortestPath;
+import org.apache.tinkerpop.gremlin.process.traversal.Operator;
+import org.apache.tinkerpop.gremlin.process.traversal.Order;
+import org.apache.tinkerpop.gremlin.process.traversal.Pop;
+import org.apache.tinkerpop.gremlin.process.traversal.Scope;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.process.traversal.step.util.WithOptions;
+import org.apache.tinkerpop.gremlin.structure.Column;
+import org.apache.tinkerpop.gremlin.structure.Direction;
+import org.apache.tinkerpop.gremlin.structure.T;
+import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.function.Function;
+
+import static org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal;
+import static org.apache.tinkerpop.gremlin.process.traversal.P.eq;
+import static org.apache.tinkerpop.gremlin.process.traversal.P.gt;
+import static org.apache.tinkerpop.gremlin.process.traversal.SackFunctions.Barrier.normSack;
+import static org.apache.tinkerpop.gremlin.process.traversal.Scope.global;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.*;
+import static org.apache.tinkerpop.gremlin.structure.T.label;
+import static org.junit.Assert.assertEquals;
+
+public class TraversalMethodVisitorTest {
+
+ private final GraphTraversalSource g = traversal().withEmbedded(EmptyGraph.instance());
+ private GremlinAntlrToJava antlrToLaunguage;
+
+ private Object eval(String query) {
+ final GremlinLexer lexer = new GremlinLexer(CharStreams.fromString(query));
+ final GremlinParser parser = new GremlinParser(new CommonTokenStream(lexer));
+ return antlrToLaunguage.visit(parser.queryList());
+ }
+
+ @Before
+ public void setup() throws Exception {
+ antlrToLaunguage = new GremlinAntlrToJava();
+ }
+
+ private void compare(Object expected, Object actual) {
+ assertEquals(((DefaultGraphTraversal) expected).asAdmin().getBytecode(),
+ ((DefaultGraphTraversal) actual).asAdmin().getBytecode());
+ }
+
+ @Test
+ public void testChainedTraversal() throws Exception {
+ // a random chain traversal.
+ compare(g.V().addE("person"), eval("g.V().addE('person')"));
+ }
+
+ @Test
+ public void testTraversalMethod_addE_String() throws Exception {
+ // same with chained traversal but uses double quotes
+ compare(g.V().addE("person"), eval("g.V().addE(\"person\")"));
+ }
+
+ @Test
+ public void testTraversalMethod_addE_Traversal() throws Exception {
+ // same with chained traversal but uses double quotes
+ compare(g.V().addE(V().hasLabel("person").label()), eval("g.V().addE(V().hasLabel(\"person\").label())"));
+ }
+
+ @Test
+ public void testTraversalMethod_addV_Empty() throws Exception {
+ compare(g.V().addV(), eval("g.V().addV()"));
+ }
+
+ @Test
+ public void testTraversalMethod_addV_String() throws Exception {
+ compare(g.V().addV("test"), eval("g.V().addV(\"test\")"));
+ }
+
+ @Test
+ public void testTraversalMethod_addV_Traversal() throws Exception {
+ compare(g.addV(V().hasLabel("person").label()), eval("g.addV(V().hasLabel(\"person\").label())"));
+ }
+
+ @Test
+ public void testTraversalMethod_aggregate() throws Exception {
+ compare(g.V().aggregate("test"), eval("g.V().aggregate('test')"));
+ }
+
+ @Test
+ public void testTraversalMethod_aggregate_Scope() throws Exception {
+ compare(g.V().aggregate(global, "test"), eval("g.V().aggregate(global, 'test')"));
+ compare(g.V().aggregate(Scope.local, "test"), eval("g.V().aggregate(Scope.local, 'test')"));
+ }
+
+ @Test
+ public void testTraversalMethod_and() throws Exception {
+ compare(g.V().and(outE("knows")), eval("g.V().and(outE('knows'))"));
+ }
+
+ @Test
+ public void testTraversalMethod_as() throws Exception {
+ compare(g.V().as("test"), eval("g.V().as('test')"));
+ }
+
+ @Test
+ public void testTraversalMethod_barrier_Consumer() throws Exception {
+ compare(g.V().barrier(normSack), eval("g.V().barrier(normSack)"));
+ }
+
+ @Test
+ public void testTraversalMethod_barrier_Empty() throws Exception {
+ compare(g.V().barrier(), eval("g.V().barrier()"));
+ }
+
+ @Test
+ public void testTraversalMethod_barrier_int() throws Exception {
+ compare(g.V().barrier(4), eval("g.V().barrier(4)"));
+ }
+
+ @Test
+ public void testTraversalMethod_both_Empty() throws Exception {
+ compare(g.V().both(), eval("g.V().both()"));
+ }
+
+ @Test
+ public void testTraversalMethod_both_SingleString() throws Exception {
+ compare(g.V().both("test"), eval("g.V().both('test')"));
+ }
+
+ @Test
+ public void testTraversalMethod_both_MultiString() throws Exception {
+ compare(g.V().both(new String[]{"a", "b"}), eval("g.V().both('a', 'b')"));
+ }
+
+ @Test
+ public void testTraversalMethod_bothE() throws Exception {
+ compare(g.V().bothE("test"), eval("g.V().bothE('test')"));
+ }
+
+ @Test
+ public void testTraversalMethod_bothV() throws Exception {
+ compare(g.V().bothV(), eval("g.V().bothV()"));
+ }
+
+ @Test
+ public void testTraversalMethod_branch_Traversal() throws Exception {
+ compare(g.V().branch(values("name")), eval("g.V().branch(values('name'))"));
+ }
+
+ @Test
+ public void testTraversalMethod_by_Comparator() throws Exception {
+ compare(g.V().order().by(Order.asc), eval("g.V().order().by(asc)"));
+ }
+
+ @Test
+ public void testTraversalMethod_by_Empty() throws Exception {
+ compare(g.V().cyclicPath().by(), eval("g.V().cyclicPath().by()"));
+ }
+
+ @Test
+ public void testTraversalMethod_by_Function() throws Exception {
+ compare(g.V().order().by(T.id), eval("g.V().order().by(id)"));
+ }
+
+ @Test
+ public void testTraversalMethod_by_Function_Comparator() throws Exception {
+ compare(g.V().order().by(Column.keys, Order.asc), eval("g.V().order().by(keys, asc)"));
+ }
+
+ @Test
+ public void testTraversalMethod_by_Order() throws Exception {
+ compare(g.V().order().by(Order.shuffle), eval("g.V().order().by(shuffle)"));
+ }
+
+ @Test
+ public void testTraversalMethod_by_String() throws Exception {
+ compare(g.V().order().by("name"), eval("g.V().order().by('name')"));
+ }
+
+ @Test
+ public void testTraversalMethod_by_String_Comparator() throws Exception {
+ compare(g.V().order().by("name", Order.asc), eval("g.V().order().by('name', asc)"));
+ }
+
+ @Test
+ public void testTraversalMethod_by_T() throws Exception {
+ compare(g.V().order().by(T.id), eval("g.V().order().by(id)"));
+ }
+
+ @Test
+ public void testTraversalMethod_by_Traversal() throws Exception {
+ compare(g.V().group().by(bothE().count()), eval("g.V().group().by(bothE().count())"));
+ }
+
+ @Test
+ public void testTraversalMethod_by_Traversal_Comparator() throws Exception {
+ compare(g.V().order().by(bothE().count(), Order.asc), eval("g.V().order().by(bothE().count(), asc)"));
+ }
+
+ @Test
+ public void testTraversalMethod_cap() throws Exception {
+ compare(g.V().cap("test"), eval("g.V().cap('test')"));
+ }
+
+ @Test
+ public void testTraversalMethod_choose_Function() throws Exception {
+ compare(g.V().choose((Function) label), eval("g.V().choose(label)"));
+ }
+
+ @Test
+ public void testTraversalMethod_choose_Predicate_Traversal() throws Exception {
+ compare(g.V().choose(is(12), values("age")), eval("g.V().choose(is(12), values(\"age\"))"));
+ }
+
+ @Test
+ public void testTraversalMethod_choose_Predicate_Traversal_Traversal() throws Exception {
+ compare(g.V().choose(is(12), values("age"), values("count")),
+ eval("g.V().choose(is(12), values(\"age\"), values(\"count\"))"));
+ }
+
+ @Test
+ public void testTraversalMethod_choose_Traversal() throws Exception {
+ compare(g.V().choose(values("age")), eval("g.V().choose(values('age'))"));
+ }
+
+ @Test
+ public void testTraversalMethod_choose_Traversal_Traversal() throws Exception {
+ compare(g.V().choose(values("age"), bothE()), eval("g.V().choose(values('age'), bothE())"));
+ }
+
+ @Test
+ public void testTraversalMethod_choose_Traversal_Traversal_Traversal() throws Exception {
+ compare(g.V().choose(values("age"), bothE(), bothE()), eval("g.V().choose(values('age'), bothE(), bothE())"));
+ }
+
+ @Test
+ public void testTraversalMethod_coalesce() throws Exception {
+ compare(g.V().coalesce(outE("knows")), eval("g.V().coalesce(outE('knows'))"));
+ }
+
+ @Test
+ public void testTraversalMethod_coin() throws Exception {
+ compare(g.V().coin(2.5), eval("g.V().coin(2.5)"));
+ }
+
+ @Test
+ public void testTraversalMethod_constant() throws Exception {
+ compare(g.V().constant("yigit"), eval("g.V().constant('yigit')"));
+ }
+
+ @Test
+ public void testTraversalMethod_count_Empty() throws Exception {
+ compare(g.V().count(), eval("g.V().count()"));
+ }
+
+ @Test
+ public void testTraversalMethod_count_Scope() throws Exception {
+ compare(g.V().count(global), eval("g.V().count(global)"));
+ }
+
+ @Test
+ public void testTraversalMethod_cyclicPath() throws Exception {
+ compare(g.V().cyclicPath(), eval("g.V().cyclicPath()"));
+ }
+
+ @Test
+ public void testTraversalMethod_dedup_Scope_String() throws Exception {
+ compare(g.V().dedup(Scope.local, "age"), eval("g.V().dedup(local, 'age')"));
+ }
+
+ @Test
+ public void testTraversalMethod_dedup_String() throws Exception {
+ compare(g.V().dedup(), eval("g.V().dedup()"));
+ }
+
+ @Test
+ public void testTraversalMethod_drop() throws Exception {
+ compare(g.V().drop(), eval("g.V().drop()"));
+ }
+
+ @Test
+ public void testTraversalMethod_emit_Empty() throws Exception {
+ compare(g.V().emit(), eval("g.V().emit()"));
+ }
+
+ @Test
+ public void testTraversalMethod_emit_Predicate() throws Exception {
+ compare(g.V().repeat(out()).emit(is("asd")), eval("g.V().repeat(out()).emit(is(\"asd\"))"));
+ }
+
+ @Test
+ public void testTraversalMethod_emit_Traversal() throws Exception {
+ compare(g.V().emit(has("name")), eval("g.V().emit(has('name'))"));
+ }
+
+ @Test
+ public void testTraversalMethod_filter_Predicate() throws Exception {
+ compare(g.V().repeat(out()).filter(is("2")), eval("g.V().repeat(out()).filter(is(\"2\"))"));
+ }
+
+ @Test
+ public void testTraversalMethod_filter_Traversal() throws Exception {
+ compare(g.V().filter(has("name")), eval("g.V().filter(has('name'))"));
+ }
+
+ @Test
+ public void testTraversalMethod_flatMap_Traversal() throws Exception {
+ compare(g.V().flatMap(has("name")), eval("g.V().flatMap(has('name'))"));
+ }
+
+ @Test
+ public void testTraversalMethod_fold_Empty() throws Exception {
+ compare(g.V().fold(), eval("g.V().fold()"));
+ }
+
+ @Test
+ public void testTraversalMethod_fold_Object_BiFunction() throws Exception {
+ compare(g.V().values("age").fold(0, Operator.max), eval("g.V().values('age').fold(0, max)"));
+ }
+
+ @Test
+ public void testTraversalMethod_from_String() throws Exception {
+ compare(g.V().cyclicPath().from("name"), eval("g.V().cyclicPath().from('name')"));
+ }
+
+ @Test
+ public void testTraversalMethod_from_Traversal() throws Exception {
+ compare(g.V().addE("as").from(V()), eval("g.V().addE('as').from(V())"));
+ }
+
+ @Test
+ public void testTraversalMethod_group_Empty() throws Exception {
+ compare(g.V().group(), eval("g.V().group()"));
+ }
+
+ @Test
+ public void testTraversalMethod_group_String() throws Exception {
+ compare(g.V().group("age"), eval("g.V().group('age')"));
+ }
+
+ @Test
+ public void testTraversalMethod_groupCount_Empty() throws Exception {
+ compare(g.V().groupCount(), eval("g.V().groupCount()"));
+ }
+
+ @Test
+ public void testTraversalMethod_groupCount_String() throws Exception {
+ compare(g.V().groupCount("age"), eval("g.V().groupCount('age')"));
+ }
+
+ @Test
+ public void testTraversalMethod_has_String() throws Exception {
+ compare(g.V().has("age"), eval("g.V().has('age')"));
+ }
+
+ @Test
+ public void testTraversalMethod_has_String_Object() throws Exception {
+ compare(g.V().has("age", 132), eval("g.V().has('age', 132)"));
+ }
+
+ @Test
+ public void testTraversalMethod_has_String_P() throws Exception {
+ compare(g.V().has("a", eq("b")), eval("g.V().has(\"a\", eq(\"b\"))"));
+ }
+
+ @Test
+ public void testTraversalMethod_has_String_String_Object() throws Exception {
+ compare(g.V().has("a", "b", 3), eval("g.V().has(\"a\", \"b\", 3)"));
+ }
+
+ @Test
+ public void testTraversalMethod_has_String_String_P() throws Exception {
+ compare(g.V().has("a", "b", eq("c")), eval("g.V().has(\"a\", \"b\", eq(\"c\"))"));
+ }
+
+ @Test
+ public void testTraversalMethod_has_String_Traversal() throws Exception {
+ compare(g.V().has("age", bothE()), eval("g.V().has('age', bothE())"));
+ }
+
+ @Test
+ public void testTraversalMethod_has_T_Object() throws Exception {
+ compare(g.V().has(T.id, 6), eval("g.V().has(id, 6)"));
+ }
+
+ @Test
+ public void testTraversalMethod_has_T_P() throws Exception {
+ compare(g.V().has(T.id, eq("asd")), eval("g.V().has(id, eq('asd'))"));
+ }
+
+ @Test
+ public void testTraversalMethod_has_T_Traversal() throws Exception {
+ compare(g.V().has(T.id, bothE()), eval("g.V().has(id, bothE())"));
+ }
+
+ @Test
+ public void testTraversalMethod_hasId_Object_Object() throws Exception {
+ compare(g.V().hasId(3, 4), eval("g.V().hasId(3, 4)"));
+ }
+
+ @Test
+ public void testTraversalMethod_hasId_P() throws Exception {
+ compare(g.V().hasId(gt(4)), eval("g.V().hasId(gt(4))"));
+ }
+
+ @Test
+ public void testTraversalMethod_hasKey_P() throws Exception {
+ compare(g.V().hasKey(eq("asd")), eval("g.V().hasKey(eq(\"asd\"))"));
+ }
+
+ @Test
+ public void testTraversalMethod_hasKey_String_String() throws Exception {
+ compare(g.V().hasKey("age"), eval("g.V().hasKey('age')"));
+ compare(g.V().hasKey("age", "3"), eval("g.V().hasKey('age', '3')"));
+ }
+
+ @Test
+ public void testTraversalMethod_hasLabel_P() throws Exception {
+ compare(g.V().hasLabel(eq("asd")), eval("g.V().hasLabel(eq(\"asd\"))"));
+ }
+
+ @Test
+ public void testTraversalMethod_hasLabel_String_String() throws Exception {
+ compare(g.V().hasLabel("age"), eval("g.V().hasLabel('age')"));
+ compare(g.V().hasLabel("age", "3"), eval("g.V().hasLabel('age', '3')"));
+ }
+
+ @Test
+ public void testTraversalMethod_hasNot() throws Exception {
+ compare(g.V().hasNot("know"), eval("g.V().hasNot('know')"));
+ }
+
+ @Test
+ public void testTraversalMethod_hasValue_Object_Object() throws Exception {
+ compare(g.V().hasValue(3, 4), eval("g.V().hasValue(3, 4)"));
+ }
+
+ @Test
+ public void testTraversalMethod_hasValue_P() throws Exception {
+ compare(g.V().hasValue(eq(2)), eval("g.V().hasValue(eq(2))"));
+ }
+
+ @Test
+ public void testTraversalMethod_id() throws Exception {
+ compare(g.V().id(), eval("g.V().id()"));
+ }
+
+ @Test
+ public void testTraversalMethod_identity() throws Exception {
+ compare(g.V().identity(), eval("g.V().identity()"));
+ }
+
+ @Test
+ public void testTraversalMethod_in() throws Exception {
+ compare(g.V().in("created"), eval("g.V().in('created')"));
+ }
+
+ @Test
+ public void testTraversalMethod_index() throws Exception {
+ compare(g.V().hasLabel("software").index(), eval("g.V().hasLabel('software').index()"));
+ }
+
+ @Test
+ public void testTraversalMethod_inE() throws Exception {
+ compare(g.V().inE("created"), eval("g.V().inE('created')"));
+ }
+
+ @Test
+ public void testTraversalMethod_inV() throws Exception {
+ compare(g.V().inV(), eval("g.V().inV()"));
+ }
+
+ @Test
+ public void testTraversalMethod_inject() throws Exception {
+ compare(g.V(4).out().values("name").inject("daniel"),
+ eval("g.V(4).out().values(\"name\").inject(\"daniel\")"));
+ }
+
+ @Test
+ public void testTraversalMethod_is_Object() throws Exception {
+ compare(g.V().is(4), eval("g.V().is(4)"));
+ }
+
+ @Test
+ public void testTraversalMethod_is_P() throws Exception {
+ compare(g.V().is(gt(4)), eval("g.V().is(gt(4))"));
+ }
+
+ @Test
+ public void testTraversalMethod_iterate() throws Exception {
+ compare(g.V().iterate(), eval("g.V().iterate()"));
+ }
+
+ @Test
+ public void testTraversalMethod_key() throws Exception {
+ compare(g.V().key(), eval("g.V().key()"));
+ }
+
+ @Test
+ public void testTraversalMethod_label() throws Exception {
+ compare(g.V().label(), eval("g.V().label()"));
+ }
+
+ @Test
+ public void testTraversalMethod_limit_Scope_long() throws Exception {
+ compare(g.V().limit(global, 3), eval("g.V().limit(global, 3)"));
+ }
+
+ @Test
+ public void testTraversalMethod_limit_long() throws Exception {
+ compare(g.V().limit(2), eval("g.V().limit(2)"));
+ }
+
+ @Test
+ public void testTraversalMethod_local() throws Exception {
+ compare(g.V().local(bothE()), eval("g.V().local(bothE())"));
+ }
+
+ @Test
+ public void testTraversalMethod_loops() throws Exception {
+ compare(g.V().loops(), eval("g.V().loops()"));
+ }
+
+ @Test
+ public void testTraversalMethod_map_Traversal() throws Exception {
+ compare(g.V().map(bothE()), eval("g.V().map(bothE())"));
+ }
+
+ @Test
+ public void testTraversalMethod_match() throws Exception {
+ compare(g.V().match(as("a"), as("b")), eval("g.V().match(as(\"a\"), as(\"b\"))"));
+ }
+
+ @Test
+ public void testTraversalMethod_max_Empty() throws Exception {
+ compare(g.V().max(), eval("g.V().max()"));
+ }
+
+ @Test
+ public void testTraversalMethod_max_Scope() throws Exception {
+ compare(g.V().max(Scope.local), eval("g.V().max(local)"));
+ }
+
+ @Test
+ public void testTraversalMethod_math() throws Exception {
+ compare(g.V().count().math("_ + 10"), eval("g.V().count().math('_ + 10')"));
+ }
+
+ @Test
+ public void testTraversalMethod_mean_Empty() throws Exception {
+ compare(g.V().mean(), eval("g.V().mean()"));
+ }
+
+ @Test
+ public void testTraversalMethod_mean_Scope() throws Exception {
+ compare(g.V().mean(global), eval("g.V().mean(global)"));
+ }
+
+ @Test
+ public void testTraversalMethod_min_Empty() throws Exception {
+ compare(g.V().min(), eval("g.V().min()"));
+ }
+
+ @Test
+ public void testTraversalMethod_min_Scope() throws Exception {
+ compare(g.V().min(Scope.local), eval("g.V().min(local)"));
+ }
+
+ @Test
+ public void testTraversalMethod_not() throws Exception {
+ compare(g.V().not(both()), eval("g.V().not(both())"));
+ }
+
+ @Test
+ public void testTraversalMethod_option_Object_Traversal() throws Exception {
+ compare(g.V().branch(values("name")).option(2, bothE()),
+ eval("g.V().branch(values(\"name\")).option(2, bothE())"));
+ }
+
+ @Test
+ public void testTraversalMethod_option_Traversal() throws Exception {
+ compare(g.V().branch(values("name")).option(both()), eval("g.V().branch(values(\"name\")).option(both())"));
+ }
+
+ @Test
+ public void testTraversalMethod_optional() throws Exception {
+ compare(g.V().optional(min()), eval("g.V().optional(min())"));
+ }
+
+ @Test
+ public void testTraversalMethod_or() throws Exception {
+ compare(g.V().or(as("a"), as("b")), eval("g.V().or(as(\"a\"), as(\"b\"))"));
+ }
+
+ @Test
+ public void testTraversalMethod_order_Empty() throws Exception {
+ compare(g.V().order(), eval("g.V().order()"));
+ }
+
+ @Test
+ public void testTraversalMethod_order_Scope() throws Exception {
+ compare(g.V().order(global), eval("g.V().order(global)"));
+ }
+
+ @Test
+ public void testTraversalMethod_otherV() throws Exception {
+ compare(g.V().otherV(), eval("g.V().otherV()"));
+ }
+
+ @Test
+ public void testTraversalMethod_out() throws Exception {
+ compare(g.V().out("a", "b"), eval("g.V().out(\"a\", \"b\")"));
+ }
+
+ @Test
+ public void testTraversalMethod_outE() throws Exception {
+ compare(g.V().outE("a", "b"), eval("g.V().outE(\"a\", \"b\")"));
+ }
+
+ @Test
+ public void testTraversalMethod_outV() throws Exception {
+ compare(g.V().outV(), eval("g.V().outV()"));
+ }
+
+ @Test
+ public void testTraversalMethod_pageRank_Empty() throws Exception {
+ compare(g.V().pageRank(), eval("g.V().pageRank()"));
+ }
+
+ @Test
+ public void testTraversalMethod_pageRank_double() throws Exception {
+ compare(g.V().pageRank(2.6), eval("g.V().pageRank(2.6)"));
+ }
+
+ @Test
+ public void testTraversalMethod_path() throws Exception {
+ compare(g.V().path(), eval("g.V().path()"));
+ }
+
+ @Test
+ public void testTraversalMethod_peerPressure() throws Exception {
+ compare(g.V().peerPressure(), eval("g.V().peerPressure()"));
+ }
+
+ @Test
+ public void testTraversalMethod_profile_Empty() throws Exception {
+ compare(g.V().profile(), eval("g.V().profile()"));
+ }
+
+ @Test
+ public void testTraversalMethod_profile_String() throws Exception {
+ compare(g.V().profile("neptune"), eval("g.V().profile('neptune')"));
+ }
+
+ @Test
+ public void testTraversalMethod_project() throws Exception {
+ compare(g.V().project("neptune"), eval("g.V().project('neptune')"));
+ compare(g.V().project("neptune", "uranus"), eval("g.V().project('neptune', 'uranus')"));
+ }
+
+ @Test
+ public void testTraversalMethod_properties() throws Exception {
+ compare(g.V().properties("venus", "mars"), eval("g.V().properties('venus', 'mars')"));
+ }
+
+ @Test
+ public void testTraversalMethod_property_Cardinality_Object_Object_Object() throws Exception {
+ compare(g.V().property(VertexProperty.Cardinality.list,1,2,"key", 4),
+ eval("g.V().property(list, 1,2,'key',4)"));
+ }
+
+ @Test
+ public void testTraversalMethod_property_Object_Object_Object() throws Exception {
+ compare(g.V().property(1,2,"key", 4), eval("g.V().property(1,2,'key',4)"));
+ }
+
+ @Test
+ public void testTraversalMethod_propertyMap() throws Exception {
+ compare(g.V().propertyMap("venus", "mars"), eval("g.V().propertyMap('venus', 'mars')"));
+ }
+
+ @Test
+ public void testTraversalMethod_range_Scope_long_long() throws Exception {
+ compare(g.V().range(global, 3,5), eval("g.V().range(global, 3,5)"));
+ }
+
+ @Test
+ public void testTraversalMethod_range_long_long() throws Exception {
+ compare(g.V().range(3,5), eval("g.V().range(3,5)"));
+ }
+
+ @Test
+ public void testTraversalMethod_repeat() throws Exception {
+ compare(g.V().repeat(both()), eval("g.V().repeat(both())"));
+ }
+
+ @Test
+ public void testTraversalMethod_sack_BiFunction() throws Exception {
+ compare(g.V().sack(), eval("g.V().sack()"));
+ compare(g.V().sack(Operator.addAll), eval("g.V().sack(addAll)"));
+ compare(g.V().sack(Operator.and), eval("g.V().sack(and)"));
+ compare(g.V().sack(Operator.assign), eval("g.V().sack(assign)"));
+ compare(g.V().sack(Operator.div), eval("g.V().sack(div)"));
+ compare(g.V().sack(Operator.max), eval("g.V().sack(max)"));
+ compare(g.V().sack(Operator.min), eval("g.V().sack(min)"));
+ compare(g.V().sack(Operator.minus), eval("g.V().sack(minus)"));
+ compare(g.V().sack(Operator.mult), eval("g.V().sack(mult)"));
+ compare(g.V().sack(Operator.or), eval("g.V().sack(or)"));
+ compare(g.V().sack(Operator.sum), eval("g.V().sack(sum)"));
+ compare(g.V().sack(Operator.sumLong), eval("g.V().sack(sumLong)"));
+ }
+
+ @Test
+ public void testTraversalMethod_sack_Empty() throws Exception {
+ compare(g.V().sack(), eval("g.V().sack()"));
+ }
+
+ @Test
+ public void testTraversalMethod_sample_Scope_int() throws Exception {
+ compare(g.V().sample(global, 2), eval("g.V().sample(global, 2)"));
+ }
+
+ @Test
+ public void testTraversalMethod_sample_int() throws Exception {
+ compare(g.V().sample(4), eval("g.V().sample(4)"));
+ }
+
+ @Test
+ public void testTraversalMethod_select_Column() throws Exception {
+ compare(g.V().select(Column.keys), eval("g.V().select(keys)"));
+ }
+
+ @Test
+ public void testTraversalMethod_select_Pop_String() throws Exception {
+ compare(g.V().select(Pop.first, "asd"), eval("g.V().select(first, 'asd')"));
+ }
+
+ @Test
+ public void testTraversalMethod_select_Pop_String_String_String() throws Exception {
+ compare(g.V().select(Pop.all, "a", "b", "c", "d"), eval("g.V().select(all, \"a\", \"b\", \"c\", \"d\")"));
+ }
+
+ @Test
+ public void testTraversalMethod_select_Pop_Traversal() throws Exception {
+ compare(g.V().select(Pop.all, out().properties("a")), eval("g.V().select(all, out().properties(\"a\"))"));
+ }
+
+ @Test
+ public void testTraversalMethod_select_String() throws Exception {
+ compare(g.V().select("yigit"), eval("g.V().select(\"yigit\")"));
+ }
+
+ @Test
+ public void testTraversalMethod_select_String_String_String() throws Exception {
+ compare(g.V().select("a", "b", "c", "d"), eval("g.V().select(\"a\", \"b\", \"c\", \"d\")"));
+ }
+
+ @Test
+ public void testTraversalMethod_select_Traversal() throws Exception {
+ compare(g.V().select(out().properties("a")), eval("g.V().select(out().properties(\"a\"))"));
+ }
+
+ @Test
+ public void testTraversalMethod_sideEffect() throws Exception {
+ compare(g.V().sideEffect(bothE()), eval("g.V().sideEffect(bothE())"));
+ }
+
+ @Test
+ public void testTraversalMethod_simplePath() throws Exception {
+ compare(g.V().simplePath(), eval("g.V().simplePath()"));
+ }
+
+ @Test
+ public void testTraversalMethod_skip_Scope_long() throws Exception {
+ compare(g.V().skip(global, 8), eval("g.V().skip(global, 8)"));
+ }
+
+ @Test
+ public void testTraversalMethod_skip_long() throws Exception {
+ compare(g.V().skip(8), eval("g.V().skip(8)"));
+ }
+
+ @Test
+ public void testTraversalMethod_store() throws Exception {
+ compare(g.V().store("asd"), eval("g.V().store(\"asd\")"));
+ }
+
+ @Test
+ public void testTraversalMethod_subgraph() throws Exception {
+ compare(g.V().subgraph("asd"), eval("g.V().subgraph('asd')"));
+ }
+
+ @Test
+ public void testTraversalMethod_sum_Empty() throws Exception {
+ compare(g.V().sum(), eval("g.V().sum()"));
+ }
+
+ @Test
+ public void testTraversalMethod_sum_Scope() throws Exception {
+ compare(g.V().sum(Scope.local), eval("g.V().sum(local)"));
+ }
+
+ @Test
+ public void testTraversalMethod_tail_Empty() throws Exception {
+ compare(g.V().tail(), eval("g.V().tail()"));
+ }
+
+ @Test
+ public void testTraversalMethod_tail_Scope() throws Exception {
+ compare(g.V().tail(Scope.local), eval("g.V().tail(local)"));
+ }
+
+ @Test
+ public void testTraversalMethod_tail_Scope_long() throws Exception {
+ compare(g.V().tail(Scope.local, 3), eval("g.V().tail(local, 3)"));
+ }
+
+ @Test
+ public void testTraversalMethod_tail_long() throws Exception {
+ compare(g.V().tail(4), eval("g.V().tail(4)"));
+ }
+
+ @Test
+ public void testTraversalMethod_timeLimit() throws Exception {
+ compare(g.V().timeLimit(5), eval("g.V().timeLimit(5)"));
+ }
+
+ @Test
+ public void testTraversalMethod_times() throws Exception {
+ compare(g.V().times(6), eval("g.V().times(6)"));
+ }
+
+ @Test
+ public void testTraversalMethod_to_Direction_String() throws Exception {
+ compare(g.V().to(Direction.IN, "asd"), eval("g.V().to(IN, 'asd')"));
+ }
+
+ @Test
+ public void testTraversalMethod_to_String() throws Exception {
+ compare(g.V().path().to("home"), eval("g.V().path().to(\"home\")"));
+ }
+
+ @Test
+ public void testTraversalMethod_to_Traversal() throws Exception {
+ compare(g.V().addE("as").to(V()), eval("g.V().addE('as').to(V())"));
+ }
+
+ @Test
+ public void testTraversalMethod_toE() throws Exception {
+ compare(g.V().toE(Direction.IN, "asd"), eval("g.V().toE(IN, 'asd')"));
+ }
+
+ @Test
+ public void testTraversalMethod_toV() throws Exception {
+ compare(g.V().toV(Direction.IN), eval("g.V().toV(IN)"));
+ }
+
+ @Test
+ public void testTraversalMethod_tree_Empty() throws Exception {
+ compare(g.V().tree(), eval("g.V().tree()"));
+ }
+
+ @Test
+ public void testTraversalMethod_tree_String() throws Exception {
+ compare(g.V().tree("hello"), eval("g.V().tree(\"hello\")"));
+ }
+
+ @Test
+ public void testTraversalMethod_unfold() throws Exception {
+ compare(g.V().unfold(), eval("g.V().unfold()"));
+ }
+
+ @Test
+ public void testTraversalMethod_union() throws Exception {
+ compare(g.V().union(in(), out()), eval("g.V().union(in(), out())"));
+ }
+
+ @Test
+ public void testTraversalMethod_until_Predicate() throws Exception {
+ compare(g.V().until(is("123")), eval("g.V().until(is(\"123\"))"));
+ }
+
+ @Test
+ public void testTraversalMethod_until_Traversal() throws Exception {
+ compare(g.V().until(has("ripple")), eval("g.V().until(has(\"ripple\"))"));
+ }
+
+ @Test
+ public void testTraversalMethod_value() throws Exception {
+ compare(g.V().value(), eval("g.V().value()"));
+ }
+
+ @Test
+ public void testTraversalMethod_valueMap_String() throws Exception {
+ compare(g.V().valueMap("yigit"), eval("g.V().valueMap(\"yigit\")"));
+ }
+
+ @Test
+ public void testTraversalMethod_valueMap_boolean_String1() throws Exception {
+ compare(g.V().valueMap(true), eval("g.V().valueMap(true)"));
+ }
+
+ @Test
+ public void testTraversalMethod_valueMap_boolean_String2() throws Exception {
+ compare(g.V().valueMap(true, "that"), eval("g.V().valueMap(true, \"that\")"));
+ }
+
+ @Test
+ public void testTraversalMethod_valueMap_withOption() throws Exception {
+ compare(g.V().valueMap().with(WithOptions.tokens, WithOptions.labels),
+ eval("g.V().valueMap().with(WithOptions.tokens, WithOptions.labels)"));
+ }
+
+ @Test
+ public void testTraversalMethod_values() throws Exception {
+ compare(g.V().values("earth", "mars"), eval("g.V().values(\"earth\", \"mars\")"));
+ }
+
+ @Test
+ public void testTraversalMethod_where_P() throws Exception {
+ compare(g.V().where(eq("123")), eval("g.V().where(eq(\"123\"))"));
+ }
+
+ @Test
+ public void testTraversalMethod_where_String_P() throws Exception {
+ compare(g.V().where("age", eq("123")), eval("g.V().where('age', eq(\"123\"))"));
+ }
+
+ @Test
+ public void testTraversalMethod_where_Traversal() throws Exception {
+ compare(g.V().where(both()), eval("g.V().where(both())"));
+ }
+
+ @Test
+ public void visitTraversalMethod_with_String() throws Exception {
+ compare(g.V().valueMap().with("hakuna"), eval("g.V().valueMap().with('hakuna')"));
+ }
+
+ @Test
+ public void visitTraversalMethod_with_String_Object() throws Exception {
+ compare(g.V().index().with(WithOptions.indexer, WithOptions.map),
+ eval("g.V().index().with(WithOptions.indexer, WithOptions.map)"));
+ }
+
+ @Test
+ public void visitTraversalMethod_withOptionsTokensAll() throws Exception {
+ compare(g.V().has("code","AUS").valueMap().with(WithOptions.tokens,WithOptions.all).unfold(),
+ eval("g.V().has('code','AUS').valueMap().with(WithOptions.tokens,WithOptions.all).unfold()"));
+ }
+
+ @Test
+ public void visitTraversalMethod_withOptionsTokensNone() throws Exception {
+ compare(g.V().has("code","AUS").valueMap().with(WithOptions.tokens,WithOptions.none),
+ eval("g.V().has('code','AUS').valueMap().with(WithOptions.tokens,WithOptions.none)"));
+ }
+
+ @Test
+ public void visitTraversalMethod_withOptionsTokensIds() throws Exception {
+ compare(g.V().has("code","AUS").valueMap().with(WithOptions.tokens,WithOptions.ids),
+ eval("g.V().has('code','AUS').valueMap().with(WithOptions.tokens,WithOptions.ids)"));
+ }
+
+ @Test
+ public void visitTraversalMethod_withOptionsTokensLabels() throws Exception {
+ compare(g.V().has("code","AUS").valueMap().with(WithOptions.tokens,WithOptions.labels),
+ eval("g.V().has('code','AUS').valueMap().with(WithOptions.tokens,WithOptions.labels)"));
+ }
+
+ @Test
+ public void visitTraversalMethod_withOptionsTokensKeys() throws Exception {
+ compare(g.V().has("code","AUS").valueMap().with(WithOptions.tokens,WithOptions.keys),
+ eval("g.V().has('code','AUS').valueMap().with(WithOptions.tokens,WithOptions.keys)"));
+ }
+
+ @Test
+ public void visitTraversalMethod_withOptionsTokensValues() throws Exception {
+ compare(g.V().has("code","AUS").valueMap().with(WithOptions.tokens,WithOptions.values),
+ eval("g.V().has('code','AUS').valueMap().with(WithOptions.tokens,WithOptions.values)"));
+ }
+
+ @Test
+ public void visitTraversalMethod_withOptionsIndexerList() throws Exception {
+ compare(g.V().has("code","AUS").valueMap().with(WithOptions.indexer,WithOptions.list),
+ eval("g.V().has('code','AUS').valueMap().with(WithOptions.indexer,WithOptions.list)"));
+ }
+ @Test
+ public void visitTraversalMethod_withOptionsIndexerMap() throws Exception {
+ compare(g.V().has("code","AUS").valueMap().with(WithOptions.indexer,WithOptions.map),
+ eval("g.V().has('code','AUS').valueMap().with(WithOptions.indexer,WithOptions.map)"));
+ }
+
+ @Test
+ public void testTraversalMethod_peerPressure_withPropertyName() throws Exception {
+ compare(g.V().peerPressure().with(PeerPressure.propertyName, "cluster"),
+ eval("g.V().peerPressure().with(PeerPressure.propertyName, 'cluster')"));
+ }
+
+ @Test
+ public void testTraversalMethod_peerPressure_withEdges() throws Exception {
+ compare(g.V().peerPressure().with(PeerPressure.edges, outE("knows")),
+ eval("g.V().peerPressure().with(PeerPressure.edges, __.outE('knows'))"));
+ }
+
+ @Test
+ public void testTraversalMethod_peerPressure_withTimes() throws Exception {
+ compare(g.V().peerPressure().with(PeerPressure.times, 2),
+ eval("g.V().peerPressure().with(PeerPressure.times, 2)"));
+ }
+
+ @Test
+ public void testTraversalMethod_pageRank_withOutEdges() throws Exception {
+ compare(g.V().pageRank(2.6).with(PageRank.edges, outE("knows")),
+ eval("g.V().pageRank(2.6).with(PageRank.edges, __.outE('knows'))"));
+ }
+
+ @Test
+ public void testTraversalMethod_pageRank_withTimes() throws Exception {
+ compare(g.V().pageRank(2.6).with(PageRank.times, 2),
+ eval("g.V().pageRank(2.6).with(PageRank.times, 2)"));
+ }
+
+ @Test
+ public void testTraversalMethod_pageRank_withPropertyName() throws Exception {
+ compare(g.V().pageRank(2.6).with(PageRank.propertyName, "blah"),
+ eval("g.V().pageRank(2.6).with(PageRank.propertyName, 'blah')"));
+ }
+
+ @Test
+ public void testTraversalMethod_shortestPath_withEdges() throws Exception {
+ compare(g.V().shortestPath().with(ShortestPath.edges, outE("knows")),
+ eval("g.V().shortestPath().with(ShortestPath.edges, __.outE('knows'))"));
+ }
+
+ @Test
+ public void testTraversalMethod_shortestPath_withIncludeEdges() throws Exception {
+ compare(g.V().shortestPath().with(ShortestPath.includeEdges, true),
+ eval("g.V().shortestPath().with(ShortestPath.includeEdges, true)"));
+ }
+
+ @Test
+ public void testTraversalMethod_shortestPath_withDistance() throws Exception {
+ compare(g.V().shortestPath().with(ShortestPath.distance, "asd"),
+ eval("g.V().shortestPath().with(ShortestPath.distance, 'asd')"));
+ }
+
+ @Test
+ public void testTraversalMethod_shortestPath_withMaxDistance() throws Exception {
+ compare(g.V().shortestPath().with(ShortestPath.maxDistance, 2),
+ eval("g.V().shortestPath().with(ShortestPath.maxDistance, 2)"));
+ }
+
+ @Test
+ public void testTraversalMethod_shortestPath_withTarget() throws Exception {
+ compare(g.V().shortestPath().with(ShortestPath.target, has("name", "peter")),
+ eval("g.V().shortestPath().with(ShortestPath.target, __.has('name','peter'))"));
+ }
+
+ @Test
+ public void testTraversalMethod_shortestPath_withEdgesWithTarget() throws Exception {
+ compare(g.V().shortestPath().with(ShortestPath.edges, Direction.IN).with(ShortestPath.target, has("name", "josh")),
+ eval("g.V().shortestPath().\n" +
+ " with(ShortestPath.edges, IN).\n" +
+ " with(ShortestPath.target, __.has('name','josh'))"));
+ }
+
+ @Test
+ public void testTraversalMethod_with() throws Exception {
+ compare(g.V().with("blah"),
+ eval("g.V().with('blah')"));
+ }
+
+ @Test
+ public void testTraversalMethod_with_multipleArgs() throws Exception {
+ compare(g.V().with("blah", "bleh"),
+ eval("g.V().with('blah', 'bleh')"));
+ }
+}
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalPredicateVisitorTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalPredicateVisitorTest.java
new file mode 100644
index 0000000..bc54f39
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalPredicateVisitorTest.java
@@ -0,0 +1,101 @@
+/*
+ * 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.language.grammar;
+
+import org.antlr.v4.runtime.CharStreams;
+import org.antlr.v4.runtime.CommonTokenStream;
+import org.apache.tinkerpop.gremlin.process.traversal.P;
+import org.apache.tinkerpop.gremlin.process.traversal.TextP;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.math.BigDecimal;
+import java.util.Arrays;
+
+@RunWith(Parameterized.class)
+public class TraversalPredicateVisitorTest {
+
+ @Parameterized.Parameter(value = 0)
+ public String script;
+
+ @Parameterized.Parameter(value = 1)
+ public P expected;
+
+ @Parameterized.Parameters()
+ public static Iterable<Object[]> generateTestParameters() {
+ return Arrays.asList(new Object[][]{
+ {"eq(10)", P.eq(10)},
+ {"neq(1.0f)", P.neq(1.0f)},
+ {"lt(0x11)", P.lt(0x11)},
+ {"lte('abc')", P.lte("abc")},
+ {"gt(1.0D)", P.gt(1d)},
+ {"gte(1L)", P.gte(1L)},
+ {"inside(100, 200)", P.inside(100, 200)},
+ {"outside(1E11, 2e-11)", P.outside(new BigDecimal("1E11"), new BigDecimal("2e-11"))},
+ {"between(\"a\", \"e\")", P.between("a", "e")},
+ {"within([\"a\", \"e\"])", P.within(Arrays.asList("a", "e"))},
+ {"without([1, 2])", P.without(Arrays.asList(1, 2))},
+ {"without([1, 2])", P.without(1, 2)},
+ {"without(1, 2)", P.without(1, 2)},
+ {"without(1)", P.without(1)},
+ {"without([1])", P.without(1)},
+ {"without(1, [1, 2])", P.without(1, Arrays.asList(1, 2))},
+ {"within([1, 2, 3], 1, [1, 2])", P.within(Arrays.asList(1, 2, 3), 1, Arrays.asList(1, 2))},
+ {"not(without(1, 2))", P.not(P.without(1, 2))},
+ {"not(eq(10))", P.not(P.eq(10))},
+ {"not(eq(10)).and(not(eq(11)))", P.not(P.eq(10)).and(P.not(P.eq(11)))},
+ {"not(eq(10)).or(not(eq(11)))", P.not(P.eq(10)).or(P.not(P.eq(11)))},
+ {"not(eq(10)).negate()", P.not(P.eq(10)).negate()},
+ {"P.eq(10)", P.eq(10)},
+ {"P.neq(1.0f)", P.neq(1.0f)},
+ {"P.lt(0x11)", P.lt(0x11)},
+ {"P.lte('abc')", P.lte("abc")},
+ {"P.gt(1.0D)", P.gt(1d)},
+ {"P.gte(1L)", P.gte(1L)},
+ {"P.inside(100, 200)", P.inside(100, 200)},
+ {"P.outside(1E11, 2e-11)", P.outside(new BigDecimal("1E11"), new BigDecimal("2e-11"))},
+ {"P.between(\"a\", \"e\")", P.between("a", "e")},
+ {"P.within([\"a\", \"e\"])", P.within(Arrays.asList("a", "e"))},
+ {"P.without([1, 2])", P.without(Arrays.asList(1, 2))},
+ {"P.not(P.without(1, 2))", P.not(P.without(1, 2))},
+ {"P.not(P.eq(10))", P.not(P.eq(10))},
+ {"P.not(eq(10)).and(P.not(eq(11)))", P.not(P.eq(10)).and(P.not(P.eq(11)))},
+ {"P.not(P.eq(10)).or(P.not(P.eq(11)))", P.not(P.eq(10)).or(P.not(P.eq(11)))},
+ {"P.not(P.eq(10)).negate()", P.not(P.eq(10)).negate()},
+ {"TextP.containing('hakuna').negate()", TextP.containing("hakuna").negate()},
+ {"TextP.notContaining('hakuna')", TextP.notContaining("hakuna")},
+ {"TextP.startingWith('hakuna')", TextP.startingWith("hakuna")},
+ {"TextP.endingWith('hakuna')", TextP.endingWith("hakuna")},
+ {"TextP.notEndingWith('hakuna')", TextP.notEndingWith("hakuna")},
+ {"TextP.notStartingWith('hakuna')", TextP.notStartingWith("hakuna")},
+ });
+ }
+
+ @Test
+ public void testPredicate() {
+ final GremlinLexer lexer = new GremlinLexer(CharStreams.fromString(script));
+ final GremlinParser parser = new GremlinParser(new CommonTokenStream(lexer));
+ final GremlinParser.TraversalPredicateContext ctx = parser.traversalPredicate();
+ final P predicate = TraversalPredicateVisitor.getInstance().visitTraversalPredicate(ctx);
+
+ Assert.assertEquals(expected, predicate);
+ }
+}
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalRootVisitorTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalRootVisitorTest.java
new file mode 100644
index 0000000..6272c41
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalRootVisitorTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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.language.grammar;
+
+import org.antlr.v4.runtime.CharStreams;
+import org.antlr.v4.runtime.CommonTokenStream;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
+import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class TraversalRootVisitorTest {
+ private GraphTraversalSource g;
+ private GremlinAntlrToJava antlrToLanguage;
+
+ @Before
+ public void setup() {
+ g = new GraphTraversalSource(EmptyGraph.instance());
+ antlrToLanguage = new GremlinAntlrToJava();
+ }
+
+ @Test
+ public void testTraversalMethod_none() {
+ compare(g.V().none(), eval("g.V().none()"));
+ compare(g.V().union(__.identity().none()), eval("g.V().union(__.identity().none())"));
+ }
+
+ private void compare(Object expected, Object actual) {
+ assertEquals(((DefaultGraphTraversal) expected).asAdmin().getBytecode(),
+ ((DefaultGraphTraversal) actual).asAdmin().getBytecode());
+ }
+
+ private Object eval(String query) {
+ final GremlinLexer lexer = new GremlinLexer(CharStreams.fromString(query));
+ final GremlinParser parser = new GremlinParser(new CommonTokenStream(lexer));
+ return antlrToLanguage.visit(parser.queryList());
+ }
+}
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalSourceSelfMethodVisitorTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalSourceSelfMethodVisitorTest.java
new file mode 100644
index 0000000..145fd9f
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalSourceSelfMethodVisitorTest.java
@@ -0,0 +1,84 @@
+/*
+ * 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.language.grammar;
+
+import org.antlr.v4.runtime.CharStreams;
+import org.antlr.v4.runtime.CommonTokenStream;
+import org.apache.tinkerpop.gremlin.process.traversal.Operator;
+import org.apache.tinkerpop.gremlin.process.traversal.P;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.EdgeLabelVerificationStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReadOnlyStrategy;
+import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.Arrays;
+import java.util.HashMap;
+
+import static org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal;
+import static org.junit.Assert.assertEquals;
+
+@RunWith(Parameterized.class)
+public class TraversalSourceSelfMethodVisitorTest {
+ private static final GraphTraversalSource g = traversal().withEmbedded(EmptyGraph.instance());
+
+ @Parameterized.Parameter(value = 0)
+ public String script;
+
+ @Parameterized.Parameter(value = 1)
+ public GraphTraversalSource expected;
+
+ @Parameterized.Parameters()
+ public static Iterable<Object[]> generateTestParameters() {
+ final HashMap<String, Integer> map = new HashMap<>();
+ map.put("one", 1);
+ return Arrays.asList(new Object[][]{
+ {"withBulk(false)", g.withBulk(false)},
+ {"withBulk(true)", g.withBulk(true)},
+ {"withPath()", g.withPath()},
+ {"withSack('hello')", g.withSack("hello")},
+ {"withSack('hello', addAll)", g.withSack("hello", Operator.addAll)},
+ {"withSideEffect('hello', 12)", g.withSideEffect("hello", 12)},
+ {"withStrategies(ReadOnlyStrategy)", g.withStrategies(ReadOnlyStrategy.instance())},
+ {"withStrategies(new EdgeLabelVerificationStrategy(logWarning: true, throwException: true))", g.withStrategies(EdgeLabelVerificationStrategy.build().logWarning(true).throwException(true).create())},
+ {"withStrategies(ReadOnlyStrategy, new EdgeLabelVerificationStrategy(logWarning: true, throwException: true))", g.withStrategies(ReadOnlyStrategy.instance(), EdgeLabelVerificationStrategy.build().logWarning(true).throwException(true).create())},
+ {"withStrategies(new EdgeLabelVerificationStrategy(logWarning: true, throwException: true), ReadOnlyStrategy)", g.withStrategies(EdgeLabelVerificationStrategy.build().logWarning(true).throwException(true).create(), ReadOnlyStrategy.instance())},
+ {"with('requestId', '7c55d4d7-809a-4f84-9720-63b48cb2fd14')", g.with("requestId", "7c55d4d7-809a-4f84-9720-63b48cb2fd14")},
+ {"with('requestId')", g.with("requestId")},
+ {"withSideEffect('hello', ['one':1])", g.withSideEffect("hello", map)},
+ {"withSideEffect('hello', ['one' : 1])", g.withSideEffect("hello", map)},
+ {"withSideEffect('hello', ['one':1, 'two':2])", g.withSideEffect("hello", new HashMap<String, Integer>() {{
+ put("one", 1);
+ put("two", 2);
+ }})}
+ });
+ }
+
+ @Test
+ public void testTraversalSourceSelfMethod() {
+ final GremlinLexer lexer = new GremlinLexer(CharStreams.fromString(script));
+ final GremlinParser parser = new GremlinParser(new CommonTokenStream(lexer));
+ final GremlinParser.TraversalSourceSelfMethodContext ctx = parser.traversalSourceSelfMethod();
+ final GraphTraversalSource source = new TraversalSourceSelfMethodVisitor(g, new GremlinAntlrToJava()).visitTraversalSourceSelfMethod(ctx);
+
+ assertEquals(expected.getBytecode(), source.getBytecode());
+ }
+}
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalSourceSpawnVisitorTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalSourceSpawnVisitorTest.java
new file mode 100644
index 0000000..33204e1
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalSourceSpawnVisitorTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.language.grammar;
+
+import org.antlr.v4.runtime.CharStreams;
+import org.antlr.v4.runtime.CommonTokenStream;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.HashMap;
+
+import static org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal;
+import static org.junit.Assert.assertEquals;
+
+public class TraversalSourceSpawnVisitorTest {
+
+ private GraphTraversalSource g;
+ private GremlinAntlrToJava antlrToLanguage;
+
+ @Before
+ public void setup() {
+ g = traversal().withEmbedded(EmptyGraph.instance());
+ antlrToLanguage = new GremlinAntlrToJava();
+ }
+
+ private void compare(Object expected, Object actual) {
+ assertEquals(expected.toString(), actual.toString());
+ }
+
+ @Test
+ public void testTraversalSourceSpawnMethod_inject() {
+ // a random spawn of inject method.
+ compare(g.inject(1,2,3,4), eval("g.inject(1,2,3,4)"));
+ compare(g.inject(1,2,3,new HashMap<>()), eval("g.inject(1,2,3,[:])"));
+ compare(g.V(4).out().values("name").inject("daniel"), eval("g.V(4).out().values('name').inject('daniel')"));
+ }
+
+ private Object eval(final String query) {
+ final GremlinLexer lexer = new GremlinLexer(CharStreams.fromString(query));
+ final GremlinParser parser = new GremlinParser(new CommonTokenStream(lexer));
+ return antlrToLanguage.visit(parser.queryList());
+ }
+}
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalStrategyVisitorTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalStrategyVisitorTest.java
new file mode 100644
index 0000000..b83fb1e
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalStrategyVisitorTest.java
@@ -0,0 +1,87 @@
+/*
+ * 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.language.grammar;
+
+import org.antlr.v4.runtime.CharStreams;
+import org.antlr.v4.runtime.CommonTokenStream;
+import org.apache.commons.configuration2.ConfigurationConverter;
+import org.apache.tinkerpop.gremlin.process.traversal.P;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.PartitionStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SubgraphStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.EdgeLabelVerificationStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReadOnlyStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReservedKeysVerificationStrategy;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.Arrays;
+import java.util.HashSet;
+
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.hasLabel;
+
+@RunWith(Parameterized.class)
+public class TraversalStrategyVisitorTest {
+
+ private GremlinAntlrToJava antlrToLanguage;
+
+ @Parameterized.Parameter(value = 0)
+ public String script;
+
+ @Parameterized.Parameter(value = 1)
+ public TraversalStrategy<?> expected;
+
+ @Parameterized.Parameters()
+ public static Iterable<Object[]> generateTestParameters() {
+ return Arrays.asList(new Object[][]{
+ {"ReadOnlyStrategy", ReadOnlyStrategy.instance()},
+ {"new PartitionStrategy(partitionKey: 'k', includeMetaProperties: true)", PartitionStrategy.build().partitionKey("k").includeMetaProperties(true).create()},
+ {"new PartitionStrategy(partitionKey: 'k', writePartition: 'p', readPartitions: ['p','x','y'])", PartitionStrategy.build().partitionKey("k").writePartition("p").readPartitions("p", "x", "y").create()},
+ {"new EdgeLabelVerificationStrategy()", EdgeLabelVerificationStrategy.build().create()},
+ {"new EdgeLabelVerificationStrategy(logWarning: true, throwException: true)", EdgeLabelVerificationStrategy.build().logWarning(true).throwException(true).create()},
+ {"new ReservedKeysVerificationStrategy()", ReservedKeysVerificationStrategy.build().create()},
+ {"new ReservedKeysVerificationStrategy(logWarning: true, throwException: true)", ReservedKeysVerificationStrategy.build().logWarning(true).throwException(true).create()},
+ {"new ReservedKeysVerificationStrategy(logWarning: true, throwException: false)", ReservedKeysVerificationStrategy.build().logWarning(true).create()},
+ {"new ReservedKeysVerificationStrategy(keys: ['a','b'])", ReservedKeysVerificationStrategy.build().reservedKeys(new HashSet<>(Arrays.asList("a", "b"))).create()},
+ {"new SubgraphStrategy(vertices: hasLabel('person'))", SubgraphStrategy.build().vertices(hasLabel("person")).create()},
+ {"new SubgraphStrategy(vertices: hasLabel('person'), edges: hasLabel('knows'), vertexProperties: has('time', between(1234, 4321), checkAdjacentVertices: true)", SubgraphStrategy.build().vertices(hasLabel("person")).edges(hasLabel("knows")).vertexProperties(has("time", P.between(1234, 4321))).checkAdjacentVertices(true).create()},
+ });
+ }
+
+ @Before
+ public void setup() throws Exception {
+ antlrToLanguage = new GremlinAntlrToJava();
+ }
+
+ @Test
+ public void testTraversalStrategy() {
+ final GremlinLexer lexer = new GremlinLexer(CharStreams.fromString(script));
+ final GremlinParser parser = new GremlinParser(new CommonTokenStream(lexer));
+ final GremlinParser.TraversalStrategyContext ctx = parser.traversalStrategy();
+ final TraversalStrategy strategy = new TraversalStrategyVisitor((GremlinBaseVisitor) antlrToLanguage.tvisitor).visitTraversalStrategy(ctx);
+
+ Assert.assertEquals(expected, strategy);
+ Assert.assertEquals(ConfigurationConverter.getMap(expected.getConfiguration()),
+ ConfigurationConverter.getMap(strategy.getConfiguration()));
+ }
+}
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/package-lock.json b/gremlin-javascript/src/main/javascript/gremlin-javascript/package-lock.json
index 41c6b17..92215b8 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/package-lock.json
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/package-lock.json
@@ -616,7 +616,7 @@
"es5-ext": {
"version": "0.10.53",
"resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.53.tgz",
- "integrity": "sha512-Xs2Stw6NiNHWypzRTY1MtaG/uJlwCk8kH81920ma8mvN8Xq1gsfhZvpkImLQArw8AHnv8MT2I45J3c0R8slE+Q==",
+ "integrity": "sha1-k8WjrP2+8nUiCtcmRK0C7hg2jeE=",
"dev": true,
"requires": {
"es6-iterator": "~2.0.3",
@@ -638,7 +638,7 @@
"es6-symbol": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.3.tgz",
- "integrity": "sha512-NJ6Yn3FuDinBaBRWl/q5X/s4koRHBrgKAu+yGI6JCBeiu3qrcbJhwT2GeR/EXVfylRk8dpQVJoLEFhK+Mu31NA==",
+ "integrity": "sha1-utXTwbzawoJp9MszHkMceKxwXRg=",
"dev": true,
"requires": {
"d": "^1.0.1",
@@ -716,7 +716,7 @@
"ext": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/ext/-/ext-1.4.0.tgz",
- "integrity": "sha512-Key5NIsUxdqKg3vIsdw9dSuXpPCQ297y6wBjL30edxwPgt2E44WcWBZey/ZvUc6sERLTxKdyCu4gZFmUbk1Q7A==",
+ "integrity": "sha1-ia56BxWPedNVF4gpBDJAd+Q3kkQ=",
"dev": true,
"requires": {
"type": "^2.0.0"
@@ -966,7 +966,7 @@
"glob": {
"version": "7.1.6",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz",
- "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==",
+ "integrity": "sha1-FB8zuBp8JJLhJVlDB0gMRmeSeKY=",
"dev": true,
"requires": {
"fs.realpath": "^1.0.0",
@@ -1052,7 +1052,7 @@
"nopt": {
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/nopt/-/nopt-4.0.3.tgz",
- "integrity": "sha512-CvaGwVMztSMJLOeXPrez7fyfObdZqNUK1cPAEzLHrTybIua9pMdmmPR5YwtfNftIOMv3DPUhFaxsZMNTQO20Kg==",
+ "integrity": "sha1-o3XK2dAv2SEnjZVMIlTVqlfhXkg=",
"dev": true,
"requires": {
"abbrev": "1",
@@ -1666,7 +1666,7 @@
"mocha": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/mocha/-/mocha-5.2.0.tgz",
- "integrity": "sha512-2IUgKDhc3J7Uug+FxMXuqIyYzH7gJjXECKe/w43IGgQHTSj3InJi+yAA7T24L9bQMRKiUEHxEX37G5JpVUGLcQ==",
+ "integrity": "sha1-bYrlCPWRZ/lA8rWzxKYSrlDJCuY=",
"dev": true,
"requires": {
"browser-stdout": "1.3.1",
@@ -1685,13 +1685,13 @@
"commander": {
"version": "2.15.1",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.15.1.tgz",
- "integrity": "sha512-VlfT9F3V0v+jr4yxPc5gg9s62/fIVWsd2Bk2iD435um1NlGMYdVCq+MjcXnhYq2icNOizHr1kK+5TI6H0Hy0ag==",
+ "integrity": "sha1-30boZ9D8Kuxmo0ZitAapzK//Ww8=",
"dev": true
},
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
- "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
+ "integrity": "sha1-W7WgZyYotkFJVmuhaBnmFRjGcmE=",
"dev": true,
"requires": {
"ms": "2.0.0"
@@ -1700,7 +1700,7 @@
"glob": {
"version": "7.1.2",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz",
- "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==",
+ "integrity": "sha1-wZyd+aAocC1nhhI4SmVSQExjbRU=",
"dev": true,
"requires": {
"fs.realpath": "^1.0.0",
@@ -1723,7 +1723,7 @@
"supports-color": {
"version": "5.4.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.4.0.tgz",
- "integrity": "sha512-zjaXglF5nnWpsq470jSv6P9DwPvgLkuapYmfDm3JWOm0vkNTVF2tI4UrN2r6jH1qM/uc/WtxYY1hYoA2dOKj5w==",
+ "integrity": "sha1-HGszdALCE3YF7+GfEP7DkPb6q1Q=",
"dev": true,
"requires": {
"has-flag": "^3.0.0"
@@ -2374,7 +2374,7 @@
"thenify": {
"version": "3.3.1",
"resolved": "https://registry.npmjs.org/thenify/-/thenify-3.3.1.tgz",
- "integrity": "sha512-RVZSIV5IG10Hk3enotrhvz0T9em6cyHBLkH/YAZuKqd8hRkKhSfCGIcP2KUY0EPxndzANBmNllzWPwak+bheSw==",
+ "integrity": "sha1-iTLmhqQGYDigFt2eLKRq3Zg4qV8=",
"dev": true,
"requires": {
"any-promise": "^1.0.0"