aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend/src/language
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2022-11-19 14:00:12 +0100
committerLibravatar Kristóf Marussy <kristof@marussy.com>2022-11-22 16:40:03 +0100
commit383137c190cab040d2609f8295ef822c3917b88d (patch)
treed0d88528de2020da51cb6e92459b84cf63609feb /subprojects/frontend/src/language
parentchore(deps): bump dependencies (diff)
downloadrefinery-383137c190cab040d2609f8295ef822c3917b88d.tar.gz
refinery-383137c190cab040d2609f8295ef822c3917b88d.tar.zst
refinery-383137c190cab040d2609f8295ef822c3917b88d.zip
feat(language): numeric expressions
Diffstat (limited to 'subprojects/frontend/src/language')
-rw-r--r--subprojects/frontend/src/language/indentation.ts2
-rw-r--r--subprojects/frontend/src/language/problem.grammar91
-rw-r--r--subprojects/frontend/src/language/problemLanguageSupport.ts11
3 files changed, 70 insertions, 34 deletions
diff --git a/subprojects/frontend/src/language/indentation.ts b/subprojects/frontend/src/language/indentation.ts
index b49d6563..a0f7032d 100644
--- a/subprojects/frontend/src/language/indentation.ts
+++ b/subprojects/frontend/src/language/indentation.ts
@@ -78,7 +78,7 @@ export function indentDeclaration(context: TreeIndentContext): number {
78 78
79export function indentPredicateOrRule(context: TreeIndentContext): number { 79export function indentPredicateOrRule(context: TreeIndentContext): number {
80 const clauseIndent = indentDeclarationStrategy(context, 1); 80 const clauseIndent = indentDeclarationStrategy(context, 1);
81 if (/^\s+(?:==>|[;.])/.exec(context.textAfter) !== null) { 81 if (/^\s+(?:->|==>|[;.])/.exec(context.textAfter) !== null) {
82 return clauseIndent - context.unit; 82 return clauseIndent - context.unit;
83 } 83 }
84 return clauseIndent; 84 return clauseIndent;
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
7statement { 16statement {
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
48ReferenceDeclaration { 61ReferenceDeclaration {
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
63Parameter { Modality? RelationName? VariableName } 76Parameter { Modality? RelationName? VariableName }
64 77
65Conjunction { ("," | Literal)+ } 78Conjunction { ("," | Expr)+ }
79
80Case { Conjunction ("->" Expr)? }
66 81
67OrOp { ";" } 82OrOp { ";" }
68 83
69Literal { 84Expr {
70 Modality? (NotOp | ckw<"count">)? Modality? Atom 85 UnaryExpr | BinaryExpr | Aggregation | VariableName | Atom | Constant | "(" Expr ")"
71 ((":=" | "<:") LogicValue | ComparisonOp int)? 86}
87
88BinaryExpr[@dynamicPrecedence=1] {
89 Expr !comparison ComparisonOp Expr |
90 Expr !additive ("+" | "-") Expr |
91 Expr !multiplicative (StarMult | Divide) Expr |
92 Expr !exponential "**" Expr
93}
94
95UnaryExpr {
96 !prefix ("+" | "-" | "!" | "#" | Modality) Expr
97}
98
99Aggregation {
100 AggregationOp "{" Expr "|" Expr "}"
72} 101}
73 102
74Atom { RelationName "+"? ParameterList<Argument> } 103Atom { 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
84Argument { VariableName | Constant }
85
86AssertionArgument { NodeName | StarArgument | Constant } 113AssertionArgument { NodeName | StarArgument | Constant }
87 114
88Constant { Real | String } 115Constant { Real | String }
89 116
90LogicValue { 117LogicValue {
91 ckw<"true"> | ckw<"false"> | ckw<"unknown"> | ckw<"error"> 118 ckw<"true"> | ckw<"false"> | kw<"unknown"> | kw<"error">
92} 119}
93 120
94Modality { 121Modality {
95 ckw<"must"> | ckw<"may"> | ckw<"current"> 122 kw<"must"> | kw<"may"> | kw<"current">
123}
124
125AggregationOp {
126 ckw<"sum"> | ckw<"prod"> | ckw<"min"> | ckw<"max">
96} 127}
97 128
98ScopeElement { RelationName ("=" | "+=") Multiplicity } 129ScopeElement { RelationName ("=" | "+=") Multiplicity }
99 130
100Multiplicity { (IntMult "..")? (IntMult | StarMult)} 131Multiplicity { (IntMult "..")? (IntMult | StarMult)}
101 132
102RelationName { QualifiedName } 133RelationName { QualifiedName ~name }
103 134
104//RuleName { QualifiedName } 135//RuleName { QualifiedName }
105 136
106IndividualNodeName { QualifiedName } 137IndividualNodeName { QualifiedName }
107 138
108VariableName { QualifiedName } 139VariableName[@dynamicPrecedence=10] { QualifiedName ~name }
109 140
110NodeName { QualifiedName } 141NodeName { 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}
diff --git a/subprojects/frontend/src/language/problemLanguageSupport.ts b/subprojects/frontend/src/language/problemLanguageSupport.ts
index a96b5402..cde8b157 100644
--- a/subprojects/frontend/src/language/problemLanguageSupport.ts
+++ b/subprojects/frontend/src/language/problemLanguageSupport.ts
@@ -21,11 +21,12 @@ const parserWithMetadata = parser.configure({
21 styleTags({ 21 styleTags({
22 LineComment: t.lineComment, 22 LineComment: t.lineComment,
23 BlockComment: t.blockComment, 23 BlockComment: t.blockComment,
24 'problem class enum pred indiv scope': t.definitionKeyword, 24 'problem class enum pred individual scope': t.definitionKeyword,
25 'abstract extends refers contains container opposite': t.modifier, 25 'abstract extends refers contains container opposite': t.modifier,
26 'default error contained containment': t.modifier, 26 'default error contained containment': t.modifier,
27 'true false unknown error': t.operatorKeyword, 27 'true false unknown error': t.operatorKeyword,
28 'may must current count': t.operatorKeyword, 28 'may must current': t.operatorKeyword,
29 'sum prod min max': t.operatorKeyword,
29 // 'new delete': t.keyword, 30 // 'new delete': t.keyword,
30 NotOp: t.operator, 31 NotOp: t.operator,
31 UnknownOp: t.operator, 32 UnknownOp: t.operator,
@@ -42,13 +43,14 @@ const parserWithMetadata = parser.configure({
42 '( )': t.paren, 43 '( )': t.paren,
43 '[ ]': t.squareBracket, 44 '[ ]': t.squareBracket,
44 '. .. , :': t.separator, 45 '. .. , :': t.separator,
45 '<-> ==>': t.definitionOperator, 46 '<-> = -> ==>': t.definitionOperator,
46 }), 47 }),
47 indentNodeProp.add({ 48 indentNodeProp.add({
48 ProblemDeclaration: indentDeclaration, 49 ProblemDeclaration: indentDeclaration,
49 UniqueDeclaration: indentDeclaration, 50 UniqueDeclaration: indentDeclaration,
50 ScopeDeclaration: indentDeclaration, 51 ScopeDeclaration: indentDeclaration,
51 PredicateBody: indentPredicateOrRule, 52 PredicateBody: indentPredicateOrRule,
53 FunctionBody: indentPredicateOrRule,
52 // RuleBody: indentPredicateOrRule, 54 // RuleBody: indentPredicateOrRule,
53 BlockComment: indentBlockComment, 55 BlockComment: indentBlockComment,
54 }), 56 }),
@@ -57,6 +59,7 @@ const parserWithMetadata = parser.configure({
57 EnumBody: foldInside, 59 EnumBody: foldInside,
58 ParameterList: foldInside, 60 ParameterList: foldInside,
59 PredicateBody: foldInside, 61 PredicateBody: foldInside,
62 FunctionBody: foldInside,
60 // RuleBody: foldInside, 63 // RuleBody: foldInside,
61 Conjunction: foldConjunction, 64 Conjunction: foldConjunction,
62 // Consequent: foldWholeNode, 65 // Consequent: foldWholeNode,
@@ -77,7 +80,7 @@ const problemLanguage = LRLanguage.define({
77 }, 80 },
78 line: '%', 81 line: '%',
79 }, 82 },
80 indentOnInput: /^\s*(?:\{|\}|\(|\)|;|\.)$/, 83 indentOnInput: /^\s*(?:\{|\}|\(|\)|->|;|\.)$/,
81 }, 84 },
82}); 85});
83 86