diff options
author | Kristóf Marussy <kristof@marussy.com> | 2022-08-10 01:00:09 +0200 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2022-08-10 01:00:09 +0200 |
commit | 10b6c4fa59abcde40dfd3c548c4df4a8b08a21d8 (patch) | |
tree | 95ebb690ff1da41033891cdeb85a799f0cfc53f3 /subprojects/language | |
parent | refactor: direct predicates (diff) | |
download | refinery-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.xtext | 10 | ||||
-rw-r--r-- | subprojects/language/src/main/java/tools/refinery/language/resource/DerivedVariableComputer.java | 18 |
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 | ||
60 | Literal: | 60 | Literal: |
61 | Atom | NegativeLiteral; | 61 | Atom | NegativeLiteral | CountLiteral; |
62 | 62 | ||
63 | NegativeLiteral: | 63 | NegativeLiteral: |
64 | modality=Modality? "!" atom=Atom; | 64 | modality=Modality? "!" atom=Atom; |
65 | 65 | ||
66 | enum ComparisonOp: | ||
67 | LESS="<" | LESS_EQ="<=" | GREATER=">" | GREATER_EQ=">=" | EQ="=:=" | NOT_EQ="=!=" ; | ||
68 | |||
69 | CountLiteral: | ||
70 | modality=Modality? "count" "{" atom=Atom "}" op=ComparisonOp threshold=INT; | ||
71 | |||
66 | Action: | 72 | Action: |
67 | AssertionAction | DeleteAction | NewAction; | 73 | AssertionAction | DeleteAction | NewAction; |
68 | 74 | ||
@@ -174,7 +180,7 @@ QualifiedName hidden(): | |||
174 | 180 | ||
175 | Identifier: | 181 | Identifier: |
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 | ||
179 | Integer returns ecore::EInt hidden(): | 185 | Integer 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 | ||
19 | import tools.refinery.language.model.problem.Argument; | 19 | import tools.refinery.language.model.problem.Argument; |
20 | import tools.refinery.language.model.problem.Atom; | 20 | import tools.refinery.language.model.problem.Atom; |
21 | import tools.refinery.language.model.problem.CompoundLiteral; | ||
21 | import tools.refinery.language.model.problem.Conjunction; | 22 | import tools.refinery.language.model.problem.Conjunction; |
22 | import tools.refinery.language.model.problem.ExistentialQuantifier; | 23 | import tools.refinery.language.model.problem.ExistentialQuantifier; |
23 | import tools.refinery.language.model.problem.ImplicitVariable; | 24 | import tools.refinery.language.model.problem.ImplicitVariable; |
24 | import tools.refinery.language.model.problem.Literal; | 25 | import tools.refinery.language.model.problem.Literal; |
25 | import tools.refinery.language.model.problem.NegativeLiteral; | ||
26 | import tools.refinery.language.model.problem.Parameter; | 26 | import tools.refinery.language.model.problem.Parameter; |
27 | import tools.refinery.language.model.problem.ParametricDefinition; | 27 | import tools.refinery.language.model.problem.ParametricDefinition; |
28 | import tools.refinery.language.model.problem.Problem; | 28 | import 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 | } |