aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/language/src/main/java/tools/refinery/language/Problem.xtext
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/language/src/main/java/tools/refinery/language/Problem.xtext')
-rw-r--r--subprojects/language/src/main/java/tools/refinery/language/Problem.xtext205
1 files changed, 205 insertions, 0 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
new file mode 100644
index 00000000..c94d40ab
--- /dev/null
+++ b/subprojects/language/src/main/java/tools/refinery/language/Problem.xtext
@@ -0,0 +1,205 @@
1grammar tools.refinery.language.Problem with org.eclipse.xtext.common.Terminals
2
3import "http://www.eclipse.org/emf/2002/Ecore" as ecore
4import "https://refinery.tools/emf/2021/Problem"
5
6Problem:
7 ("problem" name=Identifier ".")?
8 statements+=Statement*;
9
10Statement:
11 ClassDeclaration | EnumDeclaration | PredicateDefinition | RuleDefinition | Assertion | NodeValueAssertion |
12 ScopeDeclaration |
13 IndividualDeclaration;
14
15ClassDeclaration:
16 abstract?="abstract"? "class"
17 name=Identifier
18 ("extends" superTypes+=[Relation|QualifiedName] ("," superTypes+=[Relation|QualifiedName])*)?
19 ("{" (referenceDeclarations+=ReferenceDeclaration ";"?)* "}" | ".");
20
21EnumDeclaration:
22 "enum"
23 name=Identifier
24 ("{" (literals+=EnumLiteral ("," literals+=EnumLiteral)* ("," | ";")?)? "}" | ".");
25
26EnumLiteral returns Node:
27 name=Identifier;
28
29ReferenceDeclaration:
30 (containment?="contains" | "refers")?
31 referenceType=[Relation|QualifiedName]
32 ("[" multiplicity=Multiplicity "]")?
33 name=Identifier
34 ("opposite" opposite=[ReferenceDeclaration|QualifiedName])?;
35
36enum PredicateKind:
37 DIRECT="direct";
38
39PredicateDefinition:
40 (error?="error" "pred"? | kind=PredicateKind? "pred")
41 name=Identifier
42 "(" (parameters+=Parameter ("," parameters+=Parameter)*)? ")"
43 ("<->" bodies+=Conjunction (";" bodies+=Conjunction)*)?
44 ".";
45
46enum RuleKind:
47 DIRECT="direct";
48
49RuleDefinition:
50 kind=RuleKind "rule"
51 name=Identifier
52 "(" (parameters+=Parameter ("," parameters+=Parameter)*)? ")"
53 (":" bodies+=Conjunction (";" bodies+=Conjunction)*
54 "~>" action=Action)?
55 ".";
56
57Parameter:
58 parameterType=[Relation|QualifiedName]? name=Identifier;
59
60Conjunction:
61 literals+=Literal ("," literals+=Literal)*;
62
63Action:
64 actionLiterals+=ActionLiteral ("," actionLiterals+=ActionLiteral)*;
65
66Literal:
67 Atom | ValueLiteral | NegativeLiteral;
68
69ValueLiteral:
70 atom=Atom
71 (refinement?=":" | "=")
72 values+=LogicConstant ("|" values+=LogicConstant)*;
73
74NegativeLiteral:
75 "!" atom=Atom;
76
77ActionLiteral:
78 ValueActionLiteral | DeleteActionLiteral | NewActionLiteral;
79
80ValueActionLiteral:
81 atom=Atom
82 (refinement?=":" | "=")
83 value=LogicValue;
84
85DeleteActionLiteral:
86 "delete" variableOrNode=[VariableOrNode|QualifiedName];
87
88NewActionLiteral:
89 "new" variable=NewVariable;
90
91NewVariable:
92 name=Identifier;
93
94Atom:
95 relation=[Relation|QualifiedName]
96 transitiveClosure?="+"?
97 "(" (arguments+=Argument ("," arguments+=Argument)*)? ")";
98
99LogicConstant:
100 value=LogicValue;
101
102Argument:
103 VariableOrNodeArgument | ConstantArgument;
104
105VariableOrNodeArgument:
106 variableOrNode=[VariableOrNode|QualifiedName];
107
108ConstantArgument:
109 constant=Constant;
110
111Assertion:
112 default?="default"?
113 (value=ShortLogicValue?
114 relation=[Relation|QualifiedName]
115 "(" (arguments+=AssertionArgument ("," arguments+=AssertionArgument)*)? ")"
116 | relation=[Relation|QualifiedName]
117 "(" (arguments+=AssertionArgument ("," arguments+=AssertionArgument)*)? ")"
118 ":" value=LogicValue)
119 ".";
120
121AssertionArgument:
122 NodeAssertionArgument | WildcardAssertionArgument | ConstantAssertionArgument;
123
124NodeAssertionArgument:
125 node=[Node|QualifiedName];
126
127WildcardAssertionArgument:
128 {WildcardAssertionArgument} "*";
129
130ConstantAssertionArgument:
131 constant=Constant;
132
133enum LogicValue:
134 TRUE="true" | FALSE="false" | UNKNOWN="unknown" | ERROR="error";
135
136enum ShortLogicValue returns LogicValue:
137 FALSE="!" | UNKNOWN="?";
138
139NodeValueAssertion:
140 node=[Node|QualifiedName] ":" value=Constant ".";
141
142Constant:
143 RealConstant | IntConstant | StringConstant;
144
145IntConstant:
146 intValue=Integer;
147
148RealConstant:
149 realValue=Real;
150
151StringConstant:
152 stringValue=STRING;
153
154ScopeDeclaration:
155 "scope" typeScopes+=TypeScope ("," typeScopes+=TypeScope)* ".";
156
157TypeScope:
158 targetType=[ClassDeclaration|QualifiedName]
159 (increment?="+=" | "=")
160 multiplicity=DefiniteMultiplicity;
161
162Multiplicity:
163 UnboundedMultiplicity | DefiniteMultiplicity;
164
165DefiniteMultiplicity returns Multiplicity:
166 RangeMultiplicity | ExactMultiplicity;
167
168UnboundedMultiplicity:
169 {UnboundedMultiplicity};
170
171RangeMultiplicity:
172 lowerBound=INT ".." upperBound=UpperBound;
173
174ExactMultiplicity:
175 exactValue=INT;
176
177IndividualDeclaration:
178 "indiv" nodes+=EnumLiteral ("," nodes+=EnumLiteral)* ".";
179
180UpperBound returns ecore::EInt:
181 INT | "*";
182
183QualifiedName hidden():
184 Identifier ("::" Identifier)*;
185
186Identifier:
187 ID | "true" | "false" | "unknown" | "error" | "class" | "abstract" | "extends" | "enum" | "pred" |
188 "indiv" | "problem" | "new" | "delete" | "direct" | "rule";
189
190Integer returns ecore::EInt hidden():
191 "-"? INT;
192
193Real returns ecore::EDouble:
194 "-"? (EXPONENTIAL | INT "." (INT | EXPONENTIAL));
195
196@Override
197terminal ID:
198 ('a'..'z' | 'A'..'Z' | '_') ('a'..'z' | 'A'..'Z' | '_' | '0'..'9')*;
199
200terminal EXPONENTIAL:
201 INT ("e" | "E") ("+" | "-")? INT;
202
203@Override
204terminal SL_COMMENT:
205 ('%' | '//') !('\n' | '\r')* ('\r'? '\n')?;