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,12 +3,13 @@
3
3
  // Bypasses TS6133. Allow declared but unused functions.
4
4
  // @ts-ignore
5
5
  function id(d) { return d[0]; }
6
- import { HSLexer } from "./lexer.js";
7
- import { TypeCast, Application, ConsExpression, StringOperation, LogicalBinaryOperation, ComparisonOperation, ArithmeticBinaryOperation, ListBinaryOperation, ArithmeticUnaryOperation, SymbolPrimitive, ListPrimitive, Switch, CompositionExpression, Lambda, TupleExpression, DataExpression, Function, FieldExpression, If, Record, Constructor, Field, ListComprehension, Generator, RangeExpression, TypeSignature, Return, GuardedBody, Equation, Raise, UnguardedBody, Sequence, Otherwise, WildcardPattern, ConsPattern, VariablePattern, LiteralPattern, AsPattern, ConstructorPattern, ListPattern, TuplePattern, TypeAlias, ParameterizedType, Constraint, TypeApplication, LetInExpression, SimpleType, ListType, TupleType, NumberPrimitive, CharPrimitive, StringPrimitive, BooleanPrimitive, SourceLocation } from "@yukigo/ast";
6
+ import { HaskellLayoutLexer } from "./lexer.js";
7
+ import { TypeCast, Application, ConsExpression, LogicalBinaryOperation, ComparisonOperation, ArithmeticBinaryOperation, ListBinaryOperation, ArithmeticUnaryOperation, Case, SymbolPrimitive, ListPrimitive, Switch, CompositionExpression, Lambda, TupleExpression, DataExpression, Function, FieldExpression, If, Record, Constructor, Field, ListComprehension, Generator, RangeExpression, TypeSignature, Return, GuardedBody, Equation, Raise, UnguardedBody, Sequence, Otherwise, WildcardPattern, ConsPattern, VariablePattern, LiteralPattern, AsPattern, ConstructorPattern, ListPattern, TuplePattern, TypeAlias, ParameterizedType, Constraint, TypeApplication, LetInExpression, SimpleType, ListType, TupleType, TypeClass, Instance, NumberPrimitive, CharPrimitive, StringPrimitive, BooleanPrimitive, SourceLocation, TestGroup, Test, Assert, Equality, Truth, Failure } from "yukigo-ast";
8
8
  const filter = d => {
9
9
  return d.filter((token) => token !== null);
10
10
  };
11
11
  const loc = (token) => new SourceLocation(token.line, token.col);
12
+ const HSLexer = new HaskellLayoutLexer();
12
13
  ;
13
14
  ;
14
15
  ;
