@graffiticode/parser 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/src/config/config.d.ts +3 -0
- package/dist/api/src/config/config.js +4 -0
- package/dist/api/src/config/config.js.map +1 -0
- package/dist/api/src/config/index.d.ts +1 -0
- package/dist/api/src/config/index.js +3 -0
- package/dist/api/src/config/index.js.map +1 -0
- package/dist/api/src/lang/base-url.d.ts +7 -0
- package/dist/api/src/lang/base-url.js +24 -0
- package/dist/api/src/lang/base-url.js.map +1 -0
- package/dist/api/src/lang/compile.d.ts +4 -0
- package/dist/api/src/lang/compile.js +6 -0
- package/dist/api/src/lang/compile.js.map +1 -0
- package/dist/api/src/lang/get-asset.d.ts +4 -0
- package/dist/api/src/lang/get-asset.js +9 -0
- package/dist/api/src/lang/get-asset.js.map +1 -0
- package/dist/api/src/lang/index.d.ts +4 -0
- package/dist/api/src/lang/index.js +22 -0
- package/dist/api/src/lang/index.js.map +1 -0
- package/dist/api/src/lang/ping-lang.d.ts +5 -0
- package/dist/api/src/lang/ping-lang.js +31 -0
- package/dist/api/src/lang/ping-lang.js.map +1 -0
- package/dist/api/src/util.d.ts +23 -0
- package/dist/api/src/util.js +187 -0
- package/dist/api/src/util.js.map +1 -0
- package/dist/parser/src/ast.d.ts +58 -0
- package/dist/parser/src/ast.js +683 -0
- package/dist/parser/src/ast.js.map +1 -0
- package/dist/parser/src/env.d.ts +8 -0
- package/dist/parser/src/env.js +38 -0
- package/dist/parser/src/env.js.map +1 -0
- package/dist/parser/src/fold.d.ts +4 -0
- package/dist/parser/src/fold.js +217 -0
- package/dist/parser/src/fold.js.map +1 -0
- package/dist/parser/src/folder.d.ts +30 -0
- package/dist/parser/src/folder.js +231 -0
- package/dist/parser/src/folder.js.map +1 -0
- package/dist/parser/src/index.d.ts +5 -0
- package/dist/parser/src/index.js +6 -0
- package/dist/parser/src/index.js.map +1 -0
- package/dist/parser/src/parse.d.ts +56 -0
- package/dist/parser/src/parse.js +902 -0
- package/dist/parser/src/parse.js.map +1 -0
- package/dist/parser/src/parser.d.ts +17 -0
- package/dist/parser/src/parser.js +89 -0
- package/dist/parser/src/parser.js.map +1 -0
- package/dist/parser/src/parserForTests.d.ts +3 -0
- package/dist/parser/src/parserForTests.js +4 -0
- package/dist/parser/src/parserForTests.js.map +1 -0
- package/dist/parser/src/stringstream.d.ts +10 -0
- package/dist/parser/src/stringstream.js +21 -0
- package/dist/parser/src/stringstream.js.map +1 -0
- package/dist/parser/src/testing/index.d.ts +2 -0
- package/dist/parser/src/testing/index.js +17 -0
- package/dist/parser/src/testing/index.js.map +1 -0
- package/dist/parser/src/types.d.ts +44 -0
- package/dist/parser/src/types.js +2 -0
- package/dist/parser/src/types.js.map +1 -0
- package/package.json +5 -9
- package/src/ast.js +730 -0
- package/src/env.js +50 -0
- package/src/folder.js +249 -0
- package/src/folder.spec.js +42 -0
- package/src/parse.js +35 -935
- package/src/parse.spec.js +118 -0
- package/src/parse.spec.js~ +119 -0
- package/src/parse.ts~ +1037 -0
- package/src/parser.spec.js +11 -35
- package/src/{parser.js~ → parser.ts~} +25 -7
- package/src/stringstream.js +22 -0
- package/src/fold.js +0 -235
- package/src/parser.spec.js~ +0 -175
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { buildParser } from "./parser.js";
|
|
2
|
+
import { mockPromiseValue } from "./testing/index.js";
|
|
3
|
+
|
|
4
|
+
describe("parse operations", () => {
|
|
5
|
+
const log = jest.fn();
|
|
6
|
+
|
|
7
|
+
it("should parse 'apply (<a b: add a b>) [10 20]'", async () => {
|
|
8
|
+
// Arrange
|
|
9
|
+
const cache = new Map();
|
|
10
|
+
const getLangAsset = mockPromiseValue("{}");
|
|
11
|
+
const main = {
|
|
12
|
+
parse: mockPromiseValue({
|
|
13
|
+
1: {
|
|
14
|
+
elts: ["a"],
|
|
15
|
+
tag: "IDENT"
|
|
16
|
+
},
|
|
17
|
+
2: {
|
|
18
|
+
elts: ["b"],
|
|
19
|
+
tag: "IDENT"
|
|
20
|
+
},
|
|
21
|
+
3: {
|
|
22
|
+
elts: [1, 2],
|
|
23
|
+
tag: "ADD"
|
|
24
|
+
},
|
|
25
|
+
4: {
|
|
26
|
+
elts: [3],
|
|
27
|
+
tag: "EXPRS"
|
|
28
|
+
},
|
|
29
|
+
5: {
|
|
30
|
+
elts: [1, 2],
|
|
31
|
+
tag: "LIST"
|
|
32
|
+
},
|
|
33
|
+
6: {
|
|
34
|
+
elts: [5, 4],
|
|
35
|
+
tag: "LAMBDA"
|
|
36
|
+
},
|
|
37
|
+
7: {
|
|
38
|
+
elts: ["10"],
|
|
39
|
+
tag: "NUM"
|
|
40
|
+
},
|
|
41
|
+
8: {
|
|
42
|
+
elts: ["20"],
|
|
43
|
+
tag: "NUM"
|
|
44
|
+
},
|
|
45
|
+
9: {
|
|
46
|
+
elts: [7, 8],
|
|
47
|
+
tag: "LIST"
|
|
48
|
+
},
|
|
49
|
+
10: {
|
|
50
|
+
elts: [6, 9],
|
|
51
|
+
tag: "APPLY"
|
|
52
|
+
},
|
|
53
|
+
11: {
|
|
54
|
+
elts: [10],
|
|
55
|
+
tag: "EXPRS"
|
|
56
|
+
},
|
|
57
|
+
12: {
|
|
58
|
+
elts: [11],
|
|
59
|
+
tag: "PROG"
|
|
60
|
+
},
|
|
61
|
+
root: 12
|
|
62
|
+
})
|
|
63
|
+
};
|
|
64
|
+
const parser = buildParser({ log, cache, getLangAsset, main });
|
|
65
|
+
const lang = "0002";
|
|
66
|
+
const src = "apply (<a b: add a b>) [10 20]..";
|
|
67
|
+
|
|
68
|
+
// Act
|
|
69
|
+
const result = await parser.parse(lang, src);
|
|
70
|
+
|
|
71
|
+
// Assert
|
|
72
|
+
expect(result).toHaveProperty("root", 12);
|
|
73
|
+
expect(result[10].tag).toBe("APPLY");
|
|
74
|
+
expect(result[10].elts).toEqual([6, 9]);
|
|
75
|
+
expect(result[6].tag).toBe("LAMBDA");
|
|
76
|
+
expect(result[9].tag).toBe("LIST");
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("should parse 'hello, world!'", async () => {
|
|
80
|
+
// Arrange
|
|
81
|
+
const cache = new Map();
|
|
82
|
+
const getLangAsset = mockPromiseValue("{}");
|
|
83
|
+
const main = {
|
|
84
|
+
parse: mockPromiseValue({
|
|
85
|
+
1: {
|
|
86
|
+
elts: [
|
|
87
|
+
"hello, world"
|
|
88
|
+
],
|
|
89
|
+
tag: "STR"
|
|
90
|
+
},
|
|
91
|
+
2: {
|
|
92
|
+
elts: [
|
|
93
|
+
1
|
|
94
|
+
],
|
|
95
|
+
tag: "EXPRS"
|
|
96
|
+
},
|
|
97
|
+
3: {
|
|
98
|
+
elts: [
|
|
99
|
+
2
|
|
100
|
+
],
|
|
101
|
+
tag: "PROG"
|
|
102
|
+
},
|
|
103
|
+
root: 3
|
|
104
|
+
})
|
|
105
|
+
};
|
|
106
|
+
const parser = buildParser({ log, cache, getLangAsset, main });
|
|
107
|
+
const lang = "0002";
|
|
108
|
+
const src = "'hello, world'..";
|
|
109
|
+
|
|
110
|
+
// Act
|
|
111
|
+
const result = await parser.parse(lang, src);
|
|
112
|
+
|
|
113
|
+
// Assert
|
|
114
|
+
expect(result).toHaveProperty("root", 3);
|
|
115
|
+
expect(result[1].tag).toBe("STR");
|
|
116
|
+
expect(result[1].elts).toEqual(["hello, world"]);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { jest } from "@jest/globals";
|
|
2
|
+
import { parser, buildParser } from "./parser.js";
|
|
3
|
+
import { mockPromiseValue, mockPromiseError } from "./testing/index.js";
|
|
4
|
+
|
|
5
|
+
describe("parse operations", () => {
|
|
6
|
+
const log = jest.fn();
|
|
7
|
+
|
|
8
|
+
it("should parse 'apply (<a b: add a b>) [10 20]'", async () => {
|
|
9
|
+
// Arrange
|
|
10
|
+
const cache = new Map();
|
|
11
|
+
const getLangAsset = mockPromiseValue("{}");
|
|
12
|
+
const main = {
|
|
13
|
+
parse: mockPromiseValue({
|
|
14
|
+
1: {
|
|
15
|
+
elts: ["a"],
|
|
16
|
+
tag: "IDENT"
|
|
17
|
+
},
|
|
18
|
+
2: {
|
|
19
|
+
elts: ["b"],
|
|
20
|
+
tag: "IDENT"
|
|
21
|
+
},
|
|
22
|
+
3: {
|
|
23
|
+
elts: [1, 2],
|
|
24
|
+
tag: "ADD"
|
|
25
|
+
},
|
|
26
|
+
4: {
|
|
27
|
+
elts: [3],
|
|
28
|
+
tag: "EXPRS"
|
|
29
|
+
},
|
|
30
|
+
5: {
|
|
31
|
+
elts: [1, 2],
|
|
32
|
+
tag: "LIST"
|
|
33
|
+
},
|
|
34
|
+
6: {
|
|
35
|
+
elts: [5, 4],
|
|
36
|
+
tag: "LAMBDA"
|
|
37
|
+
},
|
|
38
|
+
7: {
|
|
39
|
+
elts: ["10"],
|
|
40
|
+
tag: "NUM"
|
|
41
|
+
},
|
|
42
|
+
8: {
|
|
43
|
+
elts: ["20"],
|
|
44
|
+
tag: "NUM"
|
|
45
|
+
},
|
|
46
|
+
9: {
|
|
47
|
+
elts: [7, 8],
|
|
48
|
+
tag: "LIST"
|
|
49
|
+
},
|
|
50
|
+
10: {
|
|
51
|
+
elts: [6, 9],
|
|
52
|
+
tag: "APPLY"
|
|
53
|
+
},
|
|
54
|
+
11: {
|
|
55
|
+
elts: [10],
|
|
56
|
+
tag: "EXPRS"
|
|
57
|
+
},
|
|
58
|
+
12: {
|
|
59
|
+
elts: [11],
|
|
60
|
+
tag: "PROG"
|
|
61
|
+
},
|
|
62
|
+
root: 12
|
|
63
|
+
})
|
|
64
|
+
};
|
|
65
|
+
const parser = buildParser({ log, cache, getLangAsset, main });
|
|
66
|
+
const lang = "0";
|
|
67
|
+
const src = "apply (<a b: add a b>) [10 20]..";
|
|
68
|
+
|
|
69
|
+
// Act
|
|
70
|
+
const result = await parser.parse(lang, src);
|
|
71
|
+
|
|
72
|
+
// Assert
|
|
73
|
+
expect(result).toHaveProperty("root", 12);
|
|
74
|
+
expect(result[10].tag).toBe("APPLY");
|
|
75
|
+
expect(result[10].elts).toEqual([6, 9]);
|
|
76
|
+
expect(result[6].tag).toBe("LAMBDA");
|
|
77
|
+
expect(result[9].tag).toBe("LIST");
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("should parse 'hello, world!'", async () => {
|
|
81
|
+
// Arrange
|
|
82
|
+
const cache = new Map();
|
|
83
|
+
const getLangAsset = mockPromiseValue("{}");
|
|
84
|
+
const main = {
|
|
85
|
+
parse: mockPromiseValue({
|
|
86
|
+
1: {
|
|
87
|
+
elts: [
|
|
88
|
+
"hello, world"
|
|
89
|
+
],
|
|
90
|
+
tag: "STR"
|
|
91
|
+
},
|
|
92
|
+
2: {
|
|
93
|
+
elts: [
|
|
94
|
+
1
|
|
95
|
+
],
|
|
96
|
+
tag: "EXPRS"
|
|
97
|
+
},
|
|
98
|
+
3: {
|
|
99
|
+
elts: [
|
|
100
|
+
2
|
|
101
|
+
],
|
|
102
|
+
tag: "PROG"
|
|
103
|
+
},
|
|
104
|
+
root: 3
|
|
105
|
+
})
|
|
106
|
+
};
|
|
107
|
+
const parser = buildParser({ log, cache, getLangAsset, main });
|
|
108
|
+
const lang = "0";
|
|
109
|
+
const src = "'hello, world'..";
|
|
110
|
+
|
|
111
|
+
// Act
|
|
112
|
+
const result = await parser.parse(lang, src);
|
|
113
|
+
|
|
114
|
+
// Assert
|
|
115
|
+
expect(result).toHaveProperty("root", 3);
|
|
116
|
+
expect(result[1].tag).toBe("STR");
|
|
117
|
+
expect(result[1].elts).toEqual(["hello, world"]);
|
|
118
|
+
});
|
|
119
|
+
});
|