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