@@ -16,95 +17,124 @@ const loc = (token) => new SourceLocation(token.line, token.col);
16
17
  const grammar = {
17
18
  Lexer: HSLexer,
18
19
  ParserRules: [
19
- { "name": "program$ebnf$1", "symbols": ["declaration"] },
20
- { "name": "program$ebnf$1", "symbols": ["program$ebnf$1", "declaration"], "postprocess": (d) => d[0].concat([d[1]]) },
21
- { "name": "program", "symbols": ["program$ebnf$1"], "postprocess": (d) => d[0].filter(x => x !== null) },
20
+ { "name": "program$ebnf$1", "symbols": [] },
21
+ { "name": "program$ebnf$1$subexpression$1", "symbols": [{ "literal": ";" }, "declaration"] },
22
+ { "name": "program$ebnf$1", "symbols": ["program$ebnf$1", "program$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]]) },
23
+ { "name": "program$ebnf$2", "symbols": [{ "literal": ";" }], "postprocess": id },
24
+ { "name": "program$ebnf$2", "symbols": [], "postprocess": () => null },
25
+ { "name": "program", "symbols": ["declaration", "program$ebnf$1", "program$ebnf$2"], "postprocess": (d) => [d[0], ...d[1].map(x => x[1])].flat(Infinity) },
22
26
  { "name": "declaration$subexpression$1", "symbols": ["function_declaration"] },
23
27
  { "name": "declaration$subexpression$1", "symbols": ["function_signature"] },
24
28
  { "name": "declaration$subexpression$1", "symbols": ["type_declaration"] },
25
29
  { "name": "declaration$subexpression$1", "symbols": ["data_declaration"] },
26
- { "name": "declaration$subexpression$1", "symbols": ["comment"] },
27
- { "name": "declaration$subexpression$1", "symbols": ["empty_line"] },
30
+ { "name": "declaration$subexpression$1", "symbols": ["typeclass_declaration"] },
31
+ { "name": "declaration$subexpression$1", "symbols": ["instance_declaration"] },
28
32
  { "name": "declaration$subexpression$1", "symbols": ["apply_operator"] },
29
- { "name": "declaration", "symbols": ["declaration$subexpression$1"], "postprocess": (d) => d[0][0] },
30
- { "name": "comment", "symbols": [(HSLexer.has("comment") ? { type: "comment" } : comment)], "postprocess": d => null },
31
- { "name": "empty_line", "symbols": ["_", (HSLexer.has("NL") ? { type: "NL" } : NL)], "postprocess": d => null },
33
+ { "name": "declaration$subexpression$1", "symbols": ["test_declaration"] },
34
+ { "name": "declaration$subexpression$1", "symbols": [{ "literal": "let" }, "function_declaration"] },
35
+ { "name": "declaration", "symbols": ["declaration$subexpression$1"], "postprocess": (d) => d[0][0] === "let" ? d[0][1] : d[0][0] },
32
36
  { "name": "expression$subexpression$1", "symbols": ["type_cast"] },
33
37
  { "name": "expression$subexpression$1", "symbols": ["letin_expression"] },
34
38
  { "name": "expression$subexpression$1", "symbols": ["if_expression"] },
35
39
  { "name": "expression$subexpression$1", "symbols": ["case_expression"] },
40
+ { "name": "expression$subexpression$1", "symbols": ["test_declaration"] },
36
41
  { "name": "expression", "symbols": ["expression$subexpression$1"], "postprocess": (d) => d[0][0] },
37
- { "name": "type_cast", "symbols": ["apply_operator", "_", { "literal": "::" }, "_", "type"], "postprocess": (d) => new TypeCast(d[0], d[4]) },
42
+ { "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])) },
43
+ { "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])) },
44
+ { "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])) },
45
+ { "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])) },
46
+ { "name": "test_declaration", "symbols": [{ "literal": "let" }, "function_declaration"], "postprocess": (d) => d[1] },
47
+ { "name": "test_declaration", "symbols": ["assertion"], "postprocess": id },
48
+ { "name": "test_body$ebnf$1", "symbols": [] },
49
+ { "name": "test_body$ebnf$1$subexpression$1", "symbols": [{ "literal": ";" }, "test_declaration"] },
50
+ { "name": "test_body$ebnf$1", "symbols": ["test_body$ebnf$1", "test_body$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]]) },
51
+ { "name": "test_body", "symbols": ["test_declaration", "test_body$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[1])] },
52
+ { "name": "assertion", "symbols": ["expression", { "literal": "shouldBe" }, "expression"], "postprocess": (d) => new Assert(new BooleanPrimitive(false), new Equality(d[2], d[0])) },
53
+ { "name": "assertion", "symbols": ["expression", { "literal": "`" }, { "literal": "shouldBe" }, { "literal": "`" }, "expression"], "postprocess": (d) => new Assert(new BooleanPrimitive(false), new Equality(d[4], d[0])) },
54
+ { "name": "assertion", "symbols": ["expression", { "literal": "shouldNotBe" }, "expression"], "postprocess": (d) => new Assert(new BooleanPrimitive(true), new Equality(d[2], d[0])) },
55
+ { "name": "assertion", "symbols": ["expression", { "literal": "`" }, { "literal": "shouldNotBe" }, { "literal": "`" }, "expression"], "postprocess": (d) => new Assert(new BooleanPrimitive(true), new Equality(d[4], d[0])) },
56
+ { "name": "assertion", "symbols": ["expression", { "literal": "shouldSatisfy" }, "expression"], "postprocess": (d) => new Assert(new BooleanPrimitive(false), new Truth(new Application(d[2], d[0]))) },
57
+ { "name": "assertion", "symbols": ["expression", { "literal": "`" }, { "literal": "shouldSatisfy" }, { "literal": "`" }, "expression"], "postprocess": (d) => new Assert(new BooleanPrimitive(false), new Truth(new Application(d[4], d[0]))) },
58
+ { "name": "assertion", "symbols": ["expression", { "literal": "shouldThrow" }, "expression"], "postprocess": (d) => new Assert(new BooleanPrimitive(false), new Failure(d[0], d[2])) },
59
+ { "name": "assertion", "symbols": ["expression", { "literal": "`" }, { "literal": "shouldThrow" }, { "literal": "`" }, "expression"], "postprocess": (d) => new Assert(new BooleanPrimitive(false), new Failure(d[0], d[4])) },
60
+ { "name": "type_cast", "symbols": ["apply_operator", { "literal": "::" }, "type"], "postprocess": (d) => new TypeCast(d[0], d[2]) },
38
61
  { "name": "type_cast", "symbols": ["apply_operator"], "postprocess": id },
39
- { "name": "apply_operator", "symbols": ["bind_expression", "_", { "literal": "$" }, "_", "apply_operator"], "postprocess": (d) => new Application(d[0], d[4]) },
62
+ { "name": "apply_operator$subexpression$1", "symbols": [{ "literal": "$" }] },
63
+ { "name": "apply_operator$subexpression$1", "symbols": [{ "literal": "$!" }] },
64
+ { "name": "apply_operator", "symbols": ["bind_expression", "apply_operator$subexpression$1", "apply_operator"], "postprocess": (d) => new Application(d[0], d[2]) },
40
65
  { "name": "apply_operator", "symbols": ["bind_expression"], "postprocess": id },
41
- { "name": "bind_expression", "symbols": ["logical_expression", "_", { "literal": ">>=" }, "_", "bind_expression"], "postprocess": (d) => new Application(new Application(new SymbolPrimitive("(>>=)"), d[0]), d[4]) },
42
- { "name": "bind_expression", "symbols": ["logical_expression", "_", { "literal": ">>" }, "_", "bind_expression"], "postprocess": (d) => new Application(new Application(new SymbolPrimitive("(>>)"), d[0]), d[4]) },
66
+ { "name": "bind_expression", "symbols": ["logical_expression", { "literal": ">>=" }, "bind_expression"], "postprocess": (d) => new Application(new Application(new SymbolPrimitive("(>>=)"), d[0]), d[2]) },
67
+ { "name": "bind_expression", "symbols": ["logical_expression", { "literal": ">>" }, "bind_expression"], "postprocess": (d) => new Application(new Application(new SymbolPrimitive("(>>)"), d[0]), d[2]) },
43
68
  { "name": "bind_expression", "symbols": ["logical_expression"], "postprocess": id },
44
- { "name": "logical_expression", "symbols": ["comparison", "_", { "literal": "&&" }, "_", "logical_expression"], "postprocess": (d) => new LogicalBinaryOperation("And", d[0], d[4]) },
45
- { "name": "logical_expression", "symbols": ["comparison", "_", { "literal": "||" }, "_", "logical_expression"], "postprocess": (d) => new LogicalBinaryOperation("Or", d[0], d[4]) },
69
+ { "name": "logical_expression", "symbols": ["comparison", { "literal": "&&" }, "logical_expression"], "postprocess": (d) => new LogicalBinaryOperation("And", d[0], d[2]) },
70
+ { "name": "logical_expression", "symbols": ["comparison", { "literal": "||" }, "logical_expression"], "postprocess": (d) => new LogicalBinaryOperation("Or", d[0], d[2]) },
46
71
  { "name": "logical_expression", "symbols": ["comparison"], "postprocess": id },
47
- { "name": "comparison", "symbols": ["cons_expression", "_", "comparison_operator", "_", "cons_expression"], "postprocess": (d) => new ComparisonOperation(d[2], d[0], d[4]) },
72
+ { "name": "comparison", "symbols": ["cons_expression", "comparison_operator", "cons_expression"], "postprocess": (d) => new ComparisonOperation(d[1], d[0], d[2]) },
48
73
  { "name": "comparison", "symbols": ["cons_expression"], "postprocess": id },
49
- { "name": "cons_expression", "symbols": ["concatenation", "_", { "literal": ":" }, "_", "cons_expression"], "postprocess": (d) => new ConsExpression(d[0], d[4]) },
74
+ { "name": "cons_expression", "symbols": ["concatenation", { "literal": ":" }, "cons_expression"], "postprocess": (d) => new ConsExpression(d[0], d[2]) },
50
75
  { "name": "cons_expression", "symbols": ["concatenation"], "postprocess": id },
51
- { "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]) },
76
+ { "name": "concatenation", "symbols": ["addition", { "literal": "++" }, "concatenation"], "postprocess": (d) => new ListBinaryOperation("Concat", d[0], d[2]) },
52
77
  { "name": "concatenation", "symbols": ["addition"], "postprocess": id },
53
- { "name": "addition", "symbols": ["addition", "_", { "literal": "+" }, "_", "multiplication"], "postprocess": (d) => new ArithmeticBinaryOperation("Plus", d[0], d[4]) },
54
- { "name": "addition", "symbols": ["addition", "_", { "literal": "-" }, "_", "multiplication"], "postprocess": (d) => new ArithmeticBinaryOperation("Minus", d[0], d[4]) },
78
+ { "name": "addition", "symbols": ["addition", { "literal": "+" }, "multiplication"], "postprocess": (d) => new ArithmeticBinaryOperation("Plus", d[0], d[2]) },
79
+ { "name": "addition", "symbols": ["addition", { "literal": "-" }, "multiplication"], "postprocess": (d) => new ArithmeticBinaryOperation("Minus", d[0], d[2]) },
55
80
  { "name": "addition", "symbols": ["multiplication"], "postprocess": id },
56
- { "name": "multiplication", "symbols": ["multiplication", "_", { "literal": "*" }, "_", "power"], "postprocess": (d) => new ArithmeticBinaryOperation("Multiply", d[0], d[4]) },
57
- { "name": "multiplication", "symbols": ["multiplication", "_", { "literal": "/" }, "_", "power"], "postprocess": (d) => new ArithmeticBinaryOperation("Divide", d[0], d[4]) },
81
+ { "name": "multiplication", "symbols": ["multiplication", { "literal": "*" }, "power"], "postprocess": (d) => new ArithmeticBinaryOperation("Multiply", d[0], d[2]) },
82
+ { "name": "multiplication", "symbols": ["multiplication", { "literal": "/" }, "power"], "postprocess": (d) => new ArithmeticBinaryOperation("Divide", d[0], d[2]) },
58
83
  { "name": "multiplication", "symbols": ["power"], "postprocess": id },
59
- { "name": "power", "symbols": ["unary_negation", "_", { "literal": "**" }, "_", "power"], "postprocess": (d) => new ArithmeticBinaryOperation("Power", d[0], d[4]) },
60
- { "name": "power", "symbols": ["unary_negation", "_", { "literal": "^" }, "_", "power"], "postprocess": (d) => new ArithmeticBinaryOperation("Power", d[0], d[4]) },
61
- { "name": "power", "symbols": ["unary_negation", "_", { "literal": "^^" }, "_", "power"], "postprocess": (d) => new ArithmeticBinaryOperation("Power", d[0], d[4]) },
84
+ { "name": "power", "symbols": ["unary_negation", { "literal": "**" }, "power"], "postprocess": (d) => new ArithmeticBinaryOperation("Power", d[0], d[2]) },
85
+ { "name": "power", "symbols": ["unary_negation", { "literal": "^" }, "power"], "postprocess": (d) => new ArithmeticBinaryOperation("Power", d[0], d[2]) },
86
+ { "name": "power", "symbols": ["unary_negation", { "literal": "^^" }, "power"], "postprocess": (d) => new ArithmeticBinaryOperation("Power", d[0], d[2]) },
62
87
  { "name": "power", "symbols": ["unary_negation"], "postprocess": id },
63
- { "name": "unary_negation", "symbols": [{ "literal": "-" }, "_", "unary_negation"], "postprocess": (d) => new ArithmeticUnaryOperation("Negation", d[2]) },
88
+ { "name": "unary_negation", "symbols": [{ "literal": "-" }, "unary_negation"], "postprocess": (d) => new ArithmeticUnaryOperation("Negation", d[1]) },
64
89
  { "name": "unary_negation", "symbols": ["index_access"], "postprocess": id },
65
- { "name": "index_access", "symbols": ["index_access", "_", { "literal": "!!" }, "_", "composition_expression"], "postprocess": (d) => new ListBinaryOperation("GetAt", d[0], d[4]) },
90
+ { "name": "index_access", "symbols": ["index_access", { "literal": "!!" }, "composition_expression"], "postprocess": (d) => new ListBinaryOperation("GetAt", d[0], d[2]) },
66
91
  { "name": "index_access", "symbols": ["composition_expression"], "postprocess": id },
67
- { "name": "composition_expression", "symbols": ["composition_expression", "_", { "literal": "." }, "_", "infix_operator_expression"], "postprocess": (d) => new CompositionExpression(d[0], d[4]) },
92
+ { "name": "composition_expression", "symbols": ["composition_expression", { "literal": "." }, "infix_operator_expression"], "postprocess": (d) => new CompositionExpression(d[0], d[2]) },
68
93
  { "name": "composition_expression", "symbols": ["infix_operator_expression"], "postprocess": id },
69
- { "name": "infix_operator_expression", "symbols": ["infix_operator_expression", "_", { "literal": "`" }, "_", "variable", "_", { "literal": "`" }, "_", "application"], "postprocess": (d) => new Application(new Application(d[4], d[0]), d[8]) },
94
+ { "name": "infix_operator_expression", "symbols": ["infix_operator_expression", { "literal": "`" }, "variable", { "literal": "`" }, "application"], "postprocess": (d) => new Application(new Application(d[2], d[0]), d[4]) },
70
95
  { "name": "infix_operator_expression", "symbols": ["application"], "postprocess": id },
71
- { "name": "application", "symbols": [{ "literal": "error" }, "__", "primary"], "postprocess": d => new Raise(d[2]) },
96
+ { "name": "application", "symbols": [{ "literal": "error" }, "primary"], "postprocess": d => new Raise(d[1]) },
72
97
  { "name": "application$ebnf$1", "symbols": [] },
73
- { "name": "application$ebnf$1$subexpression$1$subexpression$1", "symbols": ["_"] },
74
- { "name": "application$ebnf$1$subexpression$1$subexpression$1$subexpression$1", "symbols": ["_", (HSLexer.has("NL") ? { type: "NL" } : NL), "__"] },
75
- { "name": "application$ebnf$1$subexpression$1$subexpression$1", "symbols": ["application$ebnf$1$subexpression$1$subexpression$1$subexpression$1"] },
76
- { "name": "application$ebnf$1$subexpression$1", "symbols": ["application$ebnf$1$subexpression$1$subexpression$1", "primary"] },
77
- { "name": "application$ebnf$1", "symbols": ["application$ebnf$1", "application$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]]) },
98
+ { "name": "application$ebnf$1", "symbols": ["application$ebnf$1", "primary"], "postprocess": (d) => d[0].concat([d[1]]) },
78
99
  { "name": "application", "symbols": ["primary", "application$ebnf$1"], "postprocess": (d) => {
79
100
  if (d[1].length === 0)
80
101
  return d[0];
81
- return d[1].reduce((left, right) => new Application(left, right[1]), d[0]);
102
+ return d[1].reduce((left, right) => new Application(left, right), d[0]);
82
103
  } },
83
- { "name": "operator$subexpression$1", "symbols": [{ "literal": "==" }] },
84
- { "name": "operator$subexpression$1", "symbols": [{ "literal": "/=" }] },
85
- { "name": "operator$subexpression$1", "symbols": [{ "literal": "<" }] },
86
- { "name": "operator$subexpression$1", "symbols": [{ "literal": ">" }] },
87
- { "name": "operator$subexpression$1", "symbols": [{ "literal": "<=" }] },
88
- { "name": "operator$subexpression$1", "symbols": [{ "literal": "&&" }] },
89
- { "name": "operator$subexpression$1", "symbols": [{ "literal": "||" }] },
90
- { "name": "operator$subexpression$1", "symbols": [{ "literal": ">=" }] },
91
- { "name": "operator$subexpression$1", "symbols": [{ "literal": "++" }] },
92
- { "name": "operator$subexpression$1", "symbols": [{ "literal": "+" }] },
93
- { "name": "operator$subexpression$1", "symbols": [{ "literal": "," }] },
94
- { "name": "operator$subexpression$1", "symbols": [{ "literal": "*" }] },
95
- { "name": "operator$subexpression$1", "symbols": [{ "literal": "/" }] },
96
- { "name": "operator$subexpression$1", "symbols": [{ "literal": ":" }] },
97
- { "name": "operator", "symbols": ["operator$subexpression$1"], "postprocess": (d) => d[0][0].value },
98
- { "name": "left_section", "symbols": [{ "literal": "(" }, "_", "expression", "_", "operator", "_", { "literal": ")" }], "postprocess": (d) => new Application(new SymbolPrimitive(d[4]), d[2]) },
99
- { "name": "right_section", "symbols": [{ "literal": "(" }, "_", "operator", "_", "expression", "_", { "literal": ")" }], "postprocess": (d) => {
104
+ { "name": "operator", "symbols": ["operator_no_minus"], "postprocess": id },
105
+ { "name": "operator", "symbols": [{ "literal": "-" }], "postprocess": (d) => d[0].value },
106
+ { "name": "operator_no_minus$subexpression$1", "symbols": [{ "literal": "==" }] },
107
+ { "name": "operator_no_minus$subexpression$1", "symbols": [{ "literal": "/=" }] },
108
+ { "name": "operator_no_minus$subexpression$1", "symbols": [{ "literal": "<" }] },
109
+ { "name": "operator_no_minus$subexpression$1", "symbols": [{ "literal": ">" }] },
110
+ { "name": "operator_no_minus$subexpression$1", "symbols": [{ "literal": "<=" }] },
111
+ { "name": "operator_no_minus$subexpression$1", "symbols": [{ "literal": "&&" }] },
112
+ { "name": "operator_no_minus$subexpression$1", "symbols": [{ "literal": "||" }] },
113
+ { "name": "operator_no_minus$subexpression$1", "symbols": [{ "literal": ">=" }] },
114
+ { "name": "operator_no_minus$subexpression$1", "symbols": [{ "literal": "++" }] },
115
+ { "name": "operator_no_minus$subexpression$1", "symbols": [{ "literal": "+" }] },
116
+ { "name": "operator_no_minus$subexpression$1", "symbols": [{ "literal": "," }] },
117
+ { "name": "operator_no_minus$subexpression$1", "symbols": [{ "literal": "^^" }] },
118
+ { "name": "operator_no_minus$subexpression$1", "symbols": [{ "literal": "^" }] },
119
+ { "name": "operator_no_minus$subexpression$1", "symbols": [{ "literal": "**" }] },
120
+ { "name": "operator_no_minus$subexpression$1", "symbols": [{ "literal": "*" }] },
121
+ { "name": "operator_no_minus$subexpression$1", "symbols": [{ "literal": "!!" }] },
122
+ { "name": "operator_no_minus$subexpression$1", "symbols": [{ "literal": "/" }] },
123
+ { "name": "operator_no_minus$subexpression$1", "symbols": [{ "literal": "$" }] },
124
+ { "name": "operator_no_minus$subexpression$1", "symbols": [{ "literal": "$!" }] },
125
+ { "name": "operator_no_minus$subexpression$1", "symbols": [{ "literal": "." }] },
126
+ { "name": "operator_no_minus$subexpression$1", "symbols": [{ "literal": ":" }] },
127
+ { "name": "operator_no_minus", "symbols": ["operator_no_minus$subexpression$1"], "postprocess": (d) => d[0][0].value },
128
+ { "name": "left_section", "symbols": [{ "literal": "(" }, "expression", "operator", { "literal": ")" }], "postprocess": (d) => new Application(new SymbolPrimitive(d[2]), d[1]) },
129
+ { "name": "right_section", "symbols": [{ "literal": "(" }, "operator_no_minus", "expression", { "literal": ")" }], "postprocess": (d) => {
100
130
  const flipBody = new SymbolPrimitive("flip");
101
- const op = new SymbolPrimitive(d[2]);
102
- const expr = d[4];
131
+ const op = new SymbolPrimitive(d[1]);
132
+ const expr = d[2];
103
133
  const flipAppliedToOp = new Application(flipBody, op);
104
134
  return new Application(flipAppliedToOp, expr);
105
135
  }
106
136
  },
107
- { "name": "operator_section", "symbols": [{ "literal": "(" }, "_", "operator", "_", { "literal": ")" }], "postprocess": (d) => new SymbolPrimitive(d[2]) },
137
+ { "name": "operator_section", "symbols": [{ "literal": "(" }, "operator", { "literal": ")" }], "postprocess": (d) => new SymbolPrimitive(d[1]) },
108
138
  { "name": "primary", "symbols": ["primitive"], "postprocess": id },
109
139
  { "name": "primary", "symbols": ["variable"], "postprocess": id },
110
140
  { "name": "primary", "symbols": ["constr"], "postprocess": id },
@@ -116,151 +146,122 @@ const grammar = {
116
146
  { "name": "primary", "symbols": ["lambda_expression"], "postprocess": id },
117
147
  { "name": "primary", "symbols": ["data_expression"], "postprocess": id },
118
148
  { "name": "primary", "symbols": ["list_comprehension"], "postprocess": id },
119
- { "name": "primary", "symbols": [{ "literal": "(" }, "_", "expression", "_", { "literal": ")" }], "postprocess": (d) => d[2] },
120
- { "name": "primary", "symbols": [{ "literal": "[" }, "_", "range_expression", "_", { "literal": "]" }], "postprocess": (d) => d[2] },
121
- { "name": "list_comprehension", "symbols": [{ "literal": "[" }, "_", "expression", "_", { "literal": "|" }, "_", "comprehension_clause_list", "_", { "literal": "]" }], "postprocess": (d) => {
122
- return new ListComprehension(d[2], d[6]);
149
+ { "name": "primary", "symbols": [{ "literal": "(" }, "expression", { "literal": ")" }], "postprocess": (d) => d[1] },
150
+ { "name": "primary", "symbols": [{ "literal": "[" }, "range_expression", { "literal": "]" }], "postprocess": (d) => d[1] },
151
+ { "name": "list_comprehension", "symbols": [{ "literal": "[" }, "expression", { "literal": "|" }, "comprehension_clause_list", { "literal": "]" }], "postprocess": (d) => {
152
+ return new ListComprehension(d[1], d[3]);
123
153
  } },
124
154
  { "name": "comprehension_clause_list$ebnf$1", "symbols": [] },
125
- { "name": "comprehension_clause_list$ebnf$1$subexpression$1", "symbols": ["_", { "literal": "," }, "_", "comprehension_clause"] },
155
+ { "name": "comprehension_clause_list$ebnf$1$subexpression$1", "symbols": [{ "literal": "," }, "comprehension_clause"] },
126
156
  { "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]]) },
127
157
  { "name": "comprehension_clause_list", "symbols": ["comprehension_clause", "comprehension_clause_list$ebnf$1"], "postprocess": (d) => {
128
- return [d[0], ...d[1].map((x) => x[3])];
158
+ return [d[0], ...d[1].map((x) => x[1])];
129
159
  } },
130
- { "name": "comprehension_clause", "symbols": ["variable", "_", { "literal": "<-" }, "_", "expression"], "postprocess": (d) => new Generator(d[0], d[4]) },
160
+ { "name": "comprehension_clause", "symbols": ["variable", { "literal": "<-" }, "expression"], "postprocess": (d) => new Generator(d[0], d[2]) },
131
161
  { "name": "comprehension_clause", "symbols": ["expression"], "postprocess": id },
132
- { "name": "lambda_expression", "symbols": [{ "literal": "(" }, "_", { "literal": "\\" }, "_", "parameter_list", "_", { "literal": "->" }, "_", "expression", "_", { "literal": ")" }], "postprocess": (d) => new Lambda(d[4], d[8]) },
133
- { "name": "tuple_expression$ebnf$1$subexpression$1", "symbols": ["_", { "literal": "," }, "_", "tuple_value"] },
162
+ { "name": "lambda_expression", "symbols": [{ "literal": "(" }, { "literal": "\\" }, "parameter_list", { "literal": "->" }, "expression", { "literal": ")" }], "postprocess": (d) => new Lambda(d[2], d[4]) },
163
+ { "name": "tuple_expression$ebnf$1$subexpression$1", "symbols": [{ "literal": "," }, "expression"] },
134
164
  { "name": "tuple_expression$ebnf$1", "symbols": ["tuple_expression$ebnf$1$subexpression$1"] },
135
- { "name": "tuple_expression$ebnf$1$subexpression$2", "symbols": ["_", { "literal": "," }, "_", "tuple_value"] },
165
+ { "name": "tuple_expression$ebnf$1$subexpression$2", "symbols": [{ "literal": "," }, "expression"] },
136
166
  { "name": "tuple_expression$ebnf$1", "symbols": ["tuple_expression$ebnf$1", "tuple_expression$ebnf$1$subexpression$2"], "postprocess": (d) => d[0].concat([d[1]]) },
137
- { "name": "tuple_expression", "symbols": [{ "literal": "(" }, "_", "tuple_value", "tuple_expression$ebnf$1", "_", { "literal": ")" }], "postprocess": (d) => new TupleExpression([d[2], ...d[3].map(x => x[3])]) },
138
- { "name": "tuple_value", "symbols": ["expression"], "postprocess": id },
139
- { "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]) },
167
+ { "name": "tuple_expression", "symbols": [{ "literal": "(" }, "expression", "tuple_expression$ebnf$1", { "literal": ")" }], "postprocess": (d) => new TupleExpression([d[1], ...d[2].map(x => x[1])]) },
168
+ { "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]) },
140
169
  { "name": "fields_expressions$ebnf$1", "symbols": [] },
141
- { "name": "fields_expressions$ebnf$1$subexpression$1", "symbols": ["_", { "literal": "," }, "_", "field_exp"] },
170
+ { "name": "fields_expressions$ebnf$1$subexpression$1", "symbols": [{ "literal": "," }, "field_exp"] },
142
171
  { "name": "fields_expressions$ebnf$1", "symbols": ["fields_expressions$ebnf$1", "fields_expressions$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]]) },
143
- { "name": "fields_expressions", "symbols": ["field_exp", "fields_expressions$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[3])] },
144
- { "name": "field_exp", "symbols": ["variable", "_", { "literal": "=" }, "_", "expression"], "postprocess": (d) => new FieldExpression(d[0], d[4]) },
145
- { "name": "if_expression", "symbols": [{ "literal": "if" }, "__", "expression", "__", { "literal": "then" }, "__", "expression", "__", { "literal": "else" }, "__", "expression"], "postprocess": (d) => new If(d[2], d[6], d[10]) },
146
- { "name": "letin_expression$subexpression$1", "symbols": ["_", { "literal": "{" }, "_"] },
172
+ { "name": "fields_expressions", "symbols": ["field_exp", "fields_expressions$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[1])] },
173
+ { "name": "field_exp", "symbols": ["variable", { "literal": "=" }, "expression"], "postprocess": (d) => new FieldExpression(d[0], d[2]) },
174
+ { "name": "if_expression", "symbols": [{ "literal": "if" }, "expression", { "literal": "then" }, "expression", { "literal": "else" }, "expression"], "postprocess": (d) => new If(d[1], d[3], d[5]) },
147
175
  { "name": "letin_expression$ebnf$1", "symbols": ["bindings_list"], "postprocess": id },
148
176
  { "name": "letin_expression$ebnf$1", "symbols": [], "postprocess": () => null },
149
- { "name": "letin_expression$subexpression$2", "symbols": ["_", { "literal": "}" }, "_"] },
150
- { "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]) },
151
- { "name": "case_expression$subexpression$1", "symbols": ["_", { "literal": "{" }, "_"] },
152
- { "name": "case_expression$subexpression$2", "symbols": ["_", { "literal": "}" }, "_"] },
153
- { "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]) },
177
+ { "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]) },
178
+ { "name": "case_expression", "symbols": [{ "literal": "case" }, "expression", { "literal": "of" }, { "literal": "{" }, "case_arms", { "literal": "}" }], "postprocess": (d) => new Switch(d[1], d[4]) },
154
179
  { "name": "case_arms$ebnf$1", "symbols": [] },
155
- { "name": "case_arms$ebnf$1$subexpression$1$subexpression$1", "symbols": ["_", { "literal": ";" }, "_"] },
156
- { "name": "case_arms$ebnf$1$subexpression$1", "symbols": ["case_arms$ebnf$1$subexpression$1$subexpression$1", "case_arm"] },
180
+ { "name": "case_arms$ebnf$1$subexpression$1", "symbols": [{ "literal": ";" }, "case_arm"] },
157
181
  { "name": "case_arms$ebnf$1", "symbols": ["case_arms$ebnf$1", "case_arms$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]]) },
158
182
  { "name": "case_arms", "symbols": ["case_arm", "case_arms$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[1])] },
159
- { "name": "case_arm", "symbols": ["pattern", "_", { "literal": "->" }, "_", "expression"], "postprocess": (d) => ({ condition: d[0], body: d[4] }) },
183
+ { "name": "case_arm", "symbols": ["pattern", { "literal": "->" }, "expression"], "postprocess": (d) => new Case(d[0], d[2]) },
184
+ { "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]) },
185
+ { "name": "typeclass_body$ebnf$1", "symbols": [] },
186
+ { "name": "typeclass_body$ebnf$1$subexpression$1", "symbols": [{ "literal": ";" }, "function_signature"] },
187
+ { "name": "typeclass_body$ebnf$1", "symbols": ["typeclass_body$ebnf$1", "typeclass_body$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]]) },
188
+ { "name": "typeclass_body", "symbols": ["function_signature", "typeclass_body$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[1])] },
189
+ { "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]) },
190
+ { "name": "instance_body$subexpression$1", "symbols": ["function_declaration"] },
191
+ { "name": "instance_body$subexpression$1", "symbols": ["function_signature"] },
192
+ { "name": "instance_body$ebnf$1", "symbols": [] },
193
+ { "name": "instance_body$ebnf$1$subexpression$1$subexpression$1", "symbols": ["function_declaration"] },
194
+ { "name": "instance_body$ebnf$1$subexpression$1$subexpression$1", "symbols": ["function_signature"] },
195
+ { "name": "instance_body$ebnf$1$subexpression$1", "symbols": [{ "literal": ";" }, "instance_body$ebnf$1$subexpression$1$subexpression$1"] },
196
+ { "name": "instance_body$ebnf$1", "symbols": ["instance_body$ebnf$1", "instance_body$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]]) },
197
+ { "name": "instance_body$ebnf$2", "symbols": [{ "literal": ";" }], "postprocess": id },
198
+ { "name": "instance_body$ebnf$2", "symbols": [], "postprocess": () => null },
199
+ { "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])] },
160
200
  { "name": "data_declaration$ebnf$1", "symbols": [] },
161
- { "name": "data_declaration$ebnf$1$subexpression$1", "symbols": ["__", "type_variable"] },
162
- { "name": "data_declaration$ebnf$1", "symbols": ["data_declaration$ebnf$1", "data_declaration$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]]) },
201
+ { "name": "data_declaration$ebnf$1", "symbols": ["data_declaration$ebnf$1", "type_variable"], "postprocess": (d) => d[0].concat([d[1]]) },
163
202
  { "name": "data_declaration$ebnf$2", "symbols": [] },
164
- { "name": "data_declaration$ebnf$2$subexpression$1", "symbols": ["_", { "literal": "|" }, "_", "constructor_def"] },
203
+ { "name": "data_declaration$ebnf$2$subexpression$1", "symbols": [{ "literal": "|" }, "constructor_def"] },
165
204
  { "name": "data_declaration$ebnf$2", "symbols": ["data_declaration$ebnf$2", "data_declaration$ebnf$2$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]]) },
166
205
  { "name": "data_declaration$ebnf$3", "symbols": ["deriving_clause"], "postprocess": id },
167
206
  { "name": "data_declaration$ebnf$3", "symbols": [], "postprocess": () => null },
168
- { "name": "data_declaration", "symbols": [{ "literal": "data" }, "__", "constr", "data_declaration$ebnf$1", "_", { "literal": "=" }, "_", "constructor_def", "data_declaration$ebnf$2", "data_declaration$ebnf$3"], "postprocess": (d) => new Record(d[2], [d[7], ...d[8].map(x => x[3])], d[9])
207
+ { "name": "data_declaration", "symbols": [{ "literal": "data" }, "constr", "data_declaration$ebnf$1", { "literal": "=" }, "constructor_def", "data_declaration$ebnf$2", "data_declaration$ebnf$3"], "postprocess": (d) => new Record(d[1], [d[4], ...d[5].map(x => x[1])], d[6])
169
208
  },
170
- { "name": "deriving_clause", "symbols": ["_", { "literal": "deriving" }, "_", "deriving_spec"], "postprocess": (d) => d[3] },
171
- { "name": "deriving_spec", "symbols": [{ "literal": "(" }, "_", "deriving_classes", "_", { "literal": ")" }], "postprocess": (d) => d[2] },
209
+ { "name": "deriving_clause", "symbols": [{ "literal": "deriving" }, "deriving_spec"], "postprocess": (d) => d[1] },
210
+ { "name": "deriving_spec", "symbols": [{ "literal": "(" }, "deriving_classes", { "literal": ")" }], "postprocess": (d) => d[1] },
172
211
  { "name": "deriving_spec", "symbols": ["constr"], "postprocess": (d) => [d[0]] },
173
212
  { "name": "deriving_classes$ebnf$1", "symbols": [] },
174
- { "name": "deriving_classes$ebnf$1$subexpression$1", "symbols": ["_", { "literal": "," }, "_", (HSLexer.has("typeClass") ? { type: "typeClass" } : typeClass)] },
213
+ { "name": "deriving_classes$ebnf$1$subexpression$1", "symbols": [{ "literal": "," }, "constr"] },
175
214
  { "name": "deriving_classes$ebnf$1", "symbols": ["deriving_classes$ebnf$1", "deriving_classes$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]]) },
176
- { "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))] },
177
- { "name": "constructor_def$ebnf$1$subexpression$1", "symbols": [(HSLexer.has("NL") ? { type: "NL" } : NL), "__"] },
178
- { "name": "constructor_def$ebnf$1", "symbols": ["constructor_def$ebnf$1$subexpression$1"], "postprocess": id },
179
- { "name": "constructor_def$ebnf$1", "symbols": [], "postprocess": () => null },
180
- { "name": "constructor_def$ebnf$2$subexpression$1", "symbols": [(HSLexer.has("NL") ? { type: "NL" } : NL), "_"] },
181
- { "name": "constructor_def$ebnf$2", "symbols": ["constructor_def$ebnf$2$subexpression$1"], "postprocess": id },
182
- { "name": "constructor_def$ebnf$2", "symbols": [], "postprocess": () => null },
183
- { "name": "constructor_def$ebnf$3$subexpression$1", "symbols": [(HSLexer.has("NL") ? { type: "NL" } : NL), "_"] },
184
- { "name": "constructor_def$ebnf$3", "symbols": ["constructor_def$ebnf$3$subexpression$1"], "postprocess": id },
185
- { "name": "constructor_def$ebnf$3", "symbols": [], "postprocess": () => null },
186
- { "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]) },
187
- { "name": "constructor_def$ebnf$4", "symbols": [] },
188
- { "name": "constructor_def$ebnf$4$subexpression$1", "symbols": ["__", "simple_type"] },
189
- { "name": "constructor_def$ebnf$4", "symbols": ["constructor_def$ebnf$4", "constructor_def$ebnf$4$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]]) },
190
- { "name": "constructor_def", "symbols": ["constr", "constructor_def$ebnf$4"], "postprocess": (d) => new Constructor(d[0], d[1].map(x => new Field(undefined, x[1]))) },
215
+ { "name": "deriving_classes", "symbols": ["constr", "deriving_classes$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[1])] },
216
+ { "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]) },
217
+ { "name": "constructor_def$ebnf$1", "symbols": [] },
218
+ { "name": "constructor_def$ebnf$1", "symbols": ["constructor_def$ebnf$1", "simple_type"], "postprocess": (d) => d[0].concat([d[1]]) },
219
+ { "name": "constructor_def", "symbols": ["constr", "constructor_def$ebnf$1"], "postprocess": (d) => new Constructor(d[0], d[1].map(x => new Field(undefined, x))) },
191
220
  { "name": "field_list$ebnf$1", "symbols": [] },
192
- { "name": "field_list$ebnf$1$subexpression$1$ebnf$1$subexpression$1", "symbols": [(HSLexer.has("NL") ? { type: "NL" } : NL), "_"] },
193
- { "name": "field_list$ebnf$1$subexpression$1$ebnf$1", "symbols": ["field_list$ebnf$1$subexpression$1$ebnf$1$subexpression$1"], "postprocess": id },
194
- { "name": "field_list$ebnf$1$subexpression$1$ebnf$1", "symbols": [], "postprocess": () => null },
195
- { "name": "field_list$ebnf$1$subexpression$1", "symbols": ["_", { "literal": "," }, "_", "field_list$ebnf$1$subexpression$1$ebnf$1", "field"] },
221
+ { "name": "field_list$ebnf$1$subexpression$1", "symbols": [{ "literal": "," }, "field"] },
196
222
  { "name": "field_list$ebnf$1", "symbols": ["field_list$ebnf$1", "field_list$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]]) },
197
- { "name": "field_list", "symbols": ["field", "field_list$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[4])] },
198
- { "name": "field", "symbols": ["variable", "_", (HSLexer.has("typeEquals") ? { type: "typeEquals" } : typeEquals), "_", "type"], "postprocess": (d) => new Field(d[0], d[4]) },
199
- { "name": "binding_name", "symbols": [{ "literal": "(" }, "_", (HSLexer.has("op") ? { type: "op" } : op), "_", { "literal": ")" }], "postprocess": d => new SymbolPrimitive(`${d[2].value}`) },
223
+ { "name": "field_list", "symbols": ["field", "field_list$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[1])] },
224
+ { "name": "field", "symbols": ["variable", { "literal": "::" }, "type"], "postprocess": (d) => new Field(d[0], d[2]) },
225
+ { "name": "op_name", "symbols": [{ "literal": "(" }, "operator", { "literal": ")" }], "postprocess": d => new SymbolPrimitive(d[1]) },
226
+ { "name": "binding_name", "symbols": ["op_name"], "postprocess": id },
200
227
  { "name": "binding_name", "symbols": ["variable"], "postprocess": id },
201
- { "name": "function_signature$ebnf$1", "symbols": [] },
202
- { "name": "function_signature$ebnf$1$subexpression$1", "symbols": ["_", { "literal": "," }, "_", "binding_name"] },
203
- { "name": "function_signature$ebnf$1", "symbols": ["function_signature$ebnf$1", "function_signature$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]]) },
204
- { "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]) },
205
- { "name": "function_declaration", "symbols": ["variable", "equation"], "postprocess": (d) => new Function(d[0], [d[1]]) },
206
- { "name": "function_declaration", "symbols": [{ "literal": "(" }, "_", (HSLexer.has("op") ? { type: "op" } : op), "_", { "literal": ")" }, "equation"], "postprocess": (d) => new Function(new SymbolPrimitive(`${d[2].value}`), [d[5]]) },
228
+ { "name": "function_signature", "symbols": ["binding_name", { "literal": "::" }, "type"], "postprocess": (d) => new TypeSignature(d[0], d[2]) },
229
+ { "name": "function_declaration", "symbols": ["binding_name", "equation"], "postprocess": (d) => new Function(d[0], [d[1]]) },
207
230
  { "name": "return_expression", "symbols": ["expression"], "postprocess": d => new Return(d[0]) },
208
- { "name": "where_clause", "symbols": [{ "literal": "where" }, "_", { "literal": "{" }, "_", "bindings_list", "_", { "literal": "}" }], "postprocess": d => d[4] },
209
- { "name": "bindings_list$ebnf$1", "symbols": [] },
210
- { "name": "bindings_list$ebnf$1$subexpression$1$subexpression$1", "symbols": ["_", { "literal": ";" }, "_"] },
211
- { "name": "bindings_list$ebnf$1$subexpression$1", "symbols": ["bindings_list$ebnf$1$subexpression$1$subexpression$1", "function_declaration"] },
212
- { "name": "bindings_list$ebnf$1", "symbols": ["bindings_list$ebnf$1", "bindings_list$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]]) },
213
- { "name": "bindings_list", "symbols": ["function_declaration", "bindings_list$ebnf$1"], "postprocess": d => [d[0], ...d[1].map(x => x[1])] },
214
- { "name": "equation$ebnf$1$subexpression$1", "symbols": [(HSLexer.has("NL") ? { type: "NL" } : NL), "__"] },
215
- { "name": "equation$ebnf$1", "symbols": ["equation$ebnf$1$subexpression$1"], "postprocess": id },
231
+ { "name": "where_clause", "symbols": [{ "literal": "where" }, { "literal": "{" }, "bindings_list", { "literal": "}" }], "postprocess": d => d[2] },
232
+ { "name": "bindings_list", "symbols": ["function_declaration", { "literal": ";" }, "bindings_list"], "postprocess": d => [d[0], ...d[2]] },
233
+ { "name": "bindings_list", "symbols": ["function_declaration"], "postprocess": d => [d[0]] },
234
+ { "name": "equation$ebnf$1", "symbols": ["where_clause"], "postprocess": id },
216
235
  { "name": "equation$ebnf$1", "symbols": [], "postprocess": () => null },
217
- { "name": "equation$ebnf$2$subexpression$1", "symbols": ["_", "where_clause"] },
218
- { "name": "equation$ebnf$2", "symbols": ["equation$ebnf$2$subexpression$1"], "postprocess": id },
219
- { "name": "equation$ebnf$2", "symbols": [], "postprocess": () => null },
220
- { "name": "equation", "symbols": ["params", "equation$ebnf$1", "guarded_rhs", "equation$ebnf$2"], "postprocess": (d) => {
221
- const body = d[2];
222
- const finalBody = d[3]
223
- ? new LetInExpression(d[3], body)
236
+ { "name": "equation", "symbols": ["params", "guarded_rhs", "equation$ebnf$1"], "postprocess": (d) => {
237
+ const body = d[1];
238
+ const finalBody = d[2]
239
+ ? body.map(guard => new GuardedBody(guard.condition, new Sequence([...d[2], new Return(guard.body)])))
224
240
  : body;
225
241
  return new Equation(d[0], finalBody);
226
242
  } },
227
- { "name": "equation$subexpression$1$subexpression$1", "symbols": ["_", (HSLexer.has("NL") ? { type: "NL" } : NL), "__"] },
228
- { "name": "equation$subexpression$1", "symbols": ["equation$subexpression$1$subexpression$1"] },
229
- { "name": "equation$subexpression$1", "symbols": ["_"] },
230
- { "name": "equation$ebnf$3$subexpression$1", "symbols": ["_", "where_clause"] },
231
- { "name": "equation$ebnf$3", "symbols": ["equation$ebnf$3$subexpression$1"], "postprocess": id },
232
- { "name": "equation$ebnf$3", "symbols": [], "postprocess": () => null },
233
- { "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]) },
234
- { "name": "params", "symbols": ["__", "parameter_list", "_"], "postprocess": d => d[1] },
235
- { "name": "params", "symbols": ["_"], "postprocess": d => [] },
236
- { "name": "guarded_rhs$subexpression$1$subexpression$1", "symbols": ["_", (HSLexer.has("NL") ? { type: "NL" } : NL), "__"] },
237
- { "name": "guarded_rhs$subexpression$1", "symbols": ["guarded_rhs$subexpression$1$subexpression$1"] },
238
- { "name": "guarded_rhs$subexpression$1", "symbols": ["_"] },
239
- { "name": "guarded_rhs", "symbols": ["guarded_branch", "guarded_rhs$subexpression$1", "guarded_rhs"], "postprocess": (d) => [d[0], ...d[2]] },
240
- { "name": "guarded_rhs", "symbols": ["guarded_branch"], "postprocess": (d) => [d[0]] },
241
- { "name": "guarded_branch$subexpression$1$subexpression$1", "symbols": ["_", (HSLexer.has("NL") ? { type: "NL" } : NL), "__"] },
242
- { "name": "guarded_branch$subexpression$1", "symbols": ["guarded_branch$subexpression$1$subexpression$1"] },
243
- { "name": "guarded_branch$subexpression$1", "symbols": ["_"] },
244
- { "name": "guarded_branch$subexpression$2$subexpression$1", "symbols": ["_", (HSLexer.has("NL") ? { type: "NL" } : NL), "__"] },
245
- { "name": "guarded_branch$subexpression$2", "symbols": ["guarded_branch$subexpression$2$subexpression$1"] },
246
- { "name": "guarded_branch$subexpression$2", "symbols": ["_"] },
247
- { "name": "guarded_branch$subexpression$3$subexpression$1", "symbols": ["_", (HSLexer.has("NL") ? { type: "NL" } : NL), "__"] },
248
- { "name": "guarded_branch$subexpression$3", "symbols": ["guarded_branch$subexpression$3$subexpression$1"] },
249
- { "name": "guarded_branch$subexpression$3", "symbols": ["_"] },
250
- { "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]) },
243
+ { "name": "equation$ebnf$2", "symbols": ["where_clause"], "postprocess": id },
244
+ { "name": "equation$ebnf$2", "symbols": [], "postprocess": () => null },
245
+ { "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]) },
246
+ { "name": "params$ebnf$1", "symbols": ["parameter_list"], "postprocess": id },
247
+ { "name": "params$ebnf$1", "symbols": [], "postprocess": () => null },
248
+ { "name": "params", "symbols": ["params$ebnf$1"], "postprocess": (d) => d[0] || [] },
249
+ { "name": "guarded_rhs$ebnf$1", "symbols": ["guarded_branch"] },
250
+ { "name": "guarded_rhs$ebnf$1", "symbols": ["guarded_rhs$ebnf$1", "guarded_branch"], "postprocess": (d) => d[0].concat([d[1]]) },
251
+ { "name": "guarded_rhs", "symbols": ["guarded_rhs$ebnf$1"], "postprocess": (d) => d[0] },
252
+ { "name": "guarded_branch", "symbols": [{ "literal": "|" }, "condition", { "literal": "=" }, "expression"], "postprocess": (d) => new GuardedBody(d[1], d[3]) },
251
253
  { "name": "condition", "symbols": [{ "literal": "otherwise" }], "postprocess": d => new Otherwise() },
252
254
  { "name": "condition", "symbols": ["expression"], "postprocess": d => d[0] },
253
- { "name": "parameter_list$ebnf$1", "symbols": [] },
254
- { "name": "parameter_list$ebnf$1$subexpression$1", "symbols": ["__", "pattern"] },
255
- { "name": "parameter_list$ebnf$1", "symbols": ["parameter_list$ebnf$1", "parameter_list$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]]) },
256
- { "name": "parameter_list", "symbols": ["pattern", "parameter_list$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[1])] },
255
+ { "name": "parameter_list$ebnf$1", "symbols": ["pattern"] },
256
+ { "name": "parameter_list$ebnf$1", "symbols": ["parameter_list$ebnf$1", "pattern"], "postprocess": (d) => d[0].concat([d[1]]) },
257
+ { "name": "parameter_list", "symbols": ["parameter_list$ebnf$1"], "postprocess": id },
257
258
  { "name": "pattern", "symbols": ["cons_pattern"], "postprocess": id },
258
- { "name": "cons_pattern$ebnf$1$subexpression$1", "symbols": ["_", { "literal": ":" }, "_", "cons_pattern"] },
259
+ { "name": "cons_pattern$ebnf$1$subexpression$1", "symbols": [{ "literal": ":" }, "cons_pattern"] },
259
260
  { "name": "cons_pattern$ebnf$1", "symbols": ["cons_pattern$ebnf$1$subexpression$1"] },
260
- { "name": "cons_pattern$ebnf$1$subexpression$2", "symbols": ["_", { "literal": ":" }, "_", "cons_pattern"] },
261
+ { "name": "cons_pattern$ebnf$1$subexpression$2", "symbols": [{ "literal": ":" }, "cons_pattern"] },
261
262
  { "name": "cons_pattern$ebnf$1", "symbols": ["cons_pattern$ebnf$1", "cons_pattern$ebnf$1$subexpression$2"], "postprocess": (d) => d[0].concat([d[1]]) },
262
- { "name": "cons_pattern", "symbols": [{ "literal": "(" }, "_", "cons_pattern", "cons_pattern$ebnf$1", "_", { "literal": ")" }], "postprocess": (d) => {
263
- const patterns = [d[2], ...d[3].map(item => item[3])];
263
+ { "name": "cons_pattern", "symbols": [{ "literal": "(" }, "cons_pattern", "cons_pattern$ebnf$1", { "literal": ")" }], "postprocess": (d) => {
264
+ const patterns = [d[1], ...d[2].map(item => item[1])];
264
265
  return patterns.reduceRight((tail, head, index, arr) => {
265
266
  if (index === arr.length - 1)
266
267
  return tail;
@@ -279,68 +280,56 @@ const grammar = {
279
280
  { "name": "simple_pattern$subexpression$1", "symbols": ["paren_pattern"] },
280
281
  { "name": "simple_pattern", "symbols": ["simple_pattern$subexpression$1"], "postprocess": (d) => d[0][0] },
281
282
  { "name": "wildcard_pattern", "symbols": [(HSLexer.has("anonymousVariable") ? { type: "anonymousVariable" } : anonymousVariable)], "postprocess": (d) => new WildcardPattern() },
282
- { "name": "paren_pattern", "symbols": [{ "literal": "(" }, "_", "pattern", "_", { "literal": ")" }], "postprocess": (d) => d[2] },
283
+ { "name": "paren_pattern", "symbols": [{ "literal": "(" }, "pattern", { "literal": ")" }], "postprocess": (d) => d[1] },
283
284
  { "name": "variable_pattern", "symbols": ["variable"], "postprocess": (d) => new VariablePattern(d[0]) },
284
285
  { "name": "literal_pattern", "symbols": ["primitive"], "postprocess": (d) => new LiteralPattern(d[0]) },
285
286
  { "name": "as_pattern$subexpression$1", "symbols": ["variable_pattern"] },
286
287
  { "name": "as_pattern$subexpression$1", "symbols": ["wildcard_pattern"] },
287
288
  { "name": "as_pattern", "symbols": ["as_pattern$subexpression$1", { "literal": "@" }, "pattern"], "postprocess": (d) => new AsPattern(d[0][0], d[2]) },
288
- { "name": "constructor_pattern$ebnf$1$subexpression$1", "symbols": ["__", "pattern"] },
289
- { "name": "constructor_pattern$ebnf$1", "symbols": ["constructor_pattern$ebnf$1$subexpression$1"] },
290
- { "name": "constructor_pattern$ebnf$1$subexpression$2", "symbols": ["__", "pattern"] },
291
- { "name": "constructor_pattern$ebnf$1", "symbols": ["constructor_pattern$ebnf$1", "constructor_pattern$ebnf$1$subexpression$2"], "postprocess": (d) => d[0].concat([d[1]]) },
292
- { "name": "constructor_pattern", "symbols": [{ "literal": "(" }, "_", "constr", "constructor_pattern$ebnf$1", "_", { "literal": ")" }], "postprocess": (d) => new ConstructorPattern(d[2].value, d[3].map(x => x[1])) },
293
- { "name": "constructor_pattern", "symbols": ["constr"], "postprocess": (d) => new ConstructorPattern(d[0].value, []) },
289
+ { "name": "constructor_pattern$ebnf$1", "symbols": ["pattern"] },
290
+ { "name": "constructor_pattern$ebnf$1", "symbols": ["constructor_pattern$ebnf$1", "pattern"], "postprocess": (d) => d[0].concat([d[1]]) },
291
+ { "name": "constructor_pattern", "symbols": [{ "literal": "(" }, "constr", "constructor_pattern$ebnf$1", { "literal": ")" }], "postprocess": (d) => new ConstructorPattern(d[1], d[2]) },
292
+ { "name": "constructor_pattern", "symbols": ["constr"], "postprocess": (d) => new ConstructorPattern(d[0], []) },
294
293
  { "name": "field_pattern_list$ebnf$1", "symbols": [] },
295
- { "name": "field_pattern_list$ebnf$1$subexpression$1", "symbols": ["_", { "literal": "," }, "_", "field_pattern"] },
294
+ { "name": "field_pattern_list$ebnf$1$subexpression$1", "symbols": [{ "literal": "," }, "field_pattern"] },
296
295
  { "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]]) },
297
- { "name": "field_pattern_list", "symbols": ["field_pattern", "field_pattern_list$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[3])] },
298
- { "name": "field_pattern", "symbols": ["variable", "_", { "literal": "=" }, "_", "pattern"], "postprocess": (d) => ({ field: d[0].value, pattern: d[4] }) },
296
+ { "name": "field_pattern_list", "symbols": ["field_pattern", "field_pattern_list$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[1])] },
297
+ { "name": "field_pattern", "symbols": ["variable", { "literal": "=" }, "pattern"], "postprocess": (d) => ({ field: d[0].value, pattern: d[2] }) },
299
298
  { "name": "list_pattern$ebnf$1", "symbols": ["pattern_list"], "postprocess": id },
300
299
  { "name": "list_pattern$ebnf$1", "symbols": [], "postprocess": () => null },
301
- { "name": "list_pattern", "symbols": [{ "literal": "[" }, "_", "list_pattern$ebnf$1", "_", { "literal": "]" }], "postprocess": (d) => new ListPattern(d[2] || []) },
300
+ { "name": "list_pattern", "symbols": [{ "literal": "[" }, "list_pattern$ebnf$1", { "literal": "]" }], "postprocess": (d) => new ListPattern(d[1] || []) },
302
301
  { "name": "pattern_list$ebnf$1", "symbols": [] },
303
- { "name": "pattern_list$ebnf$1$subexpression$1", "symbols": ["_", { "literal": "," }, "_", "pattern"] },
302
+ { "name": "pattern_list$ebnf$1$subexpression$1", "symbols": [{ "literal": "," }, "pattern"] },
304
303
  { "name": "pattern_list$ebnf$1", "symbols": ["pattern_list$ebnf$1", "pattern_list$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]]) },
305
- { "name": "pattern_list", "symbols": ["pattern", "pattern_list$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[3])] },
306
- { "name": "tuple_pattern$ebnf$1$subexpression$1", "symbols": ["_", { "literal": "," }, "_", "pattern"] },
304
+ { "name": "pattern_list", "symbols": ["pattern", "pattern_list$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[1])] },
305
+ { "name": "tuple_pattern$ebnf$1$subexpression$1", "symbols": [{ "literal": "," }, "pattern"] },
307
306
  { "name": "tuple_pattern$ebnf$1", "symbols": ["tuple_pattern$ebnf$1$subexpression$1"] },
308
- { "name": "tuple_pattern$ebnf$1$subexpression$2", "symbols": ["_", { "literal": "," }, "_", "pattern"] },
307
+ { "name": "tuple_pattern$ebnf$1$subexpression$2", "symbols": [{ "literal": "," }, "pattern"] },
309
308
  { "name": "tuple_pattern$ebnf$1", "symbols": ["tuple_pattern$ebnf$1", "tuple_pattern$ebnf$1$subexpression$2"], "postprocess": (d) => d[0].concat([d[1]]) },
310
- { "name": "tuple_pattern", "symbols": [{ "literal": "(" }, "_", "pattern", "tuple_pattern$ebnf$1", "_", { "literal": ")" }], "postprocess": (d) => new TuplePattern([d[2], ...d[3].map(x => x[3])]) },
311
- { "name": "type_declaration$ebnf$1$subexpression$1", "symbols": ["__", "variable_list"] },
312
- { "name": "type_declaration$ebnf$1", "symbols": ["type_declaration$ebnf$1$subexpression$1"], "postprocess": id },
309
+ { "name": "tuple_pattern", "symbols": [{ "literal": "(" }, "pattern", "tuple_pattern$ebnf$1", { "literal": ")" }], "postprocess": (d) => new TuplePattern([d[1], ...d[2].map(x => x[1])]) },
310
+ { "name": "type_declaration$ebnf$1", "symbols": ["variable_list"], "postprocess": id },
313
311
  { "name": "type_declaration$ebnf$1", "symbols": [], "postprocess": () => null },
314
- { "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]) },
312
+ { "name": "type_declaration", "symbols": [{ "literal": "type" }, "constr", "type_declaration$ebnf$1", { "literal": "=" }, "type"], "postprocess": (d) => new TypeAlias(d[1], d[2] || [], d[4]) },
315
313
  { "name": "variable_list$ebnf$1", "symbols": [] },
316
- { "name": "variable_list$ebnf$1$subexpression$1", "symbols": ["__", "variable"] },
317
- { "name": "variable_list$ebnf$1", "symbols": ["variable_list$ebnf$1", "variable_list$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]]) },
318
- { "name": "variable_list", "symbols": ["variable", "variable_list$ebnf$1"], "postprocess": (d) => [d[0].value, ...d[1].map(x => x[1].value)] },
314
+ { "name": "variable_list$ebnf$1", "symbols": ["variable_list$ebnf$1", "variable"], "postprocess": (d) => d[0].concat([d[1]]) },
315
+ { "name": "variable_list", "symbols": ["variable", "variable_list$ebnf$1"], "postprocess": (d) => [d[0].value, ...d[1]] },
319
316
  { "name": "type", "symbols": ["function_type"], "postprocess": id },
320
- { "name": "constrained_type", "symbols": ["constraint_list", "_", (HSLexer.has("arrow") ? { type: "arrow" } : arrow), "_", "type"], "postprocess": (d) => new ParameterizedType([], d[4], d[0]) },
317
+ { "name": "constrained_type", "symbols": ["constraint_list", { "literal": "=>" }, "type"], "postprocess": (d) => new ParameterizedType([], d[2], d[0]) },
321
318
  { "name": "context", "symbols": ["constraint"], "postprocess": (d) => [d[0]] },
322
- { "name": "context", "symbols": [{ "literal": "(" }, "_", "constraint_list", "_", { "literal": ")" }], "postprocess": (d) => d[2] },
319
+ { "name": "context", "symbols": [{ "literal": "(" }, "constraint_list", { "literal": ")" }], "postprocess": (d) => d[1] },
323
320
  { "name": "constraint_list$ebnf$1", "symbols": [] },
324
- { "name": "constraint_list$ebnf$1$subexpression$1", "symbols": ["_", { "literal": "," }, "_", "constraint"] },
321
+ { "name": "constraint_list$ebnf$1$subexpression$1", "symbols": [{ "literal": "," }, "constraint"] },
325
322
  { "name": "constraint_list$ebnf$1", "symbols": ["constraint_list$ebnf$1", "constraint_list$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]]) },
326
- { "name": "constraint_list", "symbols": ["constraint", "constraint_list$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[3])]
323
+ { "name": "constraint_list", "symbols": ["constraint", "constraint_list$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[1])]
327
324
  },
328
- { "name": "constraint$ebnf$1$subexpression$1", "symbols": ["_", "application_type"] },
329
- { "name": "constraint$ebnf$1", "symbols": ["constraint$ebnf$1$subexpression$1"] },
330
- { "name": "constraint$ebnf$1$subexpression$2", "symbols": ["_", "application_type"] },
331
- { "name": "constraint$ebnf$1", "symbols": ["constraint$ebnf$1", "constraint$ebnf$1$subexpression$2"], "postprocess": (d) => d[0].concat([d[1]]) },
332
- { "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])) },
333
- { "name": "function_type$ebnf$1$subexpression$1", "symbols": ["context", "_", (HSLexer.has("arrow") ? { type: "arrow" } : arrow), "_"] },
325
+ { "name": "constraint$ebnf$1", "symbols": ["application_type"] },
326
+ { "name": "constraint$ebnf$1", "symbols": ["constraint$ebnf$1", "application_type"], "postprocess": (d) => d[0].concat([d[1]]) },
327
+ { "name": "constraint", "symbols": ["constr", "constraint$ebnf$1"], "postprocess": (d) => new Constraint(d[0].value, d[1]) },
328
+ { "name": "function_type$ebnf$1$subexpression$1", "symbols": ["context", { "literal": "=>" }] },
334
329
  { "name": "function_type$ebnf$1", "symbols": ["function_type$ebnf$1$subexpression$1"], "postprocess": id },
335
330
  { "name": "function_type$ebnf$1", "symbols": [], "postprocess": () => null },
336
331
  { "name": "function_type$ebnf$2", "symbols": [] },
337
- { "name": "function_type$ebnf$2$subexpression$1$subexpression$1", "symbols": ["_"] },
338
- { "name": "function_type$ebnf$2$subexpression$1$subexpression$1$subexpression$1", "symbols": ["_", (HSLexer.has("NL") ? { type: "NL" } : NL), "__"] },
339
- { "name": "function_type$ebnf$2$subexpression$1$subexpression$1", "symbols": ["function_type$ebnf$2$subexpression$1$subexpression$1$subexpression$1"] },
340
- { "name": "function_type$ebnf$2$subexpression$1$subexpression$2", "symbols": ["_"] },
341
- { "name": "function_type$ebnf$2$subexpression$1$subexpression$2$subexpression$1", "symbols": ["_", (HSLexer.has("NL") ? { type: "NL" } : NL), "__"] },
342
- { "name": "function_type$ebnf$2$subexpression$1$subexpression$2", "symbols": ["function_type$ebnf$2$subexpression$1$subexpression$2$subexpression$1"] },
343
- { "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"] },
332
+ { "name": "function_type$ebnf$2$subexpression$1", "symbols": ["application_type", (HSLexer.has("typeArrow") ? { type: "typeArrow" } : typeArrow)] },
344
333
  { "name": "function_type$ebnf$2", "symbols": ["function_type$ebnf$2", "function_type$ebnf$2$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]]) },
345
334
  { "name": "function_type", "symbols": ["function_type$ebnf$1", "function_type$ebnf$2", "application_type"], "postprocess": (d) => {
346
335
  const constraints = d[0] ? d[0][0] : [];
@@ -351,36 +340,32 @@ const grammar = {
351
340
  return new ParameterizedType([], d[2], constraints);
352
341
  }
353
342
  },
354
- { "name": "application_type$ebnf$1$subexpression$1", "symbols": ["_", "simple_type"] },
355
- { "name": "application_type$ebnf$1", "symbols": ["application_type$ebnf$1$subexpression$1"] },
356
- { "name": "application_type$ebnf$1$subexpression$2", "symbols": ["_", "simple_type"] },
357
- { "name": "application_type$ebnf$1", "symbols": ["application_type$ebnf$1", "application_type$ebnf$1$subexpression$2"], "postprocess": (d) => d[0].concat([d[1]]) },
358
- { "name": "application_type", "symbols": ["simple_type", "application_type$ebnf$1"], "postprocess": (d) => d[1].reduce((acc, arg) => new TypeApplication(acc, arg[1]), d[0]) },
343
+ { "name": "application_type", "symbols": ["simple_type", "application_type"], "postprocess": (d) => new TypeApplication(d[0], d[1]) },
359
344
  { "name": "application_type", "symbols": ["simple_type"], "postprocess": id },
360
345
  { "name": "simple_type$subexpression$1", "symbols": ["type_variable"] },
361
346
  { "name": "simple_type$subexpression$1", "symbols": ["type_constructor"] },
362
347
  { "name": "simple_type", "symbols": ["simple_type$subexpression$1"], "postprocess": (d) => new SimpleType(d[0][0].value, []) },
363
- { "name": "simple_type", "symbols": [{ "literal": "[" }, "_", "type", "_", { "literal": "]" }], "postprocess": (d) => new ListType(d[2], []) },
364
- { "name": "simple_type$ebnf$1$subexpression$1", "symbols": ["_", { "literal": "," }, "_", "type"] },
348
+ { "name": "simple_type", "symbols": [{ "literal": "[" }, "type", { "literal": "]" }], "postprocess": (d) => new ListType(d[1], []) },
349
+ { "name": "simple_type$ebnf$1$subexpression$1", "symbols": [{ "literal": "," }, "type"] },
365
350
  { "name": "simple_type$ebnf$1", "symbols": ["simple_type$ebnf$1$subexpression$1"] },
366
- { "name": "simple_type$ebnf$1$subexpression$2", "symbols": ["_", { "literal": "," }, "_", "type"] },
351
+ { "name": "simple_type$ebnf$1$subexpression$2", "symbols": [{ "literal": "," }, "type"] },
367
352
  { "name": "simple_type$ebnf$1", "symbols": ["simple_type$ebnf$1", "simple_type$ebnf$1$subexpression$2"], "postprocess": (d) => d[0].concat([d[1]]) },
368
- { "name": "simple_type", "symbols": [{ "literal": "(" }, "_", "type", "simple_type$ebnf$1", "_", { "literal": ")" }], "postprocess": (d) => new TupleType([d[2], ...d[3].map(x => x[3])], []) },
369
- { "name": "simple_type", "symbols": [{ "literal": "(" }, "_", "type", "_", { "literal": ")" }], "postprocess": (d) => d[2] },
353
+ { "name": "simple_type", "symbols": [{ "literal": "(" }, "type", "simple_type$ebnf$1", { "literal": ")" }], "postprocess": (d) => new TupleType([d[1], ...d[2].map(x => x[1])], []) },
354
+ { "name": "simple_type", "symbols": [{ "literal": "(" }, "type", { "literal": ")" }], "postprocess": (d) => d[1] },
370
355
  { "name": "type_variable", "symbols": ["variable"], "postprocess": ([v]) => ({ value: v.value }) },
371
356
  { "name": "type_constructor", "symbols": ["constr"], "postprocess": ([c]) => ({ value: c.value }) },
372
357
  { "name": "constr", "symbols": [(HSLexer.has("constructor") ? { type: "constructor" } : constructor)], "postprocess": ([c]) => new SymbolPrimitive(c.value, loc(c)) },
373
358
  { "name": "variable", "symbols": [(HSLexer.has("variable") ? { type: "variable" } : variable)], "postprocess": ([v]) => new SymbolPrimitive(v.value, loc(v)) },
374
- { "name": "list_literal", "symbols": [{ "literal": "[" }, "_", { "literal": "]" }], "postprocess": (_) => new ListPrimitive([]) },
375
- { "name": "list_literal", "symbols": [{ "literal": "[" }, "_", "expression_list", "_", { "literal": "]" }], "postprocess": ([_, __, list]) => new ListPrimitive(list) },
376
- { "name": "range_expression", "symbols": ["expression", "_", { "literal": ".." }], "postprocess": (d) => new RangeExpression(d[0]) },
377
- { "name": "range_expression", "symbols": ["expression", "_", { "literal": ".." }, "_", "expression"], "postprocess": (d) => new RangeExpression(d[0], d[4]) },
378
- { "name": "range_expression", "symbols": ["expression", "_", { "literal": "," }, "_", "expression", "_", { "literal": ".." }], "postprocess": (d) => new RangeExpression(d[0], undefined, d[4]) },
379
- { "name": "range_expression", "symbols": ["expression", "_", { "literal": "," }, "_", "expression", "_", { "literal": ".." }, "_", "expression"], "postprocess": (d) => new RangeExpression(d[0], d[6], d[4]) },
359
+ { "name": "list_literal", "symbols": [{ "literal": "[" }, { "literal": "]" }], "postprocess": (_) => new ListPrimitive([]) },
360
+ { "name": "list_literal", "symbols": [{ "literal": "[" }, "expression_list", { "literal": "]" }], "postprocess": (d) => new ListPrimitive(d[1]) },
361
+ { "name": "range_expression", "symbols": ["expression", { "literal": ".." }], "postprocess": (d) => new RangeExpression(d[0]) },
362
+ { "name": "range_expression", "symbols": ["expression", { "literal": ".." }, "expression"], "postprocess": (d) => new RangeExpression(d[0], d[2]) },
363
+ { "name": "range_expression", "symbols": ["expression", { "literal": "," }, "expression", { "literal": ".." }], "postprocess": (d) => new RangeExpression(d[0], undefined, d[2]) },
364
+ { "name": "range_expression", "symbols": ["expression", { "literal": "," }, "expression", { "literal": ".." }, "expression"], "postprocess": (d) => new RangeExpression(d[0], d[4], d[2]) },
380
365
  { "name": "expression_list$ebnf$1", "symbols": [] },
381
- { "name": "expression_list$ebnf$1$subexpression$1", "symbols": ["_", { "literal": "," }, "_", "expression"] },
366
+ { "name": "expression_list$ebnf$1$subexpression$1", "symbols": [{ "literal": "," }, "expression"] },
382
367
  { "name": "expression_list$ebnf$1", "symbols": ["expression_list$ebnf$1", "expression_list$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]]) },
383
- { "name": "expression_list", "symbols": ["expression", "expression_list$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[3])] },
368
+ { "name": "expression_list", "symbols": ["expression", "expression_list$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map(x => x[1])] },
384
369
  { "name": "comparison_operator", "symbols": [{ "literal": "==" }], "postprocess": (d) => "Equal" },
385
370
  { "name": "comparison_operator", "symbols": [{ "literal": "/=" }], "postprocess": (d) => "NotEqual" },
386
371
  { "name": "comparison_operator", "symbols": [{ "literal": "<" }], "postprocess": (d) => "LessThan" },
@@ -388,15 +373,19 @@ const grammar = {
388
373
  { "name": "comparison_operator", "symbols": [{ "literal": "<=" }], "postprocess": (d) => "LessOrEqualThan" },
389
374
  { "name": "comparison_operator", "symbols": [{ "literal": ">=" }], "postprocess": (d) => "GreaterOrEqualThan" },
390
375
  { "name": "primitive", "symbols": [(HSLexer.has("number") ? { type: "number" } : number)], "postprocess": ([n]) => new NumberPrimitive(Number(n.value), loc(n)) },
391
- { "name": "primitive", "symbols": [(HSLexer.has("char") ? { type: "char" } : char)], "postprocess": ([c]) => new CharPrimitive(c.value, loc(c)) },
392
- { "name": "primitive", "symbols": [(HSLexer.has("string") ? { type: "string" } : string)], "postprocess": ([s]) => new StringPrimitive(s.value.slice(1, -1), loc(s)) },
393
- { "name": "primitive", "symbols": [(HSLexer.has("bool") ? { type: "bool" } : bool)], "postprocess": ([b]) => new BooleanPrimitive(b.value === 'True' ? true : false, loc(b)) },
394
- { "name": "_$ebnf$1", "symbols": [] },
395
- { "name": "_$ebnf$1", "symbols": ["_$ebnf$1", (HSLexer.has("WS") ? { type: "WS" } : WS)], "postprocess": (d) => d[0].concat([d[1]]) },
396
- { "name": "_", "symbols": ["_$ebnf$1"] },
397
- { "name": "__$ebnf$1", "symbols": [(HSLexer.has("WS") ? { type: "WS" } : WS)] },
398
- { "name": "__$ebnf$1", "symbols": ["__$ebnf$1", (HSLexer.has("WS") ? { type: "WS" } : WS)], "postprocess": (d) => d[0].concat([d[1]]) },
399
- { "name": "__", "symbols": ["__$ebnf$1"] }
376
+ { "name": "primitive", "symbols": [(HSLexer.has("char") ? { type: "char" } : char)], "postprocess": ([c]) => new CharPrimitive(c.value.slice(1, -1), loc(c)) },
377
+ { "name": "primitive", "symbols": [(HSLexer.has("string") ? { type: "string" } : string)], "postprocess": ([s]) => {
378
+ let val = s.value.slice(1, -1);
379
+ // Haskell multiline string continuation: \ whitespace \
380
+ val = val.replace(/\\\s+\\/g, "");
381
+ // Standard escapes
382
+ val = val.replace(/\\n/g, "\n")
383
+ .replace(/\\t/g, "\t")
384
+ .replace(/\\"/g, "\"")
385
+ .replace(/\\\\/g, "\\");
386
+ return new StringPrimitive(val, loc(s));
387
+ } },
388
+ { "name": "primitive", "symbols": [(HSLexer.has("bool") ? { type: "bool" } : bool)], "postprocess": ([b]) => new BooleanPrimitive(b.value === 'True' ? true : false, loc(b)) }
400
389
  ],
401
390
  ParserStart: "program",
402
391
  };