yukigo-mini-parser 0.1.2 → 0.2.1

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.
@@ -1,158 +1,158 @@
1
- import { assert } from "chai";
2
- import {
3
- ArithmeticBinaryOperation,
4
- Assignment,
5
- ComparisonOperation,
6
- Equation,
7
- If,
8
- ListPrimitive,
9
- ListType,
10
- NilPrimitive,
11
- NumberPrimitive,
12
- ParameterizedType,
13
- Procedure,
14
- Return,
15
- Sequence,
16
- SimpleType,
17
- SymbolPrimitive,
18
- TypeSignature,
19
- UnguardedBody,
20
- Variable,
21
- VariablePattern,
22
- While,
23
- YukigoParser,
24
- } from "yukigo-ast";
25
- import { YukigoMiniParser } from "../src/index.js";
26
-
27
- describe("Parser Tests", () => {
28
- let parser: YukigoParser;
29
- beforeEach(() => {
30
- parser = new YukigoMiniParser();
31
- });
32
-
33
- it("should parse assignment", () => {
34
- const code = `int n; int result;`;
35
- assert.deepEqual(parser.parse(code), [
36
- new Variable(
37
- new SymbolPrimitive("n"),
38
- new NilPrimitive(null),
39
- new SimpleType("int", [])
40
- ),
41
- new Variable(
42
- new SymbolPrimitive("result"),
43
- new NilPrimitive(null),
44
- new SimpleType("int", [])
45
- ),
46
- ]);
47
- });
48
- it("should parse function declaration", () => {
49
- const code = `int add(int x, int y) {
50
- int result := x + y;
51
- return result;
52
- };`;
53
- assert.deepEqual(parser.parse(code), [
54
- new TypeSignature(
55
- new SymbolPrimitive("add"),
56
- new ParameterizedType(
57
- [new SimpleType("int", []), new SimpleType("int", [])],
58
- new SimpleType("int", []),
59
- []
60
- )
61
- ),
62
- new Procedure(new SymbolPrimitive("add"), [
63
- new Equation(
64
- [
65
- new VariablePattern(new SymbolPrimitive("x")),
66
- new VariablePattern(new SymbolPrimitive("y")),
67
- ],
68
- new UnguardedBody(
69
- new Sequence([
70
- new Variable(
71
- new SymbolPrimitive("result"),
72
- new ArithmeticBinaryOperation(
73
- "Plus",
74
- new SymbolPrimitive("x"),
75
- new SymbolPrimitive("y")
76
- ),
77
- new SimpleType("int", [])
78
- ),
79
- new Return(new SymbolPrimitive("result")),
80
- ])
81
- )
82
- ),
83
- ]),
84
- ]);
85
- });
86
- it("should parse list primitive", () => {
87
- const code = `int[] numberList := [1, 2, 3 + 4];`;
88
- assert.deepEqual(parser.parse(code), [
89
- new Variable(
90
- new SymbolPrimitive("numberList"),
91
- new ListPrimitive([
92
- new NumberPrimitive(1),
93
- new NumberPrimitive(2),
94
- new ArithmeticBinaryOperation(
95
- "Plus",
96
- new NumberPrimitive(3),
97
- new NumberPrimitive(4)
98
- ),
99
- ]),
100
- new ListType(new SimpleType("int", []), [])
101
- ),
102
- ]);
103
- });
104
- it("should parse if statement", () => {
105
- const code = `if (a != b) { c := a + b; } else { c := a * 2; };`;
106
- assert.deepEqual(parser.parse(code), [
107
- new If(
108
- new ComparisonOperation(
109
- "NotEqual",
110
- new SymbolPrimitive("a"),
111
- new SymbolPrimitive("b")
112
- ),
113
- new Sequence([
114
- new Assignment(
115
- new SymbolPrimitive("c"),
116
- new ArithmeticBinaryOperation(
117
- "Plus",
118
- new SymbolPrimitive("a"),
119
- new SymbolPrimitive("b")
120
- )
121
- ),
122
- ]),
123
- new Sequence([
124
- new Assignment(
125
- new SymbolPrimitive("c"),
126
- new ArithmeticBinaryOperation(
127
- "Multiply",
128
- new SymbolPrimitive("a"),
129
- new NumberPrimitive(2)
130
- )
131
- ),
132
- ])
133
- ),
134
- ]);
135
- });
136
- it("should parse while loop statement", () => {
137
- const code = `while (a < 10) { a := a + 1; };`;
138
- assert.deepEqual(parser.parse(code), [
139
- new While(
140
- new ComparisonOperation(
141
- "LessThan",
142
- new SymbolPrimitive("a"),
143
- new NumberPrimitive(10)
144
- ),
145
- new Sequence([
146
- new Assignment(
147
- new SymbolPrimitive("a"),
148
- new ArithmeticBinaryOperation(
149
- "Plus",
150
- new SymbolPrimitive("a"),
151
- new NumberPrimitive(1)
152
- )
153
- ),
154
- ])
155
- ),
156
- ]);
157
- });
158
- });
1
+ import { assert } from "chai";
2
+ import {
3
+ ArithmeticBinaryOperation,
4
+ Assignment,
5
+ ComparisonOperation,
6
+ Equation,
7
+ If,
8
+ ListPrimitive,
9
+ ListType,
10
+ NilPrimitive,
11
+ NumberPrimitive,
12
+ ParameterizedType,
13
+ Procedure,
14
+ Return,
15
+ Sequence,
16
+ SimpleType,
17
+ SymbolPrimitive,
18
+ TypeSignature,
19
+ UnguardedBody,
20
+ Variable,
21
+ VariablePattern,
22
+ While,
23
+ YukigoParser,
24
+ } from "yukigo-ast";
25
+ import { YukigoMiniParser } from "../src/index.js";
26
+
27
+ describe("Parser Tests", () => {
28
+ let parser: YukigoParser;
29
+ beforeEach(() => {
30
+ parser = new YukigoMiniParser();
31
+ });
32
+
33
+ it("should parse assignment", () => {
34
+ const code = `int n; int result;`;
35
+ assert.deepEqual(parser.parse(code), [
36
+ new Variable(
37
+ new SymbolPrimitive("n"),
38
+ new NilPrimitive(null),
39
+ new SimpleType("int", [])
40
+ ),
41
+ new Variable(
42
+ new SymbolPrimitive("result"),
43
+ new NilPrimitive(null),
44
+ new SimpleType("int", [])
45
+ ),
46
+ ]);
47
+ });
48
+ it("should parse function declaration", () => {
49
+ const code = `int add(int x, int y) {
50
+ int result := x + y;
51
+ return result;
52
+ };`;
53
+ assert.deepEqual(parser.parse(code), [
54
+ new TypeSignature(
55
+ new SymbolPrimitive("add"),
56
+ new ParameterizedType(
57
+ [new SimpleType("int", []), new SimpleType("int", [])],
58
+ new SimpleType("int", []),
59
+ []
60
+ )
61
+ ),
62
+ new Procedure(new SymbolPrimitive("add"), [
63
+ new Equation(
64
+ [
65
+ new VariablePattern(new SymbolPrimitive("x")),
66
+ new VariablePattern(new SymbolPrimitive("y")),
67
+ ],
68
+ new UnguardedBody(
69
+ new Sequence([
70
+ new Variable(
71
+ new SymbolPrimitive("result"),
72
+ new ArithmeticBinaryOperation(
73
+ "Plus",
74
+ new SymbolPrimitive("x"),
75
+ new SymbolPrimitive("y")
76
+ ),
77
+ new SimpleType("int", [])
78
+ ),
79
+ new Return(new SymbolPrimitive("result")),
80
+ ])
81
+ )
82
+ ),
83
+ ]),
84
+ ]);
85
+ });
86
+ it("should parse list primitive", () => {
87
+ const code = `int[] numberList := [1, 2, 3 + 4];`;
88
+ assert.deepEqual(parser.parse(code), [
89
+ new Variable(
90
+ new SymbolPrimitive("numberList"),
91
+ new ListPrimitive([
92
+ new NumberPrimitive(1),
93
+ new NumberPrimitive(2),
94
+ new ArithmeticBinaryOperation(
95
+ "Plus",
96
+ new NumberPrimitive(3),
97
+ new NumberPrimitive(4)
98
+ ),
99
+ ]),
100
+ new ListType(new SimpleType("int", []), [])
101
+ ),
102
+ ]);
103
+ });
104
+ it("should parse if statement", () => {
105
+ const code = `if (a != b) { c := a + b; } else { c := a * 2; };`;
106
+ assert.deepEqual(parser.parse(code), [
107
+ new If(
108
+ new ComparisonOperation(
109
+ "NotEqual",
110
+ new SymbolPrimitive("a"),
111
+ new SymbolPrimitive("b")
112
+ ),
113
+ new Sequence([
114
+ new Assignment(
115
+ new SymbolPrimitive("c"),
116
+ new ArithmeticBinaryOperation(
117
+ "Plus",
118
+ new SymbolPrimitive("a"),
119
+ new SymbolPrimitive("b")
120
+ )
121
+ ),
122
+ ]),
123
+ new Sequence([
124
+ new Assignment(
125
+ new SymbolPrimitive("c"),
126
+ new ArithmeticBinaryOperation(
127
+ "Multiply",
128
+ new SymbolPrimitive("a"),
129
+ new NumberPrimitive(2)
130
+ )
131
+ ),
132
+ ])
133
+ ),
134
+ ]);
135
+ });
136
+ it("should parse while loop statement", () => {
137
+ const code = `while (a < 10) { a := a + 1; };`;
138
+ assert.deepEqual(parser.parse(code), [
139
+ new While(
140
+ new ComparisonOperation(
141
+ "LessThan",
142
+ new SymbolPrimitive("a"),
143
+ new NumberPrimitive(10)
144
+ ),
145
+ new Sequence([
146
+ new Assignment(
147
+ new SymbolPrimitive("a"),
148
+ new ArithmeticBinaryOperation(
149
+ "Plus",
150
+ new SymbolPrimitive("a"),
151
+ new NumberPrimitive(1)
152
+ )
153
+ ),
154
+ ])
155
+ ),
156
+ ]);
157
+ });
158
+ });
package/tsconfig.json CHANGED
@@ -1,24 +1,27 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2024",
4
- "module": "NodeNext",
5
- "moduleResolution": "NodeNext",
6
- "lib": ["ES2024"],
7
- "outDir": "./dist",
8
- "declaration": true,
9
- "esModuleInterop": true,
10
- "allowSyntheticDefaultImports": true,
11
- "sourceMap": true,
12
- "forceConsistentCasingInFileNames": true,
13
- "skipLibCheck": true
14
- },
15
- "include": ["src"],
16
- "exclude": [
17
- "dist/**/*"
18
- ],
19
- "references": [
20
- {
21
- "path": "../yukigo-ast"
22
- }
23
- ]
24
- }
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2025",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "lib": ["ES2025"],
7
+ "outDir": "./dist",
8
+ "rootDir": "src",
9
+ "declaration": true,
10
+ "esModuleInterop": true,
11
+ "allowSyntheticDefaultImports": true,
12
+ "sourceMap": true,
13
+ "forceConsistentCasingInFileNames": true,
14
+ "skipLibCheck": true,
15
+ "allowJs": true,
16
+ "checkJs": false
17
+ },
18
+ "include": ["src"],
19
+ "exclude": [
20
+ "dist/**/*"
21
+ ],
22
+ "references": [
23
+ {
24
+ "path": "../yukigo-ast"
25
+ }
26
+ ]
27
+ }