Skip to content

Commit 68aa348

Browse files
committed
style: πŸ’„ run Prettier
1 parent 656c223 commit 68aa348

File tree

7 files changed

+153
-213
lines changed

7 files changed

+153
-213
lines changed

β€Žsrc/__tests__/debug.spec.tsβ€Ž

Lines changed: 85 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ test('can capture terminal debug information', () => {
1414
};
1515
const codegen = new CodegenGrammar(grammar, new CodegenContext(true, true, true));
1616
const parser = codegen.compile();
17-
const rootTraceNode: RootTraceNode = {pos: 0, children: []}
17+
const rootTraceNode: RootTraceNode = {pos: 0, children: []};
1818
const ctx = new ParseContext('value', false, [rootTraceNode]);
1919
parser(ctx, 0);
2020
expect(rootTraceNode).toMatchObject({
@@ -38,28 +38,30 @@ test('can capture debug trace in production node', () => {
3838
};
3939
const codegen = new CodegenGrammar(grammar, new CodegenContext(true, true, true));
4040
const parser = codegen.compile();
41-
const rootTraceNode: RootTraceNode = {pos: 0, children: []}
41+
const rootTraceNode: RootTraceNode = {pos: 0, children: []};
4242
const ctx = new ParseContext('{value}', false, [rootTraceNode]);
4343
parser(ctx, 0);
4444
expect(rootTraceNode).toMatchObject({
4545
pos: 0,
46-
children: [{
47-
pos: 0,
48-
children: [
49-
{
50-
pos: 0,
51-
match: {pos: 0, end: 1},
52-
},
53-
{
54-
pos: 1,
55-
match: {pos: 1, end: 6},
56-
},
57-
{
58-
pos: 6,
59-
match: {pos: 6, end: 7},
60-
},
61-
],
62-
}],
46+
children: [
47+
{
48+
pos: 0,
49+
children: [
50+
{
51+
pos: 0,
52+
match: {pos: 0, end: 1},
53+
},
54+
{
55+
pos: 1,
56+
match: {pos: 1, end: 6},
57+
},
58+
{
59+
pos: 6,
60+
match: {pos: 6, end: 7},
61+
},
62+
],
63+
},
64+
],
6365
});
6466
});
6567

@@ -68,36 +70,34 @@ test('can capture debug trace in union node', () => {
6870
start: 'Value',
6971
cst: {
7072
Value: {
71-
u: [
72-
'var',
73-
'let',
74-
'const',
75-
],
73+
u: ['var', 'let', 'const'],
7674
},
7775
},
7876
};
7977
const codegen = new CodegenGrammar(grammar, new CodegenContext(true, true, true));
8078
const parser = codegen.compile();
81-
const rootTraceNode: RootTraceNode = {pos: 0, children: []}
79+
const rootTraceNode: RootTraceNode = {pos: 0, children: []};
8280
const ctx = new ParseContext('const', false, [rootTraceNode]);
8381
parser(ctx, 0);
8482
expect(rootTraceNode).toMatchObject({
8583
pos: 0,
86-
children: [{
87-
pos: 0,
88-
children: [
89-
{
90-
pos: 0,
91-
},
92-
{
93-
pos: 0,
94-
},
95-
{
96-
pos: 0,
97-
match: {pos: 0, end: 5},
98-
},
99-
],
100-
}],
84+
children: [
85+
{
86+
pos: 0,
87+
children: [
88+
{
89+
pos: 0,
90+
},
91+
{
92+
pos: 0,
93+
},
94+
{
95+
pos: 0,
96+
match: {pos: 0, end: 5},
97+
},
98+
],
99+
},
100+
],
101101
});
102102
});
103103

@@ -112,45 +112,47 @@ test('can capture debug trace in list node', () => {
112112
};
113113
const codegen = new CodegenGrammar(grammar, new CodegenContext(true, true, true));
114114
const parser = codegen.compile();
115-
const rootTraceNode: RootTraceNode = {pos: 0, children: []}
115+
const rootTraceNode: RootTraceNode = {pos: 0, children: []};
116116
const ctx = new ParseContext('aaa', false, [rootTraceNode]);
117117
parser(ctx, 0);
118118
expect(rootTraceNode).toMatchObject({
119119
pos: 0,
120-
children: [{
121-
pos: 0,
122-
children: [
123-
{
124-
pos: 0,
125-
match: {pos: 0, end: 1},
126-
},
127-
{
128-
pos: 1,
129-
match: {pos: 1, end: 2},
130-
},
131-
{
132-
pos: 2,
133-
match: {pos: 2, end: 3},
134-
},
135-
{
136-
pos: 3,
137-
},
138-
],
139-
match: {pos: 0, end: 3},
140-
}],
120+
children: [
121+
{
122+
pos: 0,
123+
children: [
124+
{
125+
pos: 0,
126+
match: {pos: 0, end: 1},
127+
},
128+
{
129+
pos: 1,
130+
match: {pos: 1, end: 2},
131+
},
132+
{
133+
pos: 2,
134+
match: {pos: 2, end: 3},
135+
},
136+
{
137+
pos: 3,
138+
},
139+
],
140+
match: {pos: 0, end: 3},
141+
},
142+
],
141143
});
142144
});
143145

