@@ -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
144146test ( '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
214217test ( '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} ) ;
0 commit comments