This commit is contained in:
nora 2022-05-16 12:32:10 +02:00
parent 54b5c9b1f8
commit deefc18959
3 changed files with 7 additions and 5 deletions

2
js/.gitignore vendored
View file

@ -1,2 +1,2 @@
node_modules node_modules
.idea .idea

3
js/fizzbuzz.bf vendored
View file

@ -1,2 +1 @@
hello...[[].]]
++[-].

View file

@ -1,5 +1,8 @@
import fs from 'fs/promises'; import fs from 'fs/promises';
const RED = '\x1B[1;31m';
const RESET = '\x1B[1;0m';
function lex(string) { function lex(string) {
const tokens = []; const tokens = [];
@ -83,9 +86,9 @@ function reportError(source, message, span) {
const linePrefix = `${lineNumber} | `; const linePrefix = `${lineNumber} | `;
const lineSpan = span - lastNewlineIdx; const lineSpan = span - lastNewlineIdx;
console.error(`error: ${message}`); console.error(`${RED}error: ${message}${RESET}`);
console.error(`${linePrefix}${line}`); console.error(`${linePrefix}${line}`);
console.error(`${' '.repeat(linePrefix.length)}${'-'.repeat(lineSpan)}^`); console.error(`${' '.repeat(linePrefix.length + lineSpan)}${RED}^${RESET}`);
} }
const file = process.argv[2]; const file = process.argv[2];