You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@metron.apache.org by ce...@apache.org on 2017/06/09 15:49:32 UTC
[1/3] metron git commit: METRON-980: Short circuit operations for
Stellar closes apache/metron#606
Repository: metron
Updated Branches:
refs/heads/master 7d6121bfd -> 30d0e2a6f
http://git-wip-us.apache.org/repos/asf/metron/blob/30d0e2a6/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/FloatLiteralEvaluatorTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/FloatLiteralEvaluatorTest.java b/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/FloatLiteralEvaluatorTest.java
index 4f7117a..f9ecff1 100644
--- a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/FloatLiteralEvaluatorTest.java
+++ b/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/FloatLiteralEvaluatorTest.java
@@ -48,8 +48,8 @@ public class FloatLiteralEvaluatorTest {
public void verifyHappyPathEvaluation() throws Exception {
when(context.getText()).thenReturn("100f");
- Token<? extends Number> evaluated = evaluator.evaluate(context);
- assertEquals(new Token<>(100f, Float.class), evaluated);
+ Token<? extends Number> evaluated = evaluator.evaluate(context, null);
+ assertEquals(new Token<>(100f, Float.class, null), evaluated);
verify(context).getText();
verifyNoMoreInteractions(context);
@@ -60,7 +60,7 @@ public class FloatLiteralEvaluatorTest {
exception.expect(NumberFormatException.class);
when(context.getText()).thenReturn("");
- evaluator.evaluate(context);
+ evaluator.evaluate(context, null);
}
@Test
@@ -68,7 +68,7 @@ public class FloatLiteralEvaluatorTest {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("Cannot evaluate a context that is null.");
- evaluator.evaluate(null);
+ evaluator.evaluate(null, null);
}
}
http://git-wip-us.apache.org/repos/asf/metron/blob/30d0e2a6/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/IntLiteralEvaluatorTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/IntLiteralEvaluatorTest.java b/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/IntLiteralEvaluatorTest.java
index 2fd081f..bef23d1 100644
--- a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/IntLiteralEvaluatorTest.java
+++ b/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/IntLiteralEvaluatorTest.java
@@ -48,8 +48,8 @@ public class IntLiteralEvaluatorTest {
public void verifyHappyPathEvaluation() throws Exception {
when(context.getText()).thenReturn("100");
- Token<? extends Number> evaluated = evaluator.evaluate(context);
- assertEquals(new Token<>(100, Integer.class), evaluated);
+ Token<? extends Number> evaluated = evaluator.evaluate(context, null);
+ assertEquals(new Token<>(100, Integer.class, null), evaluated);
verify(context).getText();
verifyNoMoreInteractions(context);
@@ -60,7 +60,7 @@ public class IntLiteralEvaluatorTest {
exception.expect(NumberFormatException.class);
when(context.getText()).thenReturn("");
- evaluator.evaluate(context);
+ evaluator.evaluate(context, null);
}
@Test
@@ -68,7 +68,7 @@ public class IntLiteralEvaluatorTest {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("Cannot evaluate a context that is null.");
- evaluator.evaluate(null);
+ evaluator.evaluate(null, null);
}
}
http://git-wip-us.apache.org/repos/asf/metron/blob/30d0e2a6/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/LongLiteralEvaluatorTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/LongLiteralEvaluatorTest.java b/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/LongLiteralEvaluatorTest.java
index 21f75d4..e9c3aa7 100644
--- a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/LongLiteralEvaluatorTest.java
+++ b/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/LongLiteralEvaluatorTest.java
@@ -49,8 +49,8 @@ public class LongLiteralEvaluatorTest {
public void verifyHappyPathEvaluation() throws Exception {
when(context.getText()).thenReturn("100L");
- Token<? extends Number> evaluated = evaluator.evaluate(context);
- assertEquals(new Token<>(100L, Long.class), evaluated);
+ Token<? extends Number> evaluated = evaluator.evaluate(context, null);
+ assertEquals(new Token<>(100L, Long.class, null), evaluated);
verify(context).getText();
verifyNoMoreInteractions(context);
@@ -62,7 +62,7 @@ public class LongLiteralEvaluatorTest {
exception.expectMessage("Invalid format for long. Failed trying to parse a long with the following value: ");
when(context.getText()).thenReturn("");
- evaluator.evaluate(context);
+ evaluator.evaluate(context, null);
}
@Test
@@ -70,6 +70,6 @@ public class LongLiteralEvaluatorTest {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("Cannot evaluate a context that is null.");
- evaluator.evaluate(null);
+ evaluator.evaluate(null, null);
}
}
http://git-wip-us.apache.org/repos/asf/metron/blob/30d0e2a6/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/NumberLiteralEvaluatorTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/NumberLiteralEvaluatorTest.java b/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/NumberLiteralEvaluatorTest.java
index 8317737..2065e6d 100644
--- a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/NumberLiteralEvaluatorTest.java
+++ b/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/NumberLiteralEvaluatorTest.java
@@ -60,36 +60,36 @@ public class NumberLiteralEvaluatorTest {
@Test
public void verifyIntLiteralContextIsProperlyEvaluated() throws Exception {
StellarParser.IntLiteralContext context = mock(StellarParser.IntLiteralContext.class);
- NumberLiteralEvaluator.INSTANCE.evaluate(context, instanceMap);
+ NumberLiteralEvaluator.INSTANCE.evaluate(context, instanceMap, null);
- verify(intLiteralContextNumberEvaluator).evaluate(context);
+ verify(intLiteralContextNumberEvaluator).evaluate(context, null);
verifyZeroInteractions(doubleLiteralContextNumberEvaluator, floatLiteralContextNumberEvaluator, longLiteralContextNumberEvaluator);
}
@Test
public void verifyDoubleLiteralContextIsProperlyEvaluated() throws Exception {
StellarParser.DoubleLiteralContext context = mock(StellarParser.DoubleLiteralContext.class);
- NumberLiteralEvaluator.INSTANCE.evaluate(context, instanceMap);
+ NumberLiteralEvaluator.INSTANCE.evaluate(context, instanceMap, null);
- verify(doubleLiteralContextNumberEvaluator).evaluate(context);
+ verify(doubleLiteralContextNumberEvaluator).evaluate(context, null);
verifyZeroInteractions(intLiteralContextNumberEvaluator, floatLiteralContextNumberEvaluator, longLiteralContextNumberEvaluator);
}
@Test
public void verifyFloatLiteralContextIsProperlyEvaluated() throws Exception {
StellarParser.FloatLiteralContext context = mock(StellarParser.FloatLiteralContext.class);
- NumberLiteralEvaluator.INSTANCE.evaluate(context, instanceMap);
+ NumberLiteralEvaluator.INSTANCE.evaluate(context, instanceMap, null);
- verify(floatLiteralContextNumberEvaluator).evaluate(context);
+ verify(floatLiteralContextNumberEvaluator).evaluate(context, null);
verifyZeroInteractions(doubleLiteralContextNumberEvaluator, intLiteralContextNumberEvaluator, longLiteralContextNumberEvaluator);
}
@Test
public void verifyLongLiteralContextIsProperlyEvaluated() throws Exception {
StellarParser.LongLiteralContext context = mock(StellarParser.LongLiteralContext.class);
- NumberLiteralEvaluator.INSTANCE.evaluate(context, instanceMap);
+ NumberLiteralEvaluator.INSTANCE.evaluate(context, instanceMap, null);
- verify(longLiteralContextNumberEvaluator).evaluate(context);
+ verify(longLiteralContextNumberEvaluator).evaluate(context, null);
verifyZeroInteractions(doubleLiteralContextNumberEvaluator, floatLiteralContextNumberEvaluator, intLiteralContextNumberEvaluator);
}
@@ -100,7 +100,7 @@ public class NumberLiteralEvaluatorTest {
exception.expect(ParseException.class);
exception.expectMessage("Does not support evaluation for type " + context.getClass());
- NumberLiteralEvaluator.INSTANCE.evaluate(context, instanceMap);
+ NumberLiteralEvaluator.INSTANCE.evaluate(context, instanceMap, null);
verifyZeroInteractions(longLiteralContextNumberEvaluator, doubleLiteralContextNumberEvaluator, floatLiteralContextNumberEvaluator, intLiteralContextNumberEvaluator);
}
[3/3] metron git commit: METRON-980: Short circuit operations for
Stellar closes apache/metron#606
Posted by ce...@apache.org.
METRON-980: Short circuit operations for Stellar closes apache/metron#606
Project: http://git-wip-us.apache.org/repos/asf/metron/repo
Commit: http://git-wip-us.apache.org/repos/asf/metron/commit/30d0e2a6
Tree: http://git-wip-us.apache.org/repos/asf/metron/tree/30d0e2a6
Diff: http://git-wip-us.apache.org/repos/asf/metron/diff/30d0e2a6
Branch: refs/heads/master
Commit: 30d0e2a6faa1c1205522758e5fd15f35ebc9fcbb
Parents: 7d6121b
Author: cstella <ce...@gmail.com>
Authored: Fri Jun 9 11:48:27 2017 -0400
Committer: cstella <ce...@gmail.com>
Committed: Fri Jun 9 11:48:27 2017 -0400
----------------------------------------------------------------------
.../profiler/client/window/WindowProcessor.java | 2 +-
metron-platform/metron-common/README.md | 1 +
.../metron/common/stellar/generated/Stellar.g4 | 16 +-
.../org/apache/metron/common/dsl/Token.java | 14 +
.../common/stellar/BaseStellarProcessor.java | 1 +
.../metron/common/stellar/FrameContext.java | 45 ++
.../metron/common/stellar/StellarCompiler.java | 287 +++++--
.../stellar/evaluators/ArithmeticEvaluator.java | 42 +-
...mparisonExpressionWithOperatorEvaluator.java | 9 +-
.../evaluators/DoubleLiteralEvaluator.java | 5 +-
.../evaluators/FloatLiteralEvaluator.java | 5 +-
.../stellar/evaluators/IntLiteralEvaluator.java | 5 +-
.../evaluators/LongLiteralEvaluator.java | 5 +-
.../stellar/evaluators/NumberEvaluator.java | 3 +-
.../evaluators/NumberLiteralEvaluator.java | 8 +-
.../stellar/generated/StellarBaseListener.java | 36 +
.../stellar/generated/StellarListener.java | 30 +
.../common/stellar/generated/StellarParser.java | 774 +++++++++++--------
.../dsl/functions/FunctionalFunctionsTest.java | 17 +
.../common/stellar/StellarInterpreterTest.java | 24 +-
.../metron/common/stellar/StellarTest.java | 101 ++-
.../evaluators/ArithmeticEvaluatorTest.java | 58 +-
...isonExpressionWithOperatorEvaluatorTest.java | 10 +-
.../evaluators/DoubleLiteralEvaluatorTest.java | 8 +-
.../evaluators/FloatLiteralEvaluatorTest.java | 8 +-
.../evaluators/IntLiteralEvaluatorTest.java | 8 +-
.../evaluators/LongLiteralEvaluatorTest.java | 8 +-
.../evaluators/NumberLiteralEvaluatorTest.java | 18 +-
28 files changed, 1029 insertions(+), 519 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/metron/blob/30d0e2a6/metron-analytics/metron-profiler-client/src/main/java/org/apache/metron/profiler/client/window/WindowProcessor.java
----------------------------------------------------------------------
diff --git a/metron-analytics/metron-profiler-client/src/main/java/org/apache/metron/profiler/client/window/WindowProcessor.java b/metron-analytics/metron-profiler-client/src/main/java/org/apache/metron/profiler/client/window/WindowProcessor.java
index 16a7513..1ae4aaf 100644
--- a/metron-analytics/metron-profiler-client/src/main/java/org/apache/metron/profiler/client/window/WindowProcessor.java
+++ b/metron-analytics/metron-profiler-client/src/main/java/org/apache/metron/profiler/client/window/WindowProcessor.java
@@ -89,7 +89,7 @@ public class WindowProcessor extends WindowBaseListener {
if(checkForException(ctx)) {
return;
}
- stack.push(new Token<>(ctx.getText().substring(1), String.class));
+ stack.push(new Token<>(ctx.getText().substring(1), String.class ));
}
/**
http://git-wip-us.apache.org/repos/asf/metron/blob/30d0e2a6/metron-platform/metron-common/README.md
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/README.md b/metron-platform/metron-common/README.md
index 9e1de7a..95f59ba 100644
--- a/metron-platform/metron-common/README.md
+++ b/metron-platform/metron-common/README.md
@@ -26,6 +26,7 @@ The query language supports the following:
* The literal `"\"foo\""` would represent `"foo"`
* The literal `'foo \\ bar'` would represent `foo \ bar`
* Simple boolean operations: `and`, `not`, `or`
+ * Boolean expressions are short-circuited (e.g. `true or FUNC()` would never execute `FUNC`)
* Simple arithmetic operations: `*`, `/`, `+`, `-` on real numbers or integers
* Simple comparison operations `<`, `>`, `<=`, `>=`
* Simple equality comparison operations `==`, `!=`
http://git-wip-us.apache.org/repos/asf/metron/blob/30d0e2a6/metron-platform/metron-common/src/main/antlr4/org/apache/metron/common/stellar/generated/Stellar.g4
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/antlr4/org/apache/metron/common/stellar/generated/Stellar.g4 b/metron-platform/metron-common/src/main/antlr4/org/apache/metron/common/stellar/generated/Stellar.g4
index 8602fde..3577377 100644
--- a/metron-platform/metron-common/src/main/antlr4/org/apache/metron/common/stellar/generated/Stellar.g4
+++ b/metron-platform/metron-common/src/main/antlr4/org/apache/metron/common/stellar/generated/Stellar.g4
@@ -139,9 +139,21 @@ transformation_expr:
| in_expr #InExpression
;
+if_expr:
+ logical_expr
+ ;
+
+then_expr:
+ transformation_expr
+ ;
+
+else_expr:
+ transformation_expr
+ ;
+
conditional_expr :
- logical_expr QUESTION transformation_expr COLON transformation_expr #TernaryFuncWithoutIf
- | IF logical_expr THEN transformation_expr ELSE transformation_expr #TernaryFuncWithIf
+ if_expr QUESTION then_expr COLON else_expr #TernaryFuncWithoutIf
+ | IF if_expr THEN then_expr ELSE else_expr #TernaryFuncWithIf
;
logical_expr:
http://git-wip-us.apache.org/repos/asf/metron/blob/30d0e2a6/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/Token.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/Token.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/Token.java
index 4c94be0..cf168a4 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/Token.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/Token.java
@@ -18,13 +18,27 @@
package org.apache.metron.common.dsl;
+import org.apache.metron.common.stellar.FrameContext;
+
public class Token<T> {
T value;
Class<T> underlyingType;
+ FrameContext.Context multiArgContext;
+
public Token(T value, Class<T> clazz) {
+ this(value, clazz, null);
+ }
+
+ public Token(T value, Class<T> clazz, FrameContext.Context multiArgContext) {
this.value = value;
this.underlyingType = clazz;
+ this.multiArgContext = multiArgContext;
}
+
+ public FrameContext.Context getMultiArgContext() {
+ return multiArgContext;
+ }
+
public T getValue() {
return value;
}
http://git-wip-us.apache.org/repos/asf/metron/blob/30d0e2a6/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/BaseStellarProcessor.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/BaseStellarProcessor.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/BaseStellarProcessor.java
index 8f4af93..5bf4a64 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/BaseStellarProcessor.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/BaseStellarProcessor.java
@@ -24,6 +24,7 @@ import com.google.common.cache.CacheLoader;
import com.google.common.util.concurrent.UncheckedExecutionException;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
+import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.TokenStream;
import java.util.HashSet;
http://git-wip-us.apache.org/repos/asf/metron/blob/30d0e2a6/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/FrameContext.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/FrameContext.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/FrameContext.java
new file mode 100644
index 0000000..16bc07a
--- /dev/null
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/FrameContext.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.metron.common.stellar;
+
+public enum FrameContext {
+ BOOLEAN_AND,
+ BOOLEAN_OR;
+
+ public static class Context {
+ private FrameContext variety;
+ public Context(FrameContext variety) {
+ this.variety = variety;
+ }
+
+ public FrameContext getVariety() {
+ return variety;
+ }
+
+ @Override
+ public String toString() {
+ return "Context{" +
+ "variety=" + variety +
+ '}';
+ }
+ }
+
+ public Context create() {
+ return new Context(this);
+ }
+}
http://git-wip-us.apache.org/repos/asf/metron/blob/30d0e2a6/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/StellarCompiler.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/StellarCompiler.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/StellarCompiler.java
index b289f48..136728d 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/StellarCompiler.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/StellarCompiler.java
@@ -48,6 +48,15 @@ public class StellarCompiler extends StellarBaseListener {
private final NumberLiteralEvaluator numberLiteralEvaluator;
private final ComparisonExpressionWithOperatorEvaluator comparisonExpressionWithOperatorEvaluator;
+ public interface ShortCircuitOp {}
+
+ public static class ShortCircuitFrame {}
+ public static class BooleanArg implements ShortCircuitOp {}
+ public static class IfExpr implements ShortCircuitOp {}
+ public static class ThenExpr implements ShortCircuitOp {}
+ public static class ElseExpr implements ShortCircuitOp {}
+ public static class EndConditional implements ShortCircuitOp {}
+
public static class ExpressionState {
Context context;
FunctionResolver functionResolver;
@@ -64,10 +73,18 @@ public class StellarCompiler extends StellarBaseListener {
public static class Expression implements Serializable {
final Deque<Token<?>> tokenDeque;
+ final Deque<FrameContext.Context> multiArgumentState;
final Set<String> variablesUsed;
public Expression(Deque<Token<?>> tokenDeque) {
this.tokenDeque = tokenDeque;
this.variablesUsed = new HashSet<>();
+ this.multiArgumentState = new ArrayDeque<>();
+ }
+
+ public void clear() {
+ tokenDeque.clear();
+ variablesUsed.clear();
+ multiArgumentState.clear();
}
public Deque<Token<?>> getTokenDeque() {
@@ -76,14 +93,77 @@ public class StellarCompiler extends StellarBaseListener {
public Object apply(ExpressionState state) {
Deque<Token<?>> instanceDeque = new ArrayDeque<>();
- for(Iterator<Token<?>> it = getTokenDeque().descendingIterator();it.hasNext();) {
- Token<?> token = it.next();
- if(token.getUnderlyingType() == DeferredFunction.class) {
- DeferredFunction func = (DeferredFunction) token.getValue();
- func.apply(instanceDeque, state);
- }
- else {
- instanceDeque.push(token);
+ {
+ boolean skipElse = false;
+ Token<?> token = null;
+ for (Iterator<Token<?>> it = getTokenDeque().descendingIterator(); it.hasNext(); ) {
+ token = it.next();
+ //if we've skipped an else previously, then we need to skip the deferred tokens associated with the else.
+ if(skipElse && token.getUnderlyingType() == ElseExpr.class) {
+ while(it.hasNext()) {
+ token = it.next();
+ if(token.getUnderlyingType() == EndConditional.class) {
+ break;
+ }
+ }
+ skipElse = false;
+ }
+ /*
+ curr is the current value on the stack. This is the non-deferred actual evaluation for this expression
+ and with the current context.
+ */
+ Token<?> curr = instanceDeque.peek();
+ if( curr != null
+ && curr.getValue() != null && curr.getValue() instanceof Boolean
+ && ShortCircuitOp.class.isAssignableFrom(token.getUnderlyingType())
+ ) {
+ //if we have a boolean as the current value and the next non-contextual token is a short circuit op
+ //then we need to short circuit possibly
+ if(token.getUnderlyingType() == BooleanArg.class) {
+ if (curr.getMultiArgContext() != null
+ && curr.getMultiArgContext().getVariety() == FrameContext.BOOLEAN_OR
+ && (Boolean) (curr.getValue())
+ ) {
+ //short circuit the or
+ FrameContext.Context context = curr.getMultiArgContext();
+ shortCircuit(it, context);
+ } else if (curr.getMultiArgContext() != null
+ && curr.getMultiArgContext().getVariety() == FrameContext.BOOLEAN_AND
+ && !(Boolean) (curr.getValue())
+ ) {
+ //short circuit the and
+ FrameContext.Context context = curr.getMultiArgContext();
+ shortCircuit(it, context);
+ }
+ }
+ else if(token.getUnderlyingType() == IfExpr.class) {
+ //short circuit the if/then/else
+ instanceDeque.pop();
+ if((Boolean)curr.getValue()) {
+ //choose then
+ skipElse = true;
+ }
+ else {
+ //choose else
+ while(it.hasNext()) {
+ Token<?> t = it.next();
+ if(t.getUnderlyingType() == ElseExpr.class) {
+ break;
+ }
+ }
+ }
+ }
+ }
+ if (token.getUnderlyingType() == DeferredFunction.class) {
+ DeferredFunction func = (DeferredFunction) token.getValue();
+ func.apply(instanceDeque, state);
+ }
+ else if(token.getUnderlyingType() != ShortCircuitFrame.class
+ && !ShortCircuitOp.class.isAssignableFrom(token.getUnderlyingType())
+ ) {
+ instanceDeque.push(token);
+ }
+
}
}
@@ -100,6 +180,15 @@ public class StellarCompiler extends StellarBaseListener {
throw new ParseException("Invalid parse, found " + token);
}
}
+
+ public void shortCircuit(Iterator<Token<?>> it, FrameContext.Context context) {
+ while (it.hasNext()) {
+ Token<?> token = it.next();
+ if (token.getUnderlyingType() == ShortCircuitFrame.class && token.getMultiArgContext() == context) {
+ break;
+ }
+ }
+ }
}
interface DeferredFunction {
@@ -130,7 +219,7 @@ public class StellarCompiler extends StellarBaseListener {
@Override
public void enterTransformation(StellarParser.TransformationContext ctx) {
- expression.tokenDeque.clear();
+ expression.clear();
}
private boolean handleIn(final Token<?> left, final Token<?> right) {
@@ -162,39 +251,43 @@ public class StellarCompiler extends StellarBaseListener {
@Override
public void exitNullConst(StellarParser.NullConstContext ctx) {
- expression.tokenDeque.push(new Token<>(null, Object.class));
+ expression.tokenDeque.push(new Token<>(null, Object.class, getArgContext()));
}
@Override
public void exitArithExpr_plus(StellarParser.ArithExpr_plusContext ctx) {
+ final FrameContext.Context context = getArgContext();
expression.tokenDeque.push(new Token<>((tokenDeque, state) -> {
Pair<Token<? extends Number>, Token<? extends Number>> p = getArithExpressionPair(tokenDeque);
- tokenDeque.push(arithmeticEvaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.addition(), p));
- }, DeferredFunction.class));
+ tokenDeque.push(arithmeticEvaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.addition(context), p));
+ }, DeferredFunction.class, context));
}
@Override
public void exitArithExpr_minus(StellarParser.ArithExpr_minusContext ctx) {
+ final FrameContext.Context context = getArgContext();
expression.tokenDeque.push(new Token<>( (tokenDeque, state) -> {
Pair<Token<? extends Number>, Token<? extends Number>> p = getArithExpressionPair(tokenDeque);
- tokenDeque.push(arithmeticEvaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.subtraction(), p));
- }, DeferredFunction.class));
+ tokenDeque.push(arithmeticEvaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.subtraction(context), p));
+ }, DeferredFunction.class, context));
}
@Override
public void exitArithExpr_div(StellarParser.ArithExpr_divContext ctx) {
+ final FrameContext.Context context = getArgContext();
expression.tokenDeque.push(new Token<>( (tokenDeque, state) -> {
Pair<Token<? extends Number>, Token<? extends Number>> p = getArithExpressionPair(tokenDeque);
- tokenDeque.push(arithmeticEvaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.division(), p));
- }, DeferredFunction.class));
+ tokenDeque.push(arithmeticEvaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.division(context), p));
+ }, DeferredFunction.class, context));
}
@Override
public void exitArithExpr_mul(StellarParser.ArithExpr_mulContext ctx) {
+ final FrameContext.Context context = getArgContext();
expression.tokenDeque.push(new Token<>( (tokenDeque, state) -> {
Pair<Token<? extends Number>, Token<? extends Number>> p = getArithExpressionPair(tokenDeque);
- tokenDeque.push(arithmeticEvaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.multiplication(), p));
- }, DeferredFunction.class));
+ tokenDeque.push(arithmeticEvaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.multiplication(context), p));
+ }, DeferredFunction.class, context));
}
@SuppressWarnings("unchecked")
@@ -204,61 +297,62 @@ public class StellarCompiler extends StellarBaseListener {
return Pair.of(left, right);
}
- private void handleConditional() {
- expression.tokenDeque.push(new Token<>( (tokenDeque, state) -> {
- Token<?> elseExpr = popDeque(tokenDeque);
- Token<?> thenExpr = popDeque(tokenDeque);
- Token<?> ifExpr = popDeque(tokenDeque);
- @SuppressWarnings("unchecked") boolean b = ((Token<Boolean>) ifExpr).getValue();
- if (b) {
- tokenDeque.push(thenExpr);
- } else {
- tokenDeque.push(elseExpr);
- }
- }, DeferredFunction.class));
+ @Override
+ public void exitIf_expr(StellarParser.If_exprContext ctx) {
+ expression.tokenDeque.push(new Token<>(new IfExpr(), IfExpr.class, getArgContext()));
}
@Override
- public void exitTernaryFuncWithoutIf(StellarParser.TernaryFuncWithoutIfContext ctx) {
- handleConditional();
+ public void enterThen_expr(StellarParser.Then_exprContext ctx) {
+ expression.tokenDeque.push(new Token<>(new ThenExpr(), ThenExpr.class, getArgContext()));
}
@Override
- public void exitTernaryFuncWithIf(StellarParser.TernaryFuncWithIfContext ctx) {
- handleConditional();
+ public void enterElse_expr(StellarParser.Else_exprContext ctx) {
+ expression.tokenDeque.push(new Token<>(new ElseExpr(), ElseExpr.class, getArgContext()));
+ }
+
+ @Override
+ public void exitElse_expr(StellarParser.Else_exprContext ctx) {
+ expression.tokenDeque.push(new Token<>(new EndConditional(), EndConditional.class, getArgContext()));
}
@Override
public void exitInExpressionStatement(StellarParser.InExpressionStatementContext ctx) {
+ final FrameContext.Context context = getArgContext();
expression.tokenDeque.push(new Token<>( (tokenDeque, state) -> {
Token<?> left = popDeque(tokenDeque);
Token<?> right = popDeque(tokenDeque);
- tokenDeque.push(new Token<>(handleIn(left, right), Boolean.class));
- }, DeferredFunction.class));
+ tokenDeque.push(new Token<>(handleIn(left, right), Boolean.class, context));
+ }, DeferredFunction.class, context));
}
+
@Override
public void exitNInExpressionStatement(StellarParser.NInExpressionStatementContext ctx) {
+ final FrameContext.Context context = getArgContext();
expression.tokenDeque.push(new Token<>( (tokenDeque, state) -> {
Token<?> left = popDeque(tokenDeque);
Token<?> right = popDeque(tokenDeque);
- tokenDeque.push(new Token<>(!handleIn(left, right), Boolean.class));
- }, DeferredFunction.class));
+ tokenDeque.push(new Token<>(!handleIn(left, right), Boolean.class, context));
+ }, DeferredFunction.class, context));
}
@Override
public void exitNotFunc(StellarParser.NotFuncContext ctx) {
+ final FrameContext.Context context = getArgContext();
expression.tokenDeque.push(new Token<>( (tokenDeque, state) -> {
Token<Boolean> arg = (Token<Boolean>) popDeque(tokenDeque);
- tokenDeque.push(new Token<>(!arg.getValue(), Boolean.class));
- }, DeferredFunction.class));
+ tokenDeque.push(new Token<>(!arg.getValue(), Boolean.class, context));
+ }, DeferredFunction.class, context));
}
@Override
public void exitVariable(StellarParser.VariableContext ctx) {
+ final FrameContext.Context context = getArgContext();
expression.tokenDeque.push(new Token<>( (tokenDeque, state) -> {
- tokenDeque.push(new Token<>(state.variableResolver.resolve(ctx.getText()), Object.class));
- }, DeferredFunction.class));
+ tokenDeque.push(new Token<>(state.variableResolver.resolve(ctx.getText()), Object.class, context));
+ }, DeferredFunction.class, context));
expression.variablesUsed.add(ctx.getText());
}
@@ -266,46 +360,77 @@ public class StellarCompiler extends StellarBaseListener {
public void exitStringLiteral(StellarParser.StringLiteralContext ctx) {
String rawToken = ctx.getText();
String literal = StringEscapeUtils.UNESCAPE_JSON.translate(rawToken);
- expression.tokenDeque.push(new Token<>(literal.substring(1, literal.length()-1), String.class));
+ expression.tokenDeque.push(new Token<>(literal.substring(1, literal.length()-1), String.class, getArgContext()));
}
@Override
public void exitIntLiteral(StellarParser.IntLiteralContext ctx) {
- expression.tokenDeque.push(numberLiteralEvaluator.evaluate(ctx));
+ expression.tokenDeque.push(numberLiteralEvaluator.evaluate(ctx, getArgContext()));
}
@Override
public void exitDoubleLiteral(StellarParser.DoubleLiteralContext ctx) {
- expression.tokenDeque.push(numberLiteralEvaluator.evaluate(ctx));
+ expression.tokenDeque.push(numberLiteralEvaluator.evaluate(ctx, getArgContext()));
}
@Override
public void exitFloatLiteral(StellarParser.FloatLiteralContext ctx) {
- expression.tokenDeque.push(numberLiteralEvaluator.evaluate(ctx));
+ expression.tokenDeque.push(numberLiteralEvaluator.evaluate(ctx, getArgContext()));
}
@Override
public void exitLongLiteral(StellarParser.LongLiteralContext ctx) {
- expression.tokenDeque.push(numberLiteralEvaluator.evaluate(ctx));
+ expression.tokenDeque.push(numberLiteralEvaluator.evaluate(ctx, getArgContext()));
+ }
+
+ @Override
+ public void enterB_expr(StellarParser.B_exprContext ctx) {
+ //Enter is not guaranteed to be called by Antlr for logical labels, so we need to
+ //emulate it like this. See https://github.com/antlr/antlr4/issues/802
+ if(ctx.getParent() instanceof StellarParser.LogicalExpressionOrContext) {
+ expression.multiArgumentState.push(FrameContext.BOOLEAN_OR.create());
+ }
+ else if(ctx.getParent() instanceof StellarParser.LogicalExpressionAndContext) {
+ expression.multiArgumentState.push(FrameContext.BOOLEAN_AND.create());
+ }
+ }
+
+ @Override
+ public void exitB_expr(StellarParser.B_exprContext ctx) {
+ if(ctx.getParent() instanceof StellarParser.LogicalExpressionOrContext
+ || ctx.getParent() instanceof StellarParser.LogicalExpressionAndContext
+ )
+ {
+ //we want to know when the argument to the boolean expression is complete
+ expression.tokenDeque.push(new Token<>(new BooleanArg(), BooleanArg.class, getArgContext()));
+ }
}
@Override
public void exitLogicalExpressionAnd(StellarParser.LogicalExpressionAndContext ctx) {
+ final FrameContext.Context context = getArgContext();
+ popArgContext();
+ final FrameContext.Context parentContext = getArgContext();
expression.tokenDeque.push(new Token<>( (tokenDeque, state) -> {
Token<?> left = popDeque(tokenDeque);
Token<?> right = popDeque(tokenDeque);
- tokenDeque.push(new Token<>(booleanOp(left, right, (l, r) -> l && r, "&&"), Boolean.class));
- }, DeferredFunction.class));
+ tokenDeque.push(new Token<>(booleanOp(left, right, (l, r) -> l && r, "&&"), Boolean.class, parentContext));
+ }, DeferredFunction.class, context));
+ expression.tokenDeque.push(new Token<>(new ShortCircuitFrame(), ShortCircuitFrame.class, context));
}
@Override
public void exitLogicalExpressionOr(StellarParser.LogicalExpressionOrContext ctx) {
+ final FrameContext.Context context = getArgContext();
+ popArgContext();
+ final FrameContext.Context parentContext = getArgContext();
expression.tokenDeque.push(new Token<>( (tokenDeque, state) -> {
Token<?> left = popDeque(tokenDeque);
Token<?> right = popDeque(tokenDeque);
- tokenDeque.push(new Token<>(booleanOp(left, right, (l, r) -> l || r, "||"), Boolean.class));
- }, DeferredFunction.class));
+ tokenDeque.push(new Token<>(booleanOp(left, right, (l, r) -> l || r, "||"), Boolean.class, parentContext));
+ }, DeferredFunction.class, context));
+ expression.tokenDeque.push(new Token<>(new ShortCircuitFrame(), ShortCircuitFrame.class, context));
}
@Override
@@ -321,7 +446,7 @@ public class StellarCompiler extends StellarBaseListener {
default:
throw new ParseException("Unable to process " + ctx.getText() + " as a boolean constant");
}
- expression.tokenDeque.push(new Token<>(b, Boolean.class));
+ expression.tokenDeque.push(new Token<>(b, Boolean.class, getArgContext()));
}
private boolean booleanOp(final Token<?> left, final Token<?> right, final BooleanOp op, final String opName) {
@@ -356,7 +481,7 @@ public class StellarCompiler extends StellarBaseListener {
@Override
public void exitLambda_variable(StellarParser.Lambda_variableContext ctx) {
- expression.tokenDeque.push(new Token<>(ctx.getText(), String.class));
+ expression.tokenDeque.push(new Token<>(ctx.getText(), String.class, getArgContext()));
}
private void enterLambdaVariables() {
@@ -369,7 +494,7 @@ public class StellarCompiler extends StellarBaseListener {
for(; !expression.tokenDeque.isEmpty() && t != LAMBDA_VARIABLES; t = expression.tokenDeque.pop()) {
variables.addFirst(t.getValue().toString());
}
- expression.tokenDeque.push(new Token<>(variables, List.class));
+ expression.tokenDeque.push(new Token<>(variables, List.class, getArgContext()));
}
private void enterLambda() {
@@ -377,6 +502,7 @@ public class StellarCompiler extends StellarBaseListener {
}
private void exitLambda(boolean hasArgs) {
+ final FrameContext.Context context = getArgContext();
Token<?> t = expression.tokenDeque.pop();
final Deque<Token<?>> instanceDeque = new ArrayDeque<>();
for(; !expression.tokenDeque.isEmpty() && t != EXPRESSION_REFERENCE; t = expression.tokenDeque.pop()) {
@@ -385,8 +511,8 @@ public class StellarCompiler extends StellarBaseListener {
final List<String> variables = hasArgs? (List<String>) instanceDeque.removeLast().getValue() :new ArrayList<>();
expression.tokenDeque.push(new Token<>( (tokenDeque, state) -> {
LambdaExpression expr = new LambdaExpression(variables, instanceDeque, state);
- tokenDeque.push(new Token<>(expr, Object.class));
- }, DeferredFunction.class) );
+ tokenDeque.push(new Token<>(expr, Object.class, context));
+ }, DeferredFunction.class, context) );
}
@Override
@@ -411,7 +537,7 @@ public class StellarCompiler extends StellarBaseListener {
@Override
public void exitTransformationFunc(StellarParser.TransformationFuncContext ctx) {
-
+ final FrameContext.Context context = getArgContext();
expression.tokenDeque.push(new Token<>( (tokenDeque, state) -> {
// resolve and initialize the function
String functionName = ctx.getChild(0).getText();
@@ -421,8 +547,8 @@ public class StellarCompiler extends StellarBaseListener {
// fetch the args, execute, and push result onto the stack
List<Object> args = getFunctionArguments(popDeque(tokenDeque));
Object result = function.apply(args, state.context);
- tokenDeque.push(new Token<>(result, Object.class));
- }, DeferredFunction.class));
+ tokenDeque.push(new Token<>(result, Object.class, context));
+ }, DeferredFunction.class, context));
}
/**
@@ -474,22 +600,24 @@ public class StellarCompiler extends StellarBaseListener {
@Override
public void exitExistsFunc(StellarParser.ExistsFuncContext ctx) {
+ final FrameContext.Context context = getArgContext();
expression.tokenDeque.push(new Token<>( (tokenDeque, state) -> {
String variable = ctx.getChild(2).getText();
boolean exists = state.variableResolver.resolve(variable) != null;
- tokenDeque.push(new Token<>(exists, Boolean.class));
- }, DeferredFunction.class));
+ tokenDeque.push(new Token<>(exists, Boolean.class, context));
+ }, DeferredFunction.class, context));
String variable = ctx.getChild(2).getText();
expression.variablesUsed.add(variable);
}
@Override
public void enterFunc_args(StellarParser.Func_argsContext ctx) {
- expression.tokenDeque.push(new Token<>(new FunctionMarker(), FunctionMarker.class));
+ expression.tokenDeque.push(new Token<>(new FunctionMarker(), FunctionMarker.class, getArgContext()));
}
@Override
public void exitFunc_args(StellarParser.Func_argsContext ctx) {
+ final FrameContext.Context context = getArgContext();
expression.tokenDeque.push(new Token<>((tokenDeque, state) -> {
LinkedList<Object> args = new LinkedList<>();
while (true) {
@@ -500,17 +628,18 @@ public class StellarCompiler extends StellarBaseListener {
args.addFirst(token.getValue());
}
}
- tokenDeque.push(new Token<>(args, List.class));
- }, DeferredFunction.class));
+ tokenDeque.push(new Token<>(args, List.class, context));
+ }, DeferredFunction.class, context));
}
@Override
public void enterMap_entity(StellarParser.Map_entityContext ctx) {
- expression.tokenDeque.push(new Token<>(new FunctionMarker(), FunctionMarker.class));
+ expression.tokenDeque.push(new Token<>(new FunctionMarker(), FunctionMarker.class, getArgContext()));
}
@Override
public void exitMap_entity(StellarParser.Map_entityContext ctx) {
+ final FrameContext.Context context = getArgContext();
expression.tokenDeque.push(new Token<>( (tokenDeque, state) -> {
HashMap<String, Object> args = new HashMap<>();
Object value = null;
@@ -526,12 +655,13 @@ public class StellarCompiler extends StellarBaseListener {
}
}
}
- tokenDeque.push(new Token<>(args, Map.class));
- }, DeferredFunction.class));
+ tokenDeque.push(new Token<>(args, Map.class, context));
+ }, DeferredFunction.class, context));
}
@Override
public void exitList_entity(StellarParser.List_entityContext ctx) {
+ final FrameContext.Context context = getArgContext();
expression.tokenDeque.push(new Token<>( (tokenDeque, state) -> {
LinkedList<Object> args = new LinkedList<>();
while (true) {
@@ -542,24 +672,37 @@ public class StellarCompiler extends StellarBaseListener {
args.addFirst(token.getValue());
}
}
- tokenDeque.push(new Token<>(args, List.class));
- }, DeferredFunction.class));
+ tokenDeque.push(new Token<>(args, List.class, context));
+ }, DeferredFunction.class, context));
}
+
+
@Override
public void exitComparisonExpressionWithOperator(StellarParser.ComparisonExpressionWithOperatorContext ctx) {
+ final FrameContext.Context context = getArgContext();
expression.tokenDeque.push(new Token<>( (tokenDeque, state) -> {
StellarParser.Comp_operatorContext op = ctx.comp_operator();
Token<?> right = popDeque(tokenDeque);
Token<?> left = popDeque(tokenDeque);
- tokenDeque.push(comparisonExpressionWithOperatorEvaluator.evaluate(left, right, (StellarParser.ComparisonOpContext) op));
- }, DeferredFunction.class));
+ tokenDeque.push(comparisonExpressionWithOperatorEvaluator.evaluate(left, right, (StellarParser.ComparisonOpContext) op, context));
+ }, DeferredFunction.class, context));
}
@Override
public void enterList_entity(StellarParser.List_entityContext ctx) {
- expression.tokenDeque.push(new Token<>(new FunctionMarker(), FunctionMarker.class));
+ expression.tokenDeque.push(new Token<>(new FunctionMarker(), FunctionMarker.class, getArgContext()));
+ }
+
+ private void popArgContext() {
+ if(!expression.multiArgumentState.isEmpty()) {
+ expression.multiArgumentState.pop();
+ }
+ }
+
+ private FrameContext.Context getArgContext() {
+ return expression.multiArgumentState.isEmpty()?null:expression.multiArgumentState.peek();
}
private Token<?> popDeque(Deque<Token<?>> tokenDeque) {
http://git-wip-us.apache.org/repos/asf/metron/blob/30d0e2a6/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/ArithmeticEvaluator.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/ArithmeticEvaluator.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/ArithmeticEvaluator.java
index f1264e2..b458f9c 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/ArithmeticEvaluator.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/ArithmeticEvaluator.java
@@ -19,8 +19,8 @@
package org.apache.metron.common.stellar.evaluators;
import org.apache.commons.lang3.tuple.Pair;
-import org.apache.metron.common.dsl.ParseException;
import org.apache.metron.common.dsl.Token;
+import org.apache.metron.common.stellar.FrameContext;
import java.util.function.BiFunction;
@@ -44,58 +44,58 @@ public enum ArithmeticEvaluator {
* types is taken for the Java spec: http://docs.oracle.com/javase/specs/jls/se8/html/jls-5.html#jls-5.6.2
*/
public static final class ArithmeticEvaluatorFunctions {
- public static BiFunction<Number, Number, Token<? extends Number>> addition() {
+ public static BiFunction<Number, Number, Token<? extends Number>> addition(final FrameContext.Context context) {
return (Number l, Number r) -> {
if (l instanceof Double || r instanceof Double) {
- return new Token<>(l.doubleValue() + r.doubleValue(), Double.class);
+ return new Token<>(l.doubleValue() + r.doubleValue(), Double.class, context);
} else if (l instanceof Float || r instanceof Float) {
- return new Token<>(l.floatValue() + r.floatValue(), Float.class);
+ return new Token<>(l.floatValue() + r.floatValue(), Float.class, context);
} else if (l instanceof Long || r instanceof Long) {
- return new Token<>(l.longValue() + r.longValue(), Long.class);
+ return new Token<>(l.longValue() + r.longValue(), Long.class, context);
} else {
- return new Token<>(l.intValue() + r.intValue(), Integer.class);
+ return new Token<>(l.intValue() + r.intValue(), Integer.class, context);
}
};
}
- public static BiFunction<Number, Number, Token<? extends Number>> multiplication() {
+ public static BiFunction<Number, Number, Token<? extends Number>> multiplication(final FrameContext.Context context) {
return (Number l, Number r) -> {
if (l instanceof Double || r instanceof Double) {
- return new Token<>(l.doubleValue() * r.doubleValue(), Double.class);
+ return new Token<>(l.doubleValue() * r.doubleValue(), Double.class, context);
} else if (l instanceof Float || r instanceof Float) {
- return new Token<>(l.floatValue() * r.floatValue(), Float.class);
+ return new Token<>(l.floatValue() * r.floatValue(), Float.class, context);
} else if (l instanceof Long || r instanceof Long) {
- return new Token<>(l.longValue() * r.longValue(), Long.class);
+ return new Token<>(l.longValue() * r.longValue(), Long.class, context);
} else {
- return new Token<>(l.intValue() * r.intValue(), Integer.class);
+ return new Token<>(l.intValue() * r.intValue(), Integer.class, context);
}
};
}
- public static BiFunction<Number, Number, Token<? extends Number>> subtraction() {
+ public static BiFunction<Number, Number, Token<? extends Number>> subtraction(final FrameContext.Context context) {
return (Number l, Number r) -> {
if (l instanceof Double || r instanceof Double) {
- return new Token<>(l.doubleValue() - r.doubleValue(), Double.class);
+ return new Token<>(l.doubleValue() - r.doubleValue(), Double.class, context);
} else if (l instanceof Float || r instanceof Float) {
- return new Token<>(l.floatValue() - r.floatValue(), Float.class);
+ return new Token<>(l.floatValue() - r.floatValue(), Float.class, context);
} else if (l instanceof Long || r instanceof Long) {
- return new Token<>(l.longValue() - r.longValue(), Long.class);
+ return new Token<>(l.longValue() - r.longValue(), Long.class, context);
} else {
- return new Token<>(l.intValue() - r.intValue(), Integer.class);
+ return new Token<>(l.intValue() - r.intValue(), Integer.class, context);
}
};
}
- public static BiFunction<Number, Number, Token<? extends Number>> division() {
+ public static BiFunction<Number, Number, Token<? extends Number>> division(FrameContext.Context context) {
return (Number l, Number r) -> {
if (l instanceof Double || r instanceof Double) {
- return new Token<>(l.doubleValue() / r.doubleValue(), Double.class);
+ return new Token<>(l.doubleValue() / r.doubleValue(), Double.class, context);
} else if (l instanceof Float || r instanceof Float) {
- return new Token<>(l.floatValue() / r.floatValue(), Float.class);
+ return new Token<>(l.floatValue() / r.floatValue(), Float.class, context);
} else if (l instanceof Long || r instanceof Long) {
- return new Token<>(l.longValue() / r.longValue(), Long.class);
+ return new Token<>(l.longValue() / r.longValue(), Long.class, context);
} else {
- return new Token<>(l.intValue() / r.intValue(), Integer.class);
+ return new Token<>(l.intValue() / r.intValue(), Integer.class, context);
}
};
}
http://git-wip-us.apache.org/repos/asf/metron/blob/30d0e2a6/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/ComparisonExpressionWithOperatorEvaluator.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/ComparisonExpressionWithOperatorEvaluator.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/ComparisonExpressionWithOperatorEvaluator.java
index 4862684..e213eb5 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/ComparisonExpressionWithOperatorEvaluator.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/ComparisonExpressionWithOperatorEvaluator.java
@@ -20,6 +20,7 @@ package org.apache.metron.common.stellar.evaluators;
import org.apache.metron.common.dsl.ParseException;
import org.apache.metron.common.dsl.Token;
+import org.apache.metron.common.stellar.FrameContext;
import org.apache.metron.common.stellar.generated.StellarParser;
/**
@@ -81,13 +82,13 @@ public enum ComparisonExpressionWithOperatorEvaluator {
* @param op The operator in the Stellar expression.
* @return A token with type boolean. This is based on the comparison of the {@code right} and {@code left} values.
*/
- public Token<Boolean> evaluate(final Token<?> left, final Token<?> right, final StellarParser.ComparisonOpContext op) {
+ public Token<Boolean> evaluate(final Token<?> left, final Token<?> right, final StellarParser.ComparisonOpContext op, FrameContext.Context context) {
if (op.EQ() != null) {
- return new Token<>(Strategy.EQUALITY_OPERATORS.evaluator().evaluate(left, right, op), Boolean.class);
+ return new Token<>(Strategy.EQUALITY_OPERATORS.evaluator().evaluate(left, right, op), Boolean.class, context);
} else if (op.NEQ() != null) {
- return new Token<>(!Strategy.EQUALITY_OPERATORS.evaluator().evaluate(left, right, op), Boolean.class);
+ return new Token<>(!Strategy.EQUALITY_OPERATORS.evaluator().evaluate(left, right, op), Boolean.class, context);
} else if (op.LT() != null || op.GT() != null || op.LTE() != null || op.GTE() != null) {
- return new Token<>(Strategy.COMPARISON_OPERATORS.evaluator().evaluate(left, right, op), Boolean.class);
+ return new Token<>(Strategy.COMPARISON_OPERATORS.evaluator().evaluate(left, right, op), Boolean.class, context);
}
throw new ParseException("Unsupported operations. The following expression is invalid: " + left.getValue() + op.getText() + right.getValue());
http://git-wip-us.apache.org/repos/asf/metron/blob/30d0e2a6/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/DoubleLiteralEvaluator.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/DoubleLiteralEvaluator.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/DoubleLiteralEvaluator.java
index 1bd1a49..653b56c 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/DoubleLiteralEvaluator.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/DoubleLiteralEvaluator.java
@@ -19,15 +19,16 @@
package org.apache.metron.common.stellar.evaluators;
import org.apache.metron.common.dsl.Token;
+import org.apache.metron.common.stellar.FrameContext;
import org.apache.metron.common.stellar.generated.StellarParser;
public class DoubleLiteralEvaluator implements NumberEvaluator<StellarParser.DoubleLiteralContext> {
@Override
- public Token<Double> evaluate(StellarParser.DoubleLiteralContext context) {
+ public Token<Double> evaluate(StellarParser.DoubleLiteralContext context, FrameContext.Context contextVariety) {
if (context == null) {
throw new IllegalArgumentException("Cannot evaluate a context that is null.");
}
- return new Token<>(Double.parseDouble(context.getText()), Double.class);
+ return new Token<>(Double.parseDouble(context.getText()), Double.class, contextVariety);
}
}
http://git-wip-us.apache.org/repos/asf/metron/blob/30d0e2a6/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/FloatLiteralEvaluator.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/FloatLiteralEvaluator.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/FloatLiteralEvaluator.java
index 60b312b..4489d30 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/FloatLiteralEvaluator.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/FloatLiteralEvaluator.java
@@ -19,15 +19,16 @@
package org.apache.metron.common.stellar.evaluators;
import org.apache.metron.common.dsl.Token;
+import org.apache.metron.common.stellar.FrameContext;
import org.apache.metron.common.stellar.generated.StellarParser;
public class FloatLiteralEvaluator implements NumberEvaluator<StellarParser.FloatLiteralContext> {
@Override
- public Token<Float> evaluate(StellarParser.FloatLiteralContext context) {
+ public Token<Float> evaluate(StellarParser.FloatLiteralContext context, FrameContext.Context contextVariety) {
if (context == null) {
throw new IllegalArgumentException("Cannot evaluate a context that is null.");
}
- return new Token<>(Float.parseFloat(context.getText()), Float.class);
+ return new Token<>(Float.parseFloat(context.getText()), Float.class, contextVariety);
}
}
http://git-wip-us.apache.org/repos/asf/metron/blob/30d0e2a6/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/IntLiteralEvaluator.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/IntLiteralEvaluator.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/IntLiteralEvaluator.java
index c928a9a..00e62e6 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/IntLiteralEvaluator.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/IntLiteralEvaluator.java
@@ -19,15 +19,16 @@
package org.apache.metron.common.stellar.evaluators;
import org.apache.metron.common.dsl.Token;
+import org.apache.metron.common.stellar.FrameContext;
import org.apache.metron.common.stellar.generated.StellarParser;
public class IntLiteralEvaluator implements NumberEvaluator<StellarParser.IntLiteralContext> {
@Override
- public Token<Integer> evaluate(StellarParser.IntLiteralContext context) {
+ public Token<Integer> evaluate(StellarParser.IntLiteralContext context, FrameContext.Context contextVariety) {
if (context == null) {
throw new IllegalArgumentException("Cannot evaluate a context that is null.");
}
- return new Token<>(Integer.parseInt(context.getText()), Integer.class);
+ return new Token<>(Integer.parseInt(context.getText()), Integer.class, contextVariety);
}
}
http://git-wip-us.apache.org/repos/asf/metron/blob/30d0e2a6/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/LongLiteralEvaluator.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/LongLiteralEvaluator.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/LongLiteralEvaluator.java
index 05ee162..338adc4 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/LongLiteralEvaluator.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/LongLiteralEvaluator.java
@@ -20,11 +20,12 @@ package org.apache.metron.common.stellar.evaluators;
import org.apache.metron.common.dsl.ParseException;
import org.apache.metron.common.dsl.Token;
+import org.apache.metron.common.stellar.FrameContext;
import org.apache.metron.common.stellar.generated.StellarParser;
public class LongLiteralEvaluator implements NumberEvaluator<StellarParser.LongLiteralContext> {
@Override
- public Token<Long> evaluate(StellarParser.LongLiteralContext context) {
+ public Token<Long> evaluate(StellarParser.LongLiteralContext context, FrameContext.Context contextVariety) {
if (context == null) {
throw new IllegalArgumentException("Cannot evaluate a context that is null.");
}
@@ -32,7 +33,7 @@ public class LongLiteralEvaluator implements NumberEvaluator<StellarParser.LongL
String value = context.getText();
if (value.endsWith("l") || value.endsWith("L")) {
value = value.substring(0, value.length() - 1); // Drop the 'L' or 'l'. Long.parseLong does not accept a string with either of these.
- return new Token<>(Long.parseLong(value), Long.class);
+ return new Token<>(Long.parseLong(value), Long.class, contextVariety);
} else {
// Technically this should never happen, but just being safe.
throw new ParseException("Invalid format for long. Failed trying to parse a long with the following value: " + value);
http://git-wip-us.apache.org/repos/asf/metron/blob/30d0e2a6/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/NumberEvaluator.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/NumberEvaluator.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/NumberEvaluator.java
index 0007b72..2c18f9d 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/NumberEvaluator.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/NumberEvaluator.java
@@ -19,8 +19,9 @@
package org.apache.metron.common.stellar.evaluators;
import org.apache.metron.common.dsl.Token;
+import org.apache.metron.common.stellar.FrameContext;
import org.apache.metron.common.stellar.generated.StellarParser;
public interface NumberEvaluator<T extends StellarParser.Arithmetic_operandsContext> {
- Token<? extends Number> evaluate(T context);
+ Token<? extends Number> evaluate(T context, FrameContext.Context contextVariety);
}
http://git-wip-us.apache.org/repos/asf/metron/blob/30d0e2a6/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/NumberLiteralEvaluator.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/NumberLiteralEvaluator.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/NumberLiteralEvaluator.java
index 83d795f..0ec3859 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/NumberLiteralEvaluator.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/NumberLiteralEvaluator.java
@@ -20,6 +20,7 @@ package org.apache.metron.common.stellar.evaluators;
import org.apache.metron.common.dsl.ParseException;
import org.apache.metron.common.dsl.Token;
+import org.apache.metron.common.stellar.FrameContext;
import org.apache.metron.common.stellar.generated.StellarParser;
import java.util.HashMap;
@@ -53,17 +54,18 @@ public enum NumberLiteralEvaluator {
Token<? extends Number> evaluate(StellarParser.Arithmetic_operandsContext context
, Map<Class<? extends StellarParser.Arithmetic_operandsContext>, NumberEvaluator> instanceMap
+ , FrameContext.Context contextVariety
)
{
NumberEvaluator evaluator = instanceMap.get(context.getClass());
if(evaluator == null) {
throw new ParseException("Does not support evaluation for type " + context.getClass());
}
- return evaluator.evaluate(context);
+ return evaluator.evaluate(context, contextVariety);
}
- public Token<? extends Number> evaluate(StellarParser.Arithmetic_operandsContext context) {
- return evaluate(context, Strategy.strategyMap);
+ public Token<? extends Number> evaluate(StellarParser.Arithmetic_operandsContext context, FrameContext.Context contextVariety) {
+ return evaluate(context, Strategy.strategyMap, contextVariety);
}
}
http://git-wip-us.apache.org/repos/asf/metron/blob/30d0e2a6/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/generated/StellarBaseListener.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/generated/StellarBaseListener.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/generated/StellarBaseListener.java
index 2be710b..3ca1daa 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/generated/StellarBaseListener.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/generated/StellarBaseListener.java
@@ -133,6 +133,42 @@ public class StellarBaseListener implements StellarListener {
*
* <p>The default implementation does nothing.</p>
*/
+ @Override public void enterIf_expr(StellarParser.If_exprContext ctx) { }
+ /**
+ * {@inheritDoc}
+ *
+ * <p>The default implementation does nothing.</p>
+ */
+ @Override public void exitIf_expr(StellarParser.If_exprContext ctx) { }
+ /**
+ * {@inheritDoc}
+ *
+ * <p>The default implementation does nothing.</p>
+ */
+ @Override public void enterThen_expr(StellarParser.Then_exprContext ctx) { }
+ /**
+ * {@inheritDoc}
+ *
+ * <p>The default implementation does nothing.</p>
+ */
+ @Override public void exitThen_expr(StellarParser.Then_exprContext ctx) { }
+ /**
+ * {@inheritDoc}
+ *
+ * <p>The default implementation does nothing.</p>
+ */
+ @Override public void enterElse_expr(StellarParser.Else_exprContext ctx) { }
+ /**
+ * {@inheritDoc}
+ *
+ * <p>The default implementation does nothing.</p>
+ */
+ @Override public void exitElse_expr(StellarParser.Else_exprContext ctx) { }
+ /**
+ * {@inheritDoc}
+ *
+ * <p>The default implementation does nothing.</p>
+ */
@Override public void enterTernaryFuncWithoutIf(StellarParser.TernaryFuncWithoutIfContext ctx) { }
/**
* {@inheritDoc}
http://git-wip-us.apache.org/repos/asf/metron/blob/30d0e2a6/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/generated/StellarListener.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/generated/StellarListener.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/generated/StellarListener.java
index 66493f7..6c00691 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/generated/StellarListener.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/generated/StellarListener.java
@@ -123,6 +123,36 @@ public interface StellarListener extends ParseTreeListener {
*/
void exitInExpression(StellarParser.InExpressionContext ctx);
/**
+ * Enter a parse tree produced by {@link StellarParser#if_expr}.
+ * @param ctx the parse tree
+ */
+ void enterIf_expr(StellarParser.If_exprContext ctx);
+ /**
+ * Exit a parse tree produced by {@link StellarParser#if_expr}.
+ * @param ctx the parse tree
+ */
+ void exitIf_expr(StellarParser.If_exprContext ctx);
+ /**
+ * Enter a parse tree produced by {@link StellarParser#then_expr}.
+ * @param ctx the parse tree
+ */
+ void enterThen_expr(StellarParser.Then_exprContext ctx);
+ /**
+ * Exit a parse tree produced by {@link StellarParser#then_expr}.
+ * @param ctx the parse tree
+ */
+ void exitThen_expr(StellarParser.Then_exprContext ctx);
+ /**
+ * Enter a parse tree produced by {@link StellarParser#else_expr}.
+ * @param ctx the parse tree
+ */
+ void enterElse_expr(StellarParser.Else_exprContext ctx);
+ /**
+ * Exit a parse tree produced by {@link StellarParser#else_expr}.
+ * @param ctx the parse tree
+ */
+ void exitElse_expr(StellarParser.Else_exprContext ctx);
+ /**
* Enter a parse tree produced by the {@code TernaryFuncWithoutIf}
* labeled alternative in {@link StellarParser#conditional_expr}.
* @param ctx the parse tree
[2/3] metron git commit: METRON-980: Short circuit operations for
Stellar closes apache/metron#606
Posted by ce...@apache.org.
http://git-wip-us.apache.org/repos/asf/metron/blob/30d0e2a6/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/generated/StellarParser.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/generated/StellarParser.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/generated/StellarParser.java
index 51c99e4..adf7e99 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/generated/StellarParser.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/generated/StellarParser.java
@@ -45,21 +45,21 @@ public class StellarParser extends Parser {
DOUBLE_LITERAL=38, FLOAT_LITERAL=39, LONG_LITERAL=40, IDENTIFIER=41, STRING_LITERAL=42,
COMMENT=43, WS=44;
public static final int
- RULE_transformation = 0, RULE_transformation_expr = 1, RULE_conditional_expr = 2,
- RULE_logical_expr = 3, RULE_b_expr = 4, RULE_in_expr = 5, RULE_comparison_expr = 6,
- RULE_transformation_entity = 7, RULE_comp_operator = 8, RULE_func_args = 9,
- RULE_op_list = 10, RULE_list_entity = 11, RULE_kv_list = 12, RULE_map_entity = 13,
- RULE_arithmetic_expr = 14, RULE_arithmetic_expr_mul = 15, RULE_functions = 16,
- RULE_arithmetic_operands = 17, RULE_identifier_operand = 18, RULE_lambda_without_args = 19,
- RULE_lambda_with_args = 20, RULE_lambda_variables = 21, RULE_single_lambda_variable = 22,
- RULE_lambda_variable = 23;
+ RULE_transformation = 0, RULE_transformation_expr = 1, RULE_if_expr = 2,
+ RULE_then_expr = 3, RULE_else_expr = 4, RULE_conditional_expr = 5, RULE_logical_expr = 6,
+ RULE_b_expr = 7, RULE_in_expr = 8, RULE_comparison_expr = 9, RULE_transformation_entity = 10,
+ RULE_comp_operator = 11, RULE_func_args = 12, RULE_op_list = 13, RULE_list_entity = 14,
+ RULE_kv_list = 15, RULE_map_entity = 16, RULE_arithmetic_expr = 17, RULE_arithmetic_expr_mul = 18,
+ RULE_functions = 19, RULE_arithmetic_operands = 20, RULE_identifier_operand = 21,
+ RULE_lambda_without_args = 22, RULE_lambda_with_args = 23, RULE_lambda_variables = 24,
+ RULE_single_lambda_variable = 25, RULE_lambda_variable = 26;
public static final String[] ruleNames = {
- "transformation", "transformation_expr", "conditional_expr", "logical_expr",
- "b_expr", "in_expr", "comparison_expr", "transformation_entity", "comp_operator",
- "func_args", "op_list", "list_entity", "kv_list", "map_entity", "arithmetic_expr",
- "arithmetic_expr_mul", "functions", "arithmetic_operands", "identifier_operand",
- "lambda_without_args", "lambda_with_args", "lambda_variables", "single_lambda_variable",
- "lambda_variable"
+ "transformation", "transformation_expr", "if_expr", "then_expr", "else_expr",
+ "conditional_expr", "logical_expr", "b_expr", "in_expr", "comparison_expr",
+ "transformation_entity", "comp_operator", "func_args", "op_list", "list_entity",
+ "kv_list", "map_entity", "arithmetic_expr", "arithmetic_expr_mul", "functions",
+ "arithmetic_operands", "identifier_operand", "lambda_without_args", "lambda_with_args",
+ "lambda_variables", "single_lambda_variable", "lambda_variable"
};
private static final String[] _LITERAL_NAMES = {
@@ -150,9 +150,9 @@ public class StellarParser extends Parser {
try {
enterOuterAlt(_localctx, 1);
{
- setState(48);
+ setState(54);
transformation_expr();
- setState(49);
+ setState(55);
match(EOF);
}
}
@@ -283,13 +283,13 @@ public class StellarParser extends Parser {
Transformation_exprContext _localctx = new Transformation_exprContext(_ctx, getState());
enterRule(_localctx, 2, RULE_transformation_expr);
try {
- setState(61);
+ setState(67);
switch ( getInterpreter().adaptivePredict(_input,0,_ctx) ) {
case 1:
_localctx = new ConditionalExprContext(_localctx);
enterOuterAlt(_localctx, 1);
{
- setState(51);
+ setState(57);
conditional_expr();
}
break;
@@ -297,11 +297,11 @@ public class StellarParser extends Parser {
_localctx = new TransformationExprContext(_localctx);
enterOuterAlt(_localctx, 2);
{
- setState(52);
+ setState(58);
match(LPAREN);
- setState(53);
+ setState(59);
transformation_expr();
- setState(54);
+ setState(60);
match(RPAREN);
}
break;
@@ -309,7 +309,7 @@ public class StellarParser extends Parser {
_localctx = new ArithExpressionContext(_localctx);
enterOuterAlt(_localctx, 3);
{
- setState(56);
+ setState(62);
arithmetic_expr(0);
}
break;
@@ -317,7 +317,7 @@ public class StellarParser extends Parser {
_localctx = new TransformationEntityContext(_localctx);
enterOuterAlt(_localctx, 4);
{
- setState(57);
+ setState(63);
transformation_entity();
}
break;
@@ -325,7 +325,7 @@ public class StellarParser extends Parser {
_localctx = new ComparisonExpressionContext(_localctx);
enterOuterAlt(_localctx, 5);
{
- setState(58);
+ setState(64);
comparison_expr(0);
}
break;
@@ -333,7 +333,7 @@ public class StellarParser extends Parser {
_localctx = new LogicalExpressionContext(_localctx);
enterOuterAlt(_localctx, 6);
{
- setState(59);
+ setState(65);
logical_expr();
}
break;
@@ -341,7 +341,7 @@ public class StellarParser extends Parser {
_localctx = new InExpressionContext(_localctx);
enterOuterAlt(_localctx, 7);
{
- setState(60);
+ setState(66);
in_expr();
}
break;
@@ -358,6 +358,123 @@ public class StellarParser extends Parser {
return _localctx;
}
+ public static class If_exprContext extends ParserRuleContext {
+ public Logical_exprContext logical_expr() {
+ return getRuleContext(Logical_exprContext.class,0);
+ }
+ public If_exprContext(ParserRuleContext parent, int invokingState) {
+ super(parent, invokingState);
+ }
+ @Override public int getRuleIndex() { return RULE_if_expr; }
+ @Override
+ public void enterRule(ParseTreeListener listener) {
+ if ( listener instanceof StellarListener ) ((StellarListener)listener).enterIf_expr(this);
+ }
+ @Override
+ public void exitRule(ParseTreeListener listener) {
+ if ( listener instanceof StellarListener ) ((StellarListener)listener).exitIf_expr(this);
+ }
+ }
+
+ public final If_exprContext if_expr() throws RecognitionException {
+ If_exprContext _localctx = new If_exprContext(_ctx, getState());
+ enterRule(_localctx, 4, RULE_if_expr);
+ try {
+ enterOuterAlt(_localctx, 1);
+ {
+ setState(69);
+ logical_expr();
+ }
+ }
+ catch (RecognitionException re) {
+ _localctx.exception = re;
+ _errHandler.reportError(this, re);
+ _errHandler.recover(this, re);
+ }
+ finally {
+ exitRule();
+ }
+ return _localctx;
+ }
+
+ public static class Then_exprContext extends ParserRuleContext {
+ public Transformation_exprContext transformation_expr() {
+ return getRuleContext(Transformation_exprContext.class,0);
+ }
+ public Then_exprContext(ParserRuleContext parent, int invokingState) {
+ super(parent, invokingState);
+ }
+ @Override public int getRuleIndex() { return RULE_then_expr; }
+ @Override
+ public void enterRule(ParseTreeListener listener) {
+ if ( listener instanceof StellarListener ) ((StellarListener)listener).enterThen_expr(this);
+ }
+ @Override
+ public void exitRule(ParseTreeListener listener) {
+ if ( listener instanceof StellarListener ) ((StellarListener)listener).exitThen_expr(this);
+ }
+ }
+
+ public final Then_exprContext then_expr() throws RecognitionException {
+ Then_exprContext _localctx = new Then_exprContext(_ctx, getState());
+ enterRule(_localctx, 6, RULE_then_expr);
+ try {
+ enterOuterAlt(_localctx, 1);
+ {
+ setState(71);
+ transformation_expr();
+ }
+ }
+ catch (RecognitionException re) {
+ _localctx.exception = re;
+ _errHandler.reportError(this, re);
+ _errHandler.recover(this, re);
+ }
+ finally {
+ exitRule();
+ }
+ return _localctx;
+ }
+
+ public static class Else_exprContext extends ParserRuleContext {
+ public Transformation_exprContext transformation_expr() {
+ return getRuleContext(Transformation_exprContext.class,0);
+ }
+ public Else_exprContext(ParserRuleContext parent, int invokingState) {
+ super(parent, invokingState);
+ }
+ @Override public int getRuleIndex() { return RULE_else_expr; }
+ @Override
+ public void enterRule(ParseTreeListener listener) {
+ if ( listener instanceof StellarListener ) ((StellarListener)listener).enterElse_expr(this);
+ }
+ @Override
+ public void exitRule(ParseTreeListener listener) {
+ if ( listener instanceof StellarListener ) ((StellarListener)listener).exitElse_expr(this);
+ }
+ }
+
+ public final Else_exprContext else_expr() throws RecognitionException {
+ Else_exprContext _localctx = new Else_exprContext(_ctx, getState());
+ enterRule(_localctx, 8, RULE_else_expr);
+ try {
+ enterOuterAlt(_localctx, 1);
+ {
+ setState(73);
+ transformation_expr();
+ }
+ }
+ catch (RecognitionException re) {
+ _localctx.exception = re;
+ _errHandler.reportError(this, re);
+ _errHandler.recover(this, re);
+ }
+ finally {
+ exitRule();
+ }
+ return _localctx;
+ }
+
public static class Conditional_exprContext extends ParserRuleContext {
public Conditional_exprContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
@@ -370,17 +487,17 @@ public class StellarParser extends Parser {
}
}
public static class TernaryFuncWithoutIfContext extends Conditional_exprContext {
- public Logical_exprContext logical_expr() {
- return getRuleContext(Logical_exprContext.class,0);
+ public If_exprContext if_expr() {
+ return getRuleContext(If_exprContext.class,0);
}
public TerminalNode QUESTION() { return getToken(StellarParser.QUESTION, 0); }
- public List<Transformation_exprContext> transformation_expr() {
- return getRuleContexts(Transformation_exprContext.class);
- }
- public Transformation_exprContext transformation_expr(int i) {
- return getRuleContext(Transformation_exprContext.class,i);
+ public Then_exprContext then_expr() {
+ return getRuleContext(Then_exprContext.class,0);
}
public TerminalNode COLON() { return getToken(StellarParser.COLON, 0); }
+ public Else_exprContext else_expr() {
+ return getRuleContext(Else_exprContext.class,0);
+ }
public TernaryFuncWithoutIfContext(Conditional_exprContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
@@ -393,17 +510,17 @@ public class StellarParser extends Parser {
}
public static class TernaryFuncWithIfContext extends Conditional_exprContext {
public TerminalNode IF() { return getToken(StellarParser.IF, 0); }
- public Logical_exprContext logical_expr() {
- return getRuleContext(Logical_exprContext.class,0);
+ public If_exprContext if_expr() {
+ return getRuleContext(If_exprContext.class,0);
}
public TerminalNode THEN() { return getToken(StellarParser.THEN, 0); }
- public List<Transformation_exprContext> transformation_expr() {
- return getRuleContexts(Transformation_exprContext.class);
- }
- public Transformation_exprContext transformation_expr(int i) {
- return getRuleContext(Transformation_exprContext.class,i);
+ public Then_exprContext then_expr() {
+ return getRuleContext(Then_exprContext.class,0);
}
public TerminalNode ELSE() { return getToken(StellarParser.ELSE, 0); }
+ public Else_exprContext else_expr() {
+ return getRuleContext(Else_exprContext.class,0);
+ }
public TernaryFuncWithIfContext(Conditional_exprContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
@@ -417,9 +534,9 @@ public class StellarParser extends Parser {
public final Conditional_exprContext conditional_expr() throws RecognitionException {
Conditional_exprContext _localctx = new Conditional_exprContext(_ctx, getState());
- enterRule(_localctx, 4, RULE_conditional_expr);
+ enterRule(_localctx, 10, RULE_conditional_expr);
try {
- setState(76);
+ setState(88);
switch (_input.LA(1)) {
case NOT:
case TRUE:
@@ -438,34 +555,34 @@ public class StellarParser extends Parser {
_localctx = new TernaryFuncWithoutIfContext(_localctx);
enterOuterAlt(_localctx, 1);
{
- setState(63);
- logical_expr();
- setState(64);
+ setState(75);
+ if_expr();
+ setState(76);
match(QUESTION);
- setState(65);
- transformation_expr();
- setState(66);
+ setState(77);
+ then_expr();
+ setState(78);
match(COLON);
- setState(67);
- transformation_expr();
+ setState(79);
+ else_expr();
}
break;
case IF:
_localctx = new TernaryFuncWithIfContext(_localctx);
enterOuterAlt(_localctx, 2);
{
- setState(69);
+ setState(81);
match(IF);
- setState(70);
- logical_expr();
- setState(71);
+ setState(82);
+ if_expr();
+ setState(83);
match(THEN);
- setState(72);
- transformation_expr();
- setState(73);
+ setState(84);
+ then_expr();
+ setState(85);
match(ELSE);
- setState(74);
- transformation_expr();
+ setState(86);
+ else_expr();
}
break;
default:
@@ -547,19 +664,19 @@ public class StellarParser extends Parser {
public final Logical_exprContext logical_expr() throws RecognitionException {
Logical_exprContext _localctx = new Logical_exprContext(_ctx, getState());
- enterRule(_localctx, 6, RULE_logical_expr);
+ enterRule(_localctx, 12, RULE_logical_expr);
try {
- setState(87);
+ setState(99);
switch ( getInterpreter().adaptivePredict(_input,2,_ctx) ) {
case 1:
_localctx = new LogicalExpressionAndContext(_localctx);
enterOuterAlt(_localctx, 1);
{
- setState(78);
+ setState(90);
b_expr();
- setState(79);
+ setState(91);
match(AND);
- setState(80);
+ setState(92);
logical_expr();
}
break;
@@ -567,11 +684,11 @@ public class StellarParser extends Parser {
_localctx = new LogicalExpressionOrContext(_localctx);
enterOuterAlt(_localctx, 2);
{
- setState(82);
+ setState(94);
b_expr();
- setState(83);
+ setState(95);
match(OR);
- setState(84);
+ setState(96);
logical_expr();
}
break;
@@ -579,7 +696,7 @@ public class StellarParser extends Parser {
_localctx = new BoleanExpressionContext(_localctx);
enterOuterAlt(_localctx, 3);
{
- setState(86);
+ setState(98);
b_expr();
}
break;
@@ -619,21 +736,21 @@ public class StellarParser extends Parser {
public final B_exprContext b_expr() throws RecognitionException {
B_exprContext _localctx = new B_exprContext(_ctx, getState());
- enterRule(_localctx, 8, RULE_b_expr);
+ enterRule(_localctx, 14, RULE_b_expr);
try {
- setState(91);
+ setState(103);
switch ( getInterpreter().adaptivePredict(_input,3,_ctx) ) {
case 1:
enterOuterAlt(_localctx, 1);
{
- setState(89);
+ setState(101);
comparison_expr(0);
}
break;
case 2:
enterOuterAlt(_localctx, 2);
{
- setState(90);
+ setState(102);
in_expr();
}
break;
@@ -700,19 +817,19 @@ public class StellarParser extends Parser {
public final In_exprContext in_expr() throws RecognitionException {
In_exprContext _localctx = new In_exprContext(_ctx, getState());
- enterRule(_localctx, 10, RULE_in_expr);
+ enterRule(_localctx, 16, RULE_in_expr);
try {
- setState(101);
+ setState(113);
switch ( getInterpreter().adaptivePredict(_input,4,_ctx) ) {
case 1:
_localctx = new InExpressionStatementContext(_localctx);
enterOuterAlt(_localctx, 1);
{
- setState(93);
+ setState(105);
identifier_operand();
- setState(94);
+ setState(106);
match(IN);
- setState(95);
+ setState(107);
b_expr();
}
break;
@@ -720,11 +837,11 @@ public class StellarParser extends Parser {
_localctx = new NInExpressionStatementContext(_localctx);
enterOuterAlt(_localctx, 2);
{
- setState(97);
+ setState(109);
identifier_operand();
- setState(98);
+ setState(110);
match(NIN);
- setState(99);
+ setState(111);
b_expr();
}
break;
@@ -829,13 +946,13 @@ public class StellarParser extends Parser {
int _parentState = getState();
Comparison_exprContext _localctx = new Comparison_exprContext(_ctx, _parentState);
Comparison_exprContext _prevctx = _localctx;
- int _startState = 12;
- enterRecursionRule(_localctx, 12, RULE_comparison_expr, _p);
+ int _startState = 18;
+ enterRecursionRule(_localctx, 18, RULE_comparison_expr, _p);
try {
int _alt;
enterOuterAlt(_localctx, 1);
{
- setState(114);
+ setState(126);
switch ( getInterpreter().adaptivePredict(_input,5,_ctx) ) {
case 1:
{
@@ -843,13 +960,13 @@ public class StellarParser extends Parser {
_ctx = _localctx;
_prevctx = _localctx;
- setState(104);
+ setState(116);
match(NOT);
- setState(105);
+ setState(117);
match(LPAREN);
- setState(106);
+ setState(118);
logical_expr();
- setState(107);
+ setState(119);
match(RPAREN);
}
break;
@@ -858,11 +975,11 @@ public class StellarParser extends Parser {
_localctx = new ComparisonExpressionParensContext(_localctx);
_ctx = _localctx;
_prevctx = _localctx;
- setState(109);
+ setState(121);
match(LPAREN);
- setState(110);
+ setState(122);
logical_expr();
- setState(111);
+ setState(123);
match(RPAREN);
}
break;
@@ -871,13 +988,13 @@ public class StellarParser extends Parser {
_localctx = new OperandContext(_localctx);
_ctx = _localctx;
_prevctx = _localctx;
- setState(113);
+ setState(125);
identifier_operand();
}
break;
}
_ctx.stop = _input.LT(-1);
- setState(122);
+ setState(134);
_errHandler.sync(this);
_alt = getInterpreter().adaptivePredict(_input,6,_ctx);
while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) {
@@ -888,16 +1005,16 @@ public class StellarParser extends Parser {
{
_localctx = new ComparisonExpressionWithOperatorContext(new Comparison_exprContext(_parentctx, _parentState));
pushNewRecursionContext(_localctx, _startState, RULE_comparison_expr);
- setState(116);
+ setState(128);
if (!(precpred(_ctx, 4))) throw new FailedPredicateException(this, "precpred(_ctx, 4)");
- setState(117);
+ setState(129);
comp_operator();
- setState(118);
+ setState(130);
comparison_expr(5);
}
}
}
- setState(124);
+ setState(136);
_errHandler.sync(this);
_alt = getInterpreter().adaptivePredict(_input,6,_ctx);
}
@@ -934,11 +1051,11 @@ public class StellarParser extends Parser {
public final Transformation_entityContext transformation_entity() throws RecognitionException {
Transformation_entityContext _localctx = new Transformation_entityContext(_ctx, getState());
- enterRule(_localctx, 14, RULE_transformation_entity);
+ enterRule(_localctx, 20, RULE_transformation_entity);
try {
enterOuterAlt(_localctx, 1);
{
- setState(125);
+ setState(137);
identifier_operand();
}
}
@@ -984,13 +1101,13 @@ public class StellarParser extends Parser {
public final Comp_operatorContext comp_operator() throws RecognitionException {
Comp_operatorContext _localctx = new Comp_operatorContext(_ctx, getState());
- enterRule(_localctx, 16, RULE_comp_operator);
+ enterRule(_localctx, 22, RULE_comp_operator);
int _la;
try {
_localctx = new ComparisonOpContext(_localctx);
enterOuterAlt(_localctx, 1);
{
- setState(127);
+ setState(139);
_la = _input.LA(1);
if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << EQ) | (1L << NEQ) | (1L << LT) | (1L << LTE) | (1L << GT) | (1L << GTE))) != 0)) ) {
_errHandler.recoverInline(this);
@@ -1032,27 +1149,27 @@ public class StellarParser extends Parser {
public final Func_argsContext func_args() throws RecognitionException {
Func_argsContext _localctx = new Func_argsContext(_ctx, getState());
- enterRule(_localctx, 18, RULE_func_args);
+ enterRule(_localctx, 24, RULE_func_args);
try {
- setState(135);
+ setState(147);
switch ( getInterpreter().adaptivePredict(_input,7,_ctx) ) {
case 1:
enterOuterAlt(_localctx, 1);
{
- setState(129);
+ setState(141);
match(LPAREN);
- setState(130);
+ setState(142);
op_list(0);
- setState(131);
+ setState(143);
match(RPAREN);
}
break;
case 2:
enterOuterAlt(_localctx, 2);
{
- setState(133);
+ setState(145);
match(LPAREN);
- setState(134);
+ setState(146);
match(RPAREN);
}
break;
@@ -1103,29 +1220,29 @@ public class StellarParser extends Parser {
int _parentState = getState();
Op_listContext _localctx = new Op_listContext(_ctx, _parentState);
Op_listContext _prevctx = _localctx;
- int _startState = 20;
- enterRecursionRule(_localctx, 20, RULE_op_list, _p);
+ int _startState = 26;
+ enterRecursionRule(_localctx, 26, RULE_op_list, _p);
try {
int _alt;
enterOuterAlt(_localctx, 1);
{
- setState(140);
+ setState(152);
switch ( getInterpreter().adaptivePredict(_input,8,_ctx) ) {
case 1:
{
- setState(138);
+ setState(150);
identifier_operand();
}
break;
case 2:
{
- setState(139);
+ setState(151);
conditional_expr();
}
break;
}
_ctx.stop = _input.LT(-1);
- setState(150);
+ setState(162);
_errHandler.sync(this);
_alt = getInterpreter().adaptivePredict(_input,10,_ctx);
while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) {
@@ -1133,17 +1250,17 @@ public class StellarParser extends Parser {
if ( _parseListeners!=null ) triggerExitRuleEvent();
_prevctx = _localctx;
{
- setState(148);
+ setState(160);
switch ( getInterpreter().adaptivePredict(_input,9,_ctx) ) {
case 1:
{
_localctx = new Op_listContext(_parentctx, _parentState);
pushNewRecursionContext(_localctx, _startState, RULE_op_list);
- setState(142);
+ setState(154);
if (!(precpred(_ctx, 3))) throw new FailedPredicateException(this, "precpred(_ctx, 3)");
- setState(143);
+ setState(155);
match(COMMA);
- setState(144);
+ setState(156);
identifier_operand();
}
break;
@@ -1151,18 +1268,18 @@ public class StellarParser extends Parser {
{
_localctx = new Op_listContext(_parentctx, _parentState);
pushNewRecursionContext(_localctx, _startState, RULE_op_list);
- setState(145);
+ setState(157);
if (!(precpred(_ctx, 1))) throw new FailedPredicateException(this, "precpred(_ctx, 1)");
- setState(146);
+ setState(158);
match(COMMA);
- setState(147);
+ setState(159);
conditional_expr();
}
break;
}
}
}
- setState(152);
+ setState(164);
_errHandler.sync(this);
_alt = getInterpreter().adaptivePredict(_input,10,_ctx);
}
@@ -1201,27 +1318,27 @@ public class StellarParser extends Parser {
public final List_entityContext list_entity() throws RecognitionException {
List_entityContext _localctx = new List_entityContext(_ctx, getState());
- enterRule(_localctx, 22, RULE_list_entity);
+ enterRule(_localctx, 28, RULE_list_entity);
try {
- setState(159);
+ setState(171);
switch ( getInterpreter().adaptivePredict(_input,11,_ctx) ) {
case 1:
enterOuterAlt(_localctx, 1);
{
- setState(153);
+ setState(165);
match(LBRACKET);
- setState(154);
+ setState(166);
match(RBRACKET);
}
break;
case 2:
enterOuterAlt(_localctx, 2);
{
- setState(155);
+ setState(167);
match(LBRACKET);
- setState(156);
+ setState(168);
op_list(0);
- setState(157);
+ setState(169);
match(RBRACKET);
}
break;
@@ -1273,22 +1390,22 @@ public class StellarParser extends Parser {
int _parentState = getState();
Kv_listContext _localctx = new Kv_listContext(_ctx, _parentState);
Kv_listContext _prevctx = _localctx;
- int _startState = 24;
- enterRecursionRule(_localctx, 24, RULE_kv_list, _p);
+ int _startState = 30;
+ enterRecursionRule(_localctx, 30, RULE_kv_list, _p);
try {
int _alt;
enterOuterAlt(_localctx, 1);
{
{
- setState(162);
+ setState(174);
identifier_operand();
- setState(163);
+ setState(175);
match(COLON);
- setState(164);
+ setState(176);
transformation_expr();
}
_ctx.stop = _input.LT(-1);
- setState(174);
+ setState(186);
_errHandler.sync(this);
_alt = getInterpreter().adaptivePredict(_input,12,_ctx);
while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) {
@@ -1299,20 +1416,20 @@ public class StellarParser extends Parser {
{
_localctx = new Kv_listContext(_parentctx, _parentState);
pushNewRecursionContext(_localctx, _startState, RULE_kv_list);
- setState(166);
+ setState(178);
if (!(precpred(_ctx, 1))) throw new FailedPredicateException(this, "precpred(_ctx, 1)");
- setState(167);
+ setState(179);
match(COMMA);
- setState(168);
+ setState(180);
identifier_operand();
- setState(169);
+ setState(181);
match(COLON);
- setState(170);
+ setState(182);
transformation_expr();
}
}
}
- setState(176);
+ setState(188);
_errHandler.sync(this);
_alt = getInterpreter().adaptivePredict(_input,12,_ctx);
}
@@ -1351,27 +1468,27 @@ public class StellarParser extends Parser {
public final Map_entityContext map_entity() throws RecognitionException {
Map_entityContext _localctx = new Map_entityContext(_ctx, getState());
- enterRule(_localctx, 26, RULE_map_entity);
+ enterRule(_localctx, 32, RULE_map_entity);
try {
- setState(183);
+ setState(195);
switch ( getInterpreter().adaptivePredict(_input,13,_ctx) ) {
case 1:
enterOuterAlt(_localctx, 1);
{
- setState(177);
+ setState(189);
match(LBRACE);
- setState(178);
+ setState(190);
kv_list(0);
- setState(179);
+ setState(191);
match(RBRACE);
}
break;
case 2:
enterOuterAlt(_localctx, 2);
{
- setState(181);
+ setState(193);
match(LBRACE);
- setState(182);
+ setState(194);
match(RBRACE);
}
break;
@@ -1459,8 +1576,8 @@ public class StellarParser extends Parser {
int _parentState = getState();
Arithmetic_exprContext _localctx = new Arithmetic_exprContext(_ctx, _parentState);
Arithmetic_exprContext _prevctx = _localctx;
- int _startState = 28;
- enterRecursionRule(_localctx, 28, RULE_arithmetic_expr, _p);
+ int _startState = 34;
+ enterRecursionRule(_localctx, 34, RULE_arithmetic_expr, _p);
try {
int _alt;
enterOuterAlt(_localctx, 1);
@@ -1470,11 +1587,11 @@ public class StellarParser extends Parser {
_ctx = _localctx;
_prevctx = _localctx;
- setState(186);
+ setState(198);
arithmetic_expr_mul(0);
}
_ctx.stop = _input.LT(-1);
- setState(196);
+ setState(208);
_errHandler.sync(this);
_alt = getInterpreter().adaptivePredict(_input,15,_ctx);
while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) {
@@ -1482,17 +1599,17 @@ public class StellarParser extends Parser {
if ( _parseListeners!=null ) triggerExitRuleEvent();
_prevctx = _localctx;
{
- setState(194);
+ setState(206);
switch ( getInterpreter().adaptivePredict(_input,14,_ctx) ) {
case 1:
{
_localctx = new ArithExpr_plusContext(new Arithmetic_exprContext(_parentctx, _parentState));
pushNewRecursionContext(_localctx, _startState, RULE_arithmetic_expr);
- setState(188);
+ setState(200);
if (!(precpred(_ctx, 2))) throw new FailedPredicateException(this, "precpred(_ctx, 2)");
- setState(189);
+ setState(201);
match(PLUS);
- setState(190);
+ setState(202);
arithmetic_expr_mul(0);
}
break;
@@ -1500,18 +1617,18 @@ public class StellarParser extends Parser {
{
_localctx = new ArithExpr_minusContext(new Arithmetic_exprContext(_parentctx, _parentState));
pushNewRecursionContext(_localctx, _startState, RULE_arithmetic_expr);
- setState(191);
+ setState(203);
if (!(precpred(_ctx, 1))) throw new FailedPredicateException(this, "precpred(_ctx, 1)");
- setState(192);
+ setState(204);
match(MINUS);
- setState(193);
+ setState(205);
arithmetic_expr_mul(0);
}
break;
}
}
}
- setState(198);
+ setState(210);
_errHandler.sync(this);
_alt = getInterpreter().adaptivePredict(_input,15,_ctx);
}
@@ -1599,8 +1716,8 @@ public class StellarParser extends Parser {
int _parentState = getState();
Arithmetic_expr_mulContext _localctx = new Arithmetic_expr_mulContext(_ctx, _parentState);
Arithmetic_expr_mulContext _prevctx = _localctx;
- int _startState = 30;
- enterRecursionRule(_localctx, 30, RULE_arithmetic_expr_mul, _p);
+ int _startState = 36;
+ enterRecursionRule(_localctx, 36, RULE_arithmetic_expr_mul, _p);
try {
int _alt;
enterOuterAlt(_localctx, 1);
@@ -1610,11 +1727,11 @@ public class StellarParser extends Parser {
_ctx = _localctx;
_prevctx = _localctx;
- setState(200);
+ setState(212);
arithmetic_operands();
}
_ctx.stop = _input.LT(-1);
- setState(210);
+ setState(222);
_errHandler.sync(this);
_alt = getInterpreter().adaptivePredict(_input,17,_ctx);
while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) {
@@ -1622,17 +1739,17 @@ public class StellarParser extends Parser {
if ( _parseListeners!=null ) triggerExitRuleEvent();
_prevctx = _localctx;
{
- setState(208);
+ setState(220);
switch ( getInterpreter().adaptivePredict(_input,16,_ctx) ) {
case 1:
{
_localctx = new ArithExpr_mulContext(new Arithmetic_expr_mulContext(_parentctx, _parentState));
pushNewRecursionContext(_localctx, _startState, RULE_arithmetic_expr_mul);
- setState(202);
+ setState(214);
if (!(precpred(_ctx, 2))) throw new FailedPredicateException(this, "precpred(_ctx, 2)");
- setState(203);
+ setState(215);
match(MUL);
- setState(204);
+ setState(216);
arithmetic_expr_mul(3);
}
break;
@@ -1640,18 +1757,18 @@ public class StellarParser extends Parser {
{
_localctx = new ArithExpr_divContext(new Arithmetic_expr_mulContext(_parentctx, _parentState));
pushNewRecursionContext(_localctx, _startState, RULE_arithmetic_expr_mul);
- setState(205);
+ setState(217);
if (!(precpred(_ctx, 1))) throw new FailedPredicateException(this, "precpred(_ctx, 1)");
- setState(206);
+ setState(218);
match(DIV);
- setState(207);
+ setState(219);
arithmetic_expr_mul(2);
}
break;
}
}
}
- setState(212);
+ setState(224);
_errHandler.sync(this);
_alt = getInterpreter().adaptivePredict(_input,17,_ctx);
}
@@ -1697,14 +1814,14 @@ public class StellarParser extends Parser {
public final FunctionsContext functions() throws RecognitionException {
FunctionsContext _localctx = new FunctionsContext(_ctx, getState());
- enterRule(_localctx, 32, RULE_functions);
+ enterRule(_localctx, 38, RULE_functions);
try {
_localctx = new TransformationFuncContext(_localctx);
enterOuterAlt(_localctx, 1);
{
- setState(213);
+ setState(225);
match(IDENTIFIER);
- setState(214);
+ setState(226);
func_args();
}
}
@@ -1839,15 +1956,15 @@ public class StellarParser extends Parser {
public final Arithmetic_operandsContext arithmetic_operands() throws RecognitionException {
Arithmetic_operandsContext _localctx = new Arithmetic_operandsContext(_ctx, getState());
- enterRule(_localctx, 34, RULE_arithmetic_operands);
+ enterRule(_localctx, 40, RULE_arithmetic_operands);
try {
- setState(230);
+ setState(242);
switch ( getInterpreter().adaptivePredict(_input,18,_ctx) ) {
case 1:
_localctx = new NumericFunctionsContext(_localctx);
enterOuterAlt(_localctx, 1);
{
- setState(216);
+ setState(228);
functions();
}
break;
@@ -1855,7 +1972,7 @@ public class StellarParser extends Parser {
_localctx = new DoubleLiteralContext(_localctx);
enterOuterAlt(_localctx, 2);
{
- setState(217);
+ setState(229);
match(DOUBLE_LITERAL);
}
break;
@@ -1863,7 +1980,7 @@ public class StellarParser extends Parser {
_localctx = new IntLiteralContext(_localctx);
enterOuterAlt(_localctx, 3);
{
- setState(218);
+ setState(230);
match(INT_LITERAL);
}
break;
@@ -1871,7 +1988,7 @@ public class StellarParser extends Parser {
_localctx = new LongLiteralContext(_localctx);
enterOuterAlt(_localctx, 4);
{
- setState(219);
+ setState(231);
match(LONG_LITERAL);
}
break;
@@ -1879,7 +1996,7 @@ public class StellarParser extends Parser {
_localctx = new FloatLiteralContext(_localctx);
enterOuterAlt(_localctx, 5);
{
- setState(220);
+ setState(232);
match(FLOAT_LITERAL);
}
break;
@@ -1887,7 +2004,7 @@ public class StellarParser extends Parser {
_localctx = new VariableContext(_localctx);
enterOuterAlt(_localctx, 6);
{
- setState(221);
+ setState(233);
match(IDENTIFIER);
}
break;
@@ -1895,11 +2012,11 @@ public class StellarParser extends Parser {
_localctx = new ParenArithContext(_localctx);
enterOuterAlt(_localctx, 7);
{
- setState(222);
+ setState(234);
match(LPAREN);
- setState(223);
+ setState(235);
arithmetic_expr(0);
- setState(224);
+ setState(236);
match(RPAREN);
}
break;
@@ -1907,11 +2024,11 @@ public class StellarParser extends Parser {
_localctx = new CondExprContext(_localctx);
enterOuterAlt(_localctx, 8);
{
- setState(226);
+ setState(238);
match(LPAREN);
- setState(227);
+ setState(239);
conditional_expr();
- setState(228);
+ setState(240);
match(RPAREN);
}
break;
@@ -2080,16 +2197,16 @@ public class StellarParser extends Parser {
public final Identifier_operandContext identifier_operand() throws RecognitionException {
Identifier_operandContext _localctx = new Identifier_operandContext(_ctx, getState());
- enterRule(_localctx, 36, RULE_identifier_operand);
+ enterRule(_localctx, 42, RULE_identifier_operand);
int _la;
try {
- setState(248);
+ setState(260);
switch ( getInterpreter().adaptivePredict(_input,19,_ctx) ) {
case 1:
_localctx = new LogicalConstContext(_localctx);
enterOuterAlt(_localctx, 1);
{
- setState(232);
+ setState(244);
_la = _input.LA(1);
if ( !(_la==TRUE || _la==FALSE) ) {
_errHandler.recoverInline(this);
@@ -2102,7 +2219,7 @@ public class StellarParser extends Parser {
_localctx = new LambdaWithArgsExprContext(_localctx);
enterOuterAlt(_localctx, 2);
{
- setState(233);
+ setState(245);
lambda_with_args();
}
break;
@@ -2110,7 +2227,7 @@ public class StellarParser extends Parser {
_localctx = new LambdaWithoutArgsExprContext(_localctx);
enterOuterAlt(_localctx, 3);
{
- setState(234);
+ setState(246);
lambda_without_args();
}
break;
@@ -2118,7 +2235,7 @@ public class StellarParser extends Parser {
_localctx = new ArithmeticOperandsContext(_localctx);
enterOuterAlt(_localctx, 4);
{
- setState(235);
+ setState(247);
arithmetic_expr(0);
}
break;
@@ -2126,7 +2243,7 @@ public class StellarParser extends Parser {
_localctx = new StringLiteralContext(_localctx);
enterOuterAlt(_localctx, 5);
{
- setState(236);
+ setState(248);
match(STRING_LITERAL);
}
break;
@@ -2134,7 +2251,7 @@ public class StellarParser extends Parser {
_localctx = new ListContext(_localctx);
enterOuterAlt(_localctx, 6);
{
- setState(237);
+ setState(249);
list_entity();
}
break;
@@ -2142,7 +2259,7 @@ public class StellarParser extends Parser {
_localctx = new MapConstContext(_localctx);
enterOuterAlt(_localctx, 7);
{
- setState(238);
+ setState(250);
map_entity();
}
break;
@@ -2150,7 +2267,7 @@ public class StellarParser extends Parser {
_localctx = new NullConstContext(_localctx);
enterOuterAlt(_localctx, 8);
{
- setState(239);
+ setState(251);
match(NULL);
}
break;
@@ -2158,13 +2275,13 @@ public class StellarParser extends Parser {
_localctx = new ExistsFuncContext(_localctx);
enterOuterAlt(_localctx, 9);
{
- setState(240);
+ setState(252);
match(EXISTS);
- setState(241);
+ setState(253);
match(LPAREN);
- setState(242);
+ setState(254);
match(IDENTIFIER);
- setState(243);
+ setState(255);
match(RPAREN);
}
break;
@@ -2172,11 +2289,11 @@ public class StellarParser extends Parser {
_localctx = new CondExpr_parenContext(_localctx);
enterOuterAlt(_localctx, 10);
{
- setState(244);
+ setState(256);
match(LPAREN);
- setState(245);
+ setState(257);
conditional_expr();
- setState(246);
+ setState(258);
match(RPAREN);
}
break;
@@ -2216,17 +2333,17 @@ public class StellarParser extends Parser {
public final Lambda_without_argsContext lambda_without_args() throws RecognitionException {
Lambda_without_argsContext _localctx = new Lambda_without_argsContext(_ctx, getState());
- enterRule(_localctx, 38, RULE_lambda_without_args);
+ enterRule(_localctx, 44, RULE_lambda_without_args);
try {
enterOuterAlt(_localctx, 1);
{
- setState(250);
+ setState(262);
match(LPAREN);
- setState(251);
+ setState(263);
match(RPAREN);
- setState(252);
+ setState(264);
match(LAMBDA_OP);
- setState(253);
+ setState(265);
transformation_expr();
}
}
@@ -2270,33 +2387,33 @@ public class StellarParser extends Parser {
public final Lambda_with_argsContext lambda_with_args() throws RecognitionException {
Lambda_with_argsContext _localctx = new Lambda_with_argsContext(_ctx, getState());
- enterRule(_localctx, 40, RULE_lambda_with_args);
+ enterRule(_localctx, 46, RULE_lambda_with_args);
try {
- setState(265);
+ setState(277);
switch (_input.LA(1)) {
case LPAREN:
enterOuterAlt(_localctx, 1);
{
- setState(255);
+ setState(267);
match(LPAREN);
- setState(256);
+ setState(268);
lambda_variables();
- setState(257);
+ setState(269);
match(RPAREN);
- setState(258);
+ setState(270);
match(LAMBDA_OP);
- setState(259);
+ setState(271);
transformation_expr();
}
break;
case IDENTIFIER:
enterOuterAlt(_localctx, 2);
{
- setState(261);
+ setState(273);
single_lambda_variable();
- setState(262);
+ setState(274);
match(LAMBDA_OP);
- setState(263);
+ setState(275);
transformation_expr();
}
break;
@@ -2342,26 +2459,26 @@ public class StellarParser extends Parser {
public final Lambda_variablesContext lambda_variables() throws RecognitionException {
Lambda_variablesContext _localctx = new Lambda_variablesContext(_ctx, getState());
- enterRule(_localctx, 42, RULE_lambda_variables);
+ enterRule(_localctx, 48, RULE_lambda_variables);
int _la;
try {
enterOuterAlt(_localctx, 1);
{
- setState(267);
+ setState(279);
lambda_variable();
- setState(272);
+ setState(284);
_errHandler.sync(this);
_la = _input.LA(1);
while (_la==COMMA) {
{
{
- setState(268);
+ setState(280);
match(COMMA);
- setState(269);
+ setState(281);
lambda_variable();
}
}
- setState(274);
+ setState(286);
_errHandler.sync(this);
_la = _input.LA(1);
}
@@ -2398,11 +2515,11 @@ public class StellarParser extends Parser {
public final Single_lambda_variableContext single_lambda_variable() throws RecognitionException {
Single_lambda_variableContext _localctx = new Single_lambda_variableContext(_ctx, getState());
- enterRule(_localctx, 44, RULE_single_lambda_variable);
+ enterRule(_localctx, 50, RULE_single_lambda_variable);
try {
enterOuterAlt(_localctx, 1);
{
- setState(275);
+ setState(287);
lambda_variable();
}
}
@@ -2435,11 +2552,11 @@ public class StellarParser extends Parser {
public final Lambda_variableContext lambda_variable() throws RecognitionException {
Lambda_variableContext _localctx = new Lambda_variableContext(_ctx, getState());
- enterRule(_localctx, 46, RULE_lambda_variable);
+ enterRule(_localctx, 52, RULE_lambda_variable);
try {
enterOuterAlt(_localctx, 1);
{
- setState(277);
+ setState(289);
match(IDENTIFIER);
}
}
@@ -2456,15 +2573,15 @@ public class StellarParser extends Parser {
public boolean sempred(RuleContext _localctx, int ruleIndex, int predIndex) {
switch (ruleIndex) {
- case 6:
+ case 9:
return comparison_expr_sempred((Comparison_exprContext)_localctx, predIndex);
- case 10:
+ case 13:
return op_list_sempred((Op_listContext)_localctx, predIndex);
- case 12:
+ case 15:
return kv_list_sempred((Kv_listContext)_localctx, predIndex);
- case 14:
+ case 17:
return arithmetic_expr_sempred((Arithmetic_exprContext)_localctx, predIndex);
- case 15:
+ case 18:
return arithmetic_expr_mul_sempred((Arithmetic_expr_mulContext)_localctx, predIndex);
}
return true;
@@ -2512,100 +2629,105 @@ public class StellarParser extends Parser {
}
public static final String _serializedATN =
- "\3\u0430\ud6d1\u8206\uad2d\u4417\uaef1\u8d80\uaadd\3.\u011a\4\2\t\2\4"+
+ "\3\u0430\ud6d1\u8206\uad2d\u4417\uaef1\u8d80\uaadd\3.\u0126\4\2\t\2\4"+
"\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13\t"+
"\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t\17\4\20\t\20\4\21\t\21\4\22\t\22"+
"\4\23\t\23\4\24\t\24\4\25\t\25\4\26\t\26\4\27\t\27\4\30\t\30\4\31\t\31"+
- "\3\2\3\2\3\2\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\5\3@\n\3\3\4\3\4"+
- "\3\4\3\4\3\4\3\4\3\4\3\4\3\4\3\4\3\4\3\4\3\4\5\4O\n\4\3\5\3\5\3\5\3\5"+
- "\3\5\3\5\3\5\3\5\3\5\5\5Z\n\5\3\6\3\6\5\6^\n\6\3\7\3\7\3\7\3\7\3\7\3\7"+
- "\3\7\3\7\5\7h\n\7\3\b\3\b\3\b\3\b\3\b\3\b\3\b\3\b\3\b\3\b\3\b\5\bu\n\b"+
- "\3\b\3\b\3\b\3\b\7\b{\n\b\f\b\16\b~\13\b\3\t\3\t\3\n\3\n\3\13\3\13\3\13"+
- "\3\13\3\13\3\13\5\13\u008a\n\13\3\f\3\f\3\f\5\f\u008f\n\f\3\f\3\f\3\f"+
- "\3\f\3\f\3\f\7\f\u0097\n\f\f\f\16\f\u009a\13\f\3\r\3\r\3\r\3\r\3\r\3\r"+
- "\5\r\u00a2\n\r\3\16\3\16\3\16\3\16\3\16\3\16\3\16\3\16\3\16\3\16\3\16"+
- "\7\16\u00af\n\16\f\16\16\16\u00b2\13\16\3\17\3\17\3\17\3\17\3\17\3\17"+
- "\5\17\u00ba\n\17\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\7\20\u00c5"+
- "\n\20\f\20\16\20\u00c8\13\20\3\21\3\21\3\21\3\21\3\21\3\21\3\21\3\21\3"+
- "\21\7\21\u00d3\n\21\f\21\16\21\u00d6\13\21\3\22\3\22\3\22\3\23\3\23\3"+
- "\23\3\23\3\23\3\23\3\23\3\23\3\23\3\23\3\23\3\23\3\23\3\23\5\23\u00e9"+
- "\n\23\3\24\3\24\3\24\3\24\3\24\3\24\3\24\3\24\3\24\3\24\3\24\3\24\3\24"+
- "\3\24\3\24\3\24\5\24\u00fb\n\24\3\25\3\25\3\25\3\25\3\25\3\26\3\26\3\26"+
- "\3\26\3\26\3\26\3\26\3\26\3\26\3\26\5\26\u010c\n\26\3\27\3\27\3\27\7\27"+
- "\u0111\n\27\f\27\16\27\u0114\13\27\3\30\3\30\3\31\3\31\3\31\2\7\16\26"+
- "\32\36 \32\2\4\6\b\n\f\16\20\22\24\26\30\32\34\36 \"$&(*,.\60\2\4\3\2"+
- "\16\23\3\2\f\r\u012c\2\62\3\2\2\2\4?\3\2\2\2\6N\3\2\2\2\bY\3\2\2\2\n]"+
- "\3\2\2\2\fg\3\2\2\2\16t\3\2\2\2\20\177\3\2\2\2\22\u0081\3\2\2\2\24\u0089"+
- "\3\2\2\2\26\u008e\3\2\2\2\30\u00a1\3\2\2\2\32\u00a3\3\2\2\2\34\u00b9\3"+
- "\2\2\2\36\u00bb\3\2\2\2 \u00c9\3\2\2\2\"\u00d7\3\2\2\2$\u00e8\3\2\2\2"+
- "&\u00fa\3\2\2\2(\u00fc\3\2\2\2*\u010b\3\2\2\2,\u010d\3\2\2\2.\u0115\3"+
- "\2\2\2\60\u0117\3\2\2\2\62\63\5\4\3\2\63\64\7\2\2\3\64\3\3\2\2\2\65@\5"+
- "\6\4\2\66\67\7\"\2\2\678\5\4\3\289\7#\2\29@\3\2\2\2:@\5\36\20\2;@\5\20"+
- "\t\2<@\5\16\b\2=@\5\b\5\2>@\5\f\7\2?\65\3\2\2\2?\66\3\2\2\2?:\3\2\2\2"+
- "?;\3\2\2\2?<\3\2\2\2?=\3\2\2\2?>\3\2\2\2@\5\3\2\2\2AB\5\b\5\2BC\7\24\2"+
- "\2CD\5\4\3\2DE\7\25\2\2EF\5\4\3\2FO\3\2\2\2GH\7\26\2\2HI\5\b\5\2IJ\7\27"+
- "\2\2JK\5\4\3\2KL\7\30\2\2LM\5\4\3\2MO\3\2\2\2NA\3\2\2\2NG\3\2\2\2O\7\3"+
- "\2\2\2PQ\5\n\6\2QR\7\t\2\2RS\5\b\5\2SZ\3\2\2\2TU\5\n\6\2UV\7\n\2\2VW\5"+
- "\b\5\2WZ\3\2\2\2XZ\5\n\6\2YP\3\2\2\2YT\3\2\2\2YX\3\2\2\2Z\t\3\2\2\2[^"+
- "\5\16\b\2\\^\5\f\7\2][\3\2\2\2]\\\3\2\2\2^\13\3\2\2\2_`\5&\24\2`a\7\3"+
- "\2\2ab\5\n\6\2bh\3\2\2\2cd\5&\24\2de\7$\2\2ef\5\n\6\2fh\3\2\2\2g_\3\2"+
- "\2\2gc\3\2\2\2h\r\3\2\2\2ij\b\b\1\2jk\7\13\2\2kl\7\"\2\2lm\5\b\5\2mn\7"+
- "#\2\2nu\3\2\2\2op\7\"\2\2pq\5\b\5\2qr\7#\2\2ru\3\2\2\2su\5&\24\2ti\3\2"+
- "\2\2to\3\2\2\2ts\3\2\2\2u|\3\2\2\2vw\f\6\2\2wx\5\22\n\2xy\5\16\b\7y{\3"+
- "\2\2\2zv\3\2\2\2{~\3\2\2\2|z\3\2\2\2|}\3\2\2\2}\17\3\2\2\2~|\3\2\2\2\177"+
- "\u0080\5&\24\2\u0080\21\3\2\2\2\u0081\u0082\t\2\2\2\u0082\23\3\2\2\2\u0083"+
- "\u0084\7\"\2\2\u0084\u0085\5\26\f\2\u0085\u0086\7#\2\2\u0086\u008a\3\2"+
- "\2\2\u0087\u0088\7\"\2\2\u0088\u008a\7#\2\2\u0089\u0083\3\2\2\2\u0089"+
- "\u0087\3\2\2\2\u008a\25\3\2\2\2\u008b\u008c\b\f\1\2\u008c\u008f\5&\24"+
- "\2\u008d\u008f\5\6\4\2\u008e\u008b\3\2\2\2\u008e\u008d\3\2\2\2\u008f\u0098"+
- "\3\2\2\2\u0090\u0091\f\5\2\2\u0091\u0092\7\7\2\2\u0092\u0097\5&\24\2\u0093"+
- "\u0094\f\3\2\2\u0094\u0095\7\7\2\2\u0095\u0097\5\6\4\2\u0096\u0090\3\2"+
- "\2\2\u0096\u0093\3\2\2\2\u0097\u009a\3\2\2\2\u0098\u0096\3\2\2\2\u0098"+
- "\u0099\3\2\2\2\u0099\27\3\2\2\2\u009a\u0098\3\2\2\2\u009b\u009c\7 \2\2"+
- "\u009c\u00a2\7!\2\2\u009d\u009e\7 \2\2\u009e\u009f\5\26\f\2\u009f\u00a0"+
- "\7!\2\2\u00a0\u00a2\3\2\2\2\u00a1\u009b\3\2\2\2\u00a1\u009d\3\2\2\2\u00a2"+
- "\31\3\2\2\2\u00a3\u00a4\b\16\1\2\u00a4\u00a5\5&\24\2\u00a5\u00a6\7\25"+
- "\2\2\u00a6\u00a7\5\4\3\2\u00a7\u00b0\3\2\2\2\u00a8\u00a9\f\3\2\2\u00a9"+
- "\u00aa\7\7\2\2\u00aa\u00ab\5&\24\2\u00ab\u00ac\7\25\2\2\u00ac\u00ad\5"+
- "\4\3\2\u00ad\u00af\3\2\2\2\u00ae\u00a8\3\2\2\2\u00af\u00b2\3\2\2\2\u00b0"+
- "\u00ae\3\2\2\2\u00b0\u00b1\3\2\2\2\u00b1\33\3\2\2\2\u00b2\u00b0\3\2\2"+
- "\2\u00b3\u00b4\7\36\2\2\u00b4\u00b5\5\32\16\2\u00b5\u00b6\7\37\2\2\u00b6"+
- "\u00ba\3\2\2\2\u00b7\u00b8\7\36\2\2\u00b8\u00ba\7\37\2\2\u00b9\u00b3\3"+
- "\2\2\2\u00b9\u00b7\3\2\2\2\u00ba\35\3\2\2\2\u00bb\u00bc\b\20\1\2\u00bc"+
- "\u00bd\5 \21\2\u00bd\u00c6\3\2\2\2\u00be\u00bf\f\4\2\2\u00bf\u00c0\7\33"+
- "\2\2\u00c0\u00c5\5 \21\2\u00c1\u00c2\f\3\2\2\u00c2\u00c3\7\32\2\2\u00c3"+
- "\u00c5\5 \21\2\u00c4\u00be\3\2\2\2\u00c4\u00c1\3\2\2\2\u00c5\u00c8\3\2"+
- "\2\2\u00c6\u00c4\3\2\2\2\u00c6\u00c7\3\2\2\2\u00c7\37\3\2\2\2\u00c8\u00c6"+
- "\3\2\2\2\u00c9\u00ca\b\21\1\2\u00ca\u00cb\5$\23\2\u00cb\u00d4\3\2\2\2"+
- "\u00cc\u00cd\f\4\2\2\u00cd\u00ce\7\35\2\2\u00ce\u00d3\5 \21\5\u00cf\u00d0"+
- "\f\3\2\2\u00d0\u00d1\7\34\2\2\u00d1\u00d3\5 \21\4\u00d2\u00cc\3\2\2\2"+
- "\u00d2\u00cf\3\2\2\2\u00d3\u00d6\3\2\2\2\u00d4\u00d2\3\2\2\2\u00d4\u00d5"+
- "\3\2\2\2\u00d5!\3\2\2\2\u00d6\u00d4\3\2\2\2\u00d7\u00d8\7+\2\2\u00d8\u00d9"+
- "\5\24\13\2\u00d9#\3\2\2\2\u00da\u00e9\5\"\22\2\u00db\u00e9\7(\2\2\u00dc"+
- "\u00e9\7\'\2\2\u00dd\u00e9\7*\2\2\u00de\u00e9\7)\2\2\u00df\u00e9\7+\2"+
- "\2\u00e0\u00e1\7\"\2\2\u00e1\u00e2\5\36\20\2\u00e2\u00e3\7#\2\2\u00e3"+
- "\u00e9\3\2\2\2\u00e4\u00e5\7\"\2\2\u00e5\u00e6\5\6\4\2\u00e6\u00e7\7#"+
- "\2\2\u00e7\u00e9\3\2\2\2\u00e8\u00da\3\2\2\2\u00e8\u00db\3\2\2\2\u00e8"+
- "\u00dc\3\2\2\2\u00e8\u00dd\3\2\2\2\u00e8\u00de\3\2\2\2\u00e8\u00df\3\2"+
- "\2\2\u00e8\u00e0\3\2\2\2\u00e8\u00e4\3\2\2\2\u00e9%\3\2\2\2\u00ea\u00fb"+
- "\t\3\2\2\u00eb\u00fb\5*\26\2\u00ec\u00fb\5(\25\2\u00ed\u00fb\5\36\20\2"+
- "\u00ee\u00fb\7,\2\2\u00ef\u00fb\5\30\r\2\u00f0\u00fb\5\34\17\2\u00f1\u00fb"+
- "\7\31\2\2\u00f2\u00f3\7%\2\2\u00f3\u00f4\7\"\2\2\u00f4\u00f5\7+\2\2\u00f5"+
- "\u00fb\7#\2\2\u00f6\u00f7\7\"\2\2\u00f7\u00f8\5\6\4\2\u00f8\u00f9\7#\2"+
- "\2\u00f9\u00fb\3\2\2\2\u00fa\u00ea\3\2\2\2\u00fa\u00eb\3\2\2\2\u00fa\u00ec"+
- "\3\2\2\2\u00fa\u00ed\3\2\2\2\u00fa\u00ee\3\2\2\2\u00fa\u00ef\3\2\2\2\u00fa"+
- "\u00f0\3\2\2\2\u00fa\u00f1\3\2\2\2\u00fa\u00f2\3\2\2\2\u00fa\u00f6\3\2"+
- "\2\2\u00fb\'\3\2\2\2\u00fc\u00fd\7\"\2\2\u00fd\u00fe\7#\2\2\u00fe\u00ff"+
- "\7\4\2\2\u00ff\u0100\5\4\3\2\u0100)\3\2\2\2\u0101\u0102\7\"\2\2\u0102"+
- "\u0103\5,\27\2\u0103\u0104\7#\2\2\u0104\u0105\7\4\2\2\u0105\u0106\5\4"+
- "\3\2\u0106\u010c\3\2\2\2\u0107\u0108\5.\30\2\u0108\u0109\7\4\2\2\u0109"+
- "\u010a\5\4\3\2\u010a\u010c\3\2\2\2\u010b\u0101\3\2\2\2\u010b\u0107\3\2"+
- "\2\2\u010c+\3\2\2\2\u010d\u0112\5\60\31\2\u010e\u010f\7\7\2\2\u010f\u0111"+
- "\5\60\31\2\u0110\u010e\3\2\2\2\u0111\u0114\3\2\2\2\u0112\u0110\3\2\2\2"+
- "\u0112\u0113\3\2\2\2\u0113-\3\2\2\2\u0114\u0112\3\2\2\2\u0115\u0116\5"+
- "\60\31\2\u0116/\3\2\2\2\u0117\u0118\7+\2\2\u0118\61\3\2\2\2\30?NY]gt|"+
- "\u0089\u008e\u0096\u0098\u00a1\u00b0\u00b9\u00c4\u00c6\u00d2\u00d4\u00e8"+
- "\u00fa\u010b\u0112";
+ "\4\32\t\32\4\33\t\33\4\34\t\34\3\2\3\2\3\2\3\3\3\3\3\3\3\3\3\3\3\3\3\3"+
+ "\3\3\3\3\3\3\5\3F\n\3\3\4\3\4\3\5\3\5\3\6\3\6\3\7\3\7\3\7\3\7\3\7\3\7"+
+ "\3\7\3\7\3\7\3\7\3\7\3\7\3\7\5\7[\n\7\3\b\3\b\3\b\3\b\3\b\3\b\3\b\3\b"+
+ "\3\b\5\bf\n\b\3\t\3\t\5\tj\n\t\3\n\3\n\3\n\3\n\3\n\3\n\3\n\3\n\5\nt\n"+
+ "\n\3\13\3\13\3\13\3\13\3\13\3\13\3\13\3\13\3\13\3\13\3\13\5\13\u0081\n"+
+ "\13\3\13\3\13\3\13\3\13\7\13\u0087\n\13\f\13\16\13\u008a\13\13\3\f\3\f"+
+ "\3\r\3\r\3\16\3\16\3\16\3\16\3\16\3\16\5\16\u0096\n\16\3\17\3\17\3\17"+
+ "\5\17\u009b\n\17\3\17\3\17\3\17\3\17\3\17\3\17\7\17\u00a3\n\17\f\17\16"+
+ "\17\u00a6\13\17\3\20\3\20\3\20\3\20\3\20\3\20\5\20\u00ae\n\20\3\21\3\21"+
+ "\3\21\3\21\3\21\3\21\3\21\3\21\3\21\3\21\3\21\7\21\u00bb\n\21\f\21\16"+
+ "\21\u00be\13\21\3\22\3\22\3\22\3\22\3\22\3\22\5\22\u00c6\n\22\3\23\3\23"+
+ "\3\23\3\23\3\23\3\23\3\23\3\23\3\23\7\23\u00d1\n\23\f\23\16\23\u00d4\13"+
+ "\23\3\24\3\24\3\24\3\24\3\24\3\24\3\24\3\24\3\24\7\24\u00df\n\24\f\24"+
+ "\16\24\u00e2\13\24\3\25\3\25\3\25\3\26\3\26\3\26\3\26\3\26\3\26\3\26\3"+
+ "\26\3\26\3\26\3\26\3\26\3\26\3\26\5\26\u00f5\n\26\3\27\3\27\3\27\3\27"+
+ "\3\27\3\27\3\27\3\27\3\27\3\27\3\27\3\27\3\27\3\27\3\27\3\27\5\27\u0107"+
+ "\n\27\3\30\3\30\3\30\3\30\3\30\3\31\3\31\3\31\3\31\3\31\3\31\3\31\3\31"+
+ "\3\31\3\31\5\31\u0118\n\31\3\32\3\32\3\32\7\32\u011d\n\32\f\32\16\32\u0120"+
+ "\13\32\3\33\3\33\3\34\3\34\3\34\2\7\24\34 $&\35\2\4\6\b\n\f\16\20\22\24"+
+ "\26\30\32\34\36 \"$&(*,.\60\62\64\66\2\4\3\2\16\23\3\2\f\r\u0135\28\3"+
+ "\2\2\2\4E\3\2\2\2\6G\3\2\2\2\bI\3\2\2\2\nK\3\2\2\2\fZ\3\2\2\2\16e\3\2"+
+ "\2\2\20i\3\2\2\2\22s\3\2\2\2\24\u0080\3\2\2\2\26\u008b\3\2\2\2\30\u008d"+
+ "\3\2\2\2\32\u0095\3\2\2\2\34\u009a\3\2\2\2\36\u00ad\3\2\2\2 \u00af\3\2"+
+ "\2\2\"\u00c5\3\2\2\2$\u00c7\3\2\2\2&\u00d5\3\2\2\2(\u00e3\3\2\2\2*\u00f4"+
+ "\3\2\2\2,\u0106\3\2\2\2.\u0108\3\2\2\2\60\u0117\3\2\2\2\62\u0119\3\2\2"+
+ "\2\64\u0121\3\2\2\2\66\u0123\3\2\2\289\5\4\3\29:\7\2\2\3:\3\3\2\2\2;F"+
+ "\5\f\7\2<=\7\"\2\2=>\5\4\3\2>?\7#\2\2?F\3\2\2\2@F\5$\23\2AF\5\26\f\2B"+
+ "F\5\24\13\2CF\5\16\b\2DF\5\22\n\2E;\3\2\2\2E<\3\2\2\2E@\3\2\2\2EA\3\2"+
+ "\2\2EB\3\2\2\2EC\3\2\2\2ED\3\2\2\2F\5\3\2\2\2GH\5\16\b\2H\7\3\2\2\2IJ"+
+ "\5\4\3\2J\t\3\2\2\2KL\5\4\3\2L\13\3\2\2\2MN\5\6\4\2NO\7\24\2\2OP\5\b\5"+
+ "\2PQ\7\25\2\2QR\5\n\6\2R[\3\2\2\2ST\7\26\2\2TU\5\6\4\2UV\7\27\2\2VW\5"+
+ "\b\5\2WX\7\30\2\2XY\5\n\6\2Y[\3\2\2\2ZM\3\2\2\2ZS\3\2\2\2[\r\3\2\2\2\\"+
+ "]\5\20\t\2]^\7\t\2\2^_\5\16\b\2_f\3\2\2\2`a\5\20\t\2ab\7\n\2\2bc\5\16"+
+ "\b\2cf\3\2\2\2df\5\20\t\2e\\\3\2\2\2e`\3\2\2\2ed\3\2\2\2f\17\3\2\2\2g"+
+ "j\5\24\13\2hj\5\22\n\2ig\3\2\2\2ih\3\2\2\2j\21\3\2\2\2kl\5,\27\2lm\7\3"+
+ "\2\2mn\5\20\t\2nt\3\2\2\2op\5,\27\2pq\7$\2\2qr\5\20\t\2rt\3\2\2\2sk\3"+
+ "\2\2\2so\3\2\2\2t\23\3\2\2\2uv\b\13\1\2vw\7\13\2\2wx\7\"\2\2xy\5\16\b"+
+ "\2yz\7#\2\2z\u0081\3\2\2\2{|\7\"\2\2|}\5\16\b\2}~\7#\2\2~\u0081\3\2\2"+
+ "\2\177\u0081\5,\27\2\u0080u\3\2\2\2\u0080{\3\2\2\2\u0080\177\3\2\2\2\u0081"+
+ "\u0088\3\2\2\2\u0082\u0083\f\6\2\2\u0083\u0084\5\30\r\2\u0084\u0085\5"+
+ "\24\13\7\u0085\u0087\3\2\2\2\u0086\u0082\3\2\2\2\u0087\u008a\3\2\2\2\u0088"+
+ "\u0086\3\2\2\2\u0088\u0089\3\2\2\2\u0089\25\3\2\2\2\u008a\u0088\3\2\2"+
+ "\2\u008b\u008c\5,\27\2\u008c\27\3\2\2\2\u008d\u008e\t\2\2\2\u008e\31\3"+
+ "\2\2\2\u008f\u0090\7\"\2\2\u0090\u0091\5\34\17\2\u0091\u0092\7#\2\2\u0092"+
+ "\u0096\3\2\2\2\u0093\u0094\7\"\2\2\u0094\u0096\7#\2\2\u0095\u008f\3\2"+
+ "\2\2\u0095\u0093\3\2\2\2\u0096\33\3\2\2\2\u0097\u0098\b\17\1\2\u0098\u009b"+
+ "\5,\27\2\u0099\u009b\5\f\7\2\u009a\u0097\3\2\2\2\u009a\u0099\3\2\2\2\u009b"+
+ "\u00a4\3\2\2\2\u009c\u009d\f\5\2\2\u009d\u009e\7\7\2\2\u009e\u00a3\5,"+
+ "\27\2\u009f\u00a0\f\3\2\2\u00a0\u00a1\7\7\2\2\u00a1\u00a3\5\f\7\2\u00a2"+
+ "\u009c\3\2\2\2\u00a2\u009f\3\2\2\2\u00a3\u00a6\3\2\2\2\u00a4\u00a2\3\2"+
+ "\2\2\u00a4\u00a5\3\2\2\2\u00a5\35\3\2\2\2\u00a6\u00a4\3\2\2\2\u00a7\u00a8"+
+ "\7 \2\2\u00a8\u00ae\7!\2\2\u00a9\u00aa\7 \2\2\u00aa\u00ab\5\34\17\2\u00ab"+
+ "\u00ac\7!\2\2\u00ac\u00ae\3\2\2\2\u00ad\u00a7\3\2\2\2\u00ad\u00a9\3\2"+
+ "\2\2\u00ae\37\3\2\2\2\u00af\u00b0\b\21\1\2\u00b0\u00b1\5,\27\2\u00b1\u00b2"+
+ "\7\25\2\2\u00b2\u00b3\5\4\3\2\u00b3\u00bc\3\2\2\2\u00b4\u00b5\f\3\2\2"+
+ "\u00b5\u00b6\7\7\2\2\u00b6\u00b7\5,\27\2\u00b7\u00b8\7\25\2\2\u00b8\u00b9"+
+ "\5\4\3\2\u00b9\u00bb\3\2\2\2\u00ba\u00b4\3\2\2\2\u00bb\u00be\3\2\2\2\u00bc"+
+ "\u00ba\3\2\2\2\u00bc\u00bd\3\2\2\2\u00bd!\3\2\2\2\u00be\u00bc\3\2\2\2"+
+ "\u00bf\u00c0\7\36\2\2\u00c0\u00c1\5 \21\2\u00c1\u00c2\7\37\2\2\u00c2\u00c6"+
+ "\3\2\2\2\u00c3\u00c4\7\36\2\2\u00c4\u00c6\7\37\2\2\u00c5\u00bf\3\2\2\2"+
+ "\u00c5\u00c3\3\2\2\2\u00c6#\3\2\2\2\u00c7\u00c8\b\23\1\2\u00c8\u00c9\5"+
+ "&\24\2\u00c9\u00d2\3\2\2\2\u00ca\u00cb\f\4\2\2\u00cb\u00cc\7\33\2\2\u00cc"+
+ "\u00d1\5&\24\2\u00cd\u00ce\f\3\2\2\u00ce\u00cf\7\32\2\2\u00cf\u00d1\5"+
+ "&\24\2\u00d0\u00ca\3\2\2\2\u00d0\u00cd\3\2\2\2\u00d1\u00d4\3\2\2\2\u00d2"+
+ "\u00d0\3\2\2\2\u00d2\u00d3\3\2\2\2\u00d3%\3\2\2\2\u00d4\u00d2\3\2\2\2"+
+ "\u00d5\u00d6\b\24\1\2\u00d6\u00d7\5*\26\2\u00d7\u00e0\3\2\2\2\u00d8\u00d9"+
+ "\f\4\2\2\u00d9\u00da\7\35\2\2\u00da\u00df\5&\24\5\u00db\u00dc\f\3\2\2"+
+ "\u00dc\u00dd\7\34\2\2\u00dd\u00df\5&\24\4\u00de\u00d8\3\2\2\2\u00de\u00db"+
+ "\3\2\2\2\u00df\u00e2\3\2\2\2\u00e0\u00de\3\2\2\2\u00e0\u00e1\3\2\2\2\u00e1"+
+ "\'\3\2\2\2\u00e2\u00e0\3\2\2\2\u00e3\u00e4\7+\2\2\u00e4\u00e5\5\32\16"+
+ "\2\u00e5)\3\2\2\2\u00e6\u00f5\5(\25\2\u00e7\u00f5\7(\2\2\u00e8\u00f5\7"+
+ "\'\2\2\u00e9\u00f5\7*\2\2\u00ea\u00f5\7)\2\2\u00eb\u00f5\7+\2\2\u00ec"+
+ "\u00ed\7\"\2\2\u00ed\u00ee\5$\23\2\u00ee\u00ef\7#\2\2\u00ef\u00f5\3\2"+
+ "\2\2\u00f0\u00f1\7\"\2\2\u00f1\u00f2\5\f\7\2\u00f2\u00f3\7#\2\2\u00f3"+
+ "\u00f5\3\2\2\2\u00f4\u00e6\3\2\2\2\u00f4\u00e7\3\2\2\2\u00f4\u00e8\3\2"+
+ "\2\2\u00f4\u00e9\3\2\2\2\u00f4\u00ea\3\2\2\2\u00f4\u00eb\3\2\2\2\u00f4"+
+ "\u00ec\3\2\2\2\u00f4\u00f0\3\2\2\2\u00f5+\3\2\2\2\u00f6\u0107\t\3\2\2"+
+ "\u00f7\u0107\5\60\31\2\u00f8\u0107\5.\30\2\u00f9\u0107\5$\23\2\u00fa\u0107"+
+ "\7,\2\2\u00fb\u0107\5\36\20\2\u00fc\u0107\5\"\22\2\u00fd\u0107\7\31\2"+
+ "\2\u00fe\u00ff\7%\2\2\u00ff\u0100\7\"\2\2\u0100\u0101\7+\2\2\u0101\u0107"+
+ "\7#\2\2\u0102\u0103\7\"\2\2\u0103\u0104\5\f\7\2\u0104\u0105\7#\2\2\u0105"+
+ "\u0107\3\2\2\2\u0106\u00f6\3\2\2\2\u0106\u00f7\3\2\2\2\u0106\u00f8\3\2"+
+ "\2\2\u0106\u00f9\3\2\2\2\u0106\u00fa\3\2\2\2\u0106\u00fb\3\2\2\2\u0106"+
+ "\u00fc\3\2\2\2\u0106\u00fd\3\2\2\2\u0106\u00fe\3\2\2\2\u0106\u0102\3\2"+
+ "\2\2\u0107-\3\2\2\2\u0108\u0109\7\"\2\2\u0109\u010a\7#\2\2\u010a\u010b"+
+ "\7\4\2\2\u010b\u010c\5\4\3\2\u010c/\3\2\2\2\u010d\u010e\7\"\2\2\u010e"+
+ "\u010f\5\62\32\2\u010f\u0110\7#\2\2\u0110\u0111\7\4\2\2\u0111\u0112\5"+
+ "\4\3\2\u0112\u0118\3\2\2\2\u0113\u0114\5\64\33\2\u0114\u0115\7\4\2\2\u0115"+
+ "\u0116\5\4\3\2\u0116\u0118\3\2\2\2\u0117\u010d\3\2\2\2\u0117\u0113\3\2"+
+ "\2\2\u0118\61\3\2\2\2\u0119\u011e\5\66\34\2\u011a\u011b\7\7\2\2\u011b"+
+ "\u011d\5\66\34\2\u011c\u011a\3\2\2\2\u011d\u0120\3\2\2\2\u011e\u011c\3"+
+ "\2\2\2\u011e\u011f\3\2\2\2\u011f\63\3\2\2\2\u0120\u011e\3\2\2\2\u0121"+
+ "\u0122\5\66\34\2\u0122\65\3\2\2\2\u0123\u0124\7+\2\2\u0124\67\3\2\2\2"+
+ "\30EZeis\u0080\u0088\u0095\u009a\u00a2\u00a4\u00ad\u00bc\u00c5\u00d0\u00d2"+
+ "\u00de\u00e0\u00f4\u0106\u0117\u011e";
public static final ATN _ATN =
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
static {
http://git-wip-us.apache.org/repos/asf/metron/blob/30d0e2a6/metron-platform/metron-common/src/test/java/org/apache/metron/common/dsl/functions/FunctionalFunctionsTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/dsl/functions/FunctionalFunctionsTest.java b/metron-platform/metron-common/src/test/java/org/apache/metron/common/dsl/functions/FunctionalFunctionsTest.java
index bd70a33..81a9adc 100644
--- a/metron-platform/metron-common/src/test/java/org/apache/metron/common/dsl/functions/FunctionalFunctionsTest.java
+++ b/metron-platform/metron-common/src/test/java/org/apache/metron/common/dsl/functions/FunctionalFunctionsTest.java
@@ -71,6 +71,8 @@ public class FunctionalFunctionsTest {
, "MAP([ foo, 'bar'], (x) -> TO_UPPER(x) )"
, "MAP([ foo, bar], (x) -> TO_UPPER(x) )"
, "MAP([ foo, bar], x -> TO_UPPER(x) )"
+ , "MAP([ foo, bar], x -> true?TO_UPPER(x):THROW('error') )"
+ , "MAP([ foo, bar], x -> false?THROW('error'):TO_UPPER(x) )"
)
)
{
@@ -123,6 +125,21 @@ public class FunctionalFunctionsTest {
@Test
+ public void testFilter_shortcircuit() {
+ for (String expr : ImmutableList.of("FILTER([ 'foo'], item -> item == 'foo' or THROW('exception') )"
+ ,"FILTER([ 'foo'], (item) -> item == 'foo' or THROW('exception') )"
+ )
+ )
+ {
+ Object o = run(expr, ImmutableMap.of("foo", "foo", "bar", "bar"));
+ Assert.assertTrue(o instanceof List);
+ List<String> result = (List<String>) o;
+ Assert.assertEquals(1, result.size());
+ Assert.assertEquals("foo", result.get(0));
+ }
+ }
+
+ @Test
public void testFilter_null() {
for (String expr : ImmutableList.of("FILTER([ 'foo', null], item -> item == null )"
,"FILTER([ 'foo', baz], (item) -> item == null )"
http://git-wip-us.apache.org/repos/asf/metron/blob/30d0e2a6/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/StellarInterpreterTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/StellarInterpreterTest.java b/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/StellarInterpreterTest.java
index b25f0a7..39563f7 100644
--- a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/StellarInterpreterTest.java
+++ b/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/StellarInterpreterTest.java
@@ -77,9 +77,9 @@ public class StellarInterpreterTest {
StellarParser.IntLiteralContext ctx = mock(StellarParser.IntLiteralContext.class);
Token result = mock(Token.class);
when(ctx.getText()).thenReturn("1000");
- when(numberLiteralEvaluator.evaluate(ctx)).thenReturn(result);
+ when(numberLiteralEvaluator.evaluate(ctx, null)).thenReturn(result);
compiler.exitIntLiteral(ctx);
- verify(numberLiteralEvaluator).evaluate(ctx);
+ verify(numberLiteralEvaluator).evaluate(ctx, null);
Assert.assertEquals(1, tokenStack.size());
Assert.assertEquals(tokenStack.getFirst(), result);
verifyZeroInteractions(variableResolver);
@@ -93,12 +93,12 @@ public class StellarInterpreterTest {
public void exitDoubleLiteralShouldProperlyParseStringsAsDoubles() throws Exception {
StellarParser.DoubleLiteralContext ctx = mock(StellarParser.DoubleLiteralContext.class);
Token result = mock(Token.class);
- when(numberLiteralEvaluator.evaluate(ctx)).thenReturn(result);
+ when(numberLiteralEvaluator.evaluate(ctx, null)).thenReturn(result);
when(ctx.getText()).thenReturn("1000D");
compiler.exitDoubleLiteral(ctx);
- verify(numberLiteralEvaluator).evaluate(ctx);
+ verify(numberLiteralEvaluator).evaluate(ctx, null);
Assert.assertEquals(1, tokenStack.size());
Assert.assertEquals(tokenStack.getFirst(), result);
verifyZeroInteractions(variableResolver);
@@ -113,11 +113,11 @@ public class StellarInterpreterTest {
StellarParser.FloatLiteralContext ctx = mock(StellarParser.FloatLiteralContext.class);
when(ctx.getText()).thenReturn("1000f");
Token result = mock(Token.class);
- when(numberLiteralEvaluator.evaluate(ctx)).thenReturn(result);
+ when(numberLiteralEvaluator.evaluate(ctx, null)).thenReturn(result);
compiler.exitFloatLiteral(ctx);
- verify(numberLiteralEvaluator).evaluate(ctx);
+ verify(numberLiteralEvaluator).evaluate(ctx, null);
Assert.assertEquals(1, tokenStack.size());
Assert.assertEquals(tokenStack.getFirst(), result);
verifyZeroInteractions(variableResolver);
@@ -132,11 +132,11 @@ public class StellarInterpreterTest {
StellarParser.LongLiteralContext ctx = mock(StellarParser.LongLiteralContext.class);
when(ctx.getText()).thenReturn("1000l");
Token result = mock(Token.class);
- when(numberLiteralEvaluator.evaluate(ctx)).thenReturn(result);
+ when(numberLiteralEvaluator.evaluate(ctx, null)).thenReturn(result);
compiler.exitLongLiteral(ctx);
- verify(numberLiteralEvaluator).evaluate(ctx);
+ verify(numberLiteralEvaluator).evaluate(ctx, null);
Assert.assertEquals(1, tokenStack.size());
Assert.assertEquals(tokenStack.getFirst(), result);
verifyZeroInteractions(variableResolver);
@@ -152,17 +152,17 @@ public class StellarInterpreterTest {
StellarParser.ComparisonOpContext mockOp = mock(StellarParser.ComparisonOpContext.class);
when(ctx.comp_operator()).thenReturn(mockOp);
Token result = mock(Token.class);
- when(comparisonExpressionWithOperatorEvaluator.evaluate(any(Token.class), any(Token.class), any(StellarParser.ComparisonOpContext.class))).thenReturn(result);
+ when(comparisonExpressionWithOperatorEvaluator.evaluate(any(Token.class), any(Token.class), any(StellarParser.ComparisonOpContext.class), any())).thenReturn(result);
compiler.exitComparisonExpressionWithOperator(ctx);
Assert.assertEquals(1, tokenStack.size());
StellarCompiler.DeferredFunction func = (StellarCompiler.DeferredFunction) tokenStack.pop().getValue();
- tokenStack.push(new Token<>(1000, Integer.class));
- tokenStack.push(new Token<>(1500f, Float.class));
+ tokenStack.push(new Token<>(1000, Integer.class, null));
+ tokenStack.push(new Token<>(1500f, Float.class, null));
func.apply(tokenStack, new StellarCompiler.ExpressionState(context, functionResolver, variableResolver));
Assert.assertEquals(1, tokenStack.size());
Assert.assertEquals(tokenStack.getFirst(), result);
- verify(comparisonExpressionWithOperatorEvaluator).evaluate(any(Token.class), any(Token.class), eq(mockOp));
+ verify(comparisonExpressionWithOperatorEvaluator).evaluate(any(Token.class), any(Token.class), eq(mockOp), any());
verifyZeroInteractions(numberLiteralEvaluator);
verifyZeroInteractions(variableResolver);
verifyZeroInteractions(functionResolver);
http://git-wip-us.apache.org/repos/asf/metron/blob/30d0e2a6/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/StellarTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/StellarTest.java b/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/StellarTest.java
index d7a33d4..98abd57 100644
--- a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/StellarTest.java
+++ b/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/StellarTest.java
@@ -18,13 +18,11 @@
package org.apache.metron.common.stellar;
+import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import org.apache.commons.lang3.StringUtils;
-import org.apache.metron.common.dsl.ParseException;
-import org.apache.metron.common.dsl.Stellar;
-import org.apache.metron.common.dsl.StellarFunction;
-import org.apache.metron.common.dsl.StellarFunctions;
+import org.apache.metron.common.dsl.*;
import org.apache.metron.common.dsl.functions.resolver.ClasspathFunctionResolver;
import org.junit.Assert;
import org.junit.Rule;
@@ -33,12 +31,7 @@ import org.junit.rules.ExpectedException;
import org.reflections.Reflections;
import org.reflections.util.ConfigurationBuilder;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
+import java.util.*;
import static org.apache.metron.common.utils.StellarProcessorUtils.run;
import static org.apache.metron.common.utils.StellarProcessorUtils.runPredicate;
@@ -46,6 +39,58 @@ import static org.apache.metron.common.utils.StellarProcessorUtils.runPredicate;
@SuppressWarnings("ALL")
public class StellarTest {
+ @Stellar(
+ description="throw exception",
+ name="THROW",
+ params = {
+ "message - exception message"
+ },
+ returns="nothing"
+ )
+ public static class Throw implements StellarFunction {
+
+ @Override
+ public Object apply(List<Object> args, Context context) throws ParseException {
+ throw new IllegalStateException(Joiner.on(" ").join(args));
+ }
+
+ @Override
+ public void initialize(Context context) {
+
+ }
+
+ @Override
+ public boolean isInitialized() {
+ return true;
+ }
+ }
+
+ @Stellar(
+ description="Always returns true",
+ name="RET_TRUE",
+ params = {
+ "arg* - Any set of args you wish to give it (including the empty set), they're ignored."
+ },
+ returns="true"
+ )
+ public static class TrueFunc implements StellarFunction {
+
+ @Override
+ public Object apply(List<Object> args, Context context) throws ParseException {
+ return true;
+ }
+
+ @Override
+ public void initialize(Context context) {
+
+ }
+
+ @Override
+ public boolean isInitialized() {
+ return true;
+ }
+ }
+
@Test
public void ensureDocumentation() {
ClassLoader classLoader = getClass().getClassLoader();
@@ -634,6 +679,42 @@ public class StellarTest {
Assert.assertTrue(runPredicate("not(IN_SUBNET(ip_dst_addr, '192.168.0.0/24'))", v-> variableMap.get(v)));
}
+ @Test
+ public void testShortCircuit_conditional() throws Exception {
+ Assert.assertEquals("foo", run("if true then 'foo' else (if false then 'bar' else 'grok')", new HashMap<>()));
+ Assert.assertEquals("foo", run("if true_var != null && true_var then 'foo' else (if false then 'bar' else 'grok')", ImmutableMap.of("true_var", true)));
+ Assert.assertEquals("foo", run("if true then 'foo' else THROW('expression')", new HashMap<>()));
+ Assert.assertEquals("foo", run("true ? 'foo' : THROW('expression')", new HashMap<>()));
+ Assert.assertEquals("foo", run("if false then THROW('exception') else 'foo'", new HashMap<>()));
+ Assert.assertEquals("foo", run("false ? THROW('exception') : 'foo'", new HashMap<>()));
+ Assert.assertEquals(true, run("RET_TRUE(if true then 'foo' else THROW('expression'))", new HashMap<>()));
+ Assert.assertEquals("foo", run("if true or (true or THROW('if exception')) then 'foo' else THROW('expression')", new HashMap<>()));
+ Assert.assertEquals("foo", run("if true or (false or THROW('if exception')) then 'foo' else THROW('expression')", new HashMap<>()));
+ Assert.assertEquals("foo", run("if NOT(true or (false or THROW('if exception'))) then THROW('expression') else 'foo'", new HashMap<>()));
+ Assert.assertEquals("foo", run("if NOT('metron' in [ 'metron', 'metronicus'] ) then THROW('expression') else 'foo'", new HashMap<>()));
+ }
+
+ @Test
+ public void testShortCircuit_boolean() throws Exception {
+ Assert.assertTrue(runPredicate("'metron' in ['metron', 'metronicus', 'mortron'] or (true or THROW('exception'))", x -> null));
+ Assert.assertTrue(runPredicate("true or (true or THROW('exception'))", x -> null));
+ Assert.assertTrue(runPredicate("true or (false or THROW('exception'))", x -> null));
+ Assert.assertTrue(runPredicate("TO_UPPER('foo') == 'FOO' or (true or THROW('exception'))", x -> null));
+ Assert.assertFalse(runPredicate("false and (true or THROW('exception'))", x -> null));
+ Assert.assertTrue(runPredicate("true or false or false or true", x -> null));
+ Assert.assertFalse(runPredicate("false or (false and THROW('exception'))", x -> null));
+ Assert.assertTrue(runPredicate("'casey' == 'casey' or THROW('exception')", x -> null));
+ Assert.assertTrue(runPredicate("TO_UPPER('casey') == 'CASEY' or THROW('exception')", x -> null));
+ Assert.assertTrue(runPredicate("NOT(TO_UPPER('casey') != 'CASEY') or THROW('exception')", x -> null));
+ Assert.assertTrue(runPredicate("(TO_UPPER('casey') == 'CASEY') or THROW('exception')", x -> null));
+ Assert.assertFalse(runPredicate("NOT(NOT(TO_UPPER('casey') != 'CASEY') or THROW('exception'))", x -> null));
+ Assert.assertFalse(runPredicate("NOT(NOT(TO_UPPER('casey') != 'CASEY')) and THROW('exception')", x -> null));
+ Assert.assertTrue(runPredicate("RET_TRUE('foo') or THROW('exception')", x -> null));
+ Assert.assertFalse(runPredicate("NOT(foo == null or THROW('exception')) and THROW('and exception')", x -> null));
+ Assert.assertTrue(runPredicate("(foo == null or THROW('exception') ) or THROW('and exception')", x -> null));
+ Assert.assertTrue(runPredicate("( RET_TRUE('foo', true, false) or ( foo == null or THROW('exception') ) or THROW('and exception')) or THROW('or exception')", x -> null));
+ }
+
@Rule
public ExpectedException thrown = ExpectedException.none();
http://git-wip-us.apache.org/repos/asf/metron/blob/30d0e2a6/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/ArithmeticEvaluatorTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/ArithmeticEvaluatorTest.java b/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/ArithmeticEvaluatorTest.java
index f914c3c..de9f722 100644
--- a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/ArithmeticEvaluatorTest.java
+++ b/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/ArithmeticEvaluatorTest.java
@@ -44,7 +44,7 @@ public class ArithmeticEvaluatorTest {
Pair<Token<? extends Number>, Token<? extends Number>> p = Pair.of(l, r);
- Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.addition(), p);
+ Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.addition(null), p);
assertTrue(evaluated.getValue() instanceof Double);
assertEquals(3.0D, evaluated.getValue());
@@ -60,7 +60,7 @@ public class ArithmeticEvaluatorTest {
Pair<Token<? extends Number>, Token<? extends Number>> p = Pair.of(l, r);
- Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.addition(), p);
+ Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.addition(null), p);
assertTrue(evaluated.getValue() instanceof Integer);
assertEquals(3, evaluated.getValue());
@@ -76,7 +76,7 @@ public class ArithmeticEvaluatorTest {
Pair<Token<? extends Number>, Token<? extends Number>> p = Pair.of(l, r);
- Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.addition(), p);
+ Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.addition(null), p);
assertTrue(evaluated.getValue() instanceof Float);
assertEquals(3F, evaluated.getValue());
@@ -92,7 +92,7 @@ public class ArithmeticEvaluatorTest {
Pair<Token<? extends Number>, Token<? extends Number>> p = Pair.of(l, r);
- Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.addition(), p);
+ Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.addition(null), p);
assertTrue(evaluated.getValue() instanceof Long);
assertEquals(3L, evaluated.getValue());
@@ -108,7 +108,7 @@ public class ArithmeticEvaluatorTest {
Pair<Token<? extends Number>, Token<? extends Number>> p = Pair.of(l, r);
- Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.multiplication(), p);
+ Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.multiplication(null), p);
assertTrue(evaluated.getValue() instanceof Double);
assertEquals(2.0D, evaluated.getValue());
@@ -124,7 +124,7 @@ public class ArithmeticEvaluatorTest {
Pair<Token<? extends Number>, Token<? extends Number>> p = Pair.of(l, r);
- Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.multiplication(), p);
+ Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.multiplication(null), p);
assertTrue(evaluated.getValue() instanceof Integer);
assertEquals(2, evaluated.getValue());
@@ -140,7 +140,7 @@ public class ArithmeticEvaluatorTest {
Pair<Token<? extends Number>, Token<? extends Number>> p = Pair.of(l, r);
- Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.multiplication(), p);
+ Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.multiplication(null), p);
assertTrue(evaluated.getValue() instanceof Float);
assertEquals(2F, evaluated.getValue());
@@ -156,7 +156,7 @@ public class ArithmeticEvaluatorTest {
Pair<Token<? extends Number>, Token<? extends Number>> p = Pair.of(l, r);
- Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.multiplication(), p);
+ Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.multiplication(null), p);
assertTrue(evaluated.getValue() instanceof Long);
assertEquals(2L, evaluated.getValue());
@@ -172,7 +172,7 @@ public class ArithmeticEvaluatorTest {
Pair<Token<? extends Number>, Token<? extends Number>> p = Pair.of(l, r);
- Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.subtraction(), p);
+ Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.subtraction(null), p);
assertTrue(evaluated.getValue() instanceof Double);
assertEquals(-1.0D, evaluated.getValue());
@@ -188,7 +188,7 @@ public class ArithmeticEvaluatorTest {
Pair<Token<? extends Number>, Token<? extends Number>> p = Pair.of(l, r);
- Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.subtraction(), p);
+ Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.subtraction(null), p);
assertTrue(evaluated.getValue() instanceof Integer);
assertEquals(-1, evaluated.getValue());
@@ -204,7 +204,7 @@ public class ArithmeticEvaluatorTest {
Pair<Token<? extends Number>, Token<? extends Number>> p = Pair.of(l, r);
- Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.subtraction(), p);
+ Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.subtraction(null), p);
assertTrue(evaluated.getValue() instanceof Float);
assertEquals(-1F, evaluated.getValue());
@@ -220,7 +220,7 @@ public class ArithmeticEvaluatorTest {
Pair<Token<? extends Number>, Token<? extends Number>> p = Pair.of(l, r);
- Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.subtraction(), p);
+ Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.subtraction(null), p);
assertTrue(evaluated.getValue() instanceof Long);
assertEquals(-1L, evaluated.getValue());
@@ -236,7 +236,7 @@ public class ArithmeticEvaluatorTest {
Pair<Token<? extends Number>, Token<? extends Number>> p = Pair.of(l, r);
- Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.division(), p);
+ Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.division(null), p);
assertTrue(evaluated.getValue() instanceof Double);
assertEquals(1 / 2D, evaluated.getValue());
@@ -252,7 +252,7 @@ public class ArithmeticEvaluatorTest {
Pair<Token<? extends Number>, Token<? extends Number>> p = Pair.of(l, r);
- Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.division(), p);
+ Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.division(null), p);
assertTrue(evaluated.getValue() instanceof Integer);
assertEquals(1 / 2, evaluated.getValue());
@@ -268,7 +268,7 @@ public class ArithmeticEvaluatorTest {
Pair<Token<? extends Number>, Token<? extends Number>> p = Pair.of(l, r);
- Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.division(), p);
+ Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.division(null), p);
assertTrue(evaluated.getValue() instanceof Float);
assertEquals(0.5F, evaluated.getValue());
@@ -284,7 +284,7 @@ public class ArithmeticEvaluatorTest {
Pair<Token<? extends Number>, Token<? extends Number>> p = Pair.of(l, r);
- Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.division(), p);
+ Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.division(null), p);
assertTrue(evaluated.getValue() instanceof Long);
assertEquals(0L, evaluated.getValue());
@@ -292,19 +292,19 @@ public class ArithmeticEvaluatorTest {
@Test(expected = IllegalArgumentException.class)
public void evaluateShouldThroughIllegalArgumentExceptionWhenInputIsNull() throws Exception {
- evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.division(), null);
+ evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.division(null), null);
}
@Test(expected = IllegalArgumentException.class)
public void evaluateShouldThroughIllegalArgumentExceptionWhenInputsKeyIsNull() throws Exception {
Pair<Token<? extends Number>, Token<? extends Number>> p = Pair.of(null, mock(Token.class));
- evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.division(), p);
+ evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.division(null), p);
}
@Test(expected = IllegalArgumentException.class)
public void evaluateShouldThroughIllegalArgumentExceptionWhenInputsValueIsNull() throws Exception {
Pair<Token<? extends Number>, Token<? extends Number>> p = Pair.of(mock(Token.class), null);
- evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.division(), p);
+ evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.division(null), p);
}
@Test
@@ -315,10 +315,10 @@ public class ArithmeticEvaluatorTest {
Token<Short> r = mock(Token.class);
when(r.getValue()).thenReturn((short) 3);
- Token<? extends Number> evaluated0 = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.addition(), Pair.of(l, r));
- Token<? extends Number> evaluated1 = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.subtraction(), Pair.of(l, r));
- Token<? extends Number> evaluated2 = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.multiplication(), Pair.of(l, r));
- Token<? extends Number> evaluated3 = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.division(), Pair.of(l, r));
+ Token<? extends Number> evaluated0 = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.addition(null), Pair.of(l, r));
+ Token<? extends Number> evaluated1 = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.subtraction(null), Pair.of(l, r));
+ Token<? extends Number> evaluated2 = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.multiplication(null), Pair.of(l, r));
+ Token<? extends Number> evaluated3 = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.division(null), Pair.of(l, r));
assertTrue(evaluated0.getValue() instanceof Integer);
assertEquals(5, evaluated0.getValue());
@@ -343,7 +343,7 @@ public class ArithmeticEvaluatorTest {
Pair<Token<? extends Number>, Token<? extends Number>> p = Pair.of(l, r);
- Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.addition(), p);
+ Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.addition(null), p);
assertTrue(evaluated.getValue() instanceof Integer);
assertEquals(2, evaluated.getValue());
@@ -359,7 +359,7 @@ public class ArithmeticEvaluatorTest {
Pair<Token<? extends Number>, Token<? extends Number>> p = Pair.of(l, r);
- Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.addition(), p);
+ Token<? extends Number> evaluated = evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.addition(null), p);
assertTrue(evaluated.getValue() instanceof Integer);
assertEquals(1, evaluated.getValue());
@@ -403,10 +403,10 @@ public class ArithmeticEvaluatorTest {
}};
expectedReturnTypeMappings.forEach( (pair, expectedClass) -> {
- assertTrue(evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.addition(), pair).getValue().getClass() == expectedClass);
- assertTrue(evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.division(), pair).getValue().getClass() == expectedClass);
- assertTrue(evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.subtraction(), pair).getValue().getClass() == expectedClass);
- assertTrue(evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.multiplication(), pair).getValue().getClass() == expectedClass);
+ assertTrue(evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.addition(null), pair).getValue().getClass() == expectedClass);
+ assertTrue(evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.division(null), pair).getValue().getClass() == expectedClass);
+ assertTrue(evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.subtraction(null), pair).getValue().getClass() == expectedClass);
+ assertTrue(evaluator.evaluate(ArithmeticEvaluator.ArithmeticEvaluatorFunctions.multiplication(null), pair).getValue().getClass() == expectedClass);
});
}
}
http://git-wip-us.apache.org/repos/asf/metron/blob/30d0e2a6/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/ComparisonExpressionWithOperatorEvaluatorTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/ComparisonExpressionWithOperatorEvaluatorTest.java b/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/ComparisonExpressionWithOperatorEvaluatorTest.java
index 612d311..0c20eb4 100644
--- a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/ComparisonExpressionWithOperatorEvaluatorTest.java
+++ b/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/ComparisonExpressionWithOperatorEvaluatorTest.java
@@ -54,7 +54,7 @@ public class ComparisonExpressionWithOperatorEvaluatorTest {
StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class);
when(op.EQ()).thenReturn(mock(TerminalNode.class));
- Token<Boolean> evaluated = evaluator.evaluate(left, right, op);
+ Token<Boolean> evaluated = evaluator.evaluate(left, right, op, null);
assertTrue(evaluated.getValue());
}
@@ -70,7 +70,7 @@ public class ComparisonExpressionWithOperatorEvaluatorTest {
StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class);
when(op.NEQ()).thenReturn(mock(TerminalNode.class));
- Token<Boolean> evaluated = evaluator.evaluate(left, right, op);
+ Token<Boolean> evaluated = evaluator.evaluate(left, right, op, null);
assertFalse(evaluated.getValue());
}
@@ -86,7 +86,7 @@ public class ComparisonExpressionWithOperatorEvaluatorTest {
StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class);
when(op.LTE()).thenReturn(mock(TerminalNode.class));
- Token<Boolean> evaluated = evaluator.evaluate(left, right, op);
+ Token<Boolean> evaluated = evaluator.evaluate(left, right, op, null);
assertTrue(evaluated.getValue());
}
@@ -104,7 +104,7 @@ public class ComparisonExpressionWithOperatorEvaluatorTest {
StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class);
- evaluator.evaluate(left, right, op);
+ evaluator.evaluate(left, right, op, null);
}
@Test
@@ -121,6 +121,6 @@ public class ComparisonExpressionWithOperatorEvaluatorTest {
StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class);
when(op.LTE()).thenReturn(mock(TerminalNode.class));
- evaluator.evaluate(left, right, op);
+ evaluator.evaluate(left, right, op, null);
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/metron/blob/30d0e2a6/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/DoubleLiteralEvaluatorTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/DoubleLiteralEvaluatorTest.java b/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/DoubleLiteralEvaluatorTest.java
index 6f2fd40..3386f3f 100644
--- a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/DoubleLiteralEvaluatorTest.java
+++ b/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/DoubleLiteralEvaluatorTest.java
@@ -45,8 +45,8 @@ public class DoubleLiteralEvaluatorTest {
public void verifyHappyPathEvaluation() throws Exception {
when(context.getText()).thenReturn("100D");
- Token<? extends Number> evaluated = evaluator.evaluate(context);
- assertEquals(new Token<>(100D, Double.class), evaluated);
+ Token<? extends Number> evaluated = evaluator.evaluate(context, null);
+ assertEquals(new Token<>(100D, Double.class, null), evaluated);
verify(context).getText();
verifyNoMoreInteractions(context);
@@ -57,7 +57,7 @@ public class DoubleLiteralEvaluatorTest {
exception.expect(NumberFormatException.class);
when(context.getText()).thenReturn("");
- evaluator.evaluate(context);
+ evaluator.evaluate(context, null);
}
@Test
@@ -65,6 +65,6 @@ public class DoubleLiteralEvaluatorTest {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("Cannot evaluate a context that is null.");
- evaluator.evaluate(null);
+ evaluator.evaluate(null, null);
}
}