Fix bug and improve syntax colors in Befunge

This commit is contained in:
Nilay Majorwar 2022-01-31 19:12:12 +05:30
parent 9d02b3f7dd
commit 82ec95f2dc
2 changed files with 8 additions and 6 deletions

View File

@ -75,5 +75,5 @@ export const editorTokensProvider: MonacoTokensProvider = {
[/[&~0-9]/, "turquoise"], [/[&~0-9]/, "turquoise"],
], ],
}, },
defaultToken: "comment", defaultToken: "plain",
}; };

View File

@ -74,7 +74,9 @@ export default class Befunge93LanguageEngine
} }
prepare(code: string, input: string) { prepare(code: string, input: string) {
this._ast = this.parseCode(code); const { grid, bounds } = this.parseCode(code);
this._ast = grid;
this._bounds = bounds;
this._edits = this.getGridPaddingEdits(code); this._edits = this.getGridPaddingEdits(code);
this._input = new InputStream(input); this._input = new InputStream(input);
} }
@ -130,14 +132,14 @@ export default class Befunge93LanguageEngine
const maxY = lines.length - 1; const maxY = lines.length - 1;
// Define bounds for each line and column // Define bounds for each line and column
for (let i = 0; i < COLSIZE; ++i) const bounds = DEFAULT_BOUNDS();
this._bounds.x[i] = lines[i]?.length - 1 || -1; for (let i = 0; i < COLSIZE; ++i) bounds.x[i] = lines[i]?.length - 1 || -1;
for (let j = 0; j < ROWSIZE; ++j) this._bounds.y[j] = j <= maxX ? maxY : -1; for (let j = 0; j < ROWSIZE; ++j) bounds.y[j] = j <= maxX ? maxY : -1;
// Pad the program to size 80x25 for execution // Pad the program to size 80x25 for execution
const grid = lines.map((line) => line.padEnd(80, " ")); const grid = lines.map((line) => line.padEnd(80, " "));
grid.push(...new Array(25 - lines.length).fill(" ".repeat(80))); grid.push(...new Array(25 - lines.length).fill(" ".repeat(80)));
return grid; return { grid, bounds };
} }
/** /**