diff --git a/src/parse/cst-stream.ts b/src/parse/cst-stream.ts deleted file mode 100644 index 60542bcd..00000000 --- a/src/parse/cst-stream.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { Transform, TransformOptions } from 'stream' -import { StringDecoder } from 'string_decoder' -import { Parser } from './parser.js' - -export type ParseStreamOptions = Omit< - TransformOptions, - 'decodeStrings' | 'emitClose' | 'objectMode' -> - -export class CSTStream extends Transform { - decoder: StringDecoder - parser: Parser - - constructor(options: ParseStreamOptions = {}) { - super({ - ...options, - decodeStrings: false, - emitClose: true, - objectMode: true - }) - this.decoder = new StringDecoder(options.defaultEncoding || 'utf8') - this.parser = new Parser(token => this.push(token)) - } - - _flush(done: (error?: Error) => void) { - this.parser.parse('', false) - done() - } - - _transform(chunk: string | Buffer, _: any, done: (error?: Error) => void) { - try { - const src = Buffer.isBuffer(chunk) ? this.decoder.write(chunk) : chunk - this.parser.parse(src, true) - done() - } catch (error) { - done(error) // should never happen - } - } -} diff --git a/src/parse/test.ts b/src/parse/test.ts deleted file mode 100644 index 3a435a70..00000000 --- a/src/parse/test.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { CSTStream } from './cst-stream.js' -import { Parser } from './parser.js' - -export function stream(source: string) { - const ps = new CSTStream().on('data', d => console.dir(d, { depth: null })) - ps.write(source) - ps.end() -} - -export function test(source: string) { - const lines: number[] = [] - const parser = new Parser( - t => console.dir(t, { depth: null }), - n => lines.push(n) - ) - parser.parse(source) - console.log({ lines }) -}