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,29 @@
|
|
|
1
|
+
import { inspect } from "util";
|
|
2
|
+
import { AST } from "yukigo-ast";
|
|
3
|
+
import { Function } from "yukigo-ast";
|
|
4
|
+
|
|
5
|
+
export function groupFunctionDeclarations(ast: AST): AST {
|
|
6
|
+
const groups: Record<string, Function[]> = {};
|
|
7
|
+
const others: AST = [];
|
|
8
|
+
|
|
9
|
+
for (const node of ast) {
|
|
10
|
+
if (node instanceof Function) {
|
|
11
|
+
const name = node.identifier.value;
|
|
12
|
+
if (!groups[name]) {
|
|
13
|
+
groups[name] = [];
|
|
14
|
+
}
|
|
15
|
+
groups[name].push(node);
|
|
16
|
+
} else {
|
|
17
|
+
others.push(node);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Merge equations for each function name
|
|
22
|
+
const functionGroups: Function[] = Object.values(groups).map((functions) => {
|
|
23
|
+
const identifier = functions[0].identifier;
|
|
24
|
+
const allEquations = functions.flatMap((f) => f.equations);
|
|
25
|
+
return new Function(identifier, allEquations, identifier.loc);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
return [...others, ...functionGroups];
|
|
29
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { YukigoPrimitive } from "yukigo-ast";
|
|
2
|
+
|
|
3
|
+
export const keywords = [
|
|
4
|
+
"type",
|
|
5
|
+
"where",
|
|
6
|
+
"in",
|
|
7
|
+
"if",
|
|
8
|
+
"else",
|
|
9
|
+
"then",
|
|
10
|
+
"data",
|
|
11
|
+
"case",
|
|
12
|
+
"class",
|
|
13
|
+
"do",
|
|
14
|
+
"default",
|
|
15
|
+
"deriving",
|
|
16
|
+
"import",
|
|
17
|
+
"infix",
|
|
18
|
+
"infixl",
|
|
19
|
+
"infixr",
|
|
20
|
+
"instance",
|
|
21
|
+
"let",
|
|
22
|
+
"module",
|
|
23
|
+
"newtype",
|
|
24
|
+
"of",
|
|
25
|
+
"qualified",
|
|
26
|
+
"hiding",
|
|
27
|
+
"foreign",
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
export const typeMappings: { [key: string]: YukigoPrimitive } = {
|
|
31
|
+
Float: "YuNumber",
|
|
32
|
+
Double: "YuNumber",
|
|
33
|
+
Int: "YuNumber",
|
|
34
|
+
Integer: "YuNumber",
|
|
35
|
+
String: "YuString",
|
|
36
|
+
Char: "YuChar",
|
|
37
|
+
Boolean: "YuBoolean",
|
|
38
|
+
Bool: "YuBoolean",
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const typeClasses: Map<string, string[]> = new Map([
|
|
42
|
+
["Bounded", ["YuChar", "YuNumber"]],
|
|
43
|
+
["Enum", ["YuChar", "YuNumber"]],
|
|
44
|
+
["Ord", ["YuNumber", "YuString", "YuChar"]],
|
|
45
|
+
["Eq", ["YuNumber", "YuString", "YuChar", "YuBoolean"]],
|
|
46
|
+
["Floating", ["YuNumber"]],
|
|
47
|
+
["Fractional", ["YuNumber"]],
|
|
48
|
+
["Integral", ["YuNumber"]],
|
|
49
|
+
["Num", ["YuNumber"]],
|
|
50
|
+
["Random", ["YuBoolean", "YuChar", "YuNumber"]],
|
|
51
|
+
["Read", ["YuList", "YuChar", "YuNumber"]],
|
|
52
|
+
["Real", ["YuNumber"]],
|
|
53
|
+
["RealFloat", ["YuNumber"]],
|
|
54
|
+
["RealFrac", ["YuNumber"]],
|
|
55
|
+
["Show", ["YuNumber", "YuString", "YuChar", "YuList"]],
|
|
56
|
+
]);
|