aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2024-03-05 22:01:10 +0100
committerLibravatar Kristóf Marussy <kristof@marussy.com>2024-04-07 14:55:46 +0200
commitc14d8efd509f834b80573bc0339bb990698b265c (patch)
treedc3ca21785ea17bc75a861f373ee69ec64d6e97f /subprojects/frontend
parentfeat(language): validate assignment expressions (diff)
downloadrefinery-c14d8efd509f834b80573bc0339bb990698b265c.tar.gz
refinery-c14d8efd509f834b80573bc0339bb990698b265c.tar.zst
refinery-c14d8efd509f834b80573bc0339bb990698b265c.zip
feat(language): type inference
* Customizable operator overloads. * Customizable aggregation operators. * Simplify ProblemQualifiedNameProvider.
Diffstat (limited to 'subprojects/frontend')
-rw-r--r--subprojects/frontend/src/editor/EditorTheme.ts2
-rw-r--r--subprojects/frontend/src/language/problem.grammar31
-rw-r--r--subprojects/frontend/src/language/problemLanguageSupport.ts9
3 files changed, 21 insertions, 21 deletions
diff --git a/subprojects/frontend/src/editor/EditorTheme.ts b/subprojects/frontend/src/editor/EditorTheme.ts
index b211f2a7..1f8152d3 100644
--- a/subprojects/frontend/src/editor/EditorTheme.ts
+++ b/subprojects/frontend/src/editor/EditorTheme.ts
@@ -166,7 +166,7 @@ export default styled('div', {
166 '.tok-problem-abstract': { 166 '.tok-problem-abstract': {
167 fontStyle: 'italic', 167 fontStyle: 'italic',
168 }, 168 },
169 '.tok-problem-datatype': { 169 '.tok-problem-datatype, .tok-problem-aggregator': {
170 '&, & .tok-typeName': { 170 '&, & .tok-typeName': {
171 color: theme.palette.primary.main, 171 color: theme.palette.primary.main,
172 }, 172 },
diff --git a/subprojects/frontend/src/language/problem.grammar b/subprojects/frontend/src/language/problem.grammar
index 0f6ea3e1..829dc138 100644
--- a/subprojects/frontend/src/language/problem.grammar
+++ b/subprojects/frontend/src/language/problem.grammar
@@ -11,12 +11,13 @@
11@precedence { 11@precedence {
12 cast, 12 cast,
13 prefix, 13 prefix,
14 range @left,
14 exponential @right, 15 exponential @right,
15 multiplicative @left, 16 multiplicative @left,
16 additive @left, 17 additive @left,
17 range @left,
18 lattice @left, 18 lattice @left,
19 comparison @left, 19 comparison @left,
20 boolean @left,
20 assignment, 21 assignment,
21 feature @cut 22 feature @cut
22} 23}
@@ -45,7 +46,10 @@ statement {
45 (EnumBody { "{" sep<",", AtomNodeName> "}" } | ".") 46 (EnumBody { "{" sep<",", AtomNodeName> "}" } | ".")
46 } | 47 } |
47 DatatypeDeclaration { 48 DatatypeDeclaration {
48 kw<"extern"> kw<"datatype"> DatatypeName "." 49 kw<"extern"> ckw<"datatype"> DatatypeName "."
50 } |
51 AggregatorDeclaration {
52 kw<"extern"> ckw<"aggregator"> AggregatorName "."
49 } | 53 } |
50 PredicateDefinition { 54 PredicateDefinition {
51 ( 55 (
@@ -92,7 +96,7 @@ FeatureDeclaration {
92 ";"? 96 ";"?
93} 97}
94 98
95Parameter { Modality? RelationName? VariableName } 99Parameter { RelationName? VariableName }
96 100
97// Use @dynamicPrecedence to prevent a(b) from being parsed as Expr { a } Expr { b } 101// Use @dynamicPrecedence to prevent a(b) from being parsed as Expr { a } Expr { b }
98// instead of Atom { a(b) } 102// instead of Atom { a(b) }
@@ -111,22 +115,23 @@ Expr {
111AssignmentExpr { !assignment VariableName kw<"is"> Expr } 115AssignmentExpr { !assignment VariableName kw<"is"> Expr }
112 116
113BinaryExpr { 117BinaryExpr {
118 Expr !boolean ("&&" | "||" | "^^") Expr |
114 Expr !comparison ComparisonOp Expr | 119 Expr !comparison ComparisonOp Expr |
115 Expr !lattice (LatticeMeet | "\\/") Expr | 120 Expr !lattice (LatticeMeet | "\\/") Expr |
116 Expr !range ".." Expr |
117 Expr !additive ("+" | "-") Expr | 121 Expr !additive ("+" | "-") Expr |
118 Expr !multiplicative (StarMult | Divide) Expr | 122 Expr !multiplicative (StarMult | Divide) Expr |
119 Expr !exponential "**" Expr 123 Expr !exponential "**" Expr |
124 Expr !range ".." Expr
120} 125}
121 126
122UnaryExpr { 127UnaryExpr {
123 !prefix ("+" | "-" | "!" | kw<"count"> | Modality) Expr 128 !prefix ("+" | "-" | "!" | kw<"count">) Expr
124} 129}
125 130
126CastExpr { !cast Expr kw<"as"> DatatypeName } 131CastExpr { !cast Expr kw<"as"> DatatypeName }
127 132
128Aggregation { 133Aggregation {
129 AggregationOp "{" Expr "|" Expr "}" 134 AggregatorName "{" Expr "|" Expr "}"
130} 135}
131 136
132Atom { RelationName "+"? ParameterList<Expr> } 137Atom { RelationName "+"? ParameterList<Expr> }
@@ -151,14 +156,6 @@ LogicValue {
151 kw<"true"> | kw<"false"> | kw<"unknown"> | kw<"error"> 156 kw<"true"> | kw<"false"> | kw<"unknown"> | kw<"error">
152} 157}
153 158
154Modality {
155 kw<"must"> | kw<"may"> | kw<"current">
156}
157
158AggregationOp {
159 ckw<"sum"> | ckw<"prod"> | ckw<"min"> | ckw<"max">
160}
161
162ComparisonOp { SymbolicComparisonOp | kw<"in"> } 159ComparisonOp { SymbolicComparisonOp | kw<"in"> }
163 160
164ScopeElement { RelationName ("=" | "+=") Multiplicity } 161ScopeElement { RelationName ("=" | "+=") Multiplicity }
@@ -183,6 +180,8 @@ NodeName { QualifiedName }
183 180
184ModuleName { QualifiedName } 181ModuleName { QualifiedName }
185 182
183AggregatorName { QualifiedName }
184
186QualifiedName[implicitCompletion=true] { "::"? identifier (QualifiedNameSeparator "::" identifier)* } 185QualifiedName[implicitCompletion=true] { "::"? identifier (QualifiedNameSeparator "::" identifier)* }
187 186
188kw<term> { @specialize[@name={term},implicitCompletion=true]<identifier, term> } 187kw<term> { @specialize[@name={term},implicitCompletion=true]<identifier, term> }
@@ -237,7 +236,7 @@ sep1<separator, content> { content (separator content)* }
237 236
238 SymbolicComparisonOp { 237 SymbolicComparisonOp {
239 ">" | ">=" | "<" | "<=" | "==" | "!=" | 238 ">" | ">=" | "<" | "<=" | "==" | "!=" |
240 "<:" | ":>" | "===" | "!==" 239 "===" | "!=="
241 } 240 }
242 241
243 NotOp { "!" } 242 NotOp { "!" }
diff --git a/subprojects/frontend/src/language/problemLanguageSupport.ts b/subprojects/frontend/src/language/problemLanguageSupport.ts
index 3d25d699..594351d6 100644
--- a/subprojects/frontend/src/language/problemLanguageSupport.ts
+++ b/subprojects/frontend/src/language/problemLanguageSupport.ts
@@ -28,12 +28,12 @@ const parserWithMetadata = parser.configure({
28 LineComment: t.lineComment, 28 LineComment: t.lineComment,
29 BlockComment: t.blockComment, 29 BlockComment: t.blockComment,
30 'module problem class enum pred fn scope': t.definitionKeyword, 30 'module problem class enum pred fn scope': t.definitionKeyword,
31 'import as declare atom multi extern datatype': t.definitionKeyword, 31 'import as declare atom multi': t.definitionKeyword,
32 'extern datatype aggregator': t.definitionKeyword,
32 'abstract extends refers contains container opposite': t.modifier, 33 'abstract extends refers contains container opposite': t.modifier,
33 'default error contained containment': t.modifier, 34 default: t.modifier,
34 'true false unknown error': t.keyword, 35 'true false unknown error': t.keyword,
35 'may must current count': t.operatorKeyword, 36 'count in is': t.operatorKeyword,
36 'sum prod min max in is': t.operatorKeyword,
37 // 'new delete': t.keyword, 37 // 'new delete': t.keyword,
38 NotOp: t.operator, 38 NotOp: t.operator,
39 UnknownOp: t.operator, 39 UnknownOp: t.operator,
@@ -44,6 +44,7 @@ const parserWithMetadata = parser.configure({
44 String: t.string, 44 String: t.string,
45 'RelationName/QualifiedName': t.typeName, 45 'RelationName/QualifiedName': t.typeName,
46 'DatatypeName/QualifiedName': t.keyword, 46 'DatatypeName/QualifiedName': t.keyword,
47 'AggregatorName/QualifiedName': t.operatorKeyword,
47 // 'RuleName/QualifiedName': t.typeName, 48 // 'RuleName/QualifiedName': t.typeName,
48 'AtomNodeName/QualifiedName': t.atom, 49 'AtomNodeName/QualifiedName': t.atom,
49 'VariableName/QualifiedName': t.variableName, 50 'VariableName/QualifiedName': t.variableName,