Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 54 additions & 28 deletions src/main/antlr4/com/aerospike/dsl/Condition.g4
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,61 @@ grammar Condition;
parse: expression;

expression
// Declaration and Control Expressions
: 'with' '(' variableDefinition (',' variableDefinition)* ')' 'do' '(' expression ')' # WithExpression
: logicalOrExpression
;

logicalOrExpression
: logicalAndExpression ('or' logicalAndExpression)* # OrExpression
;

logicalAndExpression
: basicExpression ('and' basicExpression)* # AndExpression
;

basicExpression
: 'not' '(' expression ')' # NotExpression
| 'exclusive' '(' expression (',' expression)+ ')' # ExclusiveExpression
| 'with' '(' variableDefinition (',' variableDefinition)* ')' 'do' '(' expression ')' # WithExpression
| 'when' '(' expressionMapping (',' expressionMapping)* ',' 'default' '=>' expression ')' # WhenExpression
// Logical Expressions
| expression 'and' expression # AndExpression
| expression 'or' expression # OrExpression
| 'not' '(' expression ')' # NotExpression
| 'exclusive' '(' expression (',' expression)+ ')' # ExclusiveExpression
// Comparison Expressions
| operand '>' operand # GreaterThanExpression
| operand '>=' operand # GreaterThanOrEqualExpression
| operand '<' operand # LessThanExpression
| operand '<=' operand # LessThanOrEqualExpression
| operand '==' operand # EqualityExpression
| operand '!=' operand # InequalityExpression
// Arithmetic Expressions
| operand '+' operand # AddExpression
| operand '-' operand # SubExpression
| operand '*' operand # MulExpression
| operand '/' operand # DivExpression
| operand '%' operand # ModExpression
| operand '&' operand # IntAndExpression
| operand '|' operand # IntOrExpression
| operand '^' operand # IntXorExpression
| '~' operand # IntNotExpression
| operand '<<' operand # IntLShiftExpression
| operand '>>' operand # IntRShiftExpression
// Base Operand
| operand # OperandExpression
| comparisonExpression # ComparisonExpressionWrapper
;

comparisonExpression
: additiveExpression '>' additiveExpression # GreaterThanExpression
| additiveExpression '>=' additiveExpression # GreaterThanOrEqualExpression
| additiveExpression '<' additiveExpression # LessThanExpression
| additiveExpression '<=' additiveExpression # LessThanOrEqualExpression
| additiveExpression '==' additiveExpression # EqualityExpression
| additiveExpression '!=' additiveExpression # InequalityExpression
| additiveExpression # AdditiveExpressionWrapper
;

// Rest of the grammar rules remain the same
additiveExpression
: multiplicativeExpression # MultiplicativeExpressionWrapper
| additiveExpression '+' multiplicativeExpression # AddExpression
| additiveExpression '-' multiplicativeExpression # SubExpression
;

multiplicativeExpression
: bitwiseExpression # BitwiseExpressionWrapper
| multiplicativeExpression '*' bitwiseExpression # MulExpression
| multiplicativeExpression '/' bitwiseExpression # DivExpression
| multiplicativeExpression '%' bitwiseExpression # ModExpression
;

bitwiseExpression
: shiftExpression # ShiftExpressionWrapper
| bitwiseExpression '&' shiftExpression # IntAndExpression
| bitwiseExpression '|' shiftExpression # IntOrExpression
| bitwiseExpression '^' shiftExpression # IntXorExpression
| '~' shiftExpression # IntNotExpression
;

shiftExpression
: operand # OperandExpression
| shiftExpression '<<' operand # IntLShiftExpression
| shiftExpression '>>' operand # IntRShiftExpression
;

