diff options
author | 2022-11-19 21:39:00 +0100 | |
---|---|---|
committer | 2022-11-22 16:40:03 +0100 | |
commit | 3aa4a2b58221a3e83b17d0c04c9a6e9c41e5500c (patch) | |
tree | 1e25f513e3b34b2ea29dbcc6cc3795e5927a1362 /subprojects/frontend/src/language/problem.grammar | |
parent | feat(language): numeric expressions (diff) | |
download | refinery-3aa4a2b58221a3e83b17d0c04c9a6e9c41e5500c.tar.gz refinery-3aa4a2b58221a3e83b17d0c04c9a6e9c41e5500c.tar.zst refinery-3aa4a2b58221a3e83b17d0c04c9a6e9c41e5500c.zip |
refactor: separate primitive types from nodes
Diffstat (limited to 'subprojects/frontend/src/language/problem.grammar')
-rw-r--r-- | subprojects/frontend/src/language/problem.grammar | 59 |
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 | ||
61 | ReferenceDeclaration { | 60 | FeatureDeclaration { |
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 | ||
76 | Parameter { Modality? RelationName? VariableName } | 68 | Parameter { Modality? RelationName? VariableName } |
77 | 69 | ||
78 | Conjunction { ("," | 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. | ||
73 | Conjunction { ("," | NextConjunction[@dynamicPrecedence=-10] { Expr })+ } | ||
79 | 74 | ||
80 | Case { Conjunction ("->" Expr)? } | 75 | Case { 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 | ||
88 | BinaryExpr[@dynamicPrecedence=1] { | 83 | BinaryExpr { |
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 | ||
113 | AssertionArgument { NodeName | StarArgument | Constant } | 110 | AssertionArgument { NodeName | StarArgument } |
111 | |||
112 | Constant { Real | String | StarMult } | ||
114 | 113 | ||
115 | Constant { Real | String } | 114 | ReferenceKind { |
115 | kw<"refers"> | ckw<"contains"> | kw<"container"> | ||
116 | } | ||
117 | |||
118 | PrimitiveType { | ||
119 | kw<"int"> | kw<"real"> | kw<"string"> | ||
120 | } | ||
116 | 121 | ||
117 | LogicValue { | 122 | LogicValue { |
118 | ckw<"true"> | ckw<"false"> | kw<"unknown"> | kw<"error"> | 123 | kw<"true"> | kw<"false"> | kw<"unknown"> | kw<"error"> |
119 | } | 124 | } |
120 | 125 | ||
121 | Modality { | 126 | Modality { |
@@ -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 | ||
134 | ComparisonOp { SymbolicComparisonOp | kw<"in"> } | ||
135 | |||
129 | ScopeElement { RelationName ("=" | "+=") Multiplicity } | 136 | ScopeElement { RelationName ("=" | "+=") Multiplicity } |
130 | 137 | ||
131 | Multiplicity { (IntMult "..")? (IntMult | StarMult)} | 138 | Multiplicity { (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. | ||
133 | RelationName { QualifiedName ~name } | 144 | RelationName { 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 | ||