From 349fc823faec00adc10e2c68421d4553bac8a85a Mon Sep 17 00:00:00 2001 From: Matt Godbolt Date: Sun, 3 Nov 2024 14:27:48 -0600 Subject: [PATCH] Handle `*COMMAND`s in the tokeniser Uses the new Monaco's ability to handle `\n` specially. Adds tests for the new capabilities. With thanks to microsoft/monaco-editor#2265 --- src/bbcbasic.js | 13 +++++++++++-- src/owlet.js | 5 +++++ test/bbcbasic_test.js | 33 ++++++++++++++++++++++++++++++--- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/bbcbasic.js b/src/bbcbasic.js index e5fca15..de30938 100644 --- a/src/bbcbasic.js +++ b/src/bbcbasic.js @@ -75,6 +75,7 @@ export function registerBbcBasicLanguage() { // Register a tokens provider for the language languages.setMonarchTokensProvider("BBCBASIC", { defaultToken: "invalid", + includeLF: true, brackets: [["(", ")", "delimiter.parenthesis"]], operators: [ "+", @@ -104,6 +105,14 @@ export function registerBbcBasicLanguage() { symbols: /[-+#=> { it("should not recognize 6502 outside of []", () => { checkTokens(["LDA"], [{offset: 0, type: "variable"}]); }); - it("should recognize 6502 inside []", () => { + it("should recognise 6502 inside []", () => { checkTokens( ["0[", "1LDA"], [ - {offset: 0, type: "enum"}, + {offset: 0, type: "constant.linenum"}, {offset: 1, type: "delimiter.square"}, ], [ - {offset: 0, type: "enum"}, + {offset: 0, type: "constant.linenum"}, {offset: 1, type: "keyword"}, ], ); @@ -355,11 +355,38 @@ describe("Tokenisation", () => { {offset: 8, type: "keyword"}, {offset: 12, type: "variable"}, {offset: 16, type: "symbol"}, + {offset: 17, type: "operator"}, {offset: 18, type: "keyword"}, {offset: 20, type: "variable"}, ], ); }); + it("should handle OSCLI at start of line", () => { + checkTokens(["*INFO"], [{offset: 0, type: "keyword.oscli"}]); + }); + it("should handle OSCLI after line number", () => { + checkTokens( + ["10 *INFO"], + [ + {offset: 0, type: "constant.linenum"}, + {offset: 2, type: "white"}, + {offset: 3, type: "keyword.oscli"}, + ], + ); + }); + it("should handle OSCLI at end of line", () => { + checkTokens( + ["P.2*3:*.0:blah"], + [ + {offset: 0, type: "keyword"}, + {offset: 2, type: "number"}, + {offset: 3, type: "operator"}, + {offset: 4, type: "number"}, + {offset: 5, type: "symbol"}, + {offset: 6, type: "keyword.oscli"}, + ], + ); + }); }); function checkWarnings(text, ...expected) {