aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/yql/ProgramParser.java
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-11-22 15:18:00 +0100
committerGitHub <noreply@github.com>2021-11-22 15:18:00 +0100
commit589b52b4f74fc52597b6347abb8ccbc65eeb4f08 (patch)
tree64d17747179cf40077f1504361413add6be59936 /container-search/src/main/java/com/yahoo/search/yql/ProgramParser.java
parentaf3ed2033e8c4b9cd999196daf28f8c6eb018534 (diff)
Revert "antlr4 4.5 -> 4.9.3"
Diffstat (limited to 'container-search/src/main/java/com/yahoo/search/yql/ProgramParser.java')
-rw-r--r--container-search/src/main/java/com/yahoo/search/yql/ProgramParser.java44
1 files changed, 32 insertions, 12 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/yql/ProgramParser.java b/container-search/src/main/java/com/yahoo/search/yql/ProgramParser.java
index d32033249f1..e1e88c83725 100644
--- a/container-search/src/main/java/com/yahoo/search/yql/ProgramParser.java
+++ b/container-search/src/main/java/com/yahoo/search/yql/ProgramParser.java
@@ -65,6 +65,8 @@ import org.antlr.v4.runtime.Recognizer;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.atn.PredictionMode;
+import org.antlr.v4.runtime.misc.NotNull;
+import org.antlr.v4.runtime.misc.Nullable;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.RuleNode;
import org.antlr.v4.runtime.tree.TerminalNode;
@@ -100,12 +102,12 @@ final class ProgramParser {
lexer.addErrorListener(new BaseErrorListener() {
@Override
- public void syntaxError(Recognizer<?, ?> recognizer,
- Object offendingSymbol,
+ public void syntaxError(@NotNull Recognizer<?, ?> recognizer,
+ @Nullable Object offendingSymbol,
int line,
int charPositionInLine,
- String msg,
- RecognitionException e) {
+ @NotNull String msg,
+ @Nullable RecognitionException e) {
throw new ProgramCompileException(new Location(programName, line, charPositionInLine), "%s", msg);
}
@@ -117,12 +119,12 @@ final class ProgramParser {
parser.addErrorListener(new BaseErrorListener() {
@Override
- public void syntaxError(Recognizer<?, ?> recognizer,
- Object offendingSymbol,
+ public void syntaxError(@NotNull Recognizer<?, ?> recognizer,
+ @Nullable Object offendingSymbol,
int line,
int charPositionInLine,
- String msg,
- RecognitionException e) {
+ @NotNull String msg,
+ @Nullable RecognitionException e) {
throw new ProgramCompileException(new Location(programName, line, charPositionInLine), "%s", msg);
}
@@ -193,6 +195,7 @@ final class ProgramParser {
final Scope parent;
Set<String> cursors = ImmutableSet.of();
Set<String> variables = ImmutableSet.of();
+ Set<String> views = Sets.newHashSet();
Map<String, Binding> bindings = Maps.newHashMap();
final yqlplusParser parser;
final String programName;
@@ -244,6 +247,13 @@ final class ProgramParser {
return variables.contains(name) || (parent != null && parent.isVariable(name));
}
+ public void bindModule(Location loc, List<String> binding, String symbolName) {
+ if (isBound(symbolName)) {
+ throw new ProgramCompileException(loc, "Name '%s' is already used.", symbolName);
+ }
+ root.bindings.put(symbolName, new Binding(binding));
+ }
+
public void defineDataSource(Location loc, String name) {
if (isCursor(name)) {
throw new ProgramCompileException(loc, "Alias '%s' is already used.", name);
@@ -265,6 +275,16 @@ final class ProgramParser {
}
+ public void defineView(Location loc, String text) {
+ if (this != root) {
+ throw new IllegalStateException("Views MUST be defined in 'root' scope only");
+ }
+ if (views.contains(text)) {
+ throw new ProgramCompileException(loc, "View '%s' already defined", text);
+ }
+ views.add(text);
+ }
+
Scope child() {
return new Scope(root, this);
}
@@ -331,8 +351,8 @@ final class ProgramParser {
List<Orderby_fieldContext> orderFieds = ((OrderbyContext) child)
.orderby_fields().orderby_field();
orderby = Lists.newArrayListWithExpectedSize(orderFieds.size());
- for (var field: orderFieds) {
- orderby.add(convertSortKey(field, scope));
+ for (int j = 0; j < orderFieds.size(); ++j) {
+ orderby.add(convertSortKey(orderFieds.get(j), scope));
}
break;
case yqlplusParser.RULE_limit:
@@ -906,8 +926,8 @@ final class ProgramParser {
List<String> path = readName((Namespaced_nameContext) parseTree.getChild(0));
Location loc = toLocation(scope, parseTree.getChild(0));
String alias = path.get(0);
- OperatorNode<ExpressionOperator> result;
- int start;
+ OperatorNode<ExpressionOperator> result = null;
+ int start = 0;
if (scope.isCursor(alias)) {
if (path.size() > 1) {
result = OperatorNode.create(loc, ExpressionOperator.READ_FIELD, alias, path.get(1));