@@ -19,7 +19,7 @@ import {Bench} from 'tinybench';
1919import { Grammar } from 'ohm-js' ;
2020import { compileGrammars } from '../src/api.ts' ;
2121import { unparse } from '../test/_helpers.js' ;
22- import { createReader , CstNodeType } from '../../runtime/src/cstReader .ts' ;
22+ import { CstNodeType } from '../../runtime/src/cstView .ts' ;
2323
2424const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
2525const datadir = join ( __dirname , '../test/data' ) ;
@@ -35,7 +35,7 @@ const positionalArgs = process.argv.slice(2).filter(a => !a.startsWith('--'));
3535// https://matklad.github.io/2024/03/22/basic-things.html
3636const smallSize = flags . has ( '--small-size' ) ;
3737const includeUnparse = flags . has ( '--include-unparse' ) ;
38- const useCstReader = flags . has ( '--cst-reader ' ) ;
38+ const useCstView = flags . has ( '--cst-view ' ) ;
3939
4040// Get pattern from command line arguments
4141const pattern = positionalArgs [ 0 ] ;
@@ -104,26 +104,26 @@ const pattern = positionalArgs[0];
104104 opts
105105 ) ;
106106
107- // Walk CST using CstReader , collecting terminal text.
108- function unparseCstReader ( matchResult ) {
109- const reader = createReader ( matchResult ) ;
107+ // Walk CST using CstView , collecting terminal text.
108+ function unparseCstView ( matchResult ) {
109+ const cst = matchResult . cstView ( ) ;
110110 let ans = '' ;
111111 function walk ( handle ) {
112- if ( reader . type ( handle ) === CstNodeType . TERMINAL ) {
113- ans += reader . sourceString ( handle ) ;
112+ if ( cst . type ( handle ) === CstNodeType . TERMINAL ) {
113+ ans += cst . sourceString ( handle ) ;
114114 return ;
115115 }
116- reader . forEachChild ( handle , ( child , _leadingSpaces ) => {
116+ cst . forEachChild ( handle , ( child , _leadingSpaces ) => {
117117 walk ( child ) ;
118118 } ) ;
119119 }
120- walk ( reader . root ) ;
120+ walk ( cst . root ) ;
121121 return ans ;
122122 }
123123
124124 const wasmLabel = includeUnparse ? 'Wasm parse+unparse' : 'Wasm parse' ;
125125 bench . add (
126- useCstReader ? `${ wasmLabel } (CstReader )` : wasmLabel ,
126+ useCstView ? `${ wasmLabel } (CstView )` : wasmLabel ,
127127 ( ) => {
128128 let overriddenDuration = 0 ;
129129 for ( const { input} of files ) {
@@ -140,7 +140,7 @@ const pattern = positionalArgs[0];
140140 peakWasmMemoryBytes ,
141141 exports . memory . buffer . byteLength
142142 ) ;
143- return useCstReader ? unparseCstReader ( m ) : unparse ( g ) ;
143+ return useCstView ? unparseCstView ( m ) : unparse ( g ) ;
144144 } ) ;
145145 if ( includeUnparse ) overriddenDuration += bench . now ( ) - start ;
146146 }
0 commit comments