144146
test('can capture JSON grammar trace', () => {
145147
const codegen = new CodegenGrammar(jsonGrammar, new CodegenContext(true, true, true));
146148
const parser = codegen.compile();
147-
const rootTraceNode: RootTraceNode = {pos: 0, children: []}
149+
const rootTraceNode: RootTraceNode = {pos: 0, children: []};
148150
const json = ' {"foo": ["bar", 123]}';
149151
const ctx = new ParseContext(json, false, [rootTraceNode]);
150152
parser(ctx, 0);
151153
const formatted = printTraceNode(rootTraceNode, '', json);
152154
expect(formatted).toBe(
153-
`Root
155+
`Root
154156
└─ Value 0:22 β†’ ' {"foo": ["bar", 123]}'
155157
β”œβ”€ WOpt 0:1 β†’ " "
156158
β”œβ”€ TValue 1:22 β†’ '{"foo": ["bar", 123]}'
@@ -208,21 +210,30 @@ test('can capture JSON grammar trace', () => {
208210
β”‚ β”‚ └─ Production
209211
β”‚ β”‚ └─ Text
210212
β”‚ └─ Text 21:22 β†’ "}"
211-
└─ WOpt 22:22 β†’ ""`);
213+
└─ WOpt 22:22 β†’ ""`,
214+
);
212215
});
213216

214217
test('can capture two partial routes', () => {
215218
const grammar: Grammar = {
216219
start: 'Program',
217220
cst: {
218221
Program: {
219-
u: [
220-
{r: 'Object'},
221-
{r: 'BlockStatement'},
222-
],
222+
u: [{r: 'Object'}, {r: 'BlockStatement'}],
223223
},
224224
Whitespace: {t: [' '], repeat: '*'},
225-
Object: ['{', {r: 'Whitespace'}, {r: 'Key'}, {r: 'Whitespace'}, ':', {r: 'Whitespace'}, {r: 'Value'}, {r: 'Whitespace'}, '}', ';'],
225+
Object: [
226+
'{',
227+
{r: 'Whitespace'},
228+
{r: 'Key'},
229+
{r: 'Whitespace'},
230+
':',
231+
{r: 'Whitespace'},
232+
{r: 'Value'},
233+
{r: 'Whitespace'},
234+
'}',
235+
';',
236+
],
226237
Key: 'abc',
227238
Value: '123',
228239
BlockStatement: ['{', {r: 'Whitespace'}, {r: 'ID'}, '()', ';', {r: 'Whitespace'}, '}'],
@@ -231,13 +242,13 @@ test('can capture two partial routes', () => {
231242
};
232243
const codegen = new CodegenGrammar(grammar, new CodegenContext(true, true, true));
233244
const parser = codegen.compile();
234-
const rootTraceNode: RootTraceNode = {pos: 0, children: []}
245+
const rootTraceNode: RootTraceNode = {pos: 0, children: []};
235246
const text = '{ abc: 123 bd };';
236247
const ctx = new ParseContext(text, false, [rootTraceNode]);
237248
parser(ctx, 0);
238249
const trace = printTraceNode(rootTraceNode.children[0], '', text);
239250
expect(trace).toBe(
240-
`Program
251+
`Program
241252
β”œβ”€ Object
242253
β”‚ β”œβ”€ Text 0:1 β†’ "{"
243254
β”‚ β”œβ”€ Whitespace 1:2 β†’ " "
@@ -252,5 +263,6 @@ test('can capture two partial routes', () => {
252263
β”œβ”€ Text 0:1 β†’ "{"
253264
β”œβ”€ Whitespace 1:2 β†’ " "
254265
β”œβ”€ ID 2:5 β†’ "abc"
255-
└─ Text`);
266+
└─ Text`,
267+
);
256268
});

β€Žsrc/__tests__/generator.spec.tsβ€Ž

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import {Generator} from '../generator';
22
import {grammar as jsonGrammar} from '../grammars/json';
33
import {grammar as esqlGrammar} from '../grammars/esql';
44

5-
const generator = () => new Generator({
6-
grammar: jsonGrammar,
7-
useSamples: true,
8-
});
5+
const generator = () =>
6+
new Generator({
7+
grammar: jsonGrammar,
8+
useSamples: true,
9+
});
910

1011
test('can generate string terminal', () => {
1112
const res = generator().genTerminal('null');

β€Žsrc/__tests__/print.spec.tsβ€Ž

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ describe('GrammarPrinter', () => {
3333
cst: {
3434
Prod: {
3535
p: ['{', '}'],
36-
}
36+
},
3737
},
3838
};
3939
const result = GrammarPrinter.print(grammar);
4040
expect(result).toBe(
41-
`Prod (production)
41+
`Prod (production)
4242
β”œβ”€ Text (terminal): "{"
43-
└─ Text (terminal): "}"`);
43+
└─ Text (terminal): "}"`,
44+
);
4445
});
4546

4647
test('can print a production shorthand node', () => {
@@ -52,25 +53,27 @@ describe('GrammarPrinter', () => {
5253
};
5354
const result = GrammarPrinter.print(grammar);
5455
expect(result).toBe(
55-
`Prod (production)
56+
`Prod (production)
5657
β”œβ”€ Text (terminal): "{"
57-
└─ Text (terminal): "}"`);
58+
└─ Text (terminal): "}"`,
59+
);
5860
});
5961

6062
test('can print a union node', () => {
6163
const grammar: Grammar = {
6264
start: 'U',
6365
cst: {
6466
U: {
65-
u: ['{', '}']
66-
}
67+
u: ['{', '}'],
68+
},
6769
},
6870
};
6971
const result = GrammarPrinter.print(grammar);
7072
expect(result).toBe(
71-
`U (union)
73+
`U (union)
7274
β”œβ”€ Text (terminal): "{"
73-
└─ Text (terminal): "}"`);
75+
└─ Text (terminal): "}"`,
76+
);
7477
});
7578

7679
test('can print a list node', () => {
@@ -79,13 +82,14 @@ describe('GrammarPrinter', () => {
7982
cst: {
8083
L: {
8184
l: 'a',
82-
}
85+
},
8386
},
8487
};
8588
const result = GrammarPrinter.print(grammar);
8689
expect(result).toBe(
87-
`L (list)
88-
└─ Text (terminal): "a"`);
90+
`L (list)
91+
└─ Text (terminal): "a"`,
92+
);
8993
});
9094

9195
test('can print a reference node', () => {
@@ -98,8 +102,9 @@ describe('GrammarPrinter', () => {
98102
};
99103
const result = GrammarPrinter.print(grammar);
100104
expect(result).toBe(
101-
`Start (reference)
102-
└─ ws (terminal): /\\s+/`);
105+
`Start (reference)
106+
└─ ws (terminal): /\\s+/`,
107+
);
103108
});
104109

105110
test('can print recursive grammar', () => {
@@ -116,7 +121,7 @@ describe('GrammarPrinter', () => {
116121
test('JSON', () => {
117122
const result = GrammarPrinter.print(jsonGrammar);
118123
expect(result).toBe(
119-
`Value (production)
124+
`Value (production)
120125
β”œβ”€ WOpt (terminal): (" " | "\\n" | "\\t" | "\\r")*
121126
β”œβ”€ TValue (union)
122127
β”‚ β”œβ”€ Null (terminal): "null"
@@ -150,7 +155,8 @@ describe('GrammarPrinter', () => {
150155
β”‚ β”‚ β”‚ └─ β†’ WOpt
151156
β”‚ β”‚ └─ Text (terminal): "]"
152157
β”‚ └─ Number (terminal): /\\-?(0|([1-9][0-9]{0,25}))(\\.[0-9]{1,25})?([eE][\\+\\\-]?[0-9]{1,25})?/
153-
└─ β†’ WOpt`);
158+
└─ β†’ WOpt`,
159+
);
154160
});
155161
});
156162

@@ -162,7 +168,7 @@ describe('printCst()', () => {
162168
const cst = parser(ctx, 0);
163169
const formatted = printCst(cst!, '', json);
164170
expect(formatted).toBe(
165-
`Value 0:22 β†’ ' {"foo": ["bar", 123]}'
171+
`Value 0:22 β†’ ' {"foo": ["bar", 123]}'
166172
β”œβ”€ WOpt 0:1 β†’ " "
167173
β”œβ”€ TValue 1:22 β†’ '{"foo": ["bar", 123]}'
168174
β”‚ └─ Object 1:22 β†’ '{"foo": ["bar", 123]}'
@@ -198,6 +204,7 @@ describe('printCst()', () => {
198204
β”‚ β”‚ β”‚ └─ WOpt 21:21 β†’ ""
199205
β”‚ β”‚ └─ List 21:21 β†’ ""
200206
β”‚ └─ Text 21:22 β†’ "}"
201-
└─ WOpt 22:22 β†’ ""`);
207+
└─ WOpt 22:22 β†’ ""`,
208+
);
202209
});
203210
});

0 commit comments

Comments
Β (0)