Skip to content

Commit

Permalink
#2178 Adjust the grammar definition to use the new BNF
Browse files Browse the repository at this point in the history
  • Loading branch information
homedirectory committed Feb 23, 2024
1 parent 1e20f65 commit 11ebaea
Showing 1 changed file with 47 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package fielden.platform.eql;

import fielden.platform.eql.fling.BNF;
import fielden.platform.eql.fling.BnfToG4;
import fielden.platform.eql.fling.BnfToHtml;
import fielden.platform.eql.fling.BnfToText;
import il.ac.technion.cs.fling.internal.grammar.rules.Terminal;
import il.ac.technion.cs.fling.internal.grammar.rules.Variable;
import fielden.platform.bnf.BNF;
import fielden.platform.bnf.Terminal;
import fielden.platform.bnf.Variable;
import fielden.platform.bnf.util.BnfToG4;
import fielden.platform.bnf.util.BnfToHtml;
import fielden.platform.bnf.util.BnfToText;
import ua.com.fielden.platform.entity.query.fluent.EntityQueryProgressiveInterfaces.ICompoundCondition0;
import ua.com.fielden.platform.entity.query.model.*;
import ua.com.fielden.platform.processors.metamodel.IConvertableToPath;
Expand All @@ -14,17 +14,13 @@
import java.io.IOException;
import java.io.PrintStream;

import static fielden.platform.bnf.FluentBNF.start;
import static fielden.platform.bnf.Notation.*;
import static fielden.platform.bnf.Terms.label;
import static fielden.platform.bnf.util.BnfVerifier.verifyBnf;
import static fielden.platform.eql.CanonicalEqlGrammar.EqlTerminal.values;
import static fielden.platform.eql.CanonicalEqlGrammar.EqlTerminal.*;
import static fielden.platform.eql.CanonicalEqlGrammar.EqlVariable.*;
import static fielden.platform.eql.fling.BNF.Fluent.start;
import static fielden.platform.eql.fling.BnfVerifier.verifyBnf;
import static fielden.platform.eql.fling.LabeledTempSymbol.label;
import static il.ac.technion.cs.fling.internal.grammar.rules.Quantifiers.noneOrMore;
import static il.ac.technion.cs.fling.internal.grammar.rules.Quantifiers.optional;

// Use a forked version of Fling which has additional features:
// https://github.com/homedirectory/fling

