Skip to content
Snippets Groups Projects
parse.ts 748 B
Newer Older
marihachi's avatar
marihachi committed
import inputLine, { InputCanceledError } from './misc/inputLine';
marihachi's avatar
marihachi committed
import { parse } from '..';
marihachi's avatar
marihachi committed

async function entryPoint() {
	console.log('intaractive parser');

	while (true) {
		let input: string;
		try {
			input = await inputLine('> ');
		}
		catch (err) {
			if (err instanceof InputCanceledError) {
				console.log('bye.');
				return;
			}
			throw err;
		}

		// replace special chars
		input = input
			.replace(/\\n/g, '\n')
marihachi's avatar
marihachi committed
			.replace(/\\t/g, '\t')
			.replace(/\\u00a0/g, '\u00a0');
marihachi's avatar
marihachi committed

		try {
			const result = parse(input);
marihachi's avatar
marihachi committed
			console.log(JSON.stringify(result));
		}
		catch (err) {
			console.log('parsing error:');
			console.log(err);
		}
		console.log();
	}
}
entryPoint()
.catch(err => {
	console.log(err);
	process.exit(1);
});