aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend/src/language/problem.grammar
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/frontend/src/language/problem.grammar')
-rw-r--r--subprojects/frontend/src/language/problem.grammar59
1 files changed, 36 insertions, 23 deletions
diff --git a/subprojects/frontend/src/language/problem.grammar b/subprojects/frontend/src/language/problem.grammar
index 4235c433..7c4098d5 100644
--- a/subprojects/frontend/src/language/problem.grammar
+++ b/subprojects/frontend/src/language/problem.grammar
@@ -3,11 +3,12 @@
3@external prop implicitCompletion from './props' 3@external prop implicitCompletion from './props'
4 4
5@precedence { 5@precedence {
6 containment @cut,
7 prefix, 6 prefix,
8 exponential @right, 7 exponential @right,
9 multiplicative @left, 8 multiplicative @left,
10 additive @left, 9 additive @left,
10 range @left,
11 lattice @left,
11 comparison @left 12 comparison @left
12} 13}
13 14
@@ -20,7 +21,7 @@ statement {
20 ClassDefinition { 21 ClassDefinition {
21 kw<"abstract">? kw<"class"> RelationName 22 kw<"abstract">? kw<"class"> RelationName
22 (kw<"extends"> sep<",", RelationName>)? 23 (kw<"extends"> sep<",", RelationName>)?
23 (ClassBody { "{" ReferenceDeclaration* "}" } | ".") 24 (ClassBody { "{" FeatureDeclaration* "}" } | ".")
24 } | 25 } |
25 EnumDefinition { 26 EnumDefinition {
26 kw<"enum"> RelationName 27 kw<"enum"> RelationName
@@ -35,7 +36,7 @@ statement {
35 PredicateBody { ("<->" sep<OrOp, Conjunction>)? "." } 36 PredicateBody { ("<->" sep<OrOp, Conjunction>)? "." }
36 } | 37 } |
37 FunctionDefinition { 38 FunctionDefinition {
38 RelationName RelationName ParameterList<Parameter>? 39 PrimitiveType RelationName ParameterList<Parameter>?
39 FunctionBody { ("=" sep<OrOp, Case>)? "." } 40 FunctionBody { ("=" sep<OrOp, Case>)? "." }
40 } | 41 } |
41 //RuleDefinition { 42 //RuleDefinition {
@@ -45,10 +46,8 @@ statement {
45 //} | 46 //} |
46 Assertion { 47 Assertion {
47 kw<"default">? (NotOp | UnknownOp)? RelationName 48 kw<"default">? (NotOp | UnknownOp)? RelationName
48 ParameterList<AssertionArgument> (":" LogicValue)? "." 49 ParameterList<AssertionArgument>
49 } | 50 (":" LogicValue | ("=" | kw<"in">) Expr)? "."
50 NodeValueAssertion {
51 QualifiedName ":" Constant "."
52 } | 51 } |
53 IndividualDeclaration { 52 IndividualDeclaration {
54 kw<"individual"> sep<",", IndividualNodeName> "." 53 kw<"individual"> sep<",", IndividualNodeName> "."
@@ -58,15 +57,8 @@ statement {
58 } 57 }
59} 58}
60 59
61ReferenceDeclaration { 60FeatureDeclaration {
62 ( 61 (ReferenceKind | PrimitiveType | kw<"bool">) RelationName
63 ExplicitContainmentReference {
64 !containment (kw<"refers"> | ckw<"contains"> | kw<"container">) RelationName
65 } |
66 ImplicitContainmentReference {
67 RelationName
68 }
69 )
70 ("[" Multiplicity? "]")? 62 ("[" Multiplicity? "]")?
71 RelationName 63 RelationName
72 (kw<"opposite"> RelationName)? 64 (kw<"opposite"> RelationName)?
@@ -75,7 +67,10 @@ ReferenceDeclaration {
75 67
76Parameter { Modality? RelationName? VariableName } 68Parameter { Modality? RelationName? VariableName }
77 69
78Conjunction { ("," | Expr)+ } 70// Use @dynamicPrecedence to prevent a(b) from being parsed as Expr { a } Expr { b }
71// instead of Atom { a(b) }
72// Being looser with token sequencing enables more consistent syntactic highlighting.
73Conjunction { ("," | NextConjunction[@dynamicPrecedence=-10] { Expr })+ }
79 74
80Case { Conjunction ("->" Expr)? } 75Case { Conjunction ("->" Expr)? }
81 76
@@ -85,8 +80,10 @@ Expr {
85 UnaryExpr | BinaryExpr | Aggregation | VariableName | Atom | Constant | "(" Expr ")" 80 UnaryExpr | BinaryExpr | Aggregation | VariableName | Atom | Constant | "(" Expr ")"
86} 81}
87 82
88BinaryExpr[@dynamicPrecedence=1] { 83BinaryExpr {
89 Expr !comparison ComparisonOp Expr | 84 Expr !comparison ComparisonOp Expr |
85 Expr !lattice (LatticeMeet | "\\/") Expr |
86 Expr !range ".." Expr |
90 Expr !additive ("+" | "-") Expr | 87 Expr !additive ("+" | "-") Expr |
91 Expr !multiplicative (StarMult | Divide) Expr | 88 Expr !multiplicative (StarMult | Divide) Expr |
92 Expr !exponential "**" Expr 89 Expr !exponential "**" Expr
@@ -110,12 +107,20 @@ Atom { RelationName "+"? ParameterList<Expr> }
110// Literal 107// Literal
111//} 108//}
112 109
113AssertionArgument { NodeName | StarArgument | Constant } 110AssertionArgument { NodeName | StarArgument }
111
112Constant { Real | String | StarMult }
114 113
115Constant { Real | String } 114ReferenceKind {
115 kw<"refers"> | ckw<"contains"> | kw<"container">
116}
117
118PrimitiveType {
119 kw<"int"> | kw<"real"> | kw<"string">
120}
116 121
117LogicValue { 122LogicValue {
118 ckw<"true"> | ckw<"false"> | kw<"unknown"> | kw<"error"> 123 kw<"true"> | kw<"false"> | kw<"unknown"> | kw<"error">
119} 124}
120 125
121Modality { 126Modality {
@@ -126,10 +131,16 @@ AggregationOp {
126 ckw<"sum"> | ckw<"prod"> | ckw<"min"> | ckw<"max"> 131 ckw<"sum"> | ckw<"prod"> | ckw<"min"> | ckw<"max">
127} 132}
128 133
134ComparisonOp { SymbolicComparisonOp | kw<"in"> }
135
129ScopeElement { RelationName ("=" | "+=") Multiplicity } 136ScopeElement { RelationName ("=" | "+=") Multiplicity }
130 137
131Multiplicity { (IntMult "..")? (IntMult | StarMult)} 138Multiplicity { (IntMult "..")? (IntMult | StarMult)}
132 139
140// The ~name handles the ambiguity between transitve closure a+(b, c) and addition a+(b)
141// in the grammar. We prefer the addition interpretation by applying @dynamicPrecedence=1
142// to the VariableName rule,
143// but will go with the transtive closure (and highlight `a` as a relation) if forced.
133RelationName { QualifiedName ~name } 144RelationName { QualifiedName ~name }
134 145
135//RuleName { QualifiedName } 146//RuleName { QualifiedName }
@@ -167,7 +178,9 @@ sep1<separator, content> { content (separator content)* }
167 178
168 Divide { "/" } 179 Divide { "/" }
169 180
170 @precedence { BlockComment, LineComment, Divide } 181 LatticeMeet { "/\\" }
182
183 @precedence { BlockComment, LineComment, LatticeMeet, Divide }
171 184
172 identifier { $[A-Za-z_] $[a-zA-Z0-9_]* } 185 identifier { $[A-Za-z_] $[a-zA-Z0-9_]* }
173 186
@@ -186,7 +199,7 @@ sep1<separator, content> { content (separator content)* }
186 "\"" (![\\"\n] | "\\" (![\n] | "\n"))* "\"" 199 "\"" (![\\"\n] | "\\" (![\n] | "\n"))* "\""
187 } 200 }
188 201
189 ComparisonOp { ">" | ">=" | "<" | "<=" | "==" | "!=" } 202 SymbolicComparisonOp { ">" | ">=" | "<" | "<=" | "==" | "!=" }
190 203
191 NotOp { "!" } 204 NotOp { "!" }
192 205