1
- import { stream } from 'langium' ;
1
+ import { type NamedAstNode , stream } from 'langium' ;
2
2
import { isEmpty } from '../../helpers/collectionUtils.js' ;
3
3
import {
4
4
isSdsAbstractResult ,
5
- SdsAbstractResult ,
6
- SdsBlockLambdaResult ,
5
+ type SdsAbstractResult ,
6
+ type SdsBlockLambda ,
7
+ type SdsBlockLambdaResult ,
8
+ type SdsCallable ,
7
9
type SdsDeclaration ,
8
- SdsEnumVariant ,
9
- SdsExpression ,
10
- SdsParameter ,
11
- SdsReference ,
12
- SdsResult ,
10
+ type SdsEnumVariant ,
11
+ type SdsExpression ,
12
+ type SdsExpressionLambda ,
13
+ type SdsLambda ,
14
+ type SdsParameter ,
15
+ type SdsReference ,
13
16
} from '../generated/ast.js' ;
14
- import { getParameters } from '../helpers/nodeProperties.js' ;
17
+ import { getParameters , streamBlockLambdaResults } from '../helpers/nodeProperties.js' ;
15
18
16
19
export type ParameterSubstitutions = Map < SdsParameter , EvaluatedNode > ;
17
20
export type ResultSubstitutions = Map < SdsAbstractResult , EvaluatedNode > ;
@@ -139,20 +142,27 @@ export const isConstant = (node: EvaluatedNode): node is Constant => {
139
142
} ;
140
143
141
144
// -------------------------------------------------------------------------------------------------
142
- // Closures
145
+ // Callables
143
146
// -------------------------------------------------------------------------------------------------
144
147
145
- export abstract class Closure extends EvaluatedNode {
148
+ export abstract class EvaluatedCallable < T extends SdsCallable > extends EvaluatedNode {
149
+ abstract readonly callable : T ;
146
150
override readonly isFullyEvaluated : boolean = false ;
151
+ }
152
+
153
+ export abstract class Closure < T extends SdsLambda > extends EvaluatedCallable < T > {
147
154
abstract readonly substitutionsOnCreation : ParameterSubstitutions ;
148
155
}
149
156
150
- export class BlockLambdaClosure extends Closure {
157
+ export class BlockLambdaClosure extends Closure < SdsBlockLambda > {
158
+ readonly results : SdsBlockLambdaResult [ ] ;
159
+
151
160
constructor (
161
+ override readonly callable : SdsBlockLambda ,
152
162
override readonly substitutionsOnCreation : ParameterSubstitutions ,
153
- readonly results : SdsBlockLambdaResult [ ] ,
154
163
) {
155
164
super ( ) ;
165
+ this . results = streamBlockLambdaResults ( callable ) . toArray ( ) ;
156
166
}
157
167
158
168
override equals ( other : unknown ) : boolean {
@@ -163,9 +173,8 @@ export class BlockLambdaClosure extends Closure {
163
173
}
164
174
165
175
return (
166
- this . results . length === other . results . length &&
167
- substitutionsAreEqual ( this . substitutionsOnCreation , other . substitutionsOnCreation ) &&
168
- this . results . every ( ( thisResult , i ) => thisResult === other . results [ i ] )
176
+ this . callable === other . callable &&
177
+ substitutionsAreEqual ( this . substitutionsOnCreation , other . substitutionsOnCreation )
169
178
) ;
170
179
}
171
180
@@ -174,12 +183,15 @@ export class BlockLambdaClosure extends Closure {
174
183
}
175
184
}
176
185
177
- export class ExpressionLambdaClosure extends Closure {
186
+ export class ExpressionLambdaClosure extends Closure < SdsExpressionLambda > {
187
+ readonly result : SdsExpression ;
188
+
178
189
constructor (
190
+ override readonly callable : SdsExpressionLambda ,
179
191
override readonly substitutionsOnCreation : ParameterSubstitutions ,
180
- readonly result : SdsExpression ,
181
192
) {
182
193
super ( ) ;
194
+ this . result = callable . result ;
183
195
}
184
196
185
197
override equals ( other : unknown ) : boolean {
@@ -190,7 +202,7 @@ export class ExpressionLambdaClosure extends Closure {
190
202
}
191
203
192
204
return (
193
- this . result === other . result &&
205
+ this . callable === other . callable &&
194
206
substitutionsAreEqual ( this . substitutionsOnCreation , other . substitutionsOnCreation )
195
207
) ;
196
208
}
@@ -200,28 +212,19 @@ export class ExpressionLambdaClosure extends Closure {
200
212
}
201
213
}
202
214
203
- export class SegmentClosure extends Closure {
204
- override readonly substitutionsOnCreation = new Map < SdsParameter , EvaluatedNode > ( ) ;
215
+ export class NamedCallable < T extends SdsCallable & NamedAstNode > extends EvaluatedCallable < T > {
216
+ override readonly isFullyEvaluated : boolean = false ;
205
217
206
- constructor ( readonly results : SdsResult [ ] ) {
218
+ constructor ( override readonly callable : T ) {
207
219
super ( ) ;
208
220
}
209
221
210
222
override equals ( other : unknown ) : boolean {
211
- if ( other === this ) {
212
- return true ;
213
- } else if ( ! ( other instanceof SegmentClosure ) ) {
214
- return false ;
215
- }
216
-
217
- return (
218
- this . results . length === other . results . length &&
219
- this . results . every ( ( thisResult , i ) => thisResult === other . results [ i ] )
220
- ) ;
223
+ return other instanceof NamedCallable && this . callable === other . callable ;
221
224
}
222
225
223
226
override toString ( ) : string {
224
- return `$SegmentClosure` ;
227
+ return this . callable . name ;
225
228
}
226
229
}
227
230
0 commit comments