diff options
author | Kristóf Marussy <kristof@marussy.com> | 2024-03-05 22:01:10 +0100 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2024-04-07 14:55:46 +0200 |
commit | c14d8efd509f834b80573bc0339bb990698b265c (patch) | |
tree | dc3ca21785ea17bc75a861f373ee69ec64d6e97f /subprojects/frontend/src/language | |
parent | feat(language): validate assignment expressions (diff) | |
download | refinery-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/src/language')
-rw-r--r-- | subprojects/frontend/src/language/problem.grammar | 31 | ||||
-rw-r--r-- | subprojects/frontend/src/language/problemLanguageSupport.ts | 9 |
2 files changed, 20 insertions, 20 deletions
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 | ||
95 | Parameter { Modality? RelationName? VariableName } | 99 | Parameter { 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 { | |||
111 | AssignmentExpr { !assignment VariableName kw<"is"> Expr } | 115 | AssignmentExpr { !assignment VariableName kw<"is"> Expr } |
112 | 116 | ||
113 | BinaryExpr { | 117 | BinaryExpr { |
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 | ||
122 | UnaryExpr { | 127 | UnaryExpr { |
123 | !prefix ("+" | "-" | "!" | kw<"count"> | Modality) Expr | 128 | !prefix ("+" | "-" | "!" | kw<"count">) Expr |
124 | } | 129 | } |
125 | 130 | ||
126 | CastExpr { !cast Expr kw<"as"> DatatypeName } | 131 | CastExpr { !cast Expr kw<"as"> DatatypeName } |
127 | 132 | ||
128 | Aggregation { | 133 | Aggregation { |
129 | AggregationOp "{" Expr "|" Expr "}" | 134 | AggregatorName "{" Expr "|" Expr "}" |
130 | } | 135 | } |
131 | 136 | ||
132 | Atom { RelationName "+"? ParameterList<Expr> } | 137 | Atom { 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 | ||
154 | Modality { | ||
155 | kw<"must"> | kw<"may"> | kw<"current"> | ||
156 | } | ||
157 | |||
158 | AggregationOp { | ||
159 | ckw<"sum"> | ckw<"prod"> | ckw<"min"> | ckw<"max"> | ||
160 | } | ||
161 | |||
162 | ComparisonOp { SymbolicComparisonOp | kw<"in"> } | 159 | ComparisonOp { SymbolicComparisonOp | kw<"in"> } |
163 | 160 | ||
164 | ScopeElement { RelationName ("=" | "+=") Multiplicity } | 161 | ScopeElement { RelationName ("=" | "+=") Multiplicity } |
@@ -183,6 +180,8 @@ NodeName { QualifiedName } | |||
183 | 180 | ||
184 | ModuleName { QualifiedName } | 181 | ModuleName { QualifiedName } |
185 | 182 | ||
183 | AggregatorName { QualifiedName } | ||
184 | |||
186 | QualifiedName[implicitCompletion=true] { "::"? identifier (QualifiedNameSeparator "::" identifier)* } | 185 | QualifiedName[implicitCompletion=true] { "::"? identifier (QualifiedNameSeparator "::" identifier)* } |
187 | 186 | ||
188 | kw<term> { @specialize[@name={term},implicitCompletion=true]<identifier, term> } | 187 | kw<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, |