yukigo-haskell-parser 0.1.0

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 (63) hide show
  1. package/.mocharc.json +4 -0
  2. package/CHANGELOG.md +19 -0
  3. package/README.md +10 -0
  4. package/dist/index.d.ts +7 -0
  5. package/dist/index.js +54 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/parser/grammar.d.ts +28 -0
  8. package/dist/parser/grammar.js +404 -0
  9. package/dist/parser/grammar.js.map +1 -0
  10. package/dist/parser/layoutPreprocessor.d.ts +1 -0
  11. package/dist/parser/layoutPreprocessor.js +22 -0
  12. package/dist/parser/layoutPreprocessor.js.map +1 -0
  13. package/dist/parser/lexer.d.ts +42 -0
  14. package/dist/parser/lexer.js +75 -0
  15. package/dist/parser/lexer.js.map +1 -0
  16. package/dist/parser/preprocessor.d.ts +28 -0
  17. package/dist/parser/preprocessor.js +453 -0
  18. package/dist/parser/preprocessor.js.map +1 -0
  19. package/dist/prelude.d.ts +1 -0
  20. package/dist/prelude.js +205 -0
  21. package/dist/prelude.js.map +1 -0
  22. package/dist/typechecker/DeclarationCollector.d.ts +15 -0
  23. package/dist/typechecker/DeclarationCollector.js +80 -0
  24. package/dist/typechecker/DeclarationCollector.js.map +1 -0
  25. package/dist/typechecker/TypeBuilder.d.ts +12 -0
  26. package/dist/typechecker/TypeBuilder.js +113 -0
  27. package/dist/typechecker/TypeBuilder.js.map +1 -0
  28. package/dist/typechecker/checker.d.ts +80 -0
  29. package/dist/typechecker/checker.js +269 -0
  30. package/dist/typechecker/checker.js.map +1 -0
  31. package/dist/typechecker/core.d.ts +14 -0
  32. package/dist/typechecker/core.js +142 -0
  33. package/dist/typechecker/core.js.map +1 -0
  34. package/dist/typechecker/inference.d.ts +69 -0
  35. package/dist/typechecker/inference.js +984 -0
  36. package/dist/typechecker/inference.js.map +1 -0
  37. package/dist/utils/helpers.d.ts +2 -0
  38. package/dist/utils/helpers.js +25 -0
  39. package/dist/utils/helpers.js.map +1 -0
  40. package/dist/utils/types.d.ts +6 -0
  41. package/dist/utils/types.js +53 -0
  42. package/dist/utils/types.js.map +1 -0
  43. package/package.json +36 -0
  44. package/src/index.ts +55 -0
  45. package/src/parser/grammar.ne +463 -0
  46. package/src/parser/grammar.ts +512 -0
  47. package/src/parser/layoutPreprocessor.ts +21 -0
  48. package/src/parser/lexer.ts +77 -0
  49. package/src/parser/preprocessor.ne +375 -0
  50. package/src/parser/preprocessor.ts +502 -0
  51. package/src/prelude.ts +206 -0
  52. package/src/typechecker/DeclarationCollector.ts +104 -0
  53. package/src/typechecker/TypeBuilder.ts +148 -0
  54. package/src/typechecker/checker.ts +395 -0
  55. package/src/typechecker/core.ts +162 -0
  56. package/src/typechecker/inference.ts +1327 -0
  57. package/src/utils/helpers.ts +29 -0
  58. package/src/utils/types.ts +56 -0
  59. package/tests/parser.spec.ts +823 -0
  60. package/tests/prelude.spec.ts +22 -0
  61. package/tests/preprocessor.spec.ts +69 -0
  62. package/tests/typechecker.spec.ts +310 -0
  63. package/tsconfig.json +17 -0
