yukigo-ast 0.2.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.mocharc.json +3 -3
- package/CHANGELOG.md +41 -17
- package/dist/globals/expressions.d.ts +27 -25
- package/dist/globals/expressions.d.ts.map +1 -1
- package/dist/globals/expressions.js +47 -10
- package/dist/globals/generics.d.ts +8 -2
- package/dist/globals/generics.d.ts.map +1 -1
- package/dist/globals/generics.js +15 -1
- package/dist/globals/operators.d.ts +13 -69
- package/dist/globals/operators.d.ts.map +1 -1
- package/dist/globals/operators.js +12 -12
- package/dist/globals/patterns.d.ts +24 -25
- package/dist/globals/patterns.d.ts.map +1 -1
- package/dist/globals/patterns.js +66 -12
- package/dist/globals/primitives.d.ts +2 -5
- package/dist/globals/primitives.d.ts.map +1 -1
- package/dist/globals/primitives.js +7 -7
- package/dist/globals/statements.d.ts +28 -194
- package/dist/globals/statements.d.ts.map +1 -1
- package/dist/globals/statements.js +32 -52
- package/dist/globals/testing.d.ts +7 -31
- package/dist/globals/testing.d.ts.map +1 -1
- package/dist/globals/testing.js +6 -6
- package/dist/globals/types.d.ts +13 -35
- package/dist/globals/types.d.ts.map +1 -1
- package/dist/globals/types.js +12 -12
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/paradigms/functional.d.ts +5 -8
- package/dist/paradigms/functional.d.ts.map +1 -1
- package/dist/paradigms/functional.js +4 -4
- package/dist/paradigms/imperative.d.ts +8 -61
- package/dist/paradigms/imperative.d.ts.map +1 -1
- package/dist/paradigms/imperative.js +7 -7
- package/dist/paradigms/logic.d.ts +11 -67
- package/dist/paradigms/logic.d.ts.map +1 -1
- package/dist/paradigms/logic.js +10 -10
- package/dist/paradigms/object.d.ts +19 -105
- package/dist/paradigms/object.d.ts.map +1 -1
- package/dist/paradigms/object.js +24 -15
- package/dist/paradigms/typeclasses.d.ts +3 -51
- package/dist/paradigms/typeclasses.d.ts.map +1 -1
- package/dist/paradigms/typeclasses.js +2 -2
- package/dist/visitor/base.d.ts +4 -2
- package/dist/visitor/base.d.ts.map +1 -1
- package/dist/visitor/expressions.d.ts +34 -31
- package/dist/visitor/expressions.d.ts.map +1 -1
- package/dist/visitor/expressions.js +11 -2
- package/dist/visitor/index.d.ts +160 -164
- package/dist/visitor/index.d.ts.map +1 -1
- package/dist/visitor/operations.d.ts +25 -26
- package/dist/visitor/operations.d.ts.map +1 -1
- package/dist/visitor/operations.js +3 -2
- package/dist/visitor/patterns.d.ts +18 -19
- package/dist/visitor/patterns.d.ts.map +1 -1
- package/dist/visitor/patterns.js +4 -2
- package/dist/visitor/primitives.d.ts +13 -14
- package/dist/visitor/primitives.d.ts.map +1 -1
- package/dist/visitor/primitives.js +3 -2
- package/dist/visitor/statements.d.ts +49 -50
- package/dist/visitor/statements.d.ts.map +1 -1
- package/dist/visitor/statements.js +9 -6
- package/dist/visitor/testing.d.ts +12 -13
- package/dist/visitor/testing.d.ts.map +1 -1
- package/dist/visitor/testing.js +4 -2
- package/dist/visitor/typeclasses.d.ts +8 -9
- package/dist/visitor/typeclasses.d.ts.map +1 -1
- package/dist/visitor/typeclasses.js +4 -2
- package/dist/visitor/types.d.ts +17 -18
- package/dist/visitor/types.d.ts.map +1 -1
- package/dist/visitor/types.js +3 -2
- package/package.json +2 -11
- package/src/globals/expressions.ts +382 -338
- package/src/globals/generics.ts +86 -65
- package/src/globals/operators.ts +517 -517
- package/src/globals/patterns.ts +406 -347
- package/src/globals/primitives.ts +169 -169
- package/src/globals/statements.ts +746 -768
- package/src/globals/testing.ts +131 -131
- package/src/globals/types.ts +372 -375
- package/src/index.ts +13 -14
- package/src/paradigms/functional.ts +129 -128
- package/src/paradigms/imperative.ts +227 -227
- package/src/paradigms/logic.ts +307 -308
- package/src/paradigms/object.ts +362 -356
- package/src/paradigms/typeclasses.ts +96 -95
- package/src/visitor/base.ts +19 -17
- package/src/visitor/expressions.ts +165 -153
- package/src/visitor/index.ts +59 -52
- package/src/visitor/operations.ts +86 -82
- package/src/visitor/patterns.ts +77 -76
- package/src/visitor/primitives.ts +40 -36
- package/src/visitor/statements.ts +264 -261
- package/src/visitor/testing.ts +50 -49
- package/src/visitor/typeclasses.ts +24 -23
- package/src/visitor/types.ts +76 -75
- package/tests/ast.spec.ts +16 -16
- package/tsconfig.json +23 -25
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/globals/runtime.d.ts +0 -64
- package/dist/globals/runtime.d.ts.map +0 -1
- package/dist/globals/runtime.js +0 -32
- package/dist/types.d.ts +0 -4
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -1
- package/src/globals/runtime.ts +0 -132
|
@@ -1,339 +1,383 @@
|
|
|
1
|
-
import { CompositionExpression, Lambda, Application } from "../paradigms/functional.js";
|
|
2
|
-
import { Exist, Forall, Findall, Not } from "../paradigms/logic.js";
|
|
3
|
-
import { Self, New, Implement } from "../paradigms/object.js";
|
|
4
|
-
import { Visitor } from "../visitor/index.js";
|
|
5
|
-
import { ASTNode, SourceLocation } from "./generics.js";
|
|
6
|
-
import { Operation } from "./operators.js";
|
|
7
|
-
import { SymbolPrimitive, Primitive } from "./primitives.js";
|
|
8
|
-
import { Sequence, Print, For } from "./statements.js";
|
|
9
|
-
import { Assertion } from "./testing.js";
|
|
10
|
-
import { TypeCast } from "./types.js";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Represent tuples - generic non-uniform fixed-size collection of elements
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* (1, "Hello", true)
|
|
17
|
-
* @category Expressions
|
|
18
|
-
*/
|
|
19
|
-
export class TupleExpression extends ASTNode {
|
|
20
|
-
/** @hidden */
|
|
21
|
-
public elements: Expression[];
|
|
22
|
-
|
|
23
|
-
constructor(elements: Expression[], loc?: SourceLocation) {
|
|
24
|
-
super(loc);
|
|
25
|
-
this.elements = elements;
|
|
26
|
-
}
|
|
27
|
-
public accept<R>(visitor: Visitor<R>): R {
|
|
28
|
-
return visitor.visitTupleExpr
|
|
29
|
-
}
|
|
30
|
-
public toJSON() {
|
|
31
|
-
return {
|
|
32
|
-
type: "TupleExpression",
|
|
33
|
-
elements: this.elements.map((expr) => expr.toJSON()),
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Fields of a data expression representations
|
|
40
|
-
* @category Expressions
|
|
41
|
-
*/
|
|
42
|
-
export class FieldExpression extends ASTNode {
|
|
43
|
-
/** @hidden */
|
|
44
|
-
public expression: Expression;
|
|
45
|
-
/** @hidden */
|
|
46
|
-
public name: SymbolPrimitive;
|
|
47
|
-
|
|
48
|
-
constructor(
|
|
49
|
-
name: SymbolPrimitive,
|
|
50
|
-
expression: Expression,
|
|
51
|
-
loc?: SourceLocation
|
|
52
|
-
) {
|
|
53
|
-
super(loc);
|
|
54
|
-
this.name = name;
|
|
55
|
-
this.expression = expression;
|
|
56
|
-
}
|
|
57
|
-
public accept<R>(visitor: Visitor<R>): R {
|
|
58
|
-
return visitor.visitFieldExpr
|
|
59
|
-
}
|
|
60
|
-
public toJSON() {
|
|
61
|
-
return {
|
|
62
|
-
type: "FieldExpression",
|
|
63
|
-
name: this.name.toJSON(),
|
|
64
|
-
expression: this.expression.toJSON(),
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Data expression, used to construct Records
|
|
71
|
-
* @example
|
|
72
|
-
* f = DataName { fieldName = 2 }
|
|
73
|
-
* @category Expressions
|
|
74
|
-
*/
|
|
75
|
-
export class DataExpression extends ASTNode {
|
|
76
|
-
/** @hidden */
|
|
77
|
-
public contents: FieldExpression[];
|
|
78
|
-
/** @hidden */
|
|
79
|
-
public name: SymbolPrimitive;
|
|
80
|
-
|
|
81
|
-
constructor(
|
|
82
|
-
name: SymbolPrimitive,
|
|
83
|
-
contents: FieldExpression[],
|
|
84
|
-
loc?: SourceLocation
|
|
85
|
-
) {
|
|
86
|
-
super(loc);
|
|
87
|
-
this.name = name;
|
|
88
|
-
this.contents = contents;
|
|
89
|
-
}
|
|
90
|
-
public accept<R>(visitor: Visitor<R>): R {
|
|
91
|
-
return visitor.visitDataExpr
|
|
92
|
-
}
|
|
93
|
-
public toJSON() {
|
|
94
|
-
return {
|
|
95
|
-
type: "DataExpression",
|
|
96
|
-
name: this.name.toJSON(),
|
|
97
|
-
contents: this.contents.map((expr) => expr.toJSON()),
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Cons expression, represent a concatenation of a head and a tail
|
|
104
|
-
* @example
|
|
105
|
-
* f = x : xs
|
|
106
|
-
* @category Expressions
|
|
107
|
-
*/
|
|
108
|
-
export class ConsExpression extends ASTNode {
|
|
109
|
-
/** @hidden */
|
|
110
|
-
public tail: Expression;
|
|
111
|
-
/** @hidden */
|
|
112
|
-
public head: Expression;
|
|
113
|
-
|
|
114
|
-
constructor(head: Expression, tail: Expression, loc?: SourceLocation) {
|
|
115
|
-
super(loc);
|
|
116
|
-
this.head = head;
|
|
117
|
-
this.tail = tail;
|
|
118
|
-
}
|
|
119
|
-
public accept<R>(visitor: Visitor<R>): R {
|
|
120
|
-
return visitor.visitConsExpr
|
|
121
|
-
}
|
|
122
|
-
public toJSON() {
|
|
123
|
-
return {
|
|
124
|
-
type: "ConsExpression",
|
|
125
|
-
head: this.head.toJSON(),
|
|
126
|
-
tail: this.tail.toJSON(),
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Represent let...in expressions normally used in Haskell
|
|
133
|
-
* @example
|
|
134
|
-
* f = let x = 2 in x * 4
|
|
135
|
-
* @category Expressions
|
|
136
|
-
*/
|
|
137
|
-
export class LetInExpression extends ASTNode {
|
|
138
|
-
/** @hidden */
|
|
139
|
-
public expression: Expression;
|
|
140
|
-
/** @hidden */
|
|
141
|
-
public declarations: Sequence;
|
|
142
|
-
|
|
143
|
-
constructor(
|
|
144
|
-
declarations: Sequence,
|
|
145
|
-
expression: Expression,
|
|
146
|
-
loc?: SourceLocation
|
|
147
|
-
) {
|
|
148
|
-
super(loc);
|
|
149
|
-
this.declarations = declarations;
|
|
150
|
-
this.expression = expression;
|
|
151
|
-
}
|
|
152
|
-
public accept<R>(visitor: Visitor<R>): R {
|
|
153
|
-
return visitor.visitLetInExpr
|
|
154
|
-
}
|
|
155
|
-
public toJSON() {
|
|
156
|
-
return {
|
|
157
|
-
type: "LetInExpression",
|
|
158
|
-
declarations: this.declarations.toJSON(),
|
|
159
|
-
expression: this.expression.toJSON(),
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Otherwise used as the default case in GuardBody
|
|
166
|
-
* @example
|
|
167
|
-
* f x
|
|
168
|
-
* | x == 2 = 16
|
|
169
|
-
* | otherwise = x * 8
|
|
170
|
-
* @category Declarations
|
|
171
|
-
*/
|
|
172
|
-
export class Otherwise extends ASTNode {
|
|
173
|
-
public accept<R>(visitor: Visitor<R>): R {
|
|
174
|
-
return visitor.visitOtherwise
|
|
175
|
-
}
|
|
176
|
-
public toJSON() {
|
|
177
|
-
return {
|
|
178
|
-
type: "Otherwise",
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* ListComprehension when the for expression is a yield.
|
|
185
|
-
* Scala's for comprehensions, Erlang's and Haskell's list comprehensions
|
|
186
|
-
* @example
|
|
187
|
-
* m = [ f x | x <- [1, 2, 3, 4] ]
|
|
188
|
-
* @category Expressions
|
|
189
|
-
*/
|
|
190
|
-
export class ListComprehension extends ASTNode {
|
|
191
|
-
/** @hidden */
|
|
192
|
-
public generators: (Generator | Expression)[];
|
|
193
|
-
/** @hidden */
|
|
194
|
-
public projection: Expression;
|
|
195
|
-
|
|
196
|
-
constructor(
|
|
197
|
-
projection: Expression,
|
|
198
|
-
generators: (Generator | Expression)[],
|
|
199
|
-
loc?: SourceLocation
|
|
200
|
-
) {
|
|
201
|
-
super(loc);
|
|
202
|
-
this.projection = projection;
|
|
203
|
-
this.generators = generators;
|
|
204
|
-
}
|
|
205
|
-
public accept<R>(visitor: Visitor<R>): R {
|
|
206
|
-
return visitor.visitListComprehension
|
|
207
|
-
}
|
|
208
|
-
public toJSON() {
|
|
209
|
-
return {
|
|
210
|
-
type: "ListComprehension",
|
|
211
|
-
projection: this.projection.toJSON(),
|
|
212
|
-
generators: this.generators.map((gen) => gen.toJSON()),
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Generator represents patterns like "Just m <- ms" or "x <- [1,2,3]"
|
|
219
|
-
* @example
|
|
220
|
-
* x <- [1, 2, 3, 4]
|
|
221
|
-
* @category Declarations
|
|
222
|
-
*/
|
|
223
|
-
export class Generator extends ASTNode {
|
|
224
|
-
/** @hidden */
|
|
225
|
-
public expression: Expression;
|
|
226
|
-
/** @hidden */
|
|
227
|
-
public variable: SymbolPrimitive;
|
|
228
|
-
|
|
229
|
-
constructor(
|
|
230
|
-
variable: SymbolPrimitive,
|
|
231
|
-
expression: Expression,
|
|
232
|
-
loc?: SourceLocation
|
|
233
|
-
) {
|
|
234
|
-
super(loc);
|
|
235
|
-
this.variable = variable;
|
|
236
|
-
this.expression = expression;
|
|
237
|
-
}
|
|
238
|
-
public accept<R>(visitor: Visitor<R>): R {
|
|
239
|
-
return visitor.visitGenerator
|
|
240
|
-
}
|
|
241
|
-
public toJSON() {
|
|
242
|
-
return {
|
|
243
|
-
type: "Generator",
|
|
244
|
-
variable: this.variable.toJSON(),
|
|
245
|
-
expression: this.expression.toJSON(),
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* RangeExpression represents when a list is given by comprehension in a defined range
|
|
252
|
-
* @example
|
|
253
|
-
* (1..10)
|
|
254
|
-
* @example
|
|
255
|
-
* (1, 2..10)
|
|
256
|
-
* @example
|
|
257
|
-
* (1..)
|
|
258
|
-
* @category Expressions
|
|
259
|
-
*/
|
|
260
|
-
export class RangeExpression extends ASTNode {
|
|
261
|
-
/** @hidden */
|
|
262
|
-
public step?: Expression;
|
|
263
|
-
/** @hidden */
|
|
264
|
-
public end?: Expression;
|
|
265
|
-
/** @hidden */
|
|
266
|
-
public start: Expression;
|
|
267
|
-
|
|
268
|
-
constructor(
|
|
269
|
-
start: Expression,
|
|
270
|
-
end?: Expression, // undefined for infinite ranges like [0..]
|
|
271
|
-
step?: Expression, // for [start, second .. end] syntax
|
|
272
|
-
loc?: SourceLocation
|
|
273
|
-
) {
|
|
274
|
-
super(loc);
|
|
275
|
-
this.start = start;
|
|
276
|
-
this.end = end;
|
|
277
|
-
this.step = step;
|
|
278
|
-
}
|
|
279
|
-
public accept<R>(visitor: Visitor<R>): R {
|
|
280
|
-
return visitor.visitRangeExpression
|
|
281
|
-
}
|
|
282
|
-
public toJSON() {
|
|
283
|
-
return {
|
|
284
|
-
type: "RangeExpression",
|
|
285
|
-
start: this.start.toJSON(),
|
|
286
|
-
end: this.end?.toJSON(),
|
|
287
|
-
step: this.step?.toJSON(),
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
export class NamedArgument extends ASTNode {
|
|
293
|
-
public identifier: SymbolPrimitive;
|
|
294
|
-
public expression: Expression;
|
|
295
|
-
constructor(
|
|
296
|
-
identifier: SymbolPrimitive,
|
|
297
|
-
expression: Expression,
|
|
298
|
-
loc?: SourceLocation
|
|
299
|
-
) {
|
|
300
|
-
super(loc);
|
|
301
|
-
this.identifier = identifier;
|
|
302
|
-
this.expression = expression;
|
|
303
|
-
}
|
|
304
|
-
public accept<R>(visitor: Visitor<R>): R {
|
|
305
|
-
return visitor.visitNamedArgument
|
|
306
|
-
}
|
|
307
|
-
public toJSON() {
|
|
308
|
-
return {
|
|
309
|
-
type: "NamedArgument",
|
|
310
|
-
identifier: this.identifier.toJSON(),
|
|
311
|
-
expression: this.expression.toJSON(),
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
export
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
1
|
+
import { CompositionExpression, Lambda, Application } from "../paradigms/functional.js";
|
|
2
|
+
import { Exist, Forall, Findall, Not } from "../paradigms/logic.js";
|
|
3
|
+
import { Self, New, Implement } from "../paradigms/object.js";
|
|
4
|
+
import { Visitor } from "../visitor/index.js";
|
|
5
|
+
import { ASTNode, SerializeNode, SourceLocation } from "./generics.js";
|
|
6
|
+
import { Operation } from "./operators.js";
|
|
7
|
+
import { SymbolPrimitive, Primitive } from "./primitives.js";
|
|
8
|
+
import { Sequence, Print, For } from "./statements.js";
|
|
9
|
+
import { Assertion } from "./testing.js";
|
|
10
|
+
import { TypeCast } from "./types.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Represent tuples - generic non-uniform fixed-size collection of elements
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* (1, "Hello", true)
|
|
17
|
+
* @category Expressions
|
|
18
|
+
*/
|
|
19
|
+
export class TupleExpression extends ASTNode {
|
|
20
|
+
/** @hidden */
|
|
21
|
+
public elements: Expression[];
|
|
22
|
+
|
|
23
|
+
constructor(elements: Expression[], loc?: SourceLocation) {
|
|
24
|
+
super(loc);
|
|
25
|
+
this.elements = elements;
|
|
26
|
+
}
|
|
27
|
+
public accept<R>(visitor: Visitor<R>): R {
|
|
28
|
+
return this.dispatchVisit(visitor, visitor.visitTupleExpr);
|
|
29
|
+
}
|
|
30
|
+
public toJSON(): SerializeNode {
|
|
31
|
+
return {
|
|
32
|
+
type: "TupleExpression",
|
|
33
|
+
elements: this.elements.map((expr) => expr.toJSON()),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Fields of a data expression representations
|
|
40
|
+
* @category Expressions
|
|
41
|
+
*/
|
|
42
|
+
export class FieldExpression extends ASTNode {
|
|
43
|
+
/** @hidden */
|
|
44
|
+
public expression: Expression;
|
|
45
|
+
/** @hidden */
|
|
46
|
+
public name: SymbolPrimitive;
|
|
47
|
+
|
|
48
|
+
constructor(
|
|
49
|
+
name: SymbolPrimitive,
|
|
50
|
+
expression: Expression,
|
|
51
|
+
loc?: SourceLocation
|
|
52
|
+
) {
|
|
53
|
+
super(loc);
|
|
54
|
+
this.name = name;
|
|
55
|
+
this.expression = expression;
|
|
56
|
+
}
|
|
57
|
+
public accept<R>(visitor: Visitor<R>): R {
|
|
58
|
+
return this.dispatchVisit(visitor, visitor.visitFieldExpr);
|
|
59
|
+
}
|
|
60
|
+
public toJSON(): SerializeNode {
|
|
61
|
+
return {
|
|
62
|
+
type: "FieldExpression",
|
|
63
|
+
name: this.name.toJSON(),
|
|
64
|
+
expression: this.expression.toJSON(),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Data expression, used to construct Records
|
|
71
|
+
* @example
|
|
72
|
+
* f = DataName { fieldName = 2 }
|
|
73
|
+
* @category Expressions
|
|
74
|
+
*/
|
|
75
|
+
export class DataExpression extends ASTNode {
|
|
76
|
+
/** @hidden */
|
|
77
|
+
public contents: FieldExpression[];
|
|
78
|
+
/** @hidden */
|
|
79
|
+
public name: SymbolPrimitive;
|
|
80
|
+
|
|
81
|
+
constructor(
|
|
82
|
+
name: SymbolPrimitive,
|
|
83
|
+
contents: FieldExpression[],
|
|
84
|
+
loc?: SourceLocation
|
|
85
|
+
) {
|
|
86
|
+
super(loc);
|
|
87
|
+
this.name = name;
|
|
88
|
+
this.contents = contents;
|
|
89
|
+
}
|
|
90
|
+
public accept<R>(visitor: Visitor<R>): R {
|
|
91
|
+
return this.dispatchVisit(visitor, visitor.visitDataExpr);
|
|
92
|
+
}
|
|
93
|
+
public toJSON(): SerializeNode {
|
|
94
|
+
return {
|
|
95
|
+
type: "DataExpression",
|
|
96
|
+
name: this.name.toJSON(),
|
|
97
|
+
contents: this.contents.map((expr) => expr.toJSON()),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Cons expression, represent a concatenation of a head and a tail
|
|
104
|
+
* @example
|
|
105
|
+
* f = x : xs
|
|
106
|
+
* @category Expressions
|
|
107
|
+
*/
|
|
108
|
+
export class ConsExpression extends ASTNode {
|
|
109
|
+
/** @hidden */
|
|
110
|
+
public tail: Expression;
|
|
111
|
+
/** @hidden */
|
|
112
|
+
public head: Expression;
|
|
113
|
+
|
|
114
|
+
constructor(head: Expression, tail: Expression, loc?: SourceLocation) {
|
|
115
|
+
super(loc);
|
|
116
|
+
this.head = head;
|
|
117
|
+
this.tail = tail;
|
|
118
|
+
}
|
|
119
|
+
public accept<R>(visitor: Visitor<R>): R {
|
|
120
|
+
return this.dispatchVisit(visitor, visitor.visitConsExpr);
|
|
121
|
+
}
|
|
122
|
+
public toJSON(): SerializeNode {
|
|
123
|
+
return {
|
|
124
|
+
type: "ConsExpression",
|
|
125
|
+
head: this.head.toJSON(),
|
|
126
|
+
tail: this.tail.toJSON(),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Represent let...in expressions normally used in Haskell
|
|
133
|
+
* @example
|
|
134
|
+
* f = let x = 2 in x * 4
|
|
135
|
+
* @category Expressions
|
|
136
|
+
*/
|
|
137
|
+
export class LetInExpression extends ASTNode {
|
|
138
|
+
/** @hidden */
|
|
139
|
+
public expression: Expression;
|
|
140
|
+
/** @hidden */
|
|
141
|
+
public declarations: Sequence;
|
|
142
|
+
|
|
143
|
+
constructor(
|
|
144
|
+
declarations: Sequence,
|
|
145
|
+
expression: Expression,
|
|
146
|
+
loc?: SourceLocation
|
|
147
|
+
) {
|
|
148
|
+
super(loc);
|
|
149
|
+
this.declarations = declarations;
|
|
150
|
+
this.expression = expression;
|
|
151
|
+
}
|
|
152
|
+
public accept<R>(visitor: Visitor<R>): R {
|
|
153
|
+
return this.dispatchVisit(visitor, visitor.visitLetInExpr);
|
|
154
|
+
}
|
|
155
|
+
public toJSON(): SerializeNode {
|
|
156
|
+
return {
|
|
157
|
+
type: "LetInExpression",
|
|
158
|
+
declarations: this.declarations.toJSON(),
|
|
159
|
+
expression: this.expression.toJSON(),
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Otherwise used as the default case in GuardBody
|
|
166
|
+
* @example
|
|
167
|
+
* f x
|
|
168
|
+
* | x == 2 = 16
|
|
169
|
+
* | otherwise = x * 8
|
|
170
|
+
* @category Declarations
|
|
171
|
+
*/
|
|
172
|
+
export class Otherwise extends ASTNode {
|
|
173
|
+
public accept<R>(visitor: Visitor<R>): R {
|
|
174
|
+
return this.dispatchVisit(visitor, visitor.visitOtherwise);
|
|
175
|
+
}
|
|
176
|
+
public toJSON(): SerializeNode {
|
|
177
|
+
return {
|
|
178
|
+
type: "Otherwise",
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* ListComprehension when the for expression is a yield.
|
|
185
|
+
* Scala's for comprehensions, Erlang's and Haskell's list comprehensions
|
|
186
|
+
* @example
|
|
187
|
+
* m = [ f x | x <- [1, 2, 3, 4] ]
|
|
188
|
+
* @category Expressions
|
|
189
|
+
*/
|
|
190
|
+
export class ListComprehension extends ASTNode {
|
|
191
|
+
/** @hidden */
|
|
192
|
+
public generators: (Generator | Expression)[];
|
|
193
|
+
/** @hidden */
|
|
194
|
+
public projection: Expression;
|
|
195
|
+
|
|
196
|
+
constructor(
|
|
197
|
+
projection: Expression,
|
|
198
|
+
generators: (Generator | Expression)[],
|
|
199
|
+
loc?: SourceLocation
|
|
200
|
+
) {
|
|
201
|
+
super(loc);
|
|
202
|
+
this.projection = projection;
|
|
203
|
+
this.generators = generators;
|
|
204
|
+
}
|
|
205
|
+
public accept<R>(visitor: Visitor<R>): R {
|
|
206
|
+
return this.dispatchVisit(visitor, visitor.visitListComprehension);
|
|
207
|
+
}
|
|
208
|
+
public toJSON(): SerializeNode {
|
|
209
|
+
return {
|
|
210
|
+
type: "ListComprehension",
|
|
211
|
+
projection: this.projection.toJSON(),
|
|
212
|
+
generators: this.generators.map((gen) => gen.toJSON()),
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Generator represents patterns like "Just m <- ms" or "x <- [1,2,3]"
|
|
219
|
+
* @example
|
|
220
|
+
* x <- [1, 2, 3, 4]
|
|
221
|
+
* @category Declarations
|
|
222
|
+
*/
|
|
223
|
+
export class Generator extends ASTNode {
|
|
224
|
+
/** @hidden */
|
|
225
|
+
public expression: Expression;
|
|
226
|
+
/** @hidden */
|
|
227
|
+
public variable: SymbolPrimitive;
|
|
228
|
+
|
|
229
|
+
constructor(
|
|
230
|
+
variable: SymbolPrimitive,
|
|
231
|
+
expression: Expression,
|
|
232
|
+
loc?: SourceLocation
|
|
233
|
+
) {
|
|
234
|
+
super(loc);
|
|
235
|
+
this.variable = variable;
|
|
236
|
+
this.expression = expression;
|
|
237
|
+
}
|
|
238
|
+
public accept<R>(visitor: Visitor<R>): R {
|
|
239
|
+
return this.dispatchVisit(visitor, visitor.visitGenerator);
|
|
240
|
+
}
|
|
241
|
+
public toJSON(): SerializeNode {
|
|
242
|
+
return {
|
|
243
|
+
type: "Generator",
|
|
244
|
+
variable: this.variable.toJSON(),
|
|
245
|
+
expression: this.expression.toJSON(),
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* RangeExpression represents when a list is given by comprehension in a defined range
|
|
252
|
+
* @example
|
|
253
|
+
* (1..10)
|
|
254
|
+
* @example
|
|
255
|
+
* (1, 2..10)
|
|
256
|
+
* @example
|
|
257
|
+
* (1..)
|
|
258
|
+
* @category Expressions
|
|
259
|
+
*/
|
|
260
|
+
export class RangeExpression extends ASTNode {
|
|
261
|
+
/** @hidden */
|
|
262
|
+
public step?: Expression;
|
|
263
|
+
/** @hidden */
|
|
264
|
+
public end?: Expression;
|
|
265
|
+
/** @hidden */
|
|
266
|
+
public start: Expression;
|
|
267
|
+
|
|
268
|
+
constructor(
|
|
269
|
+
start: Expression,
|
|
270
|
+
end?: Expression, // undefined for infinite ranges like [0..]
|
|
271
|
+
step?: Expression, // for [start, second .. end] syntax
|
|
272
|
+
loc?: SourceLocation
|
|
273
|
+
) {
|
|
274
|
+
super(loc);
|
|
275
|
+
this.start = start;
|
|
276
|
+
this.end = end;
|
|
277
|
+
this.step = step;
|
|
278
|
+
}
|
|
279
|
+
public accept<R>(visitor: Visitor<R>): R {
|
|
280
|
+
return this.dispatchVisit(visitor, visitor.visitRangeExpression);
|
|
281
|
+
}
|
|
282
|
+
public toJSON(): SerializeNode {
|
|
283
|
+
return {
|
|
284
|
+
type: "RangeExpression",
|
|
285
|
+
start: this.start.toJSON(),
|
|
286
|
+
end: this.end?.toJSON(),
|
|
287
|
+
step: this.step?.toJSON(),
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export class NamedArgument extends ASTNode {
|
|
293
|
+
public identifier: SymbolPrimitive;
|
|
294
|
+
public expression: Expression;
|
|
295
|
+
constructor(
|
|
296
|
+
identifier: SymbolPrimitive,
|
|
297
|
+
expression: Expression,
|
|
298
|
+
loc?: SourceLocation
|
|
299
|
+
) {
|
|
300
|
+
super(loc);
|
|
301
|
+
this.identifier = identifier;
|
|
302
|
+
this.expression = expression;
|
|
303
|
+
}
|
|
304
|
+
public accept<R>(visitor: Visitor<R>): R {
|
|
305
|
+
return this.dispatchVisit(visitor, visitor.visitNamedArgument);
|
|
306
|
+
}
|
|
307
|
+
public toJSON(): SerializeNode {
|
|
308
|
+
return {
|
|
309
|
+
type: "NamedArgument",
|
|
310
|
+
identifier: this.identifier.toJSON(),
|
|
311
|
+
expression: this.expression.toJSON(),
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export class GuardedExpression extends ASTNode {
|
|
317
|
+
public guards: Guard[];
|
|
318
|
+
|
|
319
|
+
constructor(guards: Guard[], loc?: SourceLocation) {
|
|
320
|
+
super(loc);
|
|
321
|
+
this.guards = guards;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
public accept<R>(visitor: Visitor<R>): R {
|
|
325
|
+
return this.dispatchVisit(visitor, visitor.visitGuardedExpression);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
public toJSON(): SerializeNode {
|
|
329
|
+
return {
|
|
330
|
+
type: "GuardedExpression",
|
|
331
|
+
guards: this.guards.map((g) => g.toJSON()),
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export class Guard extends ASTNode {
|
|
337
|
+
/** @hidden */
|
|
338
|
+
public body: Expression;
|
|
339
|
+
/** @hidden */
|
|
340
|
+
public condition: Expression;
|
|
341
|
+
constructor(condition: Expression, body: Expression, loc?: SourceLocation) {
|
|
342
|
+
super(loc);
|
|
343
|
+
this.condition = condition;
|
|
344
|
+
this.body = body;
|
|
345
|
+
}
|
|
346
|
+
public accept<R>(visitor: Visitor<R>): R {
|
|
347
|
+
return this.dispatchVisit(visitor, visitor.visitGuard);
|
|
348
|
+
}
|
|
349
|
+
public toJSON(): SerializeNode {
|
|
350
|
+
return {
|
|
351
|
+
type: "Guard",
|
|
352
|
+
condition: this.condition.toJSON(),
|
|
353
|
+
body: this.body.toJSON(),
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
export type Expression =
|
|
359
|
+
| Primitive
|
|
360
|
+
| Operation
|
|
361
|
+
| TupleExpression
|
|
362
|
+
| Print
|
|
363
|
+
| Otherwise
|
|
364
|
+
| ConsExpression
|
|
365
|
+
| Self
|
|
366
|
+
| Sequence
|
|
367
|
+
| New
|
|
368
|
+
| Implement
|
|
369
|
+
| DataExpression
|
|
370
|
+
| CompositionExpression
|
|
371
|
+
| Lambda
|
|
372
|
+
| For
|
|
373
|
+
| Application
|
|
374
|
+
| Exist
|
|
375
|
+
| Forall
|
|
376
|
+
| Findall
|
|
377
|
+
| Not
|
|
378
|
+
| Guard
|
|
379
|
+
| GuardedExpression
|
|
380
|
+
| TypeCast
|
|
381
|
+
| ListComprehension
|
|
382
|
+
| RangeExpression
|
|
339
383
|
| Assertion;
|