yukigo-haskell-parser 0.1.0 → 0.1.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 (65) hide show
  1. package/.mocharc.json +3 -3
  2. package/CHANGELOG.md +6 -0
  3. package/README.md +10 -10
  4. package/dist/index.d.ts +13 -2
  5. package/dist/index.js +112 -32
  6. package/dist/index.js.map +1 -1
  7. package/dist/parser/grammar.js +220 -231
  8. package/dist/parser/grammar.js.map +1 -1
  9. package/dist/parser/lexer.d.ts +70 -15
  10. package/dist/parser/lexer.js +259 -50
  11. package/dist/parser/lexer.js.map +1 -1
  12. package/dist/prelude.d.ts +1 -1
  13. package/dist/prelude.js +280 -204
  14. package/dist/prelude.js.map +1 -1
  15. package/dist/typechecker/DeclarationCollector.d.ts +6 -1
  16. package/dist/typechecker/DeclarationCollector.js +39 -0
  17. package/dist/typechecker/DeclarationCollector.js.map +1 -1
  18. package/dist/typechecker/TypeBuilder.d.ts +1 -1
  19. package/dist/typechecker/TypeBuilder.js +6 -2
  20. package/dist/typechecker/TypeBuilder.js.map +1 -1
  21. package/dist/typechecker/checker.d.ts +15 -4
  22. package/dist/typechecker/checker.js +108 -25
  23. package/dist/typechecker/checker.js.map +1 -1
  24. package/dist/typechecker/core.d.ts +4 -0
  25. package/dist/typechecker/core.js +45 -19
  26. package/dist/typechecker/core.js.map +1 -1
  27. package/dist/typechecker/inference.d.ts +5 -1
  28. package/dist/typechecker/inference.js +95 -21
  29. package/dist/typechecker/inference.js.map +1 -1
  30. package/dist/utils/helpers.d.ts +1 -1
  31. package/dist/utils/helpers.js +1 -1
  32. package/dist/utils/helpers.js.map +1 -1
  33. package/dist/utils/types.d.ts +1 -1
  34. package/dist/utils/types.js +7 -0
  35. package/dist/utils/types.js.map +1 -1
  36. package/package.json +3 -3
  37. package/src/index.ts +192 -55
  38. package/src/parser/grammar.ne +519 -463
  39. package/src/parser/grammar.ts +230 -239
  40. package/src/parser/lexer.ts +353 -77
  41. package/src/prelude.ts +282 -206
  42. package/src/typechecker/DeclarationCollector.ts +157 -104
  43. package/src/typechecker/TypeBuilder.ts +150 -148
  44. package/src/typechecker/checker.ts +501 -395
  45. package/src/typechecker/core.ts +192 -162
  46. package/src/typechecker/inference.ts +1421 -1327
  47. package/src/utils/helpers.ts +29 -29
  48. package/src/utils/types.ts +63 -56
  49. package/tests/hspec.spec.ts +92 -0
  50. package/tests/lexer.spec.ts +175 -0
  51. package/tests/parser.spec.ts +829 -823
  52. package/tests/prelude.spec.ts +17 -22
  53. package/tests/typechecker.spec.ts +327 -310
  54. package/tsconfig.json +26 -17
  55. package/tsconfig.tsbuildinfo +1 -0
  56. package/dist/parser/layoutPreprocessor.d.ts +0 -1
  57. package/dist/parser/layoutPreprocessor.js +0 -22
  58. package/dist/parser/layoutPreprocessor.js.map +0 -1
  59. package/dist/parser/preprocessor.d.ts +0 -28
  60. package/dist/parser/preprocessor.js +0 -453
  61. package/dist/parser/preprocessor.js.map +0 -1
  62. package/src/parser/layoutPreprocessor.ts +0 -21
  63. package/src/parser/preprocessor.ne +0 -375
  64. package/src/parser/preprocessor.ts +0 -502
  65. package/tests/preprocessor.spec.ts +0 -69
@@ -3,16 +3,10 @@
3
3
  // Bypasses TS6133. Allow declared but unused functions.
4
4
  // @ts-ignore
5
5
  function id(d: any[]): any { return d[0]; }
6
- declare var comment: any;
7
- declare var NL: any;
8
6
  declare var lbracket: any;
9
7
  declare var rbracket: any;
10
- declare var typeClass: any;
11
- declare var typeEquals: any;
12
- declare var op: any;
13
8
  declare var assign: any;
14
9
  declare var anonymousVariable: any;
15
- declare var arrow: any;
16
10
  declare var typeArrow: any;
17
11
  declare var constructor: any;
18
12
  declare var variable: any;
@@ -20,9 +14,8 @@ declare var number: any;
20
14
  declare var char: any;
21
15
  declare var string: any;
22
16
  declare var bool: any;
23
- declare var WS: any;
24
17
 