variableDefinition
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/aerospike/dsl/parts/AbstractPart.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public enum PartType {
WITH_STRUCTURE,
WHEN_STRUCTURE,
EXCLUSIVE_STRUCTURE,
AND_STRUCTURE,
OR_STRUCTURE,
BASE_PATH,
BIN_PART,
LIST_PART,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public enum ExprPartsOperation {
LTEQ,
WITH_STRUCTURE, // unary
WHEN_STRUCTURE, // unary
EXCLUSIVE_STRUCTURE // unary
EXCLUSIVE_STRUCTURE, // unary
AND_STRUCTURE,
OR_STRUCTURE
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public static ListTypeDesignator from() {

@Override
public Exp constructExp(BasePath basePath, Exp.Type valueType, int cdtReturnType, CTX[] context) {
List<AbstractPart> partsUpToDesignator = !basePath.getParts().isEmpty()
? basePath.getParts().subList(0, basePath.getParts().size() - 1)
List<AbstractPart> partsUpToDesignator = !basePath.getCdtParts().isEmpty()
? basePath.getCdtParts().subList(0, basePath.getCdtParts().size() - 1)
: Collections.emptyList();

BasePath basePathUntilDesignator = new BasePath(basePath.getBinPart(), partsUpToDesignator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static MapTypeDesignator from() {

@Override
public Exp constructExp(BasePath basePath, Exp.Type valueType, int cdtReturnType, CTX[] context) {
var partsUpToDesignator = basePath.getParts().subList(0, basePath.getParts().size() - 1);
var partsUpToDesignator = basePath.getCdtParts().subList(0, basePath.getCdtParts().size() - 1);
BasePath basePathUntilDesignator = new BasePath(basePath.getBinPart(), partsUpToDesignator);
int partsUpToDesignatorSize = partsUpToDesignator.size();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.aerospike.dsl.parts.controlstructure;

import com.aerospike.dsl.parts.AbstractPart;
import com.aerospike.dsl.parts.ExpressionContainer;
import lombok.Getter;

import java.util.List;

@Getter
public class AndStructure extends AbstractPart {

private final List<ExpressionContainer> operands;

public AndStructure(List<ExpressionContainer> operands) {
super(PartType.AND_STRUCTURE);
this.operands = operands;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.aerospike.dsl.parts.controlstructure;

import com.aerospike.dsl.parts.AbstractPart;
import com.aerospike.dsl.parts.ExpressionContainer;
import lombok.Getter;

import java.util.List;

@Getter
public class OrStructure extends AbstractPart {

private final List<ExpressionContainer> operands;

public OrStructure(List<ExpressionContainer> operands) {
super(PartType.OR_STRUCTURE);
this.operands = operands;
}
}
12 changes: 6 additions & 6 deletions src/main/java/com/aerospike/dsl/parts/path/BasePath.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
public class BasePath extends AbstractPart {

private final BinPart binPart;
private final List<AbstractPart> parts;
private final List<AbstractPart> cdtParts;

public BasePath(BinPart binOperand, List<AbstractPart> parts) {
public BasePath(BinPart binPart, List<AbstractPart> cdtParts) {
super(PartType.BASE_PATH);
this.binPart = binOperand;
this.parts = parts;
this.binPart = binPart;
this.cdtParts = cdtParts;
}

// Bin type is determined by the base path's first element
public Exp.Type getBinType() {
if (!parts.isEmpty()) {
return switch (parts.get(0).getPartType()) {
if (!cdtParts.isEmpty()) {
return switch (cdtParts.get(0).getPartType()) {
case MAP_PART -> Exp.Type.MAP;
case LIST_PART -> Exp.Type.LIST;
default -> null;
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/aerospike/dsl/parts/path/BinPart.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
import com.aerospike.client.exp.Exp;
import com.aerospike.dsl.parts.ExpressionContainer;
import lombok.Getter;
import lombok.Setter;

@Getter
public class BinPart extends ExpressionContainer {

private final String binName;
@Setter
private boolean isTypeExplicitlySet;

public BinPart(String binName) {
super();
this.binName = binName;
this.partType = PartType.BIN_PART;
this.expType = null; // Exp type unknown
this.expType = Exp.Type.INT; // Set INT by default
}

public void updateExp(Exp.Type expType) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/aerospike/dsl/parts/path/Path.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public Path(BasePath basePath, PathFunction pathFunction) {
}

public Exp processPath(BasePath basePath, PathFunction pathFunction) {
List<AbstractPart> parts = basePath.getParts();
List<AbstractPart> parts = basePath.getCdtParts();
updateWithCdtTypeDesignator(basePath, pathFunction);
AbstractPart lastPathPart = !parts.isEmpty() ? parts.get(parts.size() - 1) : null;
pathFunction = processPathFunction(basePath, lastPathPart, pathFunction);
Expand Down
Loading
Loading