diff options
author | Kristóf Marussy <kristof@marussy.com> | 2022-11-19 14:00:12 +0100 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2022-11-22 16:40:03 +0100 |
commit | 383137c190cab040d2609f8295ef822c3917b88d (patch) | |
tree | d0d88528de2020da51cb6e92459b84cf63609feb /subprojects/frontend/src/language/problem.grammar | |
parent | chore(deps): bump dependencies (diff) | |
download | refinery-383137c190cab040d2609f8295ef822c3917b88d.tar.gz refinery-383137c190cab040d2609f8295ef822c3917b88d.tar.zst refinery-383137c190cab040d2609f8295ef822c3917b88d.zip |
feat(language): numeric expressions
Diffstat (limited to 'subprojects/frontend/src/language/problem.grammar')
-rw-r--r-- | subprojects/frontend/src/language/problem.grammar | 91 |
1 files changed, 62 insertions, 29 deletions
diff --git a/subprojects/frontend/src/language/problem.grammar b/subprojects/frontend/src/language/problem.grammar index d630b9c4..4235c433 100644 --- a/subprojects/frontend/src/language/problem.grammar +++ b/subprojects/frontend/src/language/problem.grammar | |||
@@ -2,56 +2,69 @@ | |||
2 | 2 | ||
3 | @external prop implicitCompletion from './props' | 3 | @external prop implicitCompletion from './props' |
4 | 4 | ||
5 | @precedence { | ||
6 | containment @cut, | ||
7 | prefix, | ||
8 | exponential @right, | ||
9 | multiplicative @left, | ||
10 | additive @left, | ||
11 | comparison @left | ||
12 | } | ||
13 | |||
5 | @top Problem { statement* } | 14 | @top Problem { statement* } |
6 | 15 | ||
7 | statement { | 16 | statement { |
8 | ProblemDeclaration { | 17 | ProblemDeclaration { |
9 | ckw<"problem"> QualifiedName "." | 18 | kw<"problem"> QualifiedName "." |
10 | } | | 19 | } | |
11 | ClassDefinition { | 20 | ClassDefinition { |
12 | ckw<"abstract">? ckw<"class"> RelationName | 21 | kw<"abstract">? kw<"class"> RelationName |
13 | (ckw<"extends"> sep<",", RelationName>)? | 22 | (kw<"extends"> sep<",", RelationName>)? |
14 | (ClassBody { "{" ReferenceDeclaration* "}" } | ".") | 23 | (ClassBody { "{" ReferenceDeclaration* "}" } | ".") |
15 | } | | 24 | } | |
16 | EnumDefinition { | 25 | EnumDefinition { |
17 | ckw<"enum"> RelationName | 26 | kw<"enum"> RelationName |
18 | (EnumBody { "{" sep<",", IndividualNodeName> "}" } | ".") | 27 | (EnumBody { "{" sep<",", IndividualNodeName> "}" } | ".") |
19 | } | | 28 | } | |
20 | PredicateDefinition { | 29 | PredicateDefinition { |
21 | ( | 30 | ( |
22 | (ckw<"error"> | ckw<"contained"> | ckw<"containment">) ckw<"pred">? | | 31 | (kw<"error"> | ckw<"contained"> | kw<"containment">)? kw<"pred"> | |
23 | ckw<"pred"> | 32 | kw<"error"> |
24 | ) | 33 | ) |
25 | RelationName ParameterList<Parameter>? | 34 | RelationName ParameterList<Parameter>? |
26 | PredicateBody { ("<->" sep<OrOp, Conjunction>)? "." } | 35 | PredicateBody { ("<->" sep<OrOp, Conjunction>)? "." } |
36 | } | | ||
37 | FunctionDefinition { | ||
38 | RelationName RelationName ParameterList<Parameter>? | ||
39 | FunctionBody { ("=" sep<OrOp, Case>)? "." } | ||
27 | } | | 40 | } | |
28 | //RuleDefinition { | 41 | //RuleDefinition { |
29 | // ckw<"rule"> | 42 | // kw<"rule"> |
30 | // RuleName ParameterList<Parameter>? | 43 | // RuleName ParameterList<Parameter>? |
31 | // RuleBody { ":" sep<OrOp, Conjunction> "==>" sep<OrOp, Consequent> "." } | 44 | // RuleBody { ":" sep<OrOp, Conjunction> "==>" sep<OrOp, Consequent> "." } |
32 | //} | | 45 | //} | |
33 | Assertion { | 46 | Assertion { |
34 | ckw<"default">? (NotOp | UnknownOp)? RelationName | 47 | kw<"default">? (NotOp | UnknownOp)? RelationName |
35 | ParameterList<AssertionArgument> (":" LogicValue)? "." | 48 | ParameterList<AssertionArgument> (":" LogicValue)? "." |
36 | } | | 49 | } | |
37 | NodeValueAssertion { | 50 | NodeValueAssertion { |
38 | QualifiedName ":" Constant "." | 51 | QualifiedName ":" Constant "." |
39 | } | | 52 | } | |
40 | IndividualDeclaration { | 53 | IndividualDeclaration { |
41 | ckw<"indiv"> sep<",", IndividualNodeName> "." | 54 | kw<"individual"> sep<",", IndividualNodeName> "." |
42 | } | | 55 | } | |
43 | ScopeDeclaration { | 56 | ScopeDeclaration { |
44 | ckw<"scope"> sep<",", ScopeElement> "." | 57 | kw<"scope"> sep<",", ScopeElement> "." |
45 | } | 58 | } |
46 | } | 59 | } |
47 | 60 | ||
48 | ReferenceDeclaration { | 61 | ReferenceDeclaration { |
49 | ( | 62 | ( |
50 | ExplicitContainmentReference[@dynamicPrecedence=1] { | 63 | ExplicitContainmentReference { |
51 | (ckw<"refers"> | ckw<"contains"> | ckw<"container">) RelationName ~containment | 64 | !containment (kw<"refers"> | ckw<"contains"> | kw<"container">) RelationName |
52 | } | | 65 | } | |
53 | ImplicitContainmentReference { | 66 | ImplicitContainmentReference { |
54 | RelationName ~containment | 67 | RelationName |
55 | } | 68 | } |
56 | ) | 69 | ) |
57 | ("[" Multiplicity? "]")? | 70 | ("[" Multiplicity? "]")? |
@@ -62,50 +75,68 @@ ReferenceDeclaration { | |||
62 | 75 | ||
63 | Parameter { Modality? RelationName? VariableName } | 76 | Parameter { Modality? RelationName? VariableName } |
64 | 77 | ||
65 | Conjunction { ("," | Literal)+ } | 78 | Conjunction { ("," | Expr)+ } |
79 | |||
80 | Case { Conjunction ("->" Expr)? } | ||
66 | 81 | ||
67 | OrOp { ";" } | 82 | OrOp { ";" } |
68 | 83 | ||
69 | Literal { | 84 | Expr { |
70 | Modality? (NotOp | ckw<"count">)? Modality? Atom | 85 | UnaryExpr | BinaryExpr | Aggregation | VariableName | Atom | Constant | "(" Expr ")" |
71 | ((":=" | "<:") LogicValue | ComparisonOp int)? | 86 | } |
87 | |||
88 | BinaryExpr[@dynamicPrecedence=1] { | ||
89 | Expr !comparison ComparisonOp Expr | | ||
90 | Expr !additive ("+" | "-") Expr | | ||
91 | Expr !multiplicative (StarMult | Divide) Expr | | ||
92 | Expr !exponential "**" Expr | ||
93 | } | ||
94 | |||
95 | UnaryExpr { | ||
96 | !prefix ("+" | "-" | "!" | "#" | Modality) Expr | ||
97 | } | ||
98 | |||
99 | Aggregation { | ||
100 | AggregationOp "{" Expr "|" Expr "}" | ||
72 | } | 101 | } |
73 | 102 | ||
74 | Atom { RelationName "+"? ParameterList<Argument> } | 103 | Atom { RelationName "+"? ParameterList<Expr> } |
75 | 104 | ||
76 | //Consequent { ("," | Action)+ } | 105 | //Consequent { ("," | Action)+ } |
77 | 106 | ||
78 | //Action { | 107 | //Action { |
79 | // ckw<"new"> VariableName ("<:" VariableName)? | | 108 | // ckw<"new"> VariableName ("<:" VariableName)? | |
80 | // ckw<"delete"> VariableName | | 109 | // kw<"delete"> VariableName | |
81 | // Literal | 110 | // Literal |
82 | //} | 111 | //} |
83 | 112 | ||
84 | Argument { VariableName | Constant } | ||
85 | |||
86 | AssertionArgument { NodeName | StarArgument | Constant } | 113 | AssertionArgument { NodeName | StarArgument | Constant } |
87 | 114 | ||
88 | Constant { Real | String } | 115 | Constant { Real | String } |
89 | 116 | ||
90 | LogicValue { | 117 | LogicValue { |
91 | ckw<"true"> | ckw<"false"> | ckw<"unknown"> | ckw<"error"> | 118 | ckw<"true"> | ckw<"false"> | kw<"unknown"> | kw<"error"> |
92 | } | 119 | } |
93 | 120 | ||
94 | Modality { | 121 | Modality { |
95 | ckw<"must"> | ckw<"may"> | ckw<"current"> | 122 | kw<"must"> | kw<"may"> | kw<"current"> |
123 | } | ||
124 | |||
125 | AggregationOp { | ||
126 | ckw<"sum"> | ckw<"prod"> | ckw<"min"> | ckw<"max"> | ||
96 | } | 127 | } |
97 | 128 | ||
98 | ScopeElement { RelationName ("=" | "+=") Multiplicity } | 129 | ScopeElement { RelationName ("=" | "+=") Multiplicity } |
99 | 130 | ||
100 | Multiplicity { (IntMult "..")? (IntMult | StarMult)} | 131 | Multiplicity { (IntMult "..")? (IntMult | StarMult)} |
101 | 132 | ||
102 | RelationName { QualifiedName } | 133 | RelationName { QualifiedName ~name } |
103 | 134 | ||
104 | //RuleName { QualifiedName } | 135 | //RuleName { QualifiedName } |
105 | 136 | ||
106 | IndividualNodeName { QualifiedName } | 137 | IndividualNodeName { QualifiedName } |
107 | 138 | ||
108 | VariableName { QualifiedName } | 139 | VariableName[@dynamicPrecedence=10] { QualifiedName ~name } |
109 | 140 | ||
110 | NodeName { QualifiedName } | 141 | NodeName { QualifiedName } |
111 | 142 | ||
@@ -134,7 +165,9 @@ sep1<separator, content> { content (separator content)* } | |||
134 | 165 | ||
135 | blockCommentAfterStar { "/" | "*" blockCommentAfterStar | ![/*] blockCommentRest } | 166 | blockCommentAfterStar { "/" | "*" blockCommentAfterStar | ![/*] blockCommentRest } |
136 | 167 | ||
137 | @precedence { BlockComment, LineComment } | 168 | Divide { "/" } |
169 | |||
170 | @precedence { BlockComment, LineComment, Divide } | ||
138 | 171 | ||
139 | identifier { $[A-Za-z_] $[a-zA-Z0-9_]* } | 172 | identifier { $[A-Za-z_] $[a-zA-Z0-9_]* } |
140 | 173 | ||
@@ -144,7 +177,7 @@ sep1<separator, content> { content (separator content)* } | |||
144 | 177 | ||
145 | StarMult { "*" } | 178 | StarMult { "*" } |
146 | 179 | ||
147 | Real { "-"? (exponential | int ("." (int | exponential))?) } | 180 | Real { (exponential | int ("." (int | exponential))?) } |
148 | 181 | ||
149 | exponential { int ("e" | "E") ("+" | "-")? int } | 182 | exponential { int ("e" | "E") ("+" | "-")? int } |
150 | 183 | ||
@@ -161,5 +194,5 @@ sep1<separator, content> { content (separator content)* } | |||
161 | 194 | ||
162 | StarArgument { "*" } | 195 | StarArgument { "*" } |
163 | 196 | ||
164 | "{" "}" "(" ")" "[" "]" "." ".." "," ":" "<->" "~>" | 197 | "{" "}" "(" ")" "[" "]" "." ".." "," ":" "->" "<->" "+" "-" "**" "=" "+=" |
165 | } | 198 | } |