aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/language
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2022-08-10 01:00:09 +0200
committerLibravatar Kristóf Marussy <kristof@marussy.com>2022-08-10 01:00:09 +0200
commit10b6c4fa59abcde40dfd3c548c4df4a8b08a21d8 (patch)
tree95ebb690ff1da41033891cdeb85a799f0cfc53f3 /subprojects/language
parentrefactor: direct predicates (diff)
downloadrefinery-10b6c4fa59abcde40dfd3c548c4df4a8b08a21d8.tar.gz
refinery-10b6c4fa59abcde40dfd3c548c4df4a8b08a21d8.tar.zst
refinery-10b6c4fa59abcde40dfd3c548c4df4a8b08a21d8.zip
feat(language): add support for count operator
Diffstat (limited to 'subprojects/language')
-rw-r--r--subprojects/language/src/main/java/tools/refinery/language/Problem.xtext10
-rw-r--r--subprojects/language/src/main/java/tools/refinery/language/resource/DerivedVariableComputer.java18
2 files changed, 17 insertions, 11 deletions
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:
58 actions+=Action ("," actions+=Action)*; 58 actions+=Action ("," actions+=Action)*;
59 59
60Literal: 60Literal:
61 Atom | NegativeLiteral; 61 Atom | NegativeLiteral | CountLiteral;
62 62
63NegativeLiteral: 63NegativeLiteral:
64 modality=Modality? "!" atom=Atom; 64 modality=Modality? "!" atom=Atom;
65 65
66enum ComparisonOp:
67 LESS="<" | LESS_EQ="<=" | GREATER=">" | GREATER_EQ=">=" | EQ="=:=" | NOT_EQ="=!=" ;
68
69CountLiteral:
70 modality=Modality? "count" "{" atom=Atom "}" op=ComparisonOp threshold=INT;
71
66Action: 72Action:
67 AssertionAction | DeleteAction | NewAction; 73 AssertionAction | DeleteAction | NewAction;
68 74
@@ -174,7 +180,7 @@ QualifiedName hidden():
174 180
175Identifier: 181Identifier:
176 ID | "true" | "false" | "unknown" | "error" | "class" | "abstract" | "extends" | "enum" | "pred" | 182 ID | "true" | "false" | "unknown" | "error" | "class" | "abstract" | "extends" | "enum" | "pred" |
177 "indiv" | "problem" | "new" | "delete" | "rule" | "may" | "must" | "current"; 183 "indiv" | "problem" | "new" | "delete" | "rule" | "may" | "must" | "current" | "count";
178 184
179Integer returns ecore::EInt hidden(): 185Integer returns ecore::EInt hidden():
180 "-"? INT; 186 "-"? 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;
18 18
19import tools.refinery.language.model.problem.Argument; 19import tools.refinery.language.model.problem.Argument;
20import tools.refinery.language.model.problem.Atom; 20import tools.refinery.language.model.problem.Atom;
21import tools.refinery.language.model.problem.CompoundLiteral;
21import tools.refinery.language.model.problem.Conjunction; 22import tools.refinery.language.model.problem.Conjunction;
22import tools.refinery.language.model.problem.ExistentialQuantifier; 23import tools.refinery.language.model.problem.ExistentialQuantifier;
23import tools.refinery.language.model.problem.ImplicitVariable; 24import tools.refinery.language.model.problem.ImplicitVariable;
24import tools.refinery.language.model.problem.Literal; 25import tools.refinery.language.model.problem.Literal;
25import tools.refinery.language.model.problem.NegativeLiteral;
26import tools.refinery.language.model.problem.Parameter; 26import tools.refinery.language.model.problem.Parameter;
27import tools.refinery.language.model.problem.ParametricDefinition; 27import tools.refinery.language.model.problem.ParametricDefinition;
28import tools.refinery.language.model.problem.Problem; 28import tools.refinery.language.model.problem.Problem;
@@ -76,16 +76,16 @@ public class DerivedVariableComputer {
76 createVariables(conjunction, newVariables); 76 createVariables(conjunction, newVariables);
77 newVariables.addAll(knownVariables); 77 newVariables.addAll(knownVariables);
78 for (Literal literal : conjunction.getLiterals()) { 78 for (Literal literal : conjunction.getLiterals()) {
79 if (literal instanceof NegativeLiteral negativeLiteral) { 79 if (literal instanceof CompoundLiteral compoundLiteral) {
80 installDeriveNegativeLiteralState(negativeLiteral, newVariables); 80 installDerivedCompoundLiteralState(compoundLiteral, newVariables);
81 } 81 }
82 } 82 }
83 } 83 }
84 84
85 protected void installDeriveNegativeLiteralState(NegativeLiteral negativeLiteral, Set<String> knownVariables) { 85 protected void installDerivedCompoundLiteralState(CompoundLiteral compoundLiteral, Set<String> knownVariables) {
86 Set<String> newVariables = new HashSet<>(); 86 Set<String> newVariables = new HashSet<>();
87 createSigletonVariablesAndCollectVariables(negativeLiteral.getAtom(), knownVariables, newVariables); 87 createSigletonVariablesAndCollectVariables(compoundLiteral.getAtom(), knownVariables, newVariables);
88 createVariables(negativeLiteral, newVariables); 88 createVariables(compoundLiteral, newVariables);
89 } 89 }
90 90
91 protected void createSigletonVariablesAndCollectVariables(Atom atom, Set<String> knownVariables, 91 protected void createSigletonVariablesAndCollectVariables(Atom atom, Set<String> knownVariables,
@@ -169,9 +169,9 @@ public class DerivedVariableComputer {
169 if (literal instanceof Atom atom) { 169 if (literal instanceof Atom atom) {
170 discardDerivedAtomState(atom); 170 discardDerivedAtomState(atom);
171 } 171 }
172 if (literal instanceof NegativeLiteral negativeLiteral) { 172 if (literal instanceof CompoundLiteral compoundLiteral) {
173 negativeLiteral.getImplicitVariables().clear(); 173 compoundLiteral.getImplicitVariables().clear();
174 discardDerivedAtomState(negativeLiteral.getAtom()); 174 discardDerivedAtomState(compoundLiteral.getAtom());
175 } 175 }
176 } 176 }
177 } 177 }