Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- logical expressions now properly report their type (Boolean) - functions return their declared types - minimal expression walker checks type equality on operations and adds errors if necessary - fixed tests
- Loading branch information
Showing
22 changed files
with
267 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 20 additions & 3 deletions
23
src/main/java/org/graylog/plugins/messageprocessor/ast/functions/Function.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,32 @@ | ||
package org.graylog.plugins.messageprocessor.ast.functions; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import org.graylog.plugins.messageprocessor.EvaluationContext; | ||
import org.graylog.plugins.messageprocessor.ast.expressions.Expression; | ||
import org.graylog2.plugin.Message; | ||
|
||
import java.util.Map; | ||
|
||
public interface Function { | ||
public interface Function<T> { | ||
|
||
Object evaluate(Map<String, Expression> args, EvaluationContext context, Message message); | ||
Function ERROR_FUNCTION = new Function<Void>() { | ||
@Override | ||
public Void evaluate(Map args, EvaluationContext context, Message message) { | ||
return null; | ||
} | ||
|
||
FunctionDescriptor descriptor(); | ||
@Override | ||
public FunctionDescriptor<Void> descriptor() { | ||
return FunctionDescriptor.<Void>builder() | ||
.name("__unresolved_function") | ||
.returnType(Void.class) | ||
.params(ImmutableList.of()) | ||
.build(); | ||
} | ||
}; | ||
|
||
T evaluate(Map<String, Expression> args, EvaluationContext context, Message message); | ||
|
||
FunctionDescriptor<T> descriptor(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/org/graylog/plugins/messageprocessor/parser/IncompatibleTypes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.graylog.plugins.messageprocessor.parser; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import org.graylog.plugins.messageprocessor.ast.expressions.BinaryExpression; | ||
import org.graylog.plugins.messageprocessor.ast.expressions.Expression; | ||
|
||
public class IncompatibleTypes extends ParseError { | ||
private final RuleLangParser.ExpressionContext ctx; | ||
private final BinaryExpression binaryExpr; | ||
|
||
public IncompatibleTypes(RuleLangParser.ExpressionContext ctx, BinaryExpression binaryExpr) { | ||
super("incompatible_types", ctx); | ||
this.ctx = ctx; | ||
this.binaryExpr = binaryExpr; | ||
} | ||
|
||
@JsonProperty("reason") | ||
@Override | ||
public String toString() { | ||
return "Incompatible types " + exprString(binaryExpr.left()) + " <=> " + exprString(binaryExpr.right()) + positionString(); | ||
} | ||
|
||
private String exprString(Expression e) { | ||
return "(" + e.toString() + ") : " + e.getType().getSimpleName(); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
src/main/java/org/graylog/plugins/messageprocessor/parser/ParseException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.