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