25
- import { HSLexer } from "./lexer.js"
18
+ import { HaskellLayoutLexer } from "./lexer.js"
26
19
  import {
27
20
  TypeCast,
28
21
  Application,
@@ -36,6 +29,7 @@ import {
36
29
  ListUnaryOperation,
37
30
  ArithmeticUnaryOperation,
38
31
  LogicalUnaryOperation,
32
+ Case,
39
33
  SymbolPrimitive,
40
34
  ListPrimitive,
41
35
  Switch,
@@ -76,11 +70,19 @@ import {
76
70
  SimpleType,
77
71
  ListType,
78
72
  TupleType,
73
+ TypeClass,
74
+ Instance,
79
75
  NumberPrimitive,
80
76
  CharPrimitive,
81
77
  StringPrimitive,
82
78
  BooleanPrimitive,
83
- SourceLocation
79
+ SourceLocation,
80
+ TestGroup,
81
+ Test,
82
+ Assert,
83
+ Equality,
84
+ Truth,
85
+ Failure
84
86
  } from "yukigo-ast";
85
87
 
86
88
  const filter = d => {
@@ -88,6 +90,7 @@ const filter = d => {
88
90
  };
89
91
 
90
92
  const loc = (token) => new SourceLocation(token.line, token.col);
93
+ const HSLexer = new HaskellLayoutLexer();
91
94
 
92
95
 
93
96
  interface NearleyToken {
@@ -120,94 +123,123 @@ interface Grammar {
120
123
  const grammar: Grammar = {
121
124
  Lexer: HSLexer,
122
125
  ParserRules: [
123
- {"name": "program$ebnf$1", "symbols": ["declaration"]},
124
- {"name": "program$ebnf$1", "symbols": ["program$ebnf$1", "declaration"], "postprocess": (d) => d[0].concat([d[1]])},
125
- {"name": "program", "symbols": ["program$ebnf$1"], "postprocess": (d) => d[0].filter(x => x !== null)},
126
+ {"name": "program$ebnf$1", "symbols": []},
127
+ {"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]])},
129
+ {"name": "program$ebnf$2", "symbols": [{"literal":";"}], "postprocess": id},
130
+ {"name": "program$ebnf$2", "symbols": [], "postprocess": () => null},
131
+ {"name": "program", "symbols": ["declaration", "program$ebnf$1", "program$ebnf$2"], "postprocess": (d) => [d[0], ...d[1].map(x => x[1])].flat(Infinity)},
126
132
  {"name": "declaration$subexpression$1", "symbols": ["function_declaration"]},
127
133
  {"name": "declaration$subexpression$1", "symbols": ["function_signature"]},
128
134
  {"name": "declaration$subexpression$1", "symbols": ["type_declaration"]},
129
135
  {"name": "declaration$subexpression$1", "symbols": ["data_declaration"]},
130
- {"name": "declaration$subexpression$1", "symbols": ["comment"]},
131
- {"name": "declaration$subexpression$1", "symbols": ["empty_line"]},
136
+ {"name": "declaration$subexpression$1", "symbols": ["typeclass_declaration"]},
137
+ {"name": "declaration$subexpression$1", "symbols": ["instance_declaration"]},
132
138
  {"name": "declaration$subexpression$1", "symbols": ["apply_operator"]},
133
- {"name": "declaration", "symbols": ["declaration$subexpression$1"], "postprocess": (d) => d[0][0]},
134
- {"name": "comment", "symbols": [(HSLexer.has("comment") ? {type: "comment"} : comment)], "postprocess": d => null},
135
- {"name": "empty_line", "symbols": ["_", (HSLexer.has("NL") ? {type: "NL"} : NL)], "postprocess": d => null},
139
+ {"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]},
136
142
  {"name": "expression$subexpression$1", "symbols": ["type_cast"]},
137
143
  {"name": "expression$subexpression$1", "symbols": ["letin_expression"]},
138
144
  {"name": "expression$subexpression$1", "symbols": ["if_expression"]},
139
145
  {"name": "expression$subexpression$1", "symbols": ["case_expression"]},
146
+ {"name": "expression$subexpression$1", "symbols": ["test_declaration"]},
140
147
  {"name": "expression", "symbols": ["expression$subexpression$1"], "postprocess": (d) => d[0][0]},
141
- {"name": "type_cast", "symbols": ["apply_operator", "_", {"literal":"::"}, "_", "type"], "postprocess": (d) => new TypeCast(d[0], d[4])},
148
+ {"name": "test_declaration", "symbols": [{"literal":"describe"}, "expression", {"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[4]))},
149
+ {"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
+ {"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
+ {"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]},
153
+ {"name": "test_declaration", "symbols": ["assertion"], "postprocess": id},
154
+ {"name": "test_body$ebnf$1", "symbols": []},
155
+ {"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]])},
157
+ {"name": "test_body", "symbols": ["test_declaration", "test_body$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[1])]},
158
+ {"name": "assertion", "symbols": ["expression", {"literal":"shouldBe"}, "expression"], "postprocess": (d) => new Assert(new BooleanPrimitive(false), new Equality(d[2], d[0]))},
159
+ {"name": "assertion", "symbols": ["expression", {"literal":"`"}, {"literal":"shouldBe"}, {"literal":"`"}, "expression"], "postprocess": (d) => new Assert(new BooleanPrimitive(false), new Equality(d[4], d[0]))},
160
+ {"name": "assertion", "symbols": ["expression", {"literal":"shouldNotBe"}, "expression"], "postprocess": (d) => new Assert(new BooleanPrimitive(true), new Equality(d[2], d[0]))},
161
+ {"name": "assertion", "symbols": ["expression", {"literal":"`"}, {"literal":"shouldNotBe"}, {"literal":"`"}, "expression"], "postprocess": (d) => new Assert(new BooleanPrimitive(true), new Equality(d[4], d[0]))},
162
+ {"name": "assertion", "symbols": ["expression", {"literal":"shouldSatisfy"}, "expression"], "postprocess": (d) => new Assert(new BooleanPrimitive(false), new Truth(new Application(d[2], d[0])))},
163
+ {"name": "assertion", "symbols": ["expression", {"literal":"`"}, {"literal":"shouldSatisfy"}, {"literal":"`"}, "expression"], "postprocess": (d) => new Assert(new BooleanPrimitive(false), new Truth(new Application(d[4], d[0])))},
164
+ {"name": "assertion", "symbols": ["expression", {"literal":"shouldThrow"}, "expression"], "postprocess": (d) => new Assert(new BooleanPrimitive(false), new Failure(d[0], d[2]))},
165
+ {"name": "assertion", "symbols": ["expression", {"literal":"`"}, {"literal":"shouldThrow"}, {"literal":"`"}, "expression"], "postprocess": (d) => new Assert(new BooleanPrimitive(false), new Failure(d[0], d[4]))},
166
+ {"name": "type_cast", "symbols": ["apply_operator", {"literal":"::"}, "type"], "postprocess": (d) => new TypeCast(d[0], d[2])},
142
167
  {"name": "type_cast", "symbols": ["apply_operator"], "postprocess": id},
143
- {"name": "apply_operator", "symbols": ["bind_expression", "_", {"literal":"$"}, "_", "apply_operator"], "postprocess": (d) => new Application(d[0], d[4])},
168
+ {"name": "apply_operator$subexpression$1", "symbols": [{"literal":"$"}]},
169
+ {"name": "apply_operator$subexpression$1", "symbols": [{"literal":"$!"}]},
170
+ {"name": "apply_operator", "symbols": ["bind_expression", "apply_operator$subexpression$1", "apply_operator"], "postprocess": (d) => new Application(d[0], d[2])},
144
171
  {"name": "apply_operator", "symbols": ["bind_expression"], "postprocess": id},
145
- {"name": "bind_expression", "symbols": ["logical_expression", "_", {"literal":">>="}, "_", "bind_expression"], "postprocess": (d) => new Application(new Application(new SymbolPrimitive("(>>=)"), d[0]), d[4])},
146
- {"name": "bind_expression", "symbols": ["logical_expression", "_", {"literal":">>"}, "_", "bind_expression"], "postprocess": (d) => new Application(new Application(new SymbolPrimitive("(>>)"), d[0]), d[4])},
172
+ {"name": "bind_expression", "symbols": ["logical_expression", {"literal":">>="}, "bind_expression"], "postprocess": (d) => new Application(new Application(new SymbolPrimitive("(>>=)"), d[0]), d[2])},
173
+ {"name": "bind_expression", "symbols": ["logical_expression", {"literal":">>"}, "bind_expression"], "postprocess": (d) => new Application(new Application(new SymbolPrimitive("(>>)"), d[0]), d[2])},
147
174
  {"name": "bind_expression", "symbols": ["logical_expression"], "postprocess": id},
148
- {"name": "logical_expression", "symbols": ["comparison", "_", {"literal":"&&"}, "_", "logical_expression"], "postprocess": (d) => new LogicalBinaryOperation("And", d[0], d[4])},
149
- {"name": "logical_expression", "symbols": ["comparison", "_", {"literal":"||"}, "_", "logical_expression"], "postprocess": (d) => new LogicalBinaryOperation("Or", d[0], d[4])},
175
+ {"name": "logical_expression", "symbols": ["comparison", {"literal":"&&"}, "logical_expression"], "postprocess": (d) => new LogicalBinaryOperation("And", d[0], d[2])},
176
+ {"name": "logical_expression", "symbols": ["comparison", {"literal":"||"}, "logical_expression"], "postprocess": (d) => new LogicalBinaryOperation("Or", d[0], d[2])},
150
177
  {"name": "logical_expression", "symbols": ["comparison"], "postprocess": id},
151
- {"name": "comparison", "symbols": ["cons_expression", "_", "comparison_operator", "_", "cons_expression"], "postprocess": (d) => new ComparisonOperation(d[2], d[0], d[4])},
178
+ {"name": "comparison", "symbols": ["cons_expression", "comparison_operator", "cons_expression"], "postprocess": (d) => new ComparisonOperation(d[1], d[0], d[2])},
152
179
  {"name": "comparison", "symbols": ["cons_expression"], "postprocess": id},
153
- {"name": "cons_expression", "symbols": ["concatenation", "_", {"literal":":"}, "_", "cons_expression"], "postprocess": (d) => new ConsExpression(d[0], d[4])},
180
+ {"name": "cons_expression", "symbols": ["concatenation", {"literal":":"}, "cons_expression"], "postprocess": (d) => new ConsExpression(d[0], d[2])},
154
181
  {"name": "cons_expression", "symbols": ["concatenation"], "postprocess": id},
155
- {"name": "concatenation", "symbols": ["addition", "_", {"literal":"++"}, "_", "concatenation"], "postprocess": (d) => d[0] instanceof StringPrimitive || d[4] instanceof StringPrimitive ? new StringOperation("Concat", d[0], d[4]) : new ListBinaryOperation("Concat", d[0], d[4])},
182
+ {"name": "concatenation", "symbols": ["addition", {"literal":"++"}, "concatenation"], "postprocess": (d) => new ListBinaryOperation("Concat", d[0], d[2])},
156
183
  {"name": "concatenation", "symbols": ["addition"], "postprocess": id},
157
- {"name": "addition", "symbols": ["addition", "_", {"literal":"+"}, "_", "multiplication"], "postprocess": (d) => new ArithmeticBinaryOperation("Plus", d[0], d[4])},
158
- {"name": "addition", "symbols": ["addition", "_", {"literal":"-"}, "_", "multiplication"], "postprocess": (d) => new ArithmeticBinaryOperation("Minus", d[0], d[4])},
184
+ {"name": "addition", "symbols": ["addition", {"literal":"+"}, "multiplication"], "postprocess": (d) => new ArithmeticBinaryOperation("Plus", d[0], d[2])},
185
+ {"name": "addition", "symbols": ["addition", {"literal":"-"}, "multiplication"], "postprocess": (d) => new ArithmeticBinaryOperation("Minus", d[0], d[2])},
159
186
  {"name": "addition", "symbols": ["multiplication"], "postprocess": id},
160
- {"name": "multiplication", "symbols": ["multiplication", "_", {"literal":"*"}, "_", "power"], "postprocess": (d) => new ArithmeticBinaryOperation("Multiply", d[0], d[4])},
161
- {"name": "multiplication", "symbols": ["multiplication", "_", {"literal":"/"}, "_", "power"], "postprocess": (d) => new ArithmeticBinaryOperation("Divide", d[0], d[4])},
187
+ {"name": "multiplication", "symbols": ["multiplication", {"literal":"*"}, "power"], "postprocess": (d) => new ArithmeticBinaryOperation("Multiply", d[0], d[2])},
188
+ {"name": "multiplication", "symbols": ["multiplication", {"literal":"/"}, "power"], "postprocess": (d) => new ArithmeticBinaryOperation("Divide", d[0], d[2])},
162
189
  {"name": "multiplication", "symbols": ["power"], "postprocess": id},
163
- {"name": "power", "symbols": ["unary_negation", "_", {"literal":"**"}, "_", "power"], "postprocess": (d) => new ArithmeticBinaryOperation("Power", d[0], d[4])},
164
- {"name": "power", "symbols": ["unary_negation", "_", {"literal":"^"}, "_", "power"], "postprocess": (d) => new ArithmeticBinaryOperation("Power", d[0], d[4])},
165
- {"name": "power", "symbols": ["unary_negation", "_", {"literal":"^^"}, "_", "power"], "postprocess": (d) => new ArithmeticBinaryOperation("Power", d[0], d[4])},
190
+ {"name": "power", "symbols": ["unary_negation", {"literal":"**"}, "power"], "postprocess": (d) => new ArithmeticBinaryOperation("Power", d[0], d[2])},
191
+ {"name": "power", "symbols": ["unary_negation", {"literal":"^"}, "power"], "postprocess": (d) => new ArithmeticBinaryOperation("Power", d[0], d[2])},
192
+ {"name": "power", "symbols": ["unary_negation", {"literal":"^^"}, "power"], "postprocess": (d) => new ArithmeticBinaryOperation("Power", d[0], d[2])},
166
193
  {"name": "power", "symbols": ["unary_negation"], "postprocess": id},
167
- {"name": "unary_negation", "symbols": [{"literal":"-"}, "_", "unary_negation"], "postprocess": (d) => new ArithmeticUnaryOperation("Negation", d[2])},
194
+ {"name": "unary_negation", "symbols": [{"literal":"-"}, "unary_negation"], "postprocess": (d) => new ArithmeticUnaryOperation("Negation", d[1])},
168
195
  {"name": "unary_negation", "symbols": ["index_access"], "postprocess": id},
169
- {"name": "index_access", "symbols": ["index_access", "_", {"literal":"!!"}, "_", "composition_expression"], "postprocess": (d) => new ListBinaryOperation("GetAt", d[0], d[4])},
196
+ {"name": "index_access", "symbols": ["index_access", {"literal":"!!"}, "composition_expression"], "postprocess": (d) => new ListBinaryOperation("GetAt", d[0], d[2])},
170
197
  {"name": "index_access", "symbols": ["composition_expression"], "postprocess": id},
171
- {"name": "composition_expression", "symbols": ["composition_expression", "_", {"literal":"."}, "_", "infix_operator_expression"], "postprocess": (d) => new CompositionExpression(d[0], d[4])},
198
+ {"name": "composition_expression", "symbols": ["composition_expression", {"literal":"."}, "infix_operator_expression"], "postprocess": (d) => new CompositionExpression(d[0], d[2])},
172
199
  {"name": "composition_expression", "symbols": ["infix_operator_expression"], "postprocess": id},
173
- {"name": "infix_operator_expression", "symbols": ["infix_operator_expression", "_", {"literal":"`"}, "_", "variable", "_", {"literal":"`"}, "_", "application"], "postprocess": (d) => new Application(new Application(d[4], d[0]), d[8])},
200
+ {"name": "infix_operator_expression", "symbols": ["infix_operator_expression", {"literal":"`"}, "variable", {"literal":"`"}, "application"], "postprocess": (d) => new Application(new Application(d[2], d[0]), d[4])},
174
201
  {"name": "infix_operator_expression", "symbols": ["application"], "postprocess": id},
175
- {"name": "application", "symbols": [{"literal":"error"}, "__", "primary"], "postprocess": d => new Raise(d[2])},
202
+ {"name": "application", "symbols": [{"literal":"error"}, "primary"], "postprocess": d => new Raise(d[1])},
176
203
  {"name": "application$ebnf$1", "symbols": []},
177
- {"name": "application$ebnf$1$subexpression$1$subexpression$1", "symbols": ["_"]},
178
- {"name": "application$ebnf$1$subexpression$1$subexpression$1$subexpression$1", "symbols": ["_", (HSLexer.has("NL") ? {type: "NL"} : NL), "__"]},
179
- {"name": "application$ebnf$1$subexpression$1$subexpression$1", "symbols": ["application$ebnf$1$subexpression$1$subexpression$1$subexpression$1"]},
180
- {"name": "application$ebnf$1$subexpression$1", "symbols": ["application$ebnf$1$subexpression$1$subexpression$1", "primary"]},
181
- {"name": "application$ebnf$1", "symbols": ["application$ebnf$1", "application$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]])},
204
+ {"name": "application$ebnf$1", "symbols": ["application$ebnf$1", "primary"], "postprocess": (d) => d[0].concat([d[1]])},
182
205
  {"name": "application", "symbols": ["primary", "application$ebnf$1"], "postprocess": (d) => {
183
206
  if (d[1].length === 0) return d[0];
184
- return d[1].reduce((left, right) => new Application(left, right[1]), d[0]);
207
+ return d[1].reduce((left, right) => new Application(left, right), d[0]);
185
208
  } },
186
- {"name": "operator$subexpression$1", "symbols": [{"literal":"=="}]},
187
- {"name": "operator$subexpression$1", "symbols": [{"literal":"/="}]},
188
- {"name": "operator$subexpression$1", "symbols": [{"literal":"<"}]},
189
- {"name": "operator$subexpression$1", "symbols": [{"literal":">"}]},
190
- {"name": "operator$subexpression$1", "symbols": [{"literal":"<="}]},
191
- {"name": "operator$subexpression$1", "symbols": [{"literal":"&&"}]},
192
- {"name": "operator$subexpression$1", "symbols": [{"literal":"||"}]},
193
- {"name": "operator$subexpression$1", "symbols": [{"literal":">="}]},
194
- {"name": "operator$subexpression$1", "symbols": [{"literal":"++"}]},
195
- {"name": "operator$subexpression$1", "symbols": [{"literal":"+"}]},
196
- {"name": "operator$subexpression$1", "symbols": [{"literal":","}]},
197
- {"name": "operator$subexpression$1", "symbols": [{"literal":"*"}]},
198
- {"name": "operator$subexpression$1", "symbols": [{"literal":"/"}]},
199
- {"name": "operator$subexpression$1", "symbols": [{"literal":":"}]},
200
- {"name": "operator", "symbols": ["operator$subexpression$1"], "postprocess": (d) => d[0][0].value},
201
- {"name": "left_section", "symbols": [{"literal":"("}, "_", "expression", "_", "operator", "_", {"literal":")"}], "postprocess": (d) => new Application(new SymbolPrimitive(d[4]), d[2])},
202
- {"name": "right_section", "symbols": [{"literal":"("}, "_", "operator", "_", "expression", "_", {"literal":")"}], "postprocess": (d) => {
209
+ {"name": "operator", "symbols": ["operator_no_minus"], "postprocess": id},
210
+ {"name": "operator", "symbols": [{"literal":"-"}], "postprocess": (d) => d[0].value},
211
+ {"name": "operator_no_minus$subexpression$1", "symbols": [{"literal":"=="}]},
212
+ {"name": "operator_no_minus$subexpression$1", "symbols": [{"literal":"/="}]},
213
+ {"name": "operator_no_minus$subexpression$1", "symbols": [{"literal":"<"}]},
214
+ {"name": "operator_no_minus$subexpression$1", "symbols": [{"literal":">"}]},
215
+ {"name": "operator_no_minus$subexpression$1", "symbols": [{"literal":"<="}]},
216
+ {"name": "operator_no_minus$subexpression$1", "symbols": [{"literal":"&&"}]},
217
+ {"name": "operator_no_minus$subexpression$1", "symbols": [{"literal":"||"}]},
218
+ {"name": "operator_no_minus$subexpression$1", "symbols": [{"literal":">="}]},
219
+ {"name": "operator_no_minus$subexpression$1", "symbols": [{"literal":"++"}]},
220
+ {"name": "operator_no_minus$subexpression$1", "symbols": [{"literal":"+"}]},
221
+ {"name": "operator_no_minus$subexpression$1", "symbols": [{"literal":","}]},
222
+ {"name": "operator_no_minus$subexpression$1", "symbols": [{"literal":"^^"}]},
223
+ {"name": "operator_no_minus$subexpression$1", "symbols": [{"literal":"^"}]},
224
+ {"name": "operator_no_minus$subexpression$1", "symbols": [{"literal":"**"}]},
225
+ {"name": "operator_no_minus$subexpression$1", "symbols": [{"literal":"*"}]},
226
+ {"name": "operator_no_minus$subexpression$1", "symbols": [{"literal":"!!"}]},
227
+ {"name": "operator_no_minus$subexpression$1", "symbols": [{"literal":"/"}]},
228
+ {"name": "operator_no_minus$subexpression$1", "symbols": [{"literal":"$"}]},
229
+ {"name": "operator_no_minus$subexpression$1", "symbols": [{"literal":"$!"}]},
230
+ {"name": "operator_no_minus$subexpression$1", "symbols": [{"literal":"."}]},
231
+ {"name": "operator_no_minus$subexpression$1", "symbols": [{"literal":":"}]},
232
+ {"name": "operator_no_minus", "symbols": ["operator_no_minus$subexpression$1"], "postprocess": (d) => d[0][0].value},
233
+ {"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) => {
203
235
  const flipBody = new SymbolPrimitive("flip");
204
- const op = new SymbolPrimitive(d[2]);
205
- const expr = d[4];
236
+ const op = new SymbolPrimitive(d[1]);
237
+ const expr = d[2];
206
238
  const flipAppliedToOp = new Application(flipBody, op);
207
239
  return new Application(flipAppliedToOp, expr);
208
240
  }
209
241
  },
210
- {"name": "operator_section", "symbols": [{"literal":"("}, "_", "operator", "_", {"literal":")"}], "postprocess": (d) => new SymbolPrimitive(d[2])},
242
+ {"name": "operator_section", "symbols": [{"literal":"("}, "operator", {"literal":")"}], "postprocess": (d) => new SymbolPrimitive(d[1])},
211
243
  {"name": "primary", "symbols": ["primitive"], "postprocess": id},
212
244
  {"name": "primary", "symbols": ["variable"], "postprocess": id},
213
245
  {"name": "primary", "symbols": ["constr"], "postprocess": id},
@@ -219,153 +251,124 @@ const grammar: Grammar = {
219
251
  {"name": "primary", "symbols": ["lambda_expression"], "postprocess": id},
220
252
  {"name": "primary", "symbols": ["data_expression"], "postprocess": id},
221
253
  {"name": "primary", "symbols": ["list_comprehension"], "postprocess": id},
222
- {"name": "primary", "symbols": [{"literal":"("}, "_", "expression", "_", {"literal":")"}], "postprocess": (d) => d[2]},
223
- {"name": "primary", "symbols": [{"literal":"["}, "_", "range_expression", "_", {"literal":"]"}], "postprocess": (d) => d[2]},
224
- {"name": "list_comprehension", "symbols": [{"literal":"["}, "_", "expression", "_", {"literal":"|"}, "_", "comprehension_clause_list", "_", {"literal":"]"}], "postprocess": (d) => {
225
- return new ListComprehension(d[2], d[6]);
254
+ {"name": "primary", "symbols": [{"literal":"("}, "expression", {"literal":")"}], "postprocess": (d) => d[1]},
255
+ {"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]);
226
258
  } },
227
259
  {"name": "comprehension_clause_list$ebnf$1", "symbols": []},
228
- {"name": "comprehension_clause_list$ebnf$1$subexpression$1", "symbols": ["_", {"literal":","}, "_", "comprehension_clause"]},
260
+ {"name": "comprehension_clause_list$ebnf$1$subexpression$1", "symbols": [{"literal":","}, "comprehension_clause"]},
229
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]])},
230
262
  {"name": "comprehension_clause_list", "symbols": ["comprehension_clause", "comprehension_clause_list$ebnf$1"], "postprocess": (d) => {
231
- return [d[0], ...d[1].map((x) => x[3])];
263
+ return [d[0], ...d[1].map((x) => x[1])];
232
264
  } },
233
- {"name": "comprehension_clause", "symbols": ["variable", "_", {"literal":"<-"}, "_", "expression"], "postprocess": (d) => new Generator(d[0], d[4])},
265
+ {"name": "comprehension_clause", "symbols": ["variable", {"literal":"<-"}, "expression"], "postprocess": (d) => new Generator(d[0], d[2])},
234
266
  {"name": "comprehension_clause", "symbols": ["expression"], "postprocess": id},
235
- {"name": "lambda_expression", "symbols": [{"literal":"("}, "_", {"literal":"\\"}, "_", "parameter_list", "_", {"literal":"->"}, "_", "expression", "_", {"literal":")"}], "postprocess": (d) => new Lambda(d[4], d[8])},
236
- {"name": "tuple_expression$ebnf$1$subexpression$1", "symbols": ["_", {"literal":","}, "_", "tuple_value"]},
267
+ {"name": "lambda_expression", "symbols": [{"literal":"("}, {"literal":"\\"}, "parameter_list", {"literal":"->"}, "expression", {"literal":")"}], "postprocess": (d) => new Lambda(d[2], d[4])},
268
+ {"name": "tuple_expression$ebnf$1$subexpression$1", "symbols": [{"literal":","}, "expression"]},
237
269
  {"name": "tuple_expression$ebnf$1", "symbols": ["tuple_expression$ebnf$1$subexpression$1"]},
238
- {"name": "tuple_expression$ebnf$1$subexpression$2", "symbols": ["_", {"literal":","}, "_", "tuple_value"]},
270
+ {"name": "tuple_expression$ebnf$1$subexpression$2", "symbols": [{"literal":","}, "expression"]},
239
271
  {"name": "tuple_expression$ebnf$1", "symbols": ["tuple_expression$ebnf$1", "tuple_expression$ebnf$1$subexpression$2"], "postprocess": (d) => d[0].concat([d[1]])},
240
- {"name": "tuple_expression", "symbols": [{"literal":"("}, "_", "tuple_value", "tuple_expression$ebnf$1", "_", {"literal":")"}], "postprocess": (d) => new TupleExpression([d[2], ...d[3].map(x => x[3])])},
241
- {"name": "tuple_value", "symbols": ["expression"], "postprocess": id},
242
- {"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[4])},
272
+ {"name": "tuple_expression", "symbols": [{"literal":"("}, "expression", "tuple_expression$ebnf$1", {"literal":")"}], "postprocess": (d) => new TupleExpression([d[1], ...d[2].map(x => x[1])])},
273
+ {"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])},
243
274
  {"name": "fields_expressions$ebnf$1", "symbols": []},
244
- {"name": "fields_expressions$ebnf$1$subexpression$1", "symbols": ["_", {"literal":","}, "_", "field_exp"]},
275
+ {"name": "fields_expressions$ebnf$1$subexpression$1", "symbols": [{"literal":","}, "field_exp"]},
245
276
  {"name": "fields_expressions$ebnf$1", "symbols": ["fields_expressions$ebnf$1", "fields_expressions$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]])},
246
- {"name": "fields_expressions", "symbols": ["field_exp", "fields_expressions$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[3])]},
247
- {"name": "field_exp", "symbols": ["variable", "_", {"literal":"="}, "_", "expression"], "postprocess": (d) => new FieldExpression(d[0], d[4])},
248
- {"name": "if_expression", "symbols": [{"literal":"if"}, "__", "expression", "__", {"literal":"then"}, "__", "expression", "__", {"literal":"else"}, "__", "expression"], "postprocess": (d) => new If(d[2], d[6], d[10])},
249
- {"name": "letin_expression$subexpression$1", "symbols": ["_", {"literal":"{"}, "_"]},
277
+ {"name": "fields_expressions", "symbols": ["field_exp", "fields_expressions$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[1])]},
278
+ {"name": "field_exp", "symbols": ["variable", {"literal":"="}, "expression"], "postprocess": (d) => new FieldExpression(d[0], d[2])},
279
+ {"name": "if_expression", "symbols": [{"literal":"if"}, "expression", {"literal":"then"}, "expression", {"literal":"else"}, "expression"], "postprocess": (d) => new If(d[1], d[3], d[5])},
250
280
  {"name": "letin_expression$ebnf$1", "symbols": ["bindings_list"], "postprocess": id},
251
281
  {"name": "letin_expression$ebnf$1", "symbols": [], "postprocess": () => null},
252
- {"name": "letin_expression$subexpression$2", "symbols": ["_", {"literal":"}"}, "_"]},
253
- {"name": "letin_expression", "symbols": [{"literal":"let"}, "letin_expression$subexpression$1", "letin_expression$ebnf$1", "letin_expression$subexpression$2", {"literal":"in"}, "_", "expression"], "postprocess": (d) => new LetInExpression(new Sequence(d[2] ?? []), d[6])},
254
- {"name": "case_expression$subexpression$1", "symbols": ["_", {"literal":"{"}, "_"]},
255
- {"name": "case_expression$subexpression$2", "symbols": ["_", {"literal":"}"}, "_"]},
256
- {"name": "case_expression", "symbols": [{"literal":"case"}, "_", "expression", "_", {"literal":"of"}, "case_expression$subexpression$1", "case_arms", "case_expression$subexpression$2"], "postprocess": (d) => new Switch(d[2], d[6])},
282
+ {"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
+ {"name": "case_expression", "symbols": [{"literal":"case"}, "expression", {"literal":"of"}, {"literal":"{"}, "case_arms", {"literal":"}"}], "postprocess": (d) => new Switch(d[1], d[4])},
257
284
  {"name": "case_arms$ebnf$1", "symbols": []},
258
- {"name": "case_arms$ebnf$1$subexpression$1$subexpression$1", "symbols": ["_", {"literal":";"}, "_"]},
259
- {"name": "case_arms$ebnf$1$subexpression$1", "symbols": ["case_arms$ebnf$1$subexpression$1$subexpression$1", "case_arm"]},
285
+ {"name": "case_arms$ebnf$1$subexpression$1", "symbols": [{"literal":";"}, "case_arm"]},
260
286
  {"name": "case_arms$ebnf$1", "symbols": ["case_arms$ebnf$1", "case_arms$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]])},
261
287
  {"name": "case_arms", "symbols": ["case_arm", "case_arms$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[1])]},
262
- {"name": "case_arm", "symbols": ["pattern", "_", {"literal":"->"}, "_", "expression"], "postprocess": (d) => ({condition: d[0], body: d[4] })},
288
+ {"name": "case_arm", "symbols": ["pattern", {"literal":"->"}, "expression"], "postprocess": (d) => new Case(d[0], d[2])},
289
+ {"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
+ {"name": "typeclass_body$ebnf$1", "symbols": []},
291
+ {"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]])},
293
+ {"name": "typeclass_body", "symbols": ["function_signature", "typeclass_body$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[1])]},
294
+ {"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
+ {"name": "instance_body$subexpression$1", "symbols": ["function_declaration"]},
296
+ {"name": "instance_body$subexpression$1", "symbols": ["function_signature"]},
297
+ {"name": "instance_body$ebnf$1", "symbols": []},
298
+ {"name": "instance_body$ebnf$1$subexpression$1$subexpression$1", "symbols": ["function_declaration"]},
299
+ {"name": "instance_body$ebnf$1$subexpression$1$subexpression$1", "symbols": ["function_signature"]},
300
+ {"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]])},
302
+ {"name": "instance_body$ebnf$2", "symbols": [{"literal":";"}], "postprocess": id},
303
+ {"name": "instance_body$ebnf$2", "symbols": [], "postprocess": () => null},
304
+ {"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])]},
263
305
  {"name": "data_declaration$ebnf$1", "symbols": []},
264
- {"name": "data_declaration$ebnf$1$subexpression$1", "symbols": ["__", "type_variable"]},
265
- {"name": "data_declaration$ebnf$1", "symbols": ["data_declaration$ebnf$1", "data_declaration$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]])},
306
+ {"name": "data_declaration$ebnf$1", "symbols": ["data_declaration$ebnf$1", "type_variable"], "postprocess": (d) => d[0].concat([d[1]])},
266
307
  {"name": "data_declaration$ebnf$2", "symbols": []},
267
- {"name": "data_declaration$ebnf$2$subexpression$1", "symbols": ["_", {"literal":"|"}, "_", "constructor_def"]},
308
+ {"name": "data_declaration$ebnf$2$subexpression$1", "symbols": [{"literal":"|"}, "constructor_def"]},
268
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
310
  {"name": "data_declaration$ebnf$3", "symbols": ["deriving_clause"], "postprocess": id},
270
311
  {"name": "data_declaration$ebnf$3", "symbols": [], "postprocess": () => null},
271
- {"name": "data_declaration", "symbols": [{"literal":"data"}, "__", "constr", "data_declaration$ebnf$1", "_", {"literal":"="}, "_", "constructor_def", "data_declaration$ebnf$2", "data_declaration$ebnf$3"], "postprocess":
272
- (d) => new Record(d[2], [d[7], ...d[8].map(x => x[3])], d[9])
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])
273
314
  },
274
- {"name": "deriving_clause", "symbols": ["_", {"literal":"deriving"}, "_", "deriving_spec"], "postprocess": (d) => d[3]},
275
- {"name": "deriving_spec", "symbols": [{"literal":"("}, "_", "deriving_classes", "_", {"literal":")"}], "postprocess": (d) => d[2]},
315
+ {"name": "deriving_clause", "symbols": [{"literal":"deriving"}, "deriving_spec"], "postprocess": (d) => d[1]},
316
+ {"name": "deriving_spec", "symbols": [{"literal":"("}, "deriving_classes", {"literal":")"}], "postprocess": (d) => d[1]},
276
317
  {"name": "deriving_spec", "symbols": ["constr"], "postprocess": (d) => [d[0]]},
277
318
  {"name": "deriving_classes$ebnf$1", "symbols": []},
278
- {"name": "deriving_classes$ebnf$1$subexpression$1", "symbols": ["_", {"literal":","}, "_", (HSLexer.has("typeClass") ? {type: "typeClass"} : typeClass)]},
319
+ {"name": "deriving_classes$ebnf$1$subexpression$1", "symbols": [{"literal":","}, "constr"]},
279
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", "symbols": [(HSLexer.has("typeClass") ? {type: "typeClass"} : typeClass), "deriving_classes$ebnf$1"], "postprocess": (d) => [new SymbolPrimitive(d[0].value), ...d[1].map(x => new SymbolPrimitive(x[3].value))]},
281
- {"name": "constructor_def$ebnf$1$subexpression$1", "symbols": [(HSLexer.has("NL") ? {type: "NL"} : NL), "__"]},
282
- {"name": "constructor_def$ebnf$1", "symbols": ["constructor_def$ebnf$1$subexpression$1"], "postprocess": id},
283
- {"name": "constructor_def$ebnf$1", "symbols": [], "postprocess": () => null},
284
- {"name": "constructor_def$ebnf$2$subexpression$1", "symbols": [(HSLexer.has("NL") ? {type: "NL"} : NL), "_"]},
285
- {"name": "constructor_def$ebnf$2", "symbols": ["constructor_def$ebnf$2$subexpression$1"], "postprocess": id},
286
- {"name": "constructor_def$ebnf$2", "symbols": [], "postprocess": () => null},
287
- {"name": "constructor_def$ebnf$3$subexpression$1", "symbols": [(HSLexer.has("NL") ? {type: "NL"} : NL), "_"]},
288
- {"name": "constructor_def$ebnf$3", "symbols": ["constructor_def$ebnf$3$subexpression$1"], "postprocess": id},
289
- {"name": "constructor_def$ebnf$3", "symbols": [], "postprocess": () => null},
290
- {"name": "constructor_def", "symbols": ["constr", "_", "constructor_def$ebnf$1", (HSLexer.has("lbracket") ? {type: "lbracket"} : lbracket), "_", "constructor_def$ebnf$2", "field_list", "_", "constructor_def$ebnf$3", (HSLexer.has("rbracket") ? {type: "rbracket"} : rbracket)], "postprocess": (d) => new Constructor(d[0], d[6])},
291
- {"name": "constructor_def$ebnf$4", "symbols": []},
292
- {"name": "constructor_def$ebnf$4$subexpression$1", "symbols": ["__", "simple_type"]},
293
- {"name": "constructor_def$ebnf$4", "symbols": ["constructor_def$ebnf$4", "constructor_def$ebnf$4$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]])},
294
- {"name": "constructor_def", "symbols": ["constr", "constructor_def$ebnf$4"], "postprocess": (d) => new Constructor(d[0], d[1].map(x => new Field(undefined, x[1])))},
321
+ {"name": "deriving_classes", "symbols": ["constr", "deriving_classes$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[1])]},
322
+ {"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
+ {"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]])},
325
+ {"name": "constructor_def", "symbols": ["constr", "constructor_def$ebnf$1"], "postprocess": (d) => new Constructor(d[0], d[1].map(x => new Field(undefined, x)))},
295
326
  {"name": "field_list$ebnf$1", "symbols": []},
296
- {"name": "field_list$ebnf$1$subexpression$1$ebnf$1$subexpression$1", "symbols": [(HSLexer.has("NL") ? {type: "NL"} : NL), "_"]},
297
- {"name": "field_list$ebnf$1$subexpression$1$ebnf$1", "symbols": ["field_list$ebnf$1$subexpression$1$ebnf$1$subexpression$1"], "postprocess": id},
298
- {"name": "field_list$ebnf$1$subexpression$1$ebnf$1", "symbols": [], "postprocess": () => null},
299
- {"name": "field_list$ebnf$1$subexpression$1", "symbols": ["_", {"literal":","}, "_", "field_list$ebnf$1$subexpression$1$ebnf$1", "field"]},
327
+ {"name": "field_list$ebnf$1$subexpression$1", "symbols": [{"literal":","}, "field"]},
300
328
  {"name": "field_list$ebnf$1", "symbols": ["field_list$ebnf$1", "field_list$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]])},
301
- {"name": "field_list", "symbols": ["field", "field_list$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[4])]},
302
- {"name": "field", "symbols": ["variable", "_", (HSLexer.has("typeEquals") ? {type: "typeEquals"} : typeEquals), "_", "type"], "postprocess": (d) => new Field(d[0], d[4])},
303
- {"name": "binding_name", "symbols": [{"literal":"("}, "_", (HSLexer.has("op") ? {type: "op"} : op), "_", {"literal":")"}], "postprocess": d => new SymbolPrimitive(`${d[2].value}`)},
329
+ {"name": "field_list", "symbols": ["field", "field_list$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[1])]},
330
+ {"name": "field", "symbols": ["variable", {"literal":"::"}, "type"], "postprocess": (d) => new Field(d[0], d[2])},
331
+ {"name": "op_name", "symbols": [{"literal":"("}, "operator", {"literal":")"}], "postprocess": d => new SymbolPrimitive(d[1])},
332
+ {"name": "binding_name", "symbols": ["op_name"], "postprocess": id},
304
333
  {"name": "binding_name", "symbols": ["variable"], "postprocess": id},
305
- {"name": "function_signature$ebnf$1", "symbols": []},
306
- {"name": "function_signature$ebnf$1$subexpression$1", "symbols": ["_", {"literal":","}, "_", "binding_name"]},
307
- {"name": "function_signature$ebnf$1", "symbols": ["function_signature$ebnf$1", "function_signature$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]])},
308
- {"name": "function_signature", "symbols": ["binding_name", "function_signature$ebnf$1", "_", (HSLexer.has("typeEquals") ? {type: "typeEquals"} : typeEquals), "_", "type"], "postprocess": (d) => new TypeSignature(d[0], d[5])},
309
- {"name": "function_declaration", "symbols": ["variable", "equation"], "postprocess": (d) => new Function(d[0], [d[1]])},
310
- {"name": "function_declaration", "symbols": [{"literal":"("}, "_", (HSLexer.has("op") ? {type: "op"} : op), "_", {"literal":")"}, "equation"], "postprocess": (d) => new Function(new SymbolPrimitive(`${d[2].value}`), [d[5]])},
334
+ {"name": "function_signature", "symbols": ["binding_name", {"literal":"::"}, "type"], "postprocess": (d) => new TypeSignature(d[0], d[2])},
335
+ {"name": "function_declaration", "symbols": ["binding_name", "equation"], "postprocess": (d) => new Function(d[0], [d[1]])},
311
336
  {"name": "return_expression", "symbols": ["expression"], "postprocess": d => new Return(d[0])},
312
- {"name": "where_clause", "symbols": [{"literal":"where"}, "_", {"literal":"{"}, "_", "bindings_list", "_", {"literal":"}"}], "postprocess": d => d[4]},
313
- {"name": "bindings_list$ebnf$1", "symbols": []},
314
- {"name": "bindings_list$ebnf$1$subexpression$1$subexpression$1", "symbols": ["_", {"literal":";"}, "_"]},
315
- {"name": "bindings_list$ebnf$1$subexpression$1", "symbols": ["bindings_list$ebnf$1$subexpression$1$subexpression$1", "function_declaration"]},
316
- {"name": "bindings_list$ebnf$1", "symbols": ["bindings_list$ebnf$1", "bindings_list$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]])},
317
- {"name": "bindings_list", "symbols": ["function_declaration", "bindings_list$ebnf$1"], "postprocess": d => [d[0], ...d[1].map(x => x[1])]},
318
- {"name": "equation$ebnf$1$subexpression$1", "symbols": [(HSLexer.has("NL") ? {type: "NL"} : NL), "__"]},
319
- {"name": "equation$ebnf$1", "symbols": ["equation$ebnf$1$subexpression$1"], "postprocess": id},
337
+ {"name": "where_clause", "symbols": [{"literal":"where"}, {"literal":"{"}, "bindings_list", {"literal":"}"}], "postprocess": d => d[2]},
338
+ {"name": "bindings_list", "symbols": ["function_declaration", {"literal":";"}, "bindings_list"], "postprocess": d => [d[0], ...d[2]]},
339
+ {"name": "bindings_list", "symbols": ["function_declaration"], "postprocess": d => [d[0]]},
340
+ {"name": "equation$ebnf$1", "symbols": ["where_clause"], "postprocess": id},
320
341
  {"name": "equation$ebnf$1", "symbols": [], "postprocess": () => null},
321
- {"name": "equation$ebnf$2$subexpression$1", "symbols": ["_", "where_clause"]},
322
- {"name": "equation$ebnf$2", "symbols": ["equation$ebnf$2$subexpression$1"], "postprocess": id},
323
- {"name": "equation$ebnf$2", "symbols": [], "postprocess": () => null},
324
- {"name": "equation", "symbols": ["params", "equation$ebnf$1", "guarded_rhs", "equation$ebnf$2"], "postprocess": (d) => {
325
- const body = d[2];
326
- const finalBody = d[3]
327
- ? new LetInExpression(d[3], body)
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)])))
328
346
  : body;
329
347
  return new Equation(d[0], finalBody);
330
348
  } },
331
- {"name": "equation$subexpression$1$subexpression$1", "symbols": ["_", (HSLexer.has("NL") ? {type: "NL"} : NL), "__"]},
332
- {"name": "equation$subexpression$1", "symbols": ["equation$subexpression$1$subexpression$1"]},
333
- {"name": "equation$subexpression$1", "symbols": ["_"]},
334
- {"name": "equation$ebnf$3$subexpression$1", "symbols": ["_", "where_clause"]},
335
- {"name": "equation$ebnf$3", "symbols": ["equation$ebnf$3$subexpression$1"], "postprocess": id},
336
- {"name": "equation$ebnf$3", "symbols": [], "postprocess": () => null},
337
- {"name": "equation", "symbols": ["params", (HSLexer.has("assign") ? {type: "assign"} : assign), "equation$subexpression$1", "return_expression", "equation$ebnf$3"], "postprocess": d => new Equation(d[0], new UnguardedBody(new Sequence(d[4] ? [...d[4][1], d[3]] : [d[3]])), d[3])},
338
- {"name": "params", "symbols": ["__", "parameter_list", "_"], "postprocess": d => d[1]},
339
- {"name": "params", "symbols": ["_"], "postprocess": d => []},
340
- {"name": "guarded_rhs$subexpression$1$subexpression$1", "symbols": ["_", (HSLexer.has("NL") ? {type: "NL"} : NL), "__"]},
341
- {"name": "guarded_rhs$subexpression$1", "symbols": ["guarded_rhs$subexpression$1$subexpression$1"]},
342
- {"name": "guarded_rhs$subexpression$1", "symbols": ["_"]},
343
- {"name": "guarded_rhs", "symbols": ["guarded_branch", "guarded_rhs$subexpression$1", "guarded_rhs"], "postprocess": (d) => [d[0], ...d[2]]},
344
- {"name": "guarded_rhs", "symbols": ["guarded_branch"], "postprocess": (d) => [d[0]]},
345
- {"name": "guarded_branch$subexpression$1$subexpression$1", "symbols": ["_", (HSLexer.has("NL") ? {type: "NL"} : NL), "__"]},
346
- {"name": "guarded_branch$subexpression$1", "symbols": ["guarded_branch$subexpression$1$subexpression$1"]},
347
- {"name": "guarded_branch$subexpression$1", "symbols": ["_"]},
348
- {"name": "guarded_branch$subexpression$2$subexpression$1", "symbols": ["_", (HSLexer.has("NL") ? {type: "NL"} : NL), "__"]},
349
- {"name": "guarded_branch$subexpression$2", "symbols": ["guarded_branch$subexpression$2$subexpression$1"]},
350
- {"name": "guarded_branch$subexpression$2", "symbols": ["_"]},
351
- {"name": "guarded_branch$subexpression$3$subexpression$1", "symbols": ["_", (HSLexer.has("NL") ? {type: "NL"} : NL), "__"]},
352
- {"name": "guarded_branch$subexpression$3", "symbols": ["guarded_branch$subexpression$3$subexpression$1"]},
353
- {"name": "guarded_branch$subexpression$3", "symbols": ["_"]},
354
- {"name": "guarded_branch", "symbols": [{"literal":"|"}, "guarded_branch$subexpression$1", "condition", "guarded_branch$subexpression$2", {"literal":"="}, "guarded_branch$subexpression$3", "expression"], "postprocess": (d) => new GuardedBody(d[2], d[6])},
349
+ {"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])},
352
+ {"name": "params$ebnf$1", "symbols": ["parameter_list"], "postprocess": id},
353
+ {"name": "params$ebnf$1", "symbols": [], "postprocess": () => null},
354
+ {"name": "params", "symbols": ["params$ebnf$1"], "postprocess": (d) => d[0] || []},
355
+ {"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]])},
357
+ {"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])},
355
359
  {"name": "condition", "symbols": [{"literal":"otherwise"}], "postprocess": d => new Otherwise()},
356
360
  {"name": "condition", "symbols": ["expression"], "postprocess": d => d[0]},
357
- {"name": "parameter_list$ebnf$1", "symbols": []},
358
- {"name": "parameter_list$ebnf$1$subexpression$1", "symbols": ["__", "pattern"]},
359
- {"name": "parameter_list$ebnf$1", "symbols": ["parameter_list$ebnf$1", "parameter_list$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]])},
360
- {"name": "parameter_list", "symbols": ["pattern", "parameter_list$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[1])]},
361
+ {"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]])},
363
+ {"name": "parameter_list", "symbols": ["parameter_list$ebnf$1"], "postprocess": id},
361
364
  {"name": "pattern", "symbols": ["cons_pattern"], "postprocess": id},
362
- {"name": "cons_pattern$ebnf$1$subexpression$1", "symbols": ["_", {"literal":":"}, "_", "cons_pattern"]},
365
+ {"name": "cons_pattern$ebnf$1$subexpression$1", "symbols": [{"literal":":"}, "cons_pattern"]},
363
366
  {"name": "cons_pattern$ebnf$1", "symbols": ["cons_pattern$ebnf$1$subexpression$1"]},
364
- {"name": "cons_pattern$ebnf$1$subexpression$2", "symbols": ["_", {"literal":":"}, "_", "cons_pattern"]},
367
+ {"name": "cons_pattern$ebnf$1$subexpression$2", "symbols": [{"literal":":"}, "cons_pattern"]},
365
368
  {"name": "cons_pattern$ebnf$1", "symbols": ["cons_pattern$ebnf$1", "cons_pattern$ebnf$1$subexpression$2"], "postprocess": (d) => d[0].concat([d[1]])},
366
- {"name": "cons_pattern", "symbols": [{"literal":"("}, "_", "cons_pattern", "cons_pattern$ebnf$1", "_", {"literal":")"}], "postprocess":
369
+ {"name": "cons_pattern", "symbols": [{"literal":"("}, "cons_pattern", "cons_pattern$ebnf$1", {"literal":")"}], "postprocess":
367
370
  (d) => {
368
- const patterns = [d[2], ...d[3].map(item => item[3])];
371
+ const patterns = [d[1], ...d[2].map(item => item[1])];
369
372
  return patterns.reduceRight((tail, head, index, arr) => {
370
373
  if (index === arr.length - 1) return tail;
371
374
  return new ConsPattern(head, tail);
@@ -383,69 +386,57 @@ const grammar: Grammar = {
383
386
  {"name": "simple_pattern$subexpression$1", "symbols": ["paren_pattern"]},
384
387
  {"name": "simple_pattern", "symbols": ["simple_pattern$subexpression$1"], "postprocess": (d) => d[0][0]},
385
388
  {"name": "wildcard_pattern", "symbols": [(HSLexer.has("anonymousVariable") ? {type: "anonymousVariable"} : anonymousVariable)], "postprocess": (d) => new WildcardPattern()},
386
- {"name": "paren_pattern", "symbols": [{"literal":"("}, "_", "pattern", "_", {"literal":")"}], "postprocess": (d) => d[2]},
389
+ {"name": "paren_pattern", "symbols": [{"literal":"("}, "pattern", {"literal":")"}], "postprocess": (d) => d[1]},
387
390
  {"name": "variable_pattern", "symbols": ["variable"], "postprocess": (d) => new VariablePattern(d[0])},
388
391
  {"name": "literal_pattern", "symbols": ["primitive"], "postprocess": (d) => new LiteralPattern(d[0])},
389
392
  {"name": "as_pattern$subexpression$1", "symbols": ["variable_pattern"]},
390
393
  {"name": "as_pattern$subexpression$1", "symbols": ["wildcard_pattern"]},
391
394
  {"name": "as_pattern", "symbols": ["as_pattern$subexpression$1", {"literal":"@"}, "pattern"], "postprocess": (d) => new AsPattern(d[0][0], d[2])},
392
- {"name": "constructor_pattern$ebnf$1$subexpression$1", "symbols": ["__", "pattern"]},
393
- {"name": "constructor_pattern$ebnf$1", "symbols": ["constructor_pattern$ebnf$1$subexpression$1"]},
394
- {"name": "constructor_pattern$ebnf$1$subexpression$2", "symbols": ["__", "pattern"]},
395
- {"name": "constructor_pattern$ebnf$1", "symbols": ["constructor_pattern$ebnf$1", "constructor_pattern$ebnf$1$subexpression$2"], "postprocess": (d) => d[0].concat([d[1]])},
396
- {"name": "constructor_pattern", "symbols": [{"literal":"("}, "_", "constr", "constructor_pattern$ebnf$1", "_", {"literal":")"}], "postprocess": (d) => new ConstructorPattern(d[2].value, d[3].map(x => x[1]))},
397
- {"name": "constructor_pattern", "symbols": ["constr"], "postprocess": (d) => new ConstructorPattern(d[0].value, [])},
395
+ {"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]])},
397
+ {"name": "constructor_pattern", "symbols": [{"literal":"("}, "constr", "constructor_pattern$ebnf$1", {"literal":")"}], "postprocess": (d) => new ConstructorPattern(d[1], d[2])},
398
+ {"name": "constructor_pattern", "symbols": ["constr"], "postprocess": (d) => new ConstructorPattern(d[0], [])},
398
399
  {"name": "field_pattern_list$ebnf$1", "symbols": []},
399
- {"name": "field_pattern_list$ebnf$1$subexpression$1", "symbols": ["_", {"literal":","}, "_", "field_pattern"]},
400
+ {"name": "field_pattern_list$ebnf$1$subexpression$1", "symbols": [{"literal":","}, "field_pattern"]},
400
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]])},
401
- {"name": "field_pattern_list", "symbols": ["field_pattern", "field_pattern_list$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[3])]},
402
- {"name": "field_pattern", "symbols": ["variable", "_", {"literal":"="}, "_", "pattern"], "postprocess": (d) => ({ field: d[0].value, pattern: d[4] })},
402
+ {"name": "field_pattern_list", "symbols": ["field_pattern", "field_pattern_list$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[1])]},
403
+ {"name": "field_pattern", "symbols": ["variable", {"literal":"="}, "pattern"], "postprocess": (d) => ({ field: d[0].value, pattern: d[2] })},
403
404
  {"name": "list_pattern$ebnf$1", "symbols": ["pattern_list"], "postprocess": id},
404
405
  {"name": "list_pattern$ebnf$1", "symbols": [], "postprocess": () => null},
405
- {"name": "list_pattern", "symbols": [{"literal":"["}, "_", "list_pattern$ebnf$1", "_", {"literal":"]"}], "postprocess": (d) => new ListPattern(d[2] || [])},
406
+ {"name": "list_pattern", "symbols": [{"literal":"["}, "list_pattern$ebnf$1", {"literal":"]"}], "postprocess": (d) => new ListPattern(d[1] || [])},
406
407
  {"name": "pattern_list$ebnf$1", "symbols": []},
407
- {"name": "pattern_list$ebnf$1$subexpression$1", "symbols": ["_", {"literal":","}, "_", "pattern"]},
408
+ {"name": "pattern_list$ebnf$1$subexpression$1", "symbols": [{"literal":","}, "pattern"]},
408
409
  {"name": "pattern_list$ebnf$1", "symbols": ["pattern_list$ebnf$1", "pattern_list$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]])},
409
- {"name": "pattern_list", "symbols": ["pattern", "pattern_list$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[3])]},
410
- {"name": "tuple_pattern$ebnf$1$subexpression$1", "symbols": ["_", {"literal":","}, "_", "pattern"]},
410
+ {"name": "pattern_list", "symbols": ["pattern", "pattern_list$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[1])]},
411
+ {"name": "tuple_pattern$ebnf$1$subexpression$1", "symbols": [{"literal":","}, "pattern"]},
411
412
  {"name": "tuple_pattern$ebnf$1", "symbols": ["tuple_pattern$ebnf$1$subexpression$1"]},
412
- {"name": "tuple_pattern$ebnf$1$subexpression$2", "symbols": ["_", {"literal":","}, "_", "pattern"]},
413
+ {"name": "tuple_pattern$ebnf$1$subexpression$2", "symbols": [{"literal":","}, "pattern"]},
413
414
  {"name": "tuple_pattern$ebnf$1", "symbols": ["tuple_pattern$ebnf$1", "tuple_pattern$ebnf$1$subexpression$2"], "postprocess": (d) => d[0].concat([d[1]])},
414
- {"name": "tuple_pattern", "symbols": [{"literal":"("}, "_", "pattern", "tuple_pattern$ebnf$1", "_", {"literal":")"}], "postprocess": (d) => new TuplePattern([d[2], ...d[3].map(x => x[3])])},
415
- {"name": "type_declaration$ebnf$1$subexpression$1", "symbols": ["__", "variable_list"]},
416
- {"name": "type_declaration$ebnf$1", "symbols": ["type_declaration$ebnf$1$subexpression$1"], "postprocess": id},
415
+ {"name": "tuple_pattern", "symbols": [{"literal":"("}, "pattern", "tuple_pattern$ebnf$1", {"literal":")"}], "postprocess": (d) => new TuplePattern([d[1], ...d[2].map(x => x[1])])},
416
+ {"name": "type_declaration$ebnf$1", "symbols": ["variable_list"], "postprocess": id},
417
417
  {"name": "type_declaration$ebnf$1", "symbols": [], "postprocess": () => null},
418
- {"name": "type_declaration", "symbols": [{"literal":"type"}, "__", "constr", "type_declaration$ebnf$1", "_", {"literal":"="}, "_", "type"], "postprocess": (d) => new TypeAlias(d[2], d[3] ? d[3][1] : [], d[7])},
418
+ {"name": "type_declaration", "symbols": [{"literal":"type"}, "constr", "type_declaration$ebnf$1", {"literal":"="}, "type"], "postprocess": (d) => new TypeAlias(d[1], d[2] || [], d[4])},
419
419
  {"name": "variable_list$ebnf$1", "symbols": []},
420
- {"name": "variable_list$ebnf$1$subexpression$1", "symbols": ["__", "variable"]},
421
- {"name": "variable_list$ebnf$1", "symbols": ["variable_list$ebnf$1", "variable_list$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]])},
422
- {"name": "variable_list", "symbols": ["variable", "variable_list$ebnf$1"], "postprocess": (d) => [d[0].value, ...d[1].map(x => x[1].value)]},
420
+ {"name": "variable_list$ebnf$1", "symbols": ["variable_list$ebnf$1", "variable"], "postprocess": (d) => d[0].concat([d[1]])},
421
+ {"name": "variable_list", "symbols": ["variable", "variable_list$ebnf$1"], "postprocess": (d) => [d[0].value, ...d[1]]},
423
422
  {"name": "type", "symbols": ["function_type"], "postprocess": id},
424
- {"name": "constrained_type", "symbols": ["constraint_list", "_", (HSLexer.has("arrow") ? {type: "arrow"} : arrow), "_", "type"], "postprocess": (d) => new ParameterizedType([], d[4], d[0])},
423
+ {"name": "constrained_type", "symbols": ["constraint_list", {"literal":"=>"}, "type"], "postprocess": (d) => new ParameterizedType([], d[2], d[0])},
425
424
  {"name": "context", "symbols": ["constraint"], "postprocess": (d) => [d[0]]},
426
- {"name": "context", "symbols": [{"literal":"("}, "_", "constraint_list", "_", {"literal":")"}], "postprocess": (d) => d[2]},
425
+ {"name": "context", "symbols": [{"literal":"("}, "constraint_list", {"literal":")"}], "postprocess": (d) => d[1]},
427
426
  {"name": "constraint_list$ebnf$1", "symbols": []},
428
- {"name": "constraint_list$ebnf$1$subexpression$1", "symbols": ["_", {"literal":","}, "_", "constraint"]},
427
+ {"name": "constraint_list$ebnf$1$subexpression$1", "symbols": [{"literal":","}, "constraint"]},
429
428
  {"name": "constraint_list$ebnf$1", "symbols": ["constraint_list$ebnf$1", "constraint_list$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]])},
430
429
  {"name": "constraint_list", "symbols": ["constraint", "constraint_list$ebnf$1"], "postprocess": (d) =>
431
- [d[0], ...d[1].map(x => x[3])]
430
+ [d[0], ...d[1].map(x => x[1])]
432
431
  },
433
- {"name": "constraint$ebnf$1$subexpression$1", "symbols": ["_", "application_type"]},
434
- {"name": "constraint$ebnf$1", "symbols": ["constraint$ebnf$1$subexpression$1"]},
435
- {"name": "constraint$ebnf$1$subexpression$2", "symbols": ["_", "application_type"]},
436
- {"name": "constraint$ebnf$1", "symbols": ["constraint$ebnf$1", "constraint$ebnf$1$subexpression$2"], "postprocess": (d) => d[0].concat([d[1]])},
437
- {"name": "constraint", "symbols": [(HSLexer.has("typeClass") ? {type: "typeClass"} : typeClass), "constraint$ebnf$1"], "postprocess": (d) => new Constraint(d[0].value, d[1].map(x => x[1]))},
438
- {"name": "function_type$ebnf$1$subexpression$1", "symbols": ["context", "_", (HSLexer.has("arrow") ? {type: "arrow"} : arrow), "_"]},
432
+ {"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]])},
434
+ {"name": "constraint", "symbols": ["constr", "constraint$ebnf$1"], "postprocess": (d) => new Constraint(d[0].value, d[1])},
435
+ {"name": "function_type$ebnf$1$subexpression$1", "symbols": ["context", {"literal":"=>"}]},
439
436
  {"name": "function_type$ebnf$1", "symbols": ["function_type$ebnf$1$subexpression$1"], "postprocess": id},
440
437
  {"name": "function_type$ebnf$1", "symbols": [], "postprocess": () => null},
441
438
  {"name": "function_type$ebnf$2", "symbols": []},
442
- {"name": "function_type$ebnf$2$subexpression$1$subexpression$1", "symbols": ["_"]},
443
- {"name": "function_type$ebnf$2$subexpression$1$subexpression$1$subexpression$1", "symbols": ["_", (HSLexer.has("NL") ? {type: "NL"} : NL), "__"]},
444
- {"name": "function_type$ebnf$2$subexpression$1$subexpression$1", "symbols": ["function_type$ebnf$2$subexpression$1$subexpression$1$subexpression$1"]},
445
- {"name": "function_type$ebnf$2$subexpression$1$subexpression$2", "symbols": ["_"]},
446
- {"name": "function_type$ebnf$2$subexpression$1$subexpression$2$subexpression$1", "symbols": ["_", (HSLexer.has("NL") ? {type: "NL"} : NL), "__"]},
447
- {"name": "function_type$ebnf$2$subexpression$1$subexpression$2", "symbols": ["function_type$ebnf$2$subexpression$1$subexpression$2$subexpression$1"]},
448
- {"name": "function_type$ebnf$2$subexpression$1", "symbols": ["application_type", "function_type$ebnf$2$subexpression$1$subexpression$1", (HSLexer.has("typeArrow") ? {type: "typeArrow"} : typeArrow), "function_type$ebnf$2$subexpression$1$subexpression$2"]},
439
+ {"name": "function_type$ebnf$2$subexpression$1", "symbols": ["application_type", (HSLexer.has("typeArrow") ? {type: "typeArrow"} : typeArrow)]},
449
440
  {"name": "function_type$ebnf$2", "symbols": ["function_type$ebnf$2", "function_type$ebnf$2$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]])},
450
441
  {"name": "function_type", "symbols": ["function_type$ebnf$1", "function_type$ebnf$2", "application_type"], "postprocess": (d) => {
451
442
  const constraints = d[0] ? d[0][0] : [];
@@ -459,36 +450,32 @@ const grammar: Grammar = {
459
450
  return new ParameterizedType([], d[2], constraints);
460
451
  }
461
452
  },
462
- {"name": "application_type$ebnf$1$subexpression$1", "symbols": ["_", "simple_type"]},
463
- {"name": "application_type$ebnf$1", "symbols": ["application_type$ebnf$1$subexpression$1"]},
464
- {"name": "application_type$ebnf$1$subexpression$2", "symbols": ["_", "simple_type"]},
465
- {"name": "application_type$ebnf$1", "symbols": ["application_type$ebnf$1", "application_type$ebnf$1$subexpression$2"], "postprocess": (d) => d[0].concat([d[1]])},
466
- {"name": "application_type", "symbols": ["simple_type", "application_type$ebnf$1"], "postprocess": (d) => d[1].reduce((acc, arg) => new TypeApplication(acc, arg[1]), d[0])},
453
+ {"name": "application_type", "symbols": ["simple_type", "application_type"], "postprocess": (d) => new TypeApplication(d[0], d[1])},
467
454
  {"name": "application_type", "symbols": ["simple_type"], "postprocess": id},
468
455
  {"name": "simple_type$subexpression$1", "symbols": ["type_variable"]},
469
456
  {"name": "simple_type$subexpression$1", "symbols": ["type_constructor"]},
470
457
  {"name": "simple_type", "symbols": ["simple_type$subexpression$1"], "postprocess": (d) => new SimpleType(d[0][0].value, [])},
471
- {"name": "simple_type", "symbols": [{"literal":"["}, "_", "type", "_", {"literal":"]"}], "postprocess": (d) => new ListType(d[2], [])},
472
- {"name": "simple_type$ebnf$1$subexpression$1", "symbols": ["_", {"literal":","}, "_", "type"]},
458
+ {"name": "simple_type", "symbols": [{"literal":"["}, "type", {"literal":"]"}], "postprocess": (d) => new ListType(d[1], [])},
459
+ {"name": "simple_type$ebnf$1$subexpression$1", "symbols": [{"literal":","}, "type"]},
473
460
  {"name": "simple_type$ebnf$1", "symbols": ["simple_type$ebnf$1$subexpression$1"]},
474
- {"name": "simple_type$ebnf$1$subexpression$2", "symbols": ["_", {"literal":","}, "_", "type"]},
461
+ {"name": "simple_type$ebnf$1$subexpression$2", "symbols": [{"literal":","}, "type"]},
475
462
  {"name": "simple_type$ebnf$1", "symbols": ["simple_type$ebnf$1", "simple_type$ebnf$1$subexpression$2"], "postprocess": (d) => d[0].concat([d[1]])},
476
- {"name": "simple_type", "symbols": [{"literal":"("}, "_", "type", "simple_type$ebnf$1", "_", {"literal":")"}], "postprocess": (d) => new TupleType([d[2], ...d[3].map(x => x[3])], [])},
477
- {"name": "simple_type", "symbols": [{"literal":"("}, "_", "type", "_", {"literal":")"}], "postprocess": (d) => d[2]},
463
+ {"name": "simple_type", "symbols": [{"literal":"("}, "type", "simple_type$ebnf$1", {"literal":")"}], "postprocess": (d) => new TupleType([d[1], ...d[2].map(x => x[1])], [])},
464
+ {"name": "simple_type", "symbols": [{"literal":"("}, "type", {"literal":")"}], "postprocess": (d) => d[1]},
478
465
  {"name": "type_variable", "symbols": ["variable"], "postprocess": ([v]) => ({ value: v.value })},
479
466
  {"name": "type_constructor", "symbols": ["constr"], "postprocess": ([c]) => ({ value: c.value })},
480
467
  {"name": "constr", "symbols": [(HSLexer.has("constructor") ? {type: "constructor"} : constructor)], "postprocess": ([c]) => new SymbolPrimitive(c.value, loc(c))},
481
468
  {"name": "variable", "symbols": [(HSLexer.has("variable") ? {type: "variable"} : variable)], "postprocess": ([v]) => new SymbolPrimitive(v.value, loc(v))},
482
- {"name": "list_literal", "symbols": [{"literal":"["}, "_", {"literal":"]"}], "postprocess": (_) => new ListPrimitive([])},
483
- {"name": "list_literal", "symbols": [{"literal":"["}, "_", "expression_list", "_", {"literal":"]"}], "postprocess": ([_, __, list]) => new ListPrimitive(list)},
484
- {"name": "range_expression", "symbols": ["expression", "_", {"literal":".."}], "postprocess": (d) => new RangeExpression(d[0])},
485
- {"name": "range_expression", "symbols": ["expression", "_", {"literal":".."}, "_", "expression"], "postprocess": (d) => new RangeExpression(d[0], d[4])},
486
- {"name": "range_expression", "symbols": ["expression", "_", {"literal":","}, "_", "expression", "_", {"literal":".."}], "postprocess": (d) => new RangeExpression(d[0], undefined, d[4])},
487
- {"name": "range_expression", "symbols": ["expression", "_", {"literal":","}, "_", "expression", "_", {"literal":".."}, "_", "expression"], "postprocess": (d) => new RangeExpression(d[0], d[6], d[4])},
469
+ {"name": "list_literal", "symbols": [{"literal":"["}, {"literal":"]"}], "postprocess": (_) => new ListPrimitive([])},
470
+ {"name": "list_literal", "symbols": [{"literal":"["}, "expression_list", {"literal":"]"}], "postprocess": (d) => new ListPrimitive(d[1])},
471
+ {"name": "range_expression", "symbols": ["expression", {"literal":".."}], "postprocess": (d) => new RangeExpression(d[0])},
472
+ {"name": "range_expression", "symbols": ["expression", {"literal":".."}, "expression"], "postprocess": (d) => new RangeExpression(d[0], d[2])},
473
+ {"name": "range_expression", "symbols": ["expression", {"literal":","}, "expression", {"literal":".."}], "postprocess": (d) => new RangeExpression(d[0], undefined, d[2])},
474
+ {"name": "range_expression", "symbols": ["expression", {"literal":","}, "expression", {"literal":".."}, "expression"], "postprocess": (d) => new RangeExpression(d[0], d[4], d[2])},
488
475
  {"name": "expression_list$ebnf$1", "symbols": []},
489
- {"name": "expression_list$ebnf$1$subexpression$1", "symbols": ["_", {"literal":","}, "_", "expression"]},
476
+ {"name": "expression_list$ebnf$1$subexpression$1", "symbols": [{"literal":","}, "expression"]},
490
477
  {"name": "expression_list$ebnf$1", "symbols": ["expression_list$ebnf$1", "expression_list$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]])},
491
- {"name": "expression_list", "symbols": ["expression", "expression_list$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[3])]},
478
+ {"name": "expression_list", "symbols": ["expression", "expression_list$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[1])]},
492
479
  {"name": "comparison_operator", "symbols": [{"literal":"=="}], "postprocess": (d) => "Equal"},
493
480
  {"name": "comparison_operator", "symbols": [{"literal":"/="}], "postprocess": (d) => "NotEqual"},
494
481
  {"name": "comparison_operator", "symbols": [{"literal":"<"}], "postprocess": (d) => "LessThan"},
@@ -496,15 +483,19 @@ const grammar: Grammar = {
496
483
  {"name": "comparison_operator", "symbols": [{"literal":"<="}], "postprocess": (d) => "LessOrEqualThan"},
497
484
  {"name": "comparison_operator", "symbols": [{"literal":">="}], "postprocess": (d) => "GreaterOrEqualThan"},
498
485
  {"name": "primitive", "symbols": [(HSLexer.has("number") ? {type: "number"} : number)], "postprocess": ([n]) => new NumberPrimitive(Number(n.value), loc(n))},
499
- {"name": "primitive", "symbols": [(HSLexer.has("char") ? {type: "char"} : char)], "postprocess": ([c]) => new CharPrimitive(c.value, loc(c))},
500
- {"name": "primitive", "symbols": [(HSLexer.has("string") ? {type: "string"} : string)], "postprocess": ([s]) => new StringPrimitive(s.value.slice(1, -1), loc(s))},
501
- {"name": "primitive", "symbols": [(HSLexer.has("bool") ? {type: "bool"} : bool)], "postprocess": ([b]) => new BooleanPrimitive(b.value === 'True' ? true : false, loc(b))},
502
- {"name": "_$ebnf$1", "symbols": []},
503
- {"name": "_$ebnf$1", "symbols": ["_$ebnf$1", (HSLexer.has("WS") ? {type: "WS"} : WS)], "postprocess": (d) => d[0].concat([d[1]])},
504
- {"name": "_", "symbols": ["_$ebnf$1"]},
505
- {"name": "__$ebnf$1", "symbols": [(HSLexer.has("WS") ? {type: "WS"} : WS)]},
506
- {"name": "__$ebnf$1", "symbols": ["__$ebnf$1", (HSLexer.has("WS") ? {type: "WS"} : WS)], "postprocess": (d) => d[0].concat([d[1]])},
507
- {"name": "__", "symbols": ["__$ebnf$1"]}
486
+ {"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));
497
+ } },
498
+ {"name": "primitive", "symbols": [(HSLexer.has("bool") ? {type: "bool"} : bool)], "postprocess": ([b]) => new BooleanPrimitive(b.value === 'True' ? true : false, loc(b))}
508
499
  ],
509
500
  ParserStart: "program",
510
501
  };