yukigo-haskell-parser 0.1.3 → 0.2.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.
Files changed (57) hide show
  1. package/.mocharc.json +3 -3
  2. package/CHANGELOG.md +51 -9
  3. package/README.md +5 -5
  4. package/dist/index.js +21 -13
  5. package/dist/index.js.map +1 -1
  6. package/dist/parser/grammar.cjs +397 -0
  7. package/dist/parser/grammar.cjs.map +1 -0
  8. package/dist/parser/grammar.d.cts +38 -0
  9. package/dist/parser/lexer.d.ts +2 -1
  10. package/dist/parser/lexer.js +6 -1
  11. package/dist/parser/lexer.js.map +1 -1
  12. package/dist/prelude.js +279 -279
  13. package/dist/typechecker/DeclarationCollector.d.ts +2 -0
  14. package/dist/typechecker/DeclarationCollector.js +6 -5
  15. package/dist/typechecker/DeclarationCollector.js.map +1 -1
  16. package/dist/typechecker/TypeBuilder.js +9 -7
  17. package/dist/typechecker/TypeBuilder.js.map +1 -1
  18. package/dist/typechecker/checker.d.ts +9 -4
  19. package/dist/typechecker/checker.js +66 -94
  20. package/dist/typechecker/checker.js.map +1 -1
  21. package/dist/typechecker/core.js +8 -7
  22. package/dist/typechecker/core.js.map +1 -1
  23. package/dist/typechecker/inference.d.ts +4 -1
  24. package/dist/typechecker/inference.js +39 -19
  25. package/dist/typechecker/inference.js.map +1 -1
  26. package/dist/utils/helpers.d.ts +3 -0
  27. package/dist/utils/helpers.js +5 -0
  28. package/dist/utils/helpers.js.map +1 -1
  29. package/dist/utils/types.d.ts +12 -3
  30. package/dist/utils/types.js +34 -22
  31. package/dist/utils/types.js.map +1 -1
  32. package/package.json +6 -9
  33. package/src/index.ts +223 -192
  34. package/src/parser/{grammar.ts → grammar.cjs} +191 -223
  35. package/src/parser/grammar.d.ts +3 -0
  36. package/src/parser/grammar.ne +521 -518
  37. package/src/parser/lexer.ts +357 -353
  38. package/src/prelude.ts +281 -281
  39. package/src/typechecker/DeclarationCollector.ts +160 -157
  40. package/src/typechecker/TypeBuilder.ts +153 -150
  41. package/src/typechecker/checker.ts +487 -501
  42. package/src/typechecker/core.ts +195 -192
  43. package/src/typechecker/inference.ts +1442 -1421
  44. package/src/utils/helpers.ts +34 -29
  45. package/src/utils/types.ts +75 -63
  46. package/tests/hspec.spec.ts +95 -92
  47. package/tests/lexer.spec.ts +175 -175
  48. package/tests/parser.spec.ts +838 -829
  49. package/tests/prelude.spec.ts +17 -17
  50. package/tests/typechecker.spec.ts +326 -327
  51. package/tsconfig.build.json +16 -0
  52. package/tsconfig.build.tsbuildinfo +1 -0
  53. package/tsconfig.json +29 -26
  54. package/tsconfig.tsbuildinfo +1 -1
  55. package/dist/parser/grammar.d.ts +0 -28
  56. package/dist/parser/grammar.js +0 -393
  57. package/dist/parser/grammar.js.map +0 -1
@@ -1,133 +1,94 @@
1
1
  // Generated automatically by nearley, version 2.20.1
2
2
  // http://github.com/Hardmath123/nearley