package/.mocharc.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "extension": ["ts"],
3
+ "spec": "tests/**/*.spec.ts"
4
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,19 @@
1
+ ## 0.1.0 (2025-12-09)
2
+
3
+ ### 🚀 Features
4
+
5
+ - **yukigo:** Nx Release added ([0bee88f](https://github.com/miyukiproject/yukigo/commit/0bee88f))
6
+ - **LogicEngine:** Added LogicEngine with unification algorithm ([57b48a0](https://github.com/miyukiproject/yukigo/commit/57b48a0))
7
+
8
+ ### 🩹 Fixes
9
+
10
+ - **general:** Remove build step from tests command ([9d6e02f](https://github.com/miyukiproject/yukigo/commit/9d6e02f))
11
+
12
+ ### 🧱 Updated Dependencies
13
+
14
+ - Updated @yukigo/ast to 0.1.0
15
+
16
+ ### ❤️ Thank You
17
+
18
+ - noiseArch
19
+ - Valtolina Matias
package/README.md ADDED
@@ -0,0 +1,10 @@
1
+ # Yukigo Haskell Parser
2
+
3
+ Parser for a subset of Haskell written in Typescript using [nearley.js](https://nearley.js.org/) and [moo](https://github.com/no-context/moo).
4
+
5
+ Parses a valid [yukigo](https://github.com/noiseArch/yukigo) AST.
6
+
7
+ ## List of missing features
8
+ - [Standard library](http://www.zvon.org/other/haskell/Outputprelude/functionIndex.html)
9
+ - [Type classes](http://www.zvon.org/other/haskell/Outputprelude/classIndex.html)
10
+ - ...
@@ -0,0 +1,7 @@
1
+ import { AST, YukigoParser } from "@yukigo/ast";
2
+ export declare class YukigoHaskellParser implements YukigoParser {
3
+ errors: string[];
4
+ private prelude;
5
+ constructor(prelude?: string);
6
+ parse(code: string): AST;
7
+ }
package/dist/index.js ADDED
@@ -0,0 +1,54 @@
1
+ import grammar from "./parser/grammar.js";
2
+ import nearley from "nearley";
3
+ import { groupFunctionDeclarations } from "./utils/helpers.js";
4
+ import { TypeChecker } from "./typechecker/checker.js";
5
+ import { preprocessor } from "./parser/layoutPreprocessor.js";
6
+ import { preludeCode } from "./prelude.js";
7
+ export class YukigoHaskellParser {
8
+ errors = [];
9
+ prelude;
10
+ constructor(prelude) {
11
+ this.errors = [];
12
+ this.prelude = prelude ?? preludeCode;
13
+ }
14
+ parse(code) {
15
+ const processedCode = preprocessor(code);
16
+ const parser = new nearley.Parser(nearley.Grammar.fromCompiled(grammar));
17
+ try {
18
+ parser.feed(this.prelude + "\n\n" + processedCode);
19
+ parser.finish();
20
+ }
21
+ catch (error) {
22
+ console.log(error);
23
+ if ("token" in error) {
24
+ const token = error.token;
25
+ const message = `Parser: Unexpected '${token.type}' token '${token.value}' at line ${token.line} col ${token.col}.`;
26
+ this.errors.push(message);
27
+ throw Error(message);
28
+ }
29
+ throw error;
30
+ }
31
+ if (parser.results.length > 1) {
32
+ const msg = `Parser: Too much ambiguity. ${parser.results.length} ASTs parsed. Output not generated.`;
33
+ this.errors.push(msg);
34
+ throw Error(msg);
35
+ }
36
+ if (parser.results.length == 0) {
37
+ this.errors.push("Parser did not generate an AST.");
38
+ throw Error("Parser did not generate an AST.");
39
+ }
40
+ const ast = groupFunctionDeclarations(parser.results[0]);
41
+ try {
42
+ const typeChecker = new TypeChecker();
43
+ const errors = typeChecker.check(ast);
44
+ if (errors.length > 0) {
45
+ this.errors.push(...errors);
46
+ }
47
+ }
48
+ catch (error) {
49
+ console.log(error);
50
+ }
51
+ return ast;
52
+ }
53
+ }
54
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,qBAAqB,CAAC;AAC1C,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGvD,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,OAAO,mBAAmB;IACvB,MAAM,GAAa,EAAE,CAAC;IACrB,OAAO,CAAS;IACxB,YAAY,OAAgB;QAC1B,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,WAAW,CAAC;IACxC,CAAC;IAEM,KAAK,CAAC,IAAY;QACvB,MAAM,aAAa,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;QACzC,MAAM,MAAM,GAAG,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;QACzE,IAAI,CAAC;YACH,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,GAAG,MAAM,GAAG,aAAa,CAAC,CAAC;YACnD,MAAM,CAAC,MAAM,EAAE,CAAC;QAClB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;YAClB,IAAI,OAAO,IAAI,KAAK,EAAE,CAAC;gBACrB,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;gBAC1B,MAAM,OAAO,GAAG,uBAAuB,KAAK,CAAC,IAAI,YAAY,KAAK,CAAC,KAAK,aAAa,KAAK,CAAC,IAAI,QAAQ,KAAK,CAAC,GAAG,GAAG,CAAC;gBACpH,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;gBAC1B,MAAM,KAAK,CAAC,OAAO,CAAC,CAAC;YACvB,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;QACD,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC9B,MAAM,GAAG,GAAG,+BAA+B,MAAM,CAAC,OAAO,CAAC,MAAM,qCAAqC,CAAC;YACtG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACtB,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;QACD,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;YAC/B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;YACpD,MAAM,KAAK,CAAC,iCAAiC,CAAC,CAAC;QACjD,CAAC;QACD,MAAM,GAAG,GAAG,yBAAyB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QACzD,IAAI,CAAC;YACH,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;YACtC,MAAM,MAAM,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACtC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACtB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC;YAC9B,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;CACF"}
@@ -0,0 +1,28 @@
1
+ interface NearleyToken {
2
+ value: any;
3
+ [key: string]: any;
4
+ }
5
+ interface NearleyLexer {
6
+ reset: (chunk: string, info: any) => void;
7
+ next: () => NearleyToken | undefined;
8
+ save: () => any;
9
+ formatError: (token: never) => string;
10
+ has: (tokenType: string) => boolean;
11
+ }
12
+ interface NearleyRule {
13
+ name: string;
14
+ symbols: NearleySymbol[];
15
+ postprocess?: (d: any[], loc?: number, reject?: {}) => any;
16
+ }
17
+ type NearleySymbol = string | {
18
+ literal: any;
19
+ } | {
20
+ test: (token: any) => boolean;
21
+ };
22
+ interface Grammar {
23
+ Lexer: NearleyLexer | undefined;
24
+ ParserRules: NearleyRule[];
25
+ ParserStart: string;
26
+ }
27
+ declare const grammar: Grammar;
28
+ export default grammar;
@@ -0,0 +1,404 @@
1
+ // Generated automatically by nearley, version 2.20.1
2
+ // http://github.com/Hardmath123/nearley
3
+ // Bypasses TS6133. Allow declared but unused functions.
4
+ // @ts-ignore
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";
8
+ const filter = d => {
9
+ return d.filter((token) => token !== null);
10
+ };
11
+ const loc = (token) => new SourceLocation(token.line, token.col);
12
+ ;
13
+ ;
14
+ ;
15
+ ;
16
+ const grammar = {
17
+ Lexer: HSLexer,
18
+ 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) },
22
+ { "name": "declaration$subexpression$1", "symbols": ["function_declaration"] },
23
+ { "name": "declaration$subexpression$1", "symbols": ["function_signature"] },
24
+ { "name": "declaration$subexpression$1", "symbols": ["type_declaration"] },
25
+ { "name": "declaration$subexpression$1", "symbols": ["data_declaration"] },
26
+ { "name": "declaration$subexpression$1", "symbols": ["comment"] },
27
+ { "name": "declaration$subexpression$1", "symbols": ["empty_line"] },
28
+ { "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 },
32
+ { "name": "expression$subexpression$1", "symbols": ["type_cast"] },
33
+ { "name": "expression$subexpression$1", "symbols": ["letin_expression"] },
34
+ { "name": "expression$subexpression$1", "symbols": ["if_expression"] },
35
+ { "name": "expression$subexpression$1", "symbols": ["case_expression"] },
36
+ { "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]) },
38
+ { "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]) },
40
+ { "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]) },
43
+ { "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]) },
46
+ { "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]) },
48
+ { "name": "comparison", "symbols": ["cons_expression"], "postprocess": id },
49
+ { "name": "cons_expression", "symbols": ["concatenation", "_", { "literal": ":" }, "_", "cons_expression"], "postprocess": (d) => new ConsExpression(d[0], d[4]) },
50
+ { "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]) },
52
+ { "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]) },
55
+ { "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]) },
58
+ { "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]) },
62
+ { "name": "power", "symbols": ["unary_negation"], "postprocess": id },
63
+ { "name": "unary_negation", "symbols": [{ "literal": "-" }, "_", "unary_negation"], "postprocess": (d) => new ArithmeticUnaryOperation("Negation", d[2]) },
64
+ { "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]) },
66
+ { "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]) },
68
+ { "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]) },
70
+ { "name": "infix_operator_expression", "symbols": ["application"], "postprocess": id },
71
+ { "name": "application", "symbols": [{ "literal": "error" }, "__", "primary"], "postprocess": d => new Raise(d[2]) },
72
+ { "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]]) },
78
+ { "name": "application", "symbols": ["primary", "application$ebnf$1"], "postprocess": (d) => {
79
+ if (d[1].length === 0)
80
+ return d[0];
81
+ return d[1].reduce((left, right) => new Application(left, right[1]), d[0]);
82
+ } },
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) => {
100
+ const flipBody = new SymbolPrimitive("flip");
101
+ const op = new SymbolPrimitive(d[2]);
102
+ const expr = d[4];
103
+ const flipAppliedToOp = new Application(flipBody, op);
104
+ return new Application(flipAppliedToOp, expr);
105
+ }
106
+ },
107
+ { "name": "operator_section", "symbols": [{ "literal": "(" }, "_", "operator", "_", { "literal": ")" }], "postprocess": (d) => new SymbolPrimitive(d[2]) },
108
+ { "name": "primary", "symbols": ["primitive"], "postprocess": id },
109
+ { "name": "primary", "symbols": ["variable"], "postprocess": id },
110
+ { "name": "primary", "symbols": ["constr"], "postprocess": id },
111
+ { "name": "primary", "symbols": ["tuple_expression"], "postprocess": id },
112
+ { "name": "primary", "symbols": ["left_section"], "postprocess": id },
113
+ { "name": "primary", "symbols": ["right_section"], "postprocess": id },
114
+ { "name": "primary", "symbols": ["operator_section"], "postprocess": id },
115
+ { "name": "primary", "symbols": ["list_literal"], "postprocess": id },
116
+ { "name": "primary", "symbols": ["lambda_expression"], "postprocess": id },
117
+ { "name": "primary", "symbols": ["data_expression"], "postprocess": id },
118
+ { "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]);
123
+ } },
124
+ { "name": "comprehension_clause_list$ebnf$1", "symbols": [] },
125
+ { "name": "comprehension_clause_list$ebnf$1$subexpression$1", "symbols": ["_", { "literal": "," }, "_", "comprehension_clause"] },
126
+ { "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
+ { "name": "comprehension_clause_list", "symbols": ["comprehension_clause", "comprehension_clause_list$ebnf$1"], "postprocess": (d) => {
128
+ return [d[0], ...d[1].map((x) => x[3])];
129
+ } },
130
+ { "name": "comprehension_clause", "symbols": ["variable", "_", { "literal": "<-" }, "_", "expression"], "postprocess": (d) => new Generator(d[0], d[4]) },
131
+ { "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"] },
134
+ { "name": "tuple_expression$ebnf$1", "symbols": ["tuple_expression$ebnf$1$subexpression$1"] },
135
+ { "name": "tuple_expression$ebnf$1$subexpression$2", "symbols": ["_", { "literal": "," }, "_", "tuple_value"] },
136
+ { "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]) },
140
+ { "name": "fields_expressions$ebnf$1", "symbols": [] },
141
+ { "name": "fields_expressions$ebnf$1$subexpression$1", "symbols": ["_", { "literal": "," }, "_", "field_exp"] },
142
+ { "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": "{" }, "_"] },
147
+ { "name": "letin_expression$ebnf$1", "symbols": ["bindings_list"], "postprocess": id },
148
+ { "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]) },
154
+ { "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"] },
157
+ { "name": "case_arms$ebnf$1", "symbols": ["case_arms$ebnf$1", "case_arms$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]]) },
158
+ { "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] }) },
160
+ { "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]]) },
163
+ { "name": "data_declaration$ebnf$2", "symbols": [] },
164
+ { "name": "data_declaration$ebnf$2$subexpression$1", "symbols": ["_", { "literal": "|" }, "_", "constructor_def"] },
165
+ { "name": "data_declaration$ebnf$2", "symbols": ["data_declaration$ebnf$2", "data_declaration$ebnf$2$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]]) },
166
+ { "name": "data_declaration$ebnf$3", "symbols": ["deriving_clause"], "postprocess": id },
167
+ { "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])
169
+ },
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] },
172
+ { "name": "deriving_spec", "symbols": ["constr"], "postprocess": (d) => [d[0]] },
173
+ { "name": "deriving_classes$ebnf$1", "symbols": [] },
174
+ { "name": "deriving_classes$ebnf$1$subexpression$1", "symbols": ["_", { "literal": "," }, "_", (HSLexer.has("typeClass") ? { type: "typeClass" } : typeClass)] },
175
+ { "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]))) },
191
+ { "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"] },
196
+ { "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}`) },
200
+ { "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]]) },
207
+ { "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 },
216
+ { "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)
224
+ : body;
225
+ return new Equation(d[0], finalBody);
226
+ } },
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]) },
251
+ { "name": "condition", "symbols": [{ "literal": "otherwise" }], "postprocess": d => new Otherwise() },
252
+ { "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])] },
257
+ { "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", "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", "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])];
264
+ return patterns.reduceRight((tail, head, index, arr) => {
265
+ if (index === arr.length - 1)
266
+ return tail;
267
+ return new ConsPattern(head, tail);
268
+ });
269
+ }
270
+ },
271
+ { "name": "cons_pattern", "symbols": ["simple_pattern"], "postprocess": id },
272
+ { "name": "simple_pattern$subexpression$1", "symbols": ["as_pattern"] },
273
+ { "name": "simple_pattern$subexpression$1", "symbols": ["constructor_pattern"] },
274
+ { "name": "simple_pattern$subexpression$1", "symbols": ["list_pattern"] },
275
+ { "name": "simple_pattern$subexpression$1", "symbols": ["tuple_pattern"] },
276
+ { "name": "simple_pattern$subexpression$1", "symbols": ["literal_pattern"] },
277
+ { "name": "simple_pattern$subexpression$1", "symbols": ["variable_pattern"] },
278
+ { "name": "simple_pattern$subexpression$1", "symbols": ["wildcard_pattern"] },
279
+ { "name": "simple_pattern$subexpression$1", "symbols": ["paren_pattern"] },
280
+ { "name": "simple_pattern", "symbols": ["simple_pattern$subexpression$1"], "postprocess": (d) => d[0][0] },
281
+ { "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": "variable_pattern", "symbols": ["variable"], "postprocess": (d) => new VariablePattern(d[0]) },
284
+ { "name": "literal_pattern", "symbols": ["primitive"], "postprocess": (d) => new LiteralPattern(d[0]) },
285
+ { "name": "as_pattern$subexpression$1", "symbols": ["variable_pattern"] },
286
+ { "name": "as_pattern$subexpression$1", "symbols": ["wildcard_pattern"] },
287
+ { "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, []) },
294
+ { "name": "field_pattern_list$ebnf$1", "symbols": [] },
295
+ { "name": "field_pattern_list$ebnf$1$subexpression$1", "symbols": ["_", { "literal": "," }, "_", "field_pattern"] },
296
+ { "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] }) },
299
+ { "name": "list_pattern$ebnf$1", "symbols": ["pattern_list"], "postprocess": id },
300
+ { "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] || []) },
302
+ { "name": "pattern_list$ebnf$1", "symbols": [] },
303
+ { "name": "pattern_list$ebnf$1$subexpression$1", "symbols": ["_", { "literal": "," }, "_", "pattern"] },
304
+ { "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"] },
307
+ { "name": "tuple_pattern$ebnf$1", "symbols": ["tuple_pattern$ebnf$1$subexpression$1"] },
308
+ { "name": "tuple_pattern$ebnf$1$subexpression$2", "symbols": ["_", { "literal": "," }, "_", "pattern"] },
309
+ { "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 },
313
+ { "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]) },
315
+ { "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)] },
319
+ { "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]) },
321
+ { "name": "context", "symbols": ["constraint"], "postprocess": (d) => [d[0]] },
322
+ { "name": "context", "symbols": [{ "literal": "(" }, "_", "constraint_list", "_", { "literal": ")" }], "postprocess": (d) => d[2] },
323
+ { "name": "constraint_list$ebnf$1", "symbols": [] },
324
+ { "name": "constraint_list$ebnf$1$subexpression$1", "symbols": ["_", { "literal": "," }, "_", "constraint"] },
325
+ { "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])]
327
+ },
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), "_"] },
334
+ { "name": "function_type$ebnf$1", "symbols": ["function_type$ebnf$1$subexpression$1"], "postprocess": id },
335
+ { "name": "function_type$ebnf$1", "symbols": [], "postprocess": () => null },
336
+ { "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"] },
344
+ { "name": "function_type$ebnf$2", "symbols": ["function_type$ebnf$2", "function_type$ebnf$2$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]]) },
345
+ { "name": "function_type", "symbols": ["function_type$ebnf$1", "function_type$ebnf$2", "application_type"], "postprocess": (d) => {
346
+ const constraints = d[0] ? d[0][0] : [];
347
+ if (d[1].length > 0)
348
+ return new ParameterizedType(d[1].map(x => x[0]), d[2], constraints);
349
+ if (constraints.length === 0)
350
+ return d[2];
351
+ return new ParameterizedType([], d[2], constraints);
352
+ }
353
+ },
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]) },
359
+ { "name": "application_type", "symbols": ["simple_type"], "postprocess": id },
360
+ { "name": "simple_type$subexpression$1", "symbols": ["type_variable"] },
361
+ { "name": "simple_type$subexpression$1", "symbols": ["type_constructor"] },
362
+ { "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"] },
365
+ { "name": "simple_type$ebnf$1", "symbols": ["simple_type$ebnf$1$subexpression$1"] },
366
+ { "name": "simple_type$ebnf$1$subexpression$2", "symbols": ["_", { "literal": "," }, "_", "type"] },
367
+ { "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] },
370
+ { "name": "type_variable", "symbols": ["variable"], "postprocess": ([v]) => ({ value: v.value }) },
371
+ { "name": "type_constructor", "symbols": ["constr"], "postprocess": ([c]) => ({ value: c.value }) },
372
+ { "name": "constr", "symbols": [(HSLexer.has("constructor") ? { type: "constructor" } : constructor)], "postprocess": ([c]) => new SymbolPrimitive(c.value, loc(c)) },
373
+ { "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]) },
380
+ { "name": "expression_list$ebnf$1", "symbols": [] },
381
+ { "name": "expression_list$ebnf$1$subexpression$1", "symbols": ["_", { "literal": "," }, "_", "expression"] },
382
+ { "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])] },
384
+ { "name": "comparison_operator", "symbols": [{ "literal": "==" }], "postprocess": (d) => "Equal" },
385
+ { "name": "comparison_operator", "symbols": [{ "literal": "/=" }], "postprocess": (d) => "NotEqual" },
386
+ { "name": "comparison_operator", "symbols": [{ "literal": "<" }], "postprocess": (d) => "LessThan" },
387
+ { "name": "comparison_operator", "symbols": [{ "literal": ">" }], "postprocess": (d) => "GreaterThan" },
388
+ { "name": "comparison_operator", "symbols": [{ "literal": "<=" }], "postprocess": (d) => "LessOrEqualThan" },
389
+ { "name": "comparison_operator", "symbols": [{ "literal": ">=" }], "postprocess": (d) => "GreaterOrEqualThan" },
390
+ { "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"] }
400
+ ],
401
+ ParserStart: "program",
402
+ };
403
+ export default grammar;
404
+ //# sourceMappingURL=grammar.js.map