From 10b6c4fa59abcde40dfd3c548c4df4a8b08a21d8 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Wed, 10 Aug 2022 01:00:09 +0200 Subject: feat(language): add support for count operator --- .../main/java/tools/refinery/language/Problem.xtext | 10 ++++++++-- .../language/resource/DerivedVariableComputer.java | 18 +++++++++--------- 2 files changed, 17 insertions(+), 11 deletions(-) (limited to 'subprojects/language/src/main/java') diff --git a/subprojects/language/src/main/java/tools/refinery/language/Problem.xtext b/subprojects/language/src/main/java/tools/refinery/language/Problem.xtext index ba885e3c..93d066af 100644 --- a/subprojects/language/src/main/java/tools/refinery/language/Problem.xtext +++ b/subprojects/language/src/main/java/tools/refinery/language/Problem.xtext @@ -58,11 +58,17 @@ Consequent: actions+=Action ("," actions+=Action)*; Literal: - Atom | NegativeLiteral; + Atom | NegativeLiteral | CountLiteral; NegativeLiteral: modality=Modality? "!" atom=Atom; +enum ComparisonOp: + LESS="<" | LESS_EQ="<=" | GREATER=">" | GREATER_EQ=">=" | EQ="=:=" | NOT_EQ="=!=" ; + +CountLiteral: + modality=Modality? "count" "{" atom=Atom "}" op=ComparisonOp threshold=INT; + Action: AssertionAction | DeleteAction | NewAction; @@ -174,7 +180,7 @@ QualifiedName hidden(): Identifier: ID | "true" | "false" | "unknown" | "error" | "class" | "abstract" | "extends" | "enum" | "pred" | - "indiv" | "problem" | "new" | "delete" | "rule" | "may" | "must" | "current"; + "indiv" | "problem" | "new" | "delete" | "rule" | "may" | "must" | "current" | "count"; Integer returns ecore::EInt hidden(): "-"? INT; diff --git a/subprojects/language/src/main/java/tools/refinery/language/resource/DerivedVariableComputer.java b/subprojects/language/src/main/java/tools/refinery/language/resource/DerivedVariableComputer.java index 4d19006f..b76c4bf7 100644 --- a/subprojects/language/src/main/java/tools/refinery/language/resource/DerivedVariableComputer.java +++ b/subprojects/language/src/main/java/tools/refinery/language/resource/DerivedVariableComputer.java @@ -18,11 +18,11 @@ import com.google.inject.name.Named; import tools.refinery.language.model.problem.Argument; import tools.refinery.language.model.problem.Atom; +import tools.refinery.language.model.problem.CompoundLiteral; import tools.refinery.language.model.problem.Conjunction; import tools.refinery.language.model.problem.ExistentialQuantifier; import tools.refinery.language.model.problem.ImplicitVariable; import tools.refinery.language.model.problem.Literal; -import tools.refinery.language.model.problem.NegativeLiteral; import tools.refinery.language.model.problem.Parameter; import tools.refinery.language.model.problem.ParametricDefinition; import tools.refinery.language.model.problem.Problem; @@ -76,16 +76,16 @@ public class DerivedVariableComputer { createVariables(conjunction, newVariables); newVariables.addAll(knownVariables); for (Literal literal : conjunction.getLiterals()) { - if (literal instanceof NegativeLiteral negativeLiteral) { - installDeriveNegativeLiteralState(negativeLiteral, newVariables); + if (literal instanceof CompoundLiteral compoundLiteral) { + installDerivedCompoundLiteralState(compoundLiteral, newVariables); } } } - protected void installDeriveNegativeLiteralState(NegativeLiteral negativeLiteral, Set knownVariables) { + protected void installDerivedCompoundLiteralState(CompoundLiteral compoundLiteral, Set knownVariables) { Set newVariables = new HashSet<>(); - createSigletonVariablesAndCollectVariables(negativeLiteral.getAtom(), knownVariables, newVariables); - createVariables(negativeLiteral, newVariables); + createSigletonVariablesAndCollectVariables(compoundLiteral.getAtom(), knownVariables, newVariables); + createVariables(compoundLiteral, newVariables); } protected void createSigletonVariablesAndCollectVariables(Atom atom, Set knownVariables, @@ -169,9 +169,9 @@ public class DerivedVariableComputer { if (literal instanceof Atom atom) { discardDerivedAtomState(atom); } - if (literal instanceof NegativeLiteral negativeLiteral) { - negativeLiteral.getImplicitVariables().clear(); - discardDerivedAtomState(negativeLiteral.getAtom()); + if (literal instanceof CompoundLiteral compoundLiteral) { + compoundLiteral.getImplicitVariables().clear(); + discardDerivedAtomState(compoundLiteral.getAtom()); } } } -- cgit v1.2.3-54-g00ecf