3
- // Bypasses TS6133. Allow declared but unused functions.
4
- // @ts-ignore
5
- function id(d: any[]): any { return d[0]; }
6
- declare var lbracket: any;
7
- declare var rbracket: any;
8
- declare var assign: any;
9
- declare var anonymousVariable: any;
10
- declare var typeArrow: any;
11
- declare var constructor: any;
12
- declare var variable: any;
13
- declare var number: any;
14
- declare var char: any;
15
- declare var string: any;
16
- declare var bool: any;
17
-
18
- import { HaskellLayoutLexer } from "./lexer.js"
19
- import {
20
- TypeCast,
21
- Application,
22
- ConsExpression,
23
- StringOperation,
24
- LogicalBinaryOperation,
25
- ComparisonOperation,
26
- ArithmeticBinaryOperation,
27
- Print,
28
- ListBinaryOperation,
29
- ListUnaryOperation,
30
- ArithmeticUnaryOperation,
31
- LogicalUnaryOperation,
32
- Case,
33
- SymbolPrimitive,
34
- ListPrimitive,
35
- Switch,
36
- CompositionExpression,
37
- Lambda,
38
- TupleExpression,
39
- DataExpression,
40
- Function,
41
- FieldExpression,
42
- If,
43
- Record,
44
- Constructor,
45
- Field,
46
- ListComprehension,
47
- Generator,
48
- RangeExpression,
49
- TypeSignature,
50
- Return,
51
- GuardedBody,
52
- Equation,
53
- Raise,
54
- UnguardedBody,
55
- Sequence,
56
- Otherwise,
57
- WildcardPattern,
58
- ConsPattern,
59
- VariablePattern,
60
- LiteralPattern,
61
- AsPattern,
62
- ConstructorPattern,
63
- ListPattern,
64
- TuplePattern,
65
- TypeAlias,
66
- ParameterizedType,
67
- Constraint,
68
- TypeApplication,
69
- LetInExpression,
70
- SimpleType,
71
- ListType,
72
- TupleType,
73
- TypeClass,
74
- Instance,
75
- NumberPrimitive,
76
- CharPrimitive,
77
- StringPrimitive,
78
- BooleanPrimitive,
79
- SourceLocation,
80
- TestGroup,
81
- Test,
82
- Assert,
83
- Equality,
84
- Truth,
85
- Failure
86
- } from "yukigo-ast";
87
-
88
- const filter = d => {
89
- return d.filter((token) => token !== null);
90
- };
91
-
92
- const loc = (token) => new SourceLocation(token.line, token.col);
93
- const HSLexer = new HaskellLayoutLexer();
94
-
95
-
96
- interface NearleyToken {
97
- value: any;
98
- [key: string]: any;
99
- };
100
-
101
- interface NearleyLexer {
102
- reset: (chunk: string, info: any) => void;
103
- next: () => NearleyToken | undefined;
104
- save: () => any;
105
- formatError: (token: never) => string;
106
- has: (tokenType: string) => boolean;
107
- };
108
-
109
- interface NearleyRule {
110
- name: string;
111
- symbols: NearleySymbol[];
112
- postprocess?: (d: any[], loc?: number, reject?: {}) => any;
113
- };
114
-
115
- type NearleySymbol = string | { literal: any } | { test: (token: any) => boolean };
116
-
117
- interface Grammar {
118
- Lexer: NearleyLexer | undefined;
119
- ParserRules: NearleyRule[];
120
- ParserStart: string;
121
- };
122
-
123
- const grammar: Grammar = {
124
- Lexer: HSLexer,
125
- ParserRules: [
3
+ (function () {
4
+ function id(x) { return x[0]; }
5
+
6
+ const { HaskellLayoutLexer } = require("./lexer.js")
7
+ const {
8
+ TypeCast,
9
+ Application,
10
+ ConsExpression,
11
+ StringOperation,
12
+ LogicalBinaryOperation,
13
+ ComparisonOperation,
14
+ ArithmeticBinaryOperation,
15
+ Print,
16
+ ListBinaryOperation,
17
+ ListUnaryOperation,
18
+ ArithmeticUnaryOperation,
19
+ LogicalUnaryOperation,
20
+ Case,
21
+ SymbolPrimitive,
22
+ ListPrimitive,
23
+ Switch,
24
+ CompositionExpression,
25
+ Lambda,
26
+ TupleExpression,
27
+ DataExpression,
28
+ Function,
29
+ FieldExpression,
30
+ If,
31
+ Record,
32
+ Constructor,
33
+ Field,
34
+ ListComprehension,
35
+ Generator,
36
+ RangeExpression,
37
+ TypeSignature,
38
+ Return,
39
+ GuardedExpression,
40
+ Guard,
41
+ Equation,
42
+ Raise,
43
+ UnguardedBody,
44
+ Sequence,
45
+ Otherwise,
46
+ WildcardPattern,
47
+ ConsPattern,
48
+ VariablePattern,
49
+ LiteralPattern,
50
+ AsPattern,
51
+ ConstructorPattern,
52
+ ListPattern,
53
+ TuplePattern,
54
+ TypeAlias,
55
+ ParameterizedType,
56
+ Constraint,
57
+ TypeApplication,
58
+ LetInExpression,
59
+ SimpleType,
60
+ ListType,
61
+ TupleType,
62
+ TypeClass,
63
+ Instance,
64
+ NumberPrimitive,
65
+ CharPrimitive,
66
+ StringPrimitive,
67
+ BooleanPrimitive,
68
+ SourceLocation,
69
+ TestGroup,
70
+ Test,
71
+ Assert,
72
+ Equality,
73
+ Truth,
74
+ Failure
75
+ } = require("yukigo-ast");
76
+
77
+ const filter = d => {
78
+ return d.filter((token) => token !== null);
79
+ };
80
+
81
+ const loc = (token) => new SourceLocation(token.line, token.col);
82
+ const HSLexer = new HaskellLayoutLexer();
83
+
84
+ var grammar = {
85
+ Lexer: HSLexer,
86
+ ParserRules: [
126
87
  {"name": "program$ebnf$1", "symbols": []},
127
88
  {"name": "program$ebnf$1$subexpression$1", "symbols": [{"literal":";"}, "declaration"]},
128
- {"name": "program$ebnf$1", "symbols": ["program$ebnf$1", "program$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]])},
89
+ {"name": "program$ebnf$1", "symbols": ["program$ebnf$1", "program$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
129
90
  {"name": "program$ebnf$2", "symbols": [{"literal":";"}], "postprocess": id},
130
- {"name": "program$ebnf$2", "symbols": [], "postprocess": () => null},
91
+ {"name": "program$ebnf$2", "symbols": [], "postprocess": function(d) {return null;}},
131
92
  {"name": "program", "symbols": ["declaration", "program$ebnf$1", "program$ebnf$2"], "postprocess": (d) => [d[0], ...d[1].map(x => x[1])].flat(Infinity)},
132
93
  {"name": "declaration$subexpression$1", "symbols": ["function_declaration"]},
133
94
  {"name": "declaration$subexpression$1", "symbols": ["function_signature"]},
@@ -137,8 +98,7 @@ const grammar: Grammar = {
137
98
  {"name": "declaration$subexpression$1", "symbols": ["instance_declaration"]},
138
99
  {"name": "declaration$subexpression$1", "symbols": ["apply_operator"]},
139
100
  {"name": "declaration$subexpression$1", "symbols": ["test_declaration"]},
140
- {"name": "declaration$subexpression$1", "symbols": [{"literal":"let"}, "function_declaration"]},
141
- {"name": "declaration", "symbols": ["declaration$subexpression$1"], "postprocess": (d) => d[0][0] === "let" ? d[0][1] : d[0][0]},
101
+ {"name": "declaration", "symbols": ["declaration$subexpression$1"], "postprocess": (d) => d[0][0]},
142
102
  {"name": "expression$subexpression$1", "symbols": ["type_cast"]},
143
103
  {"name": "expression$subexpression$1", "symbols": ["letin_expression"]},
144
104
  {"name": "expression$subexpression$1", "symbols": ["if_expression"]},
@@ -149,11 +109,11 @@ const grammar: Grammar = {
149
109
  {"name": "test_declaration", "symbols": [{"literal":"describe"}, "expression", {"literal":"$"}, {"literal":"do"}, (HSLexer.has("lbracket") ? {type: "lbracket"} : lbracket), "test_body", (HSLexer.has("rbracket") ? {type: "rbracket"} : rbracket)], "postprocess": (d) => new TestGroup(d[1], new Sequence(d[5]))},
150
110
  {"name": "test_declaration", "symbols": [{"literal":"it"}, "expression", {"literal":"do"}, (HSLexer.has("lbracket") ? {type: "lbracket"} : lbracket), "test_body", (HSLexer.has("rbracket") ? {type: "rbracket"} : rbracket)], "postprocess": (d) => new Test(d[1], new Sequence(d[4]))},
151
111
  {"name": "test_declaration", "symbols": [{"literal":"it"}, "expression", {"literal":"$"}, {"literal":"do"}, (HSLexer.has("lbracket") ? {type: "lbracket"} : lbracket), "test_body", (HSLexer.has("rbracket") ? {type: "rbracket"} : rbracket)], "postprocess": (d) => new Test(d[1], new Sequence(d[5]))},
152
- {"name": "test_declaration", "symbols": [{"literal":"let"}, "function_declaration"], "postprocess": (d) => d[1]},
112
+ {"name": "test_declaration", "symbols": [{"literal":"let"}, (HSLexer.has("lbracket") ? {type: "lbracket"} : lbracket), "function_declaration", (HSLexer.has("rbracket") ? {type: "rbracket"} : rbracket)], "postprocess": (d) => d[2]},
153
113
  {"name": "test_declaration", "symbols": ["assertion"], "postprocess": id},
154
114
  {"name": "test_body$ebnf$1", "symbols": []},
155
115
  {"name": "test_body$ebnf$1$subexpression$1", "symbols": [{"literal":";"}, "test_declaration"]},
156
- {"name": "test_body$ebnf$1", "symbols": ["test_body$ebnf$1", "test_body$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]])},
116
+ {"name": "test_body$ebnf$1", "symbols": ["test_body$ebnf$1", "test_body$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
157
117
  {"name": "test_body", "symbols": ["test_declaration", "test_body$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[1])]},
158
118
  {"name": "assertion", "symbols": ["expression", {"literal":"shouldBe"}, "expression"], "postprocess": (d) => new Assert(new BooleanPrimitive(false), new Equality(d[2], d[0]))},
159
119
  {"name": "assertion", "symbols": ["expression", {"literal":"`"}, {"literal":"shouldBe"}, {"literal":"`"}, "expression"], "postprocess": (d) => new Assert(new BooleanPrimitive(false), new Equality(d[4], d[0]))},
@@ -201,10 +161,10 @@ const grammar: Grammar = {
201
161
  {"name": "infix_operator_expression", "symbols": ["application"], "postprocess": id},
202
162
  {"name": "application", "symbols": [{"literal":"error"}, "primary"], "postprocess": d => new Raise(d[1])},
203
163
  {"name": "application$ebnf$1", "symbols": []},
204
- {"name": "application$ebnf$1", "symbols": ["application$ebnf$1", "primary"], "postprocess": (d) => d[0].concat([d[1]])},
205
- {"name": "application", "symbols": ["primary", "application$ebnf$1"], "postprocess": (d) => {
206
- if (d[1].length === 0) return d[0];
207
- return d[1].reduce((left, right) => new Application(left, right), d[0]);
164
+ {"name": "application$ebnf$1", "symbols": ["application$ebnf$1", "primary"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
165
+ {"name": "application", "symbols": ["primary", "application$ebnf$1"], "postprocess": (d) => {
166
+ if (d[1].length === 0) return d[0];
167
+ return d[1].reduce((left, right) => new Application(left, right), d[0]);
208
168
  } },
209
169
  {"name": "operator", "symbols": ["operator_no_minus"], "postprocess": id},
210
170
  {"name": "operator", "symbols": [{"literal":"-"}], "postprocess": (d) => d[0].value},
@@ -231,13 +191,13 @@ const grammar: Grammar = {
231
191
  {"name": "operator_no_minus$subexpression$1", "symbols": [{"literal":":"}]},
232
192
  {"name": "operator_no_minus", "symbols": ["operator_no_minus$subexpression$1"], "postprocess": (d) => d[0][0].value},
233
193
  {"name": "left_section", "symbols": [{"literal":"("}, "expression", "operator", {"literal":")"}], "postprocess": (d) => new Application(new SymbolPrimitive(d[2]), d[1])},
234
- {"name": "right_section", "symbols": [{"literal":"("}, "operator_no_minus", "expression", {"literal":")"}], "postprocess": (d) => {
235
- const flipBody = new SymbolPrimitive("flip");
236
- const op = new SymbolPrimitive(d[1]);
237
- const expr = d[2];
238
- const flipAppliedToOp = new Application(flipBody, op);
239
- return new Application(flipAppliedToOp, expr);
240
- }
194
+ {"name": "right_section", "symbols": [{"literal":"("}, "operator_no_minus", "expression", {"literal":")"}], "postprocess": (d) => {
195
+ const flipBody = new SymbolPrimitive("flip");
196
+ const op = new SymbolPrimitive(d[1]);
197
+ const expr = d[2];
198
+ const flipAppliedToOp = new Application(flipBody, op);
199
+ return new Application(flipAppliedToOp, expr);
200
+ }
241
201
  },
242
202
  {"name": "operator_section", "symbols": [{"literal":"("}, "operator", {"literal":")"}], "postprocess": (d) => new SymbolPrimitive(d[1])},
243
203
  {"name": "primary", "symbols": ["primitive"], "postprocess": id},
@@ -253,14 +213,14 @@ const grammar: Grammar = {
253
213
  {"name": "primary", "symbols": ["list_comprehension"], "postprocess": id},
254
214
  {"name": "primary", "symbols": [{"literal":"("}, "expression", {"literal":")"}], "postprocess": (d) => d[1]},
255
215
  {"name": "primary", "symbols": [{"literal":"["}, "range_expression", {"literal":"]"}], "postprocess": (d) => d[1]},
256
- {"name": "list_comprehension", "symbols": [{"literal":"["}, "expression", {"literal":"|"}, "comprehension_clause_list", {"literal":"]"}], "postprocess": (d) => {
257
- return new ListComprehension(d[1], d[3]);
216
+ {"name": "list_comprehension", "symbols": [{"literal":"["}, "expression", {"literal":"|"}, "comprehension_clause_list", {"literal":"]"}], "postprocess": (d) => {
217
+ return new ListComprehension(d[1], d[3]);
258
218
  } },
259
219
  {"name": "comprehension_clause_list$ebnf$1", "symbols": []},
260
220
  {"name": "comprehension_clause_list$ebnf$1$subexpression$1", "symbols": [{"literal":","}, "comprehension_clause"]},
261
- {"name": "comprehension_clause_list$ebnf$1", "symbols": ["comprehension_clause_list$ebnf$1", "comprehension_clause_list$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]])},
262
- {"name": "comprehension_clause_list", "symbols": ["comprehension_clause", "comprehension_clause_list$ebnf$1"], "postprocess": (d) => {
263
- return [d[0], ...d[1].map((x) => x[1])];
221
+ {"name": "comprehension_clause_list$ebnf$1", "symbols": ["comprehension_clause_list$ebnf$1", "comprehension_clause_list$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
222
+ {"name": "comprehension_clause_list", "symbols": ["comprehension_clause", "comprehension_clause_list$ebnf$1"], "postprocess": (d) => {
223
+ return [d[0], ...d[1].map((x) => x[1])];
264
224
  } },
265
225
  {"name": "comprehension_clause", "symbols": ["variable", {"literal":"<-"}, "expression"], "postprocess": (d) => new Generator(d[0], d[2])},
266
226
  {"name": "comprehension_clause", "symbols": ["expression"], "postprocess": id},
@@ -268,28 +228,28 @@ const grammar: Grammar = {
268
228
  {"name": "tuple_expression$ebnf$1$subexpression$1", "symbols": [{"literal":","}, "expression"]},
269
229
  {"name": "tuple_expression$ebnf$1", "symbols": ["tuple_expression$ebnf$1$subexpression$1"]},
270
230
  {"name": "tuple_expression$ebnf$1$subexpression$2", "symbols": [{"literal":","}, "expression"]},
271
- {"name": "tuple_expression$ebnf$1", "symbols": ["tuple_expression$ebnf$1", "tuple_expression$ebnf$1$subexpression$2"], "postprocess": (d) => d[0].concat([d[1]])},
231
+ {"name": "tuple_expression$ebnf$1", "symbols": ["tuple_expression$ebnf$1", "tuple_expression$ebnf$1$subexpression$2"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
272
232
  {"name": "tuple_expression", "symbols": [{"literal":"("}, "expression", "tuple_expression$ebnf$1", {"literal":")"}], "postprocess": (d) => new TupleExpression([d[1], ...d[2].map(x => x[1])])},
273
233
  {"name": "data_expression", "symbols": ["constr", (HSLexer.has("lbracket") ? {type: "lbracket"} : lbracket), "fields_expressions", (HSLexer.has("rbracket") ? {type: "rbracket"} : rbracket)], "postprocess": (d) => new DataExpression(d[0], d[2])},
274
234
  {"name": "fields_expressions$ebnf$1", "symbols": []},
275
235
  {"name": "fields_expressions$ebnf$1$subexpression$1", "symbols": [{"literal":","}, "field_exp"]},
276
- {"name": "fields_expressions$ebnf$1", "symbols": ["fields_expressions$ebnf$1", "fields_expressions$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]])},
236
+ {"name": "fields_expressions$ebnf$1", "symbols": ["fields_expressions$ebnf$1", "fields_expressions$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
277
237
  {"name": "fields_expressions", "symbols": ["field_exp", "fields_expressions$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[1])]},
278
238
  {"name": "field_exp", "symbols": ["variable", {"literal":"="}, "expression"], "postprocess": (d) => new FieldExpression(d[0], d[2])},
279
239
  {"name": "if_expression", "symbols": [{"literal":"if"}, "expression", {"literal":"then"}, "expression", {"literal":"else"}, "expression"], "postprocess": (d) => new If(d[1], d[3], d[5])},
280
240
  {"name": "letin_expression$ebnf$1", "symbols": ["bindings_list"], "postprocess": id},
281
- {"name": "letin_expression$ebnf$1", "symbols": [], "postprocess": () => null},
241
+ {"name": "letin_expression$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}},
282
242
  {"name": "letin_expression", "symbols": [{"literal":"let"}, {"literal":"{"}, "letin_expression$ebnf$1", {"literal":"}"}, {"literal":"in"}, "expression"], "postprocess": (d) => new LetInExpression(new Sequence(d[2] ?? []), d[5])},
283
243
  {"name": "case_expression", "symbols": [{"literal":"case"}, "expression", {"literal":"of"}, {"literal":"{"}, "case_arms", {"literal":"}"}], "postprocess": (d) => new Switch(d[1], d[4])},
284
244
  {"name": "case_arms$ebnf$1", "symbols": []},
285
245
  {"name": "case_arms$ebnf$1$subexpression$1", "symbols": [{"literal":";"}, "case_arm"]},
286
- {"name": "case_arms$ebnf$1", "symbols": ["case_arms$ebnf$1", "case_arms$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]])},
246
+ {"name": "case_arms$ebnf$1", "symbols": ["case_arms$ebnf$1", "case_arms$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
287
247
  {"name": "case_arms", "symbols": ["case_arm", "case_arms$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[1])]},
288
248
  {"name": "case_arm", "symbols": ["pattern", {"literal":"->"}, "expression"], "postprocess": (d) => new Case(d[0], d[2])},
289
249
  {"name": "typeclass_declaration", "symbols": [{"literal":"class"}, "constr", "variable", {"literal":"where"}, (HSLexer.has("lbracket") ? {type: "lbracket"} : lbracket), "typeclass_body", (HSLexer.has("rbracket") ? {type: "rbracket"} : rbracket)], "postprocess": (d) => new TypeClass(d[1], d[2], d[5])},
290
250
  {"name": "typeclass_body$ebnf$1", "symbols": []},
291
251
  {"name": "typeclass_body$ebnf$1$subexpression$1", "symbols": [{"literal":";"}, "function_signature"]},
292
- {"name": "typeclass_body$ebnf$1", "symbols": ["typeclass_body$ebnf$1", "typeclass_body$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]])},
252
+ {"name": "typeclass_body$ebnf$1", "symbols": ["typeclass_body$ebnf$1", "typeclass_body$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
293
253
  {"name": "typeclass_body", "symbols": ["function_signature", "typeclass_body$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[1])]},
294
254
  {"name": "instance_declaration", "symbols": [{"literal":"instance"}, "constr", "type", {"literal":"where"}, (HSLexer.has("lbracket") ? {type: "lbracket"} : lbracket), "instance_body", (HSLexer.has("rbracket") ? {type: "rbracket"} : rbracket)], "postprocess": (d) => new Instance(d[1], d[2], d[5])},
295
255
  {"name": "instance_body$subexpression$1", "symbols": ["function_declaration"]},
@@ -298,34 +258,34 @@ const grammar: Grammar = {
298
258
  {"name": "instance_body$ebnf$1$subexpression$1$subexpression$1", "symbols": ["function_declaration"]},
299
259
  {"name": "instance_body$ebnf$1$subexpression$1$subexpression$1", "symbols": ["function_signature"]},
300
260
  {"name": "instance_body$ebnf$1$subexpression$1", "symbols": [{"literal":";"}, "instance_body$ebnf$1$subexpression$1$subexpression$1"]},
301
- {"name": "instance_body$ebnf$1", "symbols": ["instance_body$ebnf$1", "instance_body$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]])},
261
+ {"name": "instance_body$ebnf$1", "symbols": ["instance_body$ebnf$1", "instance_body$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
302
262
  {"name": "instance_body$ebnf$2", "symbols": [{"literal":";"}], "postprocess": id},
303
- {"name": "instance_body$ebnf$2", "symbols": [], "postprocess": () => null},
263
+ {"name": "instance_body$ebnf$2", "symbols": [], "postprocess": function(d) {return null;}},
304
264
  {"name": "instance_body", "symbols": ["instance_body$subexpression$1", "instance_body$ebnf$1", "instance_body$ebnf$2"], "postprocess": (d) => [d[0][0], ...d[1].map(x => x[1][0])]},
305
265
  {"name": "data_declaration$ebnf$1", "symbols": []},
306
- {"name": "data_declaration$ebnf$1", "symbols": ["data_declaration$ebnf$1", "type_variable"], "postprocess": (d) => d[0].concat([d[1]])},
266
+ {"name": "data_declaration$ebnf$1", "symbols": ["data_declaration$ebnf$1", "type_variable"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
307
267
  {"name": "data_declaration$ebnf$2", "symbols": []},
308
268
  {"name": "data_declaration$ebnf$2$subexpression$1", "symbols": [{"literal":"|"}, "constructor_def"]},
309
- {"name": "data_declaration$ebnf$2", "symbols": ["data_declaration$ebnf$2", "data_declaration$ebnf$2$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]])},
269
+ {"name": "data_declaration$ebnf$2", "symbols": ["data_declaration$ebnf$2", "data_declaration$ebnf$2$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
310
270
  {"name": "data_declaration$ebnf$3", "symbols": ["deriving_clause"], "postprocess": id},
311
- {"name": "data_declaration$ebnf$3", "symbols": [], "postprocess": () => null},
312
- {"name": "data_declaration", "symbols": [{"literal":"data"}, "constr", "data_declaration$ebnf$1", {"literal":"="}, "constructor_def", "data_declaration$ebnf$2", "data_declaration$ebnf$3"], "postprocess":
313
- (d) => new Record(d[1], [d[4], ...d[5].map(x => x[1])], d[6])
271
+ {"name": "data_declaration$ebnf$3", "symbols": [], "postprocess": function(d) {return null;}},
272
+ {"name": "data_declaration", "symbols": [{"literal":"data"}, "constr", "data_declaration$ebnf$1", {"literal":"="}, "constructor_def", "data_declaration$ebnf$2", "data_declaration$ebnf$3"], "postprocess":
273
+ (d) => new Record(d[1], [d[4], ...d[5].map(x => x[1])], d[6])
314
274
  },
315
275
  {"name": "deriving_clause", "symbols": [{"literal":"deriving"}, "deriving_spec"], "postprocess": (d) => d[1]},
316
276
  {"name": "deriving_spec", "symbols": [{"literal":"("}, "deriving_classes", {"literal":")"}], "postprocess": (d) => d[1]},
317
277
  {"name": "deriving_spec", "symbols": ["constr"], "postprocess": (d) => [d[0]]},
318
278
  {"name": "deriving_classes$ebnf$1", "symbols": []},
319
279
  {"name": "deriving_classes$ebnf$1$subexpression$1", "symbols": [{"literal":","}, "constr"]},
320
- {"name": "deriving_classes$ebnf$1", "symbols": ["deriving_classes$ebnf$1", "deriving_classes$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]])},
280
+ {"name": "deriving_classes$ebnf$1", "symbols": ["deriving_classes$ebnf$1", "deriving_classes$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
321
281
  {"name": "deriving_classes", "symbols": ["constr", "deriving_classes$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[1])]},
322
282
  {"name": "constructor_def", "symbols": ["constr", (HSLexer.has("lbracket") ? {type: "lbracket"} : lbracket), "field_list", (HSLexer.has("rbracket") ? {type: "rbracket"} : rbracket)], "postprocess": (d) => new Constructor(d[0], d[2])},
323
283
  {"name": "constructor_def$ebnf$1", "symbols": []},
324
- {"name": "constructor_def$ebnf$1", "symbols": ["constructor_def$ebnf$1", "simple_type"], "postprocess": (d) => d[0].concat([d[1]])},
284
+ {"name": "constructor_def$ebnf$1", "symbols": ["constructor_def$ebnf$1", "simple_type"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
325
285
  {"name": "constructor_def", "symbols": ["constr", "constructor_def$ebnf$1"], "postprocess": (d) => new Constructor(d[0], d[1].map(x => new Field(undefined, x)))},
326
286
  {"name": "field_list$ebnf$1", "symbols": []},
327
287
  {"name": "field_list$ebnf$1$subexpression$1", "symbols": [{"literal":","}, "field"]},
328
- {"name": "field_list$ebnf$1", "symbols": ["field_list$ebnf$1", "field_list$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]])},
288
+ {"name": "field_list$ebnf$1", "symbols": ["field_list$ebnf$1", "field_list$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
329
289
  {"name": "field_list", "symbols": ["field", "field_list$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[1])]},
330
290
  {"name": "field", "symbols": ["variable", {"literal":"::"}, "type"], "postprocess": (d) => new Field(d[0], d[2])},
331
291
  {"name": "op_name", "symbols": [{"literal":"("}, "operator", {"literal":")"}], "postprocess": d => new SymbolPrimitive(d[1])},
@@ -338,42 +298,46 @@ const grammar: Grammar = {
338
298
  {"name": "bindings_list", "symbols": ["function_declaration", {"literal":";"}, "bindings_list"], "postprocess": d => [d[0], ...d[2]]},
339
299
  {"name": "bindings_list", "symbols": ["function_declaration"], "postprocess": d => [d[0]]},
340
300
  {"name": "equation$ebnf$1", "symbols": ["where_clause"], "postprocess": id},
341
- {"name": "equation$ebnf$1", "symbols": [], "postprocess": () => null},
342
- {"name": "equation", "symbols": ["params", "guarded_rhs", "equation$ebnf$1"], "postprocess": (d) => {
343
- const body = d[1];
344
- const finalBody = d[2]
345
- ? body.map(guard => new GuardedBody(guard.condition, new Sequence([...d[2], new Return(guard.body)])))
346
- : body;
347
- return new Equation(d[0], finalBody);
301
+ {"name": "equation$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}},
302
+ {"name": "equation", "symbols": ["params", "guarded_rhs", "equation$ebnf$1"], "postprocess": (d) => {
303
+ const guardsExpr = new GuardedExpression(d[1]);
304
+ const locals = d[2] || [];
305
+ const returnExpr = new Return(guardsExpr);
306
+ const sequence = new Sequence([...locals, returnExpr]);
307
+
308
+ return new Equation(d[0], new UnguardedBody(sequence), returnExpr);
348
309
  } },
349
310
  {"name": "equation$ebnf$2", "symbols": ["where_clause"], "postprocess": id},
350
- {"name": "equation$ebnf$2", "symbols": [], "postprocess": () => null},
351
- {"name": "equation", "symbols": ["params", (HSLexer.has("assign") ? {type: "assign"} : assign), "return_expression", "equation$ebnf$2"], "postprocess": d => new Equation(d[0], new UnguardedBody(new Sequence(d[3] ? [...d[3], d[2]] : [d[2]])), d[2])},
311
+ {"name": "equation$ebnf$2", "symbols": [], "postprocess": function(d) {return null;}},
312
+ {"name": "equation", "symbols": ["params", (HSLexer.has("assign") ? {type: "assign"} : assign), "return_expression", "equation$ebnf$2"], "postprocess": (d) => {
313
+ const locals = d[3] || [];
314
+ return new Equation(d[0], new UnguardedBody(new Sequence([...locals, d[2]])), d[2]);
315
+ } },
352
316
  {"name": "params$ebnf$1", "symbols": ["parameter_list"], "postprocess": id},
353
- {"name": "params$ebnf$1", "symbols": [], "postprocess": () => null},
317
+ {"name": "params$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}},
354
318
  {"name": "params", "symbols": ["params$ebnf$1"], "postprocess": (d) => d[0] || []},
355
319
  {"name": "guarded_rhs$ebnf$1", "symbols": ["guarded_branch"]},
356
- {"name": "guarded_rhs$ebnf$1", "symbols": ["guarded_rhs$ebnf$1", "guarded_branch"], "postprocess": (d) => d[0].concat([d[1]])},
320
+ {"name": "guarded_rhs$ebnf$1", "symbols": ["guarded_rhs$ebnf$1", "guarded_branch"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
357
321
  {"name": "guarded_rhs", "symbols": ["guarded_rhs$ebnf$1"], "postprocess": (d) => d[0]},
358
- {"name": "guarded_branch", "symbols": [{"literal":"|"}, "condition", {"literal":"="}, "expression"], "postprocess": (d) => new GuardedBody(d[1], d[3])},
322
+ {"name": "guarded_branch", "symbols": [{"literal":"|"}, "condition", {"literal":"="}, "expression"], "postprocess": (d) => new Guard(d[1], d[3])},
359
323
  {"name": "condition", "symbols": [{"literal":"otherwise"}], "postprocess": d => new Otherwise()},
360
324
  {"name": "condition", "symbols": ["expression"], "postprocess": d => d[0]},
361
325
  {"name": "parameter_list$ebnf$1", "symbols": ["pattern"]},
362
- {"name": "parameter_list$ebnf$1", "symbols": ["parameter_list$ebnf$1", "pattern"], "postprocess": (d) => d[0].concat([d[1]])},
326
+ {"name": "parameter_list$ebnf$1", "symbols": ["parameter_list$ebnf$1", "pattern"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
363
327
  {"name": "parameter_list", "symbols": ["parameter_list$ebnf$1"], "postprocess": id},
364
328
  {"name": "pattern", "symbols": ["cons_pattern"], "postprocess": id},
365
329
  {"name": "cons_pattern$ebnf$1$subexpression$1", "symbols": [{"literal":":"}, "cons_pattern"]},
366
330
  {"name": "cons_pattern$ebnf$1", "symbols": ["cons_pattern$ebnf$1$subexpression$1"]},
367
331
  {"name": "cons_pattern$ebnf$1$subexpression$2", "symbols": [{"literal":":"}, "cons_pattern"]},
368
- {"name": "cons_pattern$ebnf$1", "symbols": ["cons_pattern$ebnf$1", "cons_pattern$ebnf$1$subexpression$2"], "postprocess": (d) => d[0].concat([d[1]])},
369
- {"name": "cons_pattern", "symbols": [{"literal":"("}, "cons_pattern", "cons_pattern$ebnf$1", {"literal":")"}], "postprocess":
370
- (d) => {
371
- const patterns = [d[1], ...d[2].map(item => item[1])];
372
- return patterns.reduceRight((tail, head, index, arr) => {
373
- if (index === arr.length - 1) return tail;
374
- return new ConsPattern(head, tail);
375
- });
376
- }
332
+ {"name": "cons_pattern$ebnf$1", "symbols": ["cons_pattern$ebnf$1", "cons_pattern$ebnf$1$subexpression$2"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
333
+ {"name": "cons_pattern", "symbols": [{"literal":"("}, "cons_pattern", "cons_pattern$ebnf$1", {"literal":")"}], "postprocess":
334
+ (d) => {
335
+ const patterns = [d[1], ...d[2].map(item => item[1])];
336
+ return patterns.reduceRight((tail, head, index, arr) => {
337
+ if (index === arr.length - 1) return tail;
338
+ return new ConsPattern(head, tail);
339
+ });
340
+ }
377
341
  },
378
342
  {"name": "cons_pattern", "symbols": ["simple_pattern"], "postprocess": id},
379
343
  {"name": "simple_pattern$subexpression$1", "symbols": ["as_pattern"]},
@@ -393,31 +357,31 @@ const grammar: Grammar = {
393
357
  {"name": "as_pattern$subexpression$1", "symbols": ["wildcard_pattern"]},
394
358
  {"name": "as_pattern", "symbols": ["as_pattern$subexpression$1", {"literal":"@"}, "pattern"], "postprocess": (d) => new AsPattern(d[0][0], d[2])},
395
359
  {"name": "constructor_pattern$ebnf$1", "symbols": ["pattern"]},
396
- {"name": "constructor_pattern$ebnf$1", "symbols": ["constructor_pattern$ebnf$1", "pattern"], "postprocess": (d) => d[0].concat([d[1]])},
360
+ {"name": "constructor_pattern$ebnf$1", "symbols": ["constructor_pattern$ebnf$1", "pattern"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
397
361
  {"name": "constructor_pattern", "symbols": [{"literal":"("}, "constr", "constructor_pattern$ebnf$1", {"literal":")"}], "postprocess": (d) => new ConstructorPattern(d[1], d[2])},
398
362
  {"name": "constructor_pattern", "symbols": ["constr"], "postprocess": (d) => new ConstructorPattern(d[0], [])},
399
363
  {"name": "field_pattern_list$ebnf$1", "symbols": []},
400
364
  {"name": "field_pattern_list$ebnf$1$subexpression$1", "symbols": [{"literal":","}, "field_pattern"]},
401
- {"name": "field_pattern_list$ebnf$1", "symbols": ["field_pattern_list$ebnf$1", "field_pattern_list$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]])},
365
+ {"name": "field_pattern_list$ebnf$1", "symbols": ["field_pattern_list$ebnf$1", "field_pattern_list$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
402
366
  {"name": "field_pattern_list", "symbols": ["field_pattern", "field_pattern_list$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[1])]},
403
367
  {"name": "field_pattern", "symbols": ["variable", {"literal":"="}, "pattern"], "postprocess": (d) => ({ field: d[0].value, pattern: d[2] })},
404
368
  {"name": "list_pattern$ebnf$1", "symbols": ["pattern_list"], "postprocess": id},
405
- {"name": "list_pattern$ebnf$1", "symbols": [], "postprocess": () => null},
369
+ {"name": "list_pattern$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}},
406
370
  {"name": "list_pattern", "symbols": [{"literal":"["}, "list_pattern$ebnf$1", {"literal":"]"}], "postprocess": (d) => new ListPattern(d[1] || [])},
407
371
  {"name": "pattern_list$ebnf$1", "symbols": []},
408
372
  {"name": "pattern_list$ebnf$1$subexpression$1", "symbols": [{"literal":","}, "pattern"]},
409
- {"name": "pattern_list$ebnf$1", "symbols": ["pattern_list$ebnf$1", "pattern_list$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]])},
373
+ {"name": "pattern_list$ebnf$1", "symbols": ["pattern_list$ebnf$1", "pattern_list$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
410
374
  {"name": "pattern_list", "symbols": ["pattern", "pattern_list$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[1])]},
411
375
  {"name": "tuple_pattern$ebnf$1$subexpression$1", "symbols": [{"literal":","}, "pattern"]},
412
376
  {"name": "tuple_pattern$ebnf$1", "symbols": ["tuple_pattern$ebnf$1$subexpression$1"]},
413
377
  {"name": "tuple_pattern$ebnf$1$subexpression$2", "symbols": [{"literal":","}, "pattern"]},
414
- {"name": "tuple_pattern$ebnf$1", "symbols": ["tuple_pattern$ebnf$1", "tuple_pattern$ebnf$1$subexpression$2"], "postprocess": (d) => d[0].concat([d[1]])},
378
+ {"name": "tuple_pattern$ebnf$1", "symbols": ["tuple_pattern$ebnf$1", "tuple_pattern$ebnf$1$subexpression$2"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
415
379
  {"name": "tuple_pattern", "symbols": [{"literal":"("}, "pattern", "tuple_pattern$ebnf$1", {"literal":")"}], "postprocess": (d) => new TuplePattern([d[1], ...d[2].map(x => x[1])])},
416
380
  {"name": "type_declaration$ebnf$1", "symbols": ["variable_list"], "postprocess": id},
417
- {"name": "type_declaration$ebnf$1", "symbols": [], "postprocess": () => null},
381
+ {"name": "type_declaration$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}},
418
382
  {"name": "type_declaration", "symbols": [{"literal":"type"}, "constr", "type_declaration$ebnf$1", {"literal":"="}, "type"], "postprocess": (d) => new TypeAlias(d[1], d[2] || [], d[4])},
419
383
  {"name": "variable_list$ebnf$1", "symbols": []},
420
- {"name": "variable_list$ebnf$1", "symbols": ["variable_list$ebnf$1", "variable"], "postprocess": (d) => d[0].concat([d[1]])},
384
+ {"name": "variable_list$ebnf$1", "symbols": ["variable_list$ebnf$1", "variable"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
421
385
  {"name": "variable_list", "symbols": ["variable", "variable_list$ebnf$1"], "postprocess": (d) => [d[0].value, ...d[1]]},
422
386
  {"name": "type", "symbols": ["function_type"], "postprocess": id},
423
387
  {"name": "constrained_type", "symbols": ["constraint_list", {"literal":"=>"}, "type"], "postprocess": (d) => new ParameterizedType([], d[2], d[0])},
@@ -425,30 +389,30 @@ const grammar: Grammar = {
425
389
  {"name": "context", "symbols": [{"literal":"("}, "constraint_list", {"literal":")"}], "postprocess": (d) => d[1]},
426
390
  {"name": "constraint_list$ebnf$1", "symbols": []},
427
391
  {"name": "constraint_list$ebnf$1$subexpression$1", "symbols": [{"literal":","}, "constraint"]},
428
- {"name": "constraint_list$ebnf$1", "symbols": ["constraint_list$ebnf$1", "constraint_list$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]])},
429
- {"name": "constraint_list", "symbols": ["constraint", "constraint_list$ebnf$1"], "postprocess": (d) =>
430
- [d[0], ...d[1].map(x => x[1])]
392
+ {"name": "constraint_list$ebnf$1", "symbols": ["constraint_list$ebnf$1", "constraint_list$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
393
+ {"name": "constraint_list", "symbols": ["constraint", "constraint_list$ebnf$1"], "postprocess": (d) =>
394
+ [d[0], ...d[1].map(x => x[1])]
431
395
  },
432
396
  {"name": "constraint$ebnf$1", "symbols": ["application_type"]},
433
- {"name": "constraint$ebnf$1", "symbols": ["constraint$ebnf$1", "application_type"], "postprocess": (d) => d[0].concat([d[1]])},
397
+ {"name": "constraint$ebnf$1", "symbols": ["constraint$ebnf$1", "application_type"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
434
398
  {"name": "constraint", "symbols": ["constr", "constraint$ebnf$1"], "postprocess": (d) => new Constraint(d[0].value, d[1])},
435
399
  {"name": "function_type$ebnf$1$subexpression$1", "symbols": ["context", {"literal":"=>"}]},
436
400
  {"name": "function_type$ebnf$1", "symbols": ["function_type$ebnf$1$subexpression$1"], "postprocess": id},
437
- {"name": "function_type$ebnf$1", "symbols": [], "postprocess": () => null},
401
+ {"name": "function_type$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}},
438
402
  {"name": "function_type$ebnf$2", "symbols": []},
439
403
  {"name": "function_type$ebnf$2$subexpression$1", "symbols": ["application_type", (HSLexer.has("typeArrow") ? {type: "typeArrow"} : typeArrow)]},
440
- {"name": "function_type$ebnf$2", "symbols": ["function_type$ebnf$2", "function_type$ebnf$2$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]])},
441
- {"name": "function_type", "symbols": ["function_type$ebnf$1", "function_type$ebnf$2", "application_type"], "postprocess": (d) => {
442
- const constraints = d[0] ? d[0][0] : [];
443
-
444
- if (d[1].length > 0)
445
- return new ParameterizedType(d[1].map(x => x[0]), d[2], constraints);
446
-
447
- if (constraints.length === 0)
448
- return d[2];
449
-
450
- return new ParameterizedType([], d[2], constraints);
451
- }
404
+ {"name": "function_type$ebnf$2", "symbols": ["function_type$ebnf$2", "function_type$ebnf$2$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
405
+ {"name": "function_type", "symbols": ["function_type$ebnf$1", "function_type$ebnf$2", "application_type"], "postprocess": (d) => {
406
+ const constraints = d[0] ? d[0][0] : [];
407
+
408
+ if (d[1].length > 0)
409
+ return new ParameterizedType(d[1].map(x => x[0]), d[2], constraints);
410
+
411
+ if (constraints.length === 0)
412
+ return d[2];
413
+
414
+ return new ParameterizedType([], d[2], constraints);
415
+ }
452
416
  },
453
417
  {"name": "application_type", "symbols": ["simple_type", "application_type"], "postprocess": (d) => new TypeApplication(d[0], d[1])},
454
418
  {"name": "application_type", "symbols": ["simple_type"], "postprocess": id},
@@ -459,7 +423,7 @@ const grammar: Grammar = {
459
423
  {"name": "simple_type$ebnf$1$subexpression$1", "symbols": [{"literal":","}, "type"]},
460
424
  {"name": "simple_type$ebnf$1", "symbols": ["simple_type$ebnf$1$subexpression$1"]},
461
425
  {"name": "simple_type$ebnf$1$subexpression$2", "symbols": [{"literal":","}, "type"]},
462
- {"name": "simple_type$ebnf$1", "symbols": ["simple_type$ebnf$1", "simple_type$ebnf$1$subexpression$2"], "postprocess": (d) => d[0].concat([d[1]])},
426
+ {"name": "simple_type$ebnf$1", "symbols": ["simple_type$ebnf$1", "simple_type$ebnf$1$subexpression$2"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
463
427
  {"name": "simple_type", "symbols": [{"literal":"("}, "type", "simple_type$ebnf$1", {"literal":")"}], "postprocess": (d) => new TupleType([d[1], ...d[2].map(x => x[1])], [])},
464
428
  {"name": "simple_type", "symbols": [{"literal":"("}, "type", {"literal":")"}], "postprocess": (d) => d[1]},
465
429
  {"name": "type_variable", "symbols": ["variable"], "postprocess": ([v]) => ({ value: v.value })},
@@ -474,7 +438,7 @@ const grammar: Grammar = {
474
438
  {"name": "range_expression", "symbols": ["expression", {"literal":","}, "expression", {"literal":".."}, "expression"], "postprocess": (d) => new RangeExpression(d[0], d[4], d[2])},
475
439
  {"name": "expression_list$ebnf$1", "symbols": []},
476
440
  {"name": "expression_list$ebnf$1$subexpression$1", "symbols": [{"literal":","}, "expression"]},
477
- {"name": "expression_list$ebnf$1", "symbols": ["expression_list$ebnf$1", "expression_list$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]])},
441
+ {"name": "expression_list$ebnf$1", "symbols": ["expression_list$ebnf$1", "expression_list$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
478
442
  {"name": "expression_list", "symbols": ["expression", "expression_list$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[1])]},
479
443
  {"name": "comparison_operator", "symbols": [{"literal":"=="}], "postprocess": (d) => "Equal"},
480
444
  {"name": "comparison_operator", "symbols": [{"literal":"/="}], "postprocess": (d) => "NotEqual"},
@@ -484,20 +448,24 @@ const grammar: Grammar = {
484
448
  {"name": "comparison_operator", "symbols": [{"literal":">="}], "postprocess": (d) => "GreaterOrEqualThan"},
485
449
  {"name": "primitive", "symbols": [(HSLexer.has("number") ? {type: "number"} : number)], "postprocess": ([n]) => new NumberPrimitive(Number(n.value), loc(n))},
486
450
  {"name": "primitive", "symbols": [(HSLexer.has("char") ? {type: "char"} : char)], "postprocess": ([c]) => new CharPrimitive(c.value.slice(1, -1), loc(c))},
487
- {"name": "primitive", "symbols": [(HSLexer.has("string") ? {type: "string"} : string)], "postprocess": ([s]) => {
488
- let val = s.value.slice(1, -1);
489
- // Haskell multiline string continuation: \ whitespace \
490
- val = val.replace(/\\\s+\\/g, "");
491
- // Standard escapes
492
- val = val.replace(/\\n/g, "\n")
493
- .replace(/\\t/g, "\t")
494
- .replace(/\\"/g, "\"")
495
- .replace(/\\\\/g, "\\");
496
- return new StringPrimitive(val, loc(s));
451
+ {"name": "primitive", "symbols": [(HSLexer.has("string") ? {type: "string"} : string)], "postprocess": ([s]) => {
452
+ let val = s.value.slice(1, -1);
453
+ // Haskell multiline string continuation: \ whitespace \
454
+ val = val.replace(/\\\s+\\/g, "");
455
+ // Standard escapes
456
+ val = val.replace(/\\n/g, "\n")
457
+ .replace(/\\t/g, "\t")
458
+ .replace(/\\"/g, "\"")
459
+ .replace(/\\\\/g, "\\");
460
+ return new StringPrimitive(val, loc(s));
497
461
  } },
498
462
  {"name": "primitive", "symbols": [(HSLexer.has("bool") ? {type: "bool"} : bool)], "postprocess": ([b]) => new BooleanPrimitive(b.value === 'True' ? true : false, loc(b))}
499
- ],
500
- ParserStart: "program",
501
- };
502
-
503
- export default grammar;
463
+ ]
464
+ , ParserStart: "program"
465
+ }
466
+ if (typeof module !== 'undefined'&& typeof module.exports !== 'undefined') {
467
+ module.exports = grammar;
468
+ } else {
469
+ window.grammar = grammar;
470
+ }
471
+ })();