/**
* Canonical representation of EQL's grammar.
Expand All @@ -51,16 +47,16 @@ public final class CanonicalEqlGrammar {

derive(Select).
to(select.with(Class.class),
optional(as.with(STR)),
optional(Join),
optional(Where),
optional(GroupBy),
opt(as.with(STR)),
opt(Join),
opt(Where),
opt(GroupBy),
FirstYield).
or(select.with(Class.class),
optional(as.with(STR)),
optional(Join),
optional(Where),
optional(GroupBy),
opt(as.with(STR)),
opt(Join),
opt(Where),
opt(GroupBy),
Model).

derive(Where).
Expand Down Expand Up @@ -111,7 +107,7 @@ public final class CanonicalEqlGrammar {
derive(Expr).
to(beginExpr, ExprBody, endExpr).
derive(ExprBody).
to(SingleOperandOrExpr, noneOrMore(ArithmeticalOperator, SingleOperandOrExpr)).
to(SingleOperandOrExpr, repeat(ArithmeticalOperator, SingleOperandOrExpr)).
derive(SingleOperandOrExpr).
to(SingleOperand).or(Expr).
derive(ArithmeticalOperator).
Expand Down Expand Up @@ -158,12 +154,12 @@ public final class CanonicalEqlGrammar {
to(round, SingleOperandOrExpr, to.with(Integer.class)).

derive(Concat).
to(concat, SingleOperandOrExpr, (noneOrMore(with, SingleOperandOrExpr)), end).
to(concat, SingleOperandOrExpr, (repeat(with, SingleOperandOrExpr)), end).

derive(CaseWhen).
to(caseWhen, Condition, then, SingleOperandOrExpr,
noneOrMore(when, Condition, then, SingleOperandOrExpr),
optional(otherwise, label("otherwiseOperand", SingleOperandOrExpr)),
repeat(when, Condition, then, SingleOperandOrExpr),
opt(otherwise, label("otherwiseOperand", SingleOperandOrExpr)),
CaseWhenEnd).

derive(CaseWhenEnd).
Expand All @@ -185,32 +181,32 @@ public final class CanonicalEqlGrammar {
or(iParam.with(STR)).or(iParam.with(ENUM)).

derive(MultiOperand).
to(anyOfProps.many(STR)).or(anyOfProps.many(PROP_PATH)).
or(allOfProps.many(STR)).or(allOfProps.many(PROP_PATH)).
or(anyOfValues.many(OBJ)).or(allOfValues.many(OBJ)).
or(anyOfParams.many(STR)).or(anyOfIParams.many(STR)).
or(allOfParams.many(STR)).or(allOfIParams.many(STR)).
or(anyOfModels.many(PrimitiveResultQueryModel.class)).
or(allOfModels.many(PrimitiveResultQueryModel.class)).
or(anyOfExpressions.many(ExpressionModel.class)).
or(allOfExpressions.many(ExpressionModel.class)).
to(anyOfProps.rest(STR)).or(anyOfProps.rest(PROP_PATH)).
or(allOfProps.rest(STR)).or(allOfProps.rest(PROP_PATH)).
or(anyOfValues.rest(OBJ)).or(allOfValues.rest(OBJ)).
or(anyOfParams.rest(STR)).or(anyOfIParams.rest(STR)).
or(allOfParams.rest(STR)).or(allOfIParams.rest(STR)).
or(anyOfModels.rest(PrimitiveResultQueryModel.class)).
or(allOfModels.rest(PrimitiveResultQueryModel.class)).
or(anyOfExpressions.rest(ExpressionModel.class)).
or(allOfExpressions.rest(ExpressionModel.class)).

derive(MembershipOperator).
to(in).or(notIn).

derive(MembershipOperand).
to(values.many(OBJ)).
or(props.many(STR)).or(props.many(PROP_PATH)).
or(params.many(STR)).or(iParams.many(STR)).
to(values.rest(OBJ)).
or(props.rest(STR)).or(props.rest(PROP_PATH)).
or(params.rest(STR)).or(iParams.rest(STR)).
or(model.with(SingleResultQueryModel.class)).

derive(SingleConditionPredicate).
to(exists.with(QueryModel.class)).
or(notExists.with(QueryModel.class)).
or(existsAnyOf.many(QueryModel.class)).
or(notExistsAnyOf.many(QueryModel.class)).
or(existsAllOf.many(QueryModel.class)).
or(notExistsAllOf.many(QueryModel.class)).
or(existsAnyOf.rest(QueryModel.class)).
or(notExistsAnyOf.rest(QueryModel.class)).
or(existsAllOf.rest(QueryModel.class)).
or(notExistsAllOf.rest(QueryModel.class)).
or(critCondition.with(STR, STR)).
or(critCondition.with(PROP_PATH, PROP_PATH)).
or(critCondition.with(ICompoundCondition0.class, STR, STR)).
Expand All @@ -219,7 +215,7 @@ public final class CanonicalEqlGrammar {
or(negatedCondition.with(ConditionModel.class)).

derive(Join).
to(JoinOperator, (optional(label("alias", as).with(STR))), JoinCondition, optional(Join)).
to(JoinOperator, opt(label("alias", as).with(STR)), JoinCondition, opt(Join)).

derive(JoinOperator).
to(join.with(Class.class)).
Expand All @@ -233,7 +229,7 @@ public final class CanonicalEqlGrammar {
to(on, Condition).

derive(GroupBy).
to(groupBy, label("operand", SingleOperandOrExpr), optional(GroupBy)).
to(groupBy, label("operand", SingleOperandOrExpr), opt(GroupBy)).

derive(FirstYield).
to(yield, YieldOperand, modelAsEntity.with(Class.class)).
Expand Down Expand Up @@ -288,9 +284,9 @@ public enum EqlVariable implements Variable {
MembershipOperand, ComparisonOperator, ComparisonOperand, QuantifiedOperand, SingleConditionPredicate, Join, JoinOperator,
JoinCondition,
Model, GroupBy,
FirstYield, YieldOperand, YieldOperandFunction, YieldOperandFunctionName, YieldAlias, LikeOperator, SubsequentYield
FirstYield, YieldOperand, YieldOperandFunction, YieldOperandFunctionName, YieldAlias, LikeOperator, SubsequentYield,
UnaryPredicate,
ComparisonPredicate, QuantifiedComparisonPredicate, LikePredicate, MembershipPredicate, SubsequentYield
ComparisonPredicate, QuantifiedComparisonPredicate, LikePredicate, MembershipPredicate
}

public enum EqlTerminal implements Terminal {
Expand Down Expand Up @@ -361,10 +357,13 @@ public static void main(String[] args) throws IOException {
String format = args[1];

final PrintStream out;
final String outName;
if (args.length > 2) {
out = new PrintStream(new FileOutputStream(args[2]));
outName = args[2];
} else {
out = System.out;
outName = "stdout";
}

if ("html".equals(format)) {
Expand All @@ -374,6 +373,8 @@ public static void main(String[] args) throws IOException {
} else {
out.println(new BnfToText().bnfToText(canonical_bnf));
}

System.out.println("Output written to %s".formatted(outName));
}
} else if ("verify".equals(command)) {
verifyBnf(canonical_bnf);
Expand Down

0 comments on commit 11ebaea

Please sign in to comment.