Skip to content

Commit

Permalink
Highlight DATA statement contents better (#128)
Browse files Browse the repository at this point in the history
Fixes #43
  • Loading branch information
ojwb authored Jan 27, 2025
1 parent 68fc71a commit 085dda4
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/bbcbasic.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export function registerBbcBasicLanguage() {
[":", "symbol", "@pop"],
[/(\bREM|\xf4)/, {token: "keyword", next: "@remStatement"}], // A REM consumes to EOL
[/(FN|PROC|PRO\.|\xa4|\xf2)/, {token: "keyword", next: "@fnProcName"}],
[/(\bDATA|\bDAT\.|\bDA\.|\bD\.|\xdc)/, {token: "keyword", next: "@dataStatement"}], // DATA consumes to EOL
[
/THEN|THE\.|TH\.|ELSE|ELS\.|EL\.|ERROR|ERRO\.|ERR\.|\u018c|\u018b|\u0185/,
"keyword",
Expand Down Expand Up @@ -177,6 +178,13 @@ export function registerBbcBasicLanguage() {
[/["\u201c\u201d]/, {token: "string.quote", next: "@pop"}],
],
remStatement: [[/.*/, "comment", "@pop"]],
dataStatement: [
[/(?=\n)/, "", "@pop"],
[",", "symbol"],
{include: "@whitespace"},
[/["\u201c\u201d]/, {token: "string.quote", next: "@string"}],
[/[^,\n]*[^,\n ]/, "string.unquoted"],
],
asm: [
[
/ADC|AND|ASL|B(CC|CS|EQ|MI|NE|PL|VC|VS)|BIT|BRK|CL[CDIV]|CMP|CP[XY]|DE[CXY]|EOR|IN[CXY]|JMP|JSR|LD[AXY]|LSR|NOP|ORA|PH[AP]|PL[AP]|RO[LR]|RTI|RTS|SBC|SE[CDI]|ST[AXY]|TA[XY]|TSX|TX[AS]|TYA/,
Expand Down
58 changes: 58 additions & 0 deletions test/bbcbasic_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,64 @@ describe("Tokenisation", () => {
[{offset: 0, type: "keyword"}],
);
});
it("should suitably highlight DATA statements", () => {
checkTokens(
[
"DATA",
"D.a b,c",
"DA.,,,7,",
"DAT.PI,COS0,SQRLN@%",
"DATA3 ,\"comma,quoted\", \"esc\"\"ape\", qu\"te,q\", 3x",
],
[
{offset: 0, type: "keyword"},
],
[
{offset: 0, type: "keyword"},
{offset: 2, type: "string.unquoted"},
{offset: 5, type: "symbol"},
{offset: 6, type: "string.unquoted"},
],
[
{offset: 0, type: "keyword"},
{offset: 3, type: "symbol"},
{offset: 6, type: "string.unquoted"},
{offset: 7, type: "symbol"},
],
[
{offset: 0, type: "keyword"},
{offset: 4, type: "string.unquoted"},
{offset: 6, type: "symbol"},
{offset: 7, type: "string.unquoted"},
{offset: 11, type: "symbol"},
{offset: 12, type: "string.unquoted"},
],
[
{offset: 0, type: "keyword"},
{offset: 4, type: "string.unquoted"},
{offset: 5, type: "white"},
{offset: 6, type: "symbol"},
{offset: 7, type: "string.quote"},
{offset: 8, type: "string"},
{offset: 20, type: "string.quote"},
{offset: 21, type: "symbol"},
{offset: 22, type: "white"},
{offset: 23, type: "string.quote"},
{offset: 24, type: "string"},
{offset: 27, type: "string.quote"},
{offset: 29, type: "string"},
{offset: 32, type: "string.quote"},
{offset: 33, type: "symbol"},
{offset: 34, type: "white"},
{offset: 35, type: "string.unquoted"},
{offset: 40, type: "symbol"},
{offset: 41, type: "string.unquoted"},
{offset: 43, type: "symbol"},
{offset: 44, type: "white"},
{offset: 45, type: "string.unquoted"},
],
);
});
it("should handle symbols and operators", () => {
checkTokens(["~"], [{offset: 0, type: "operator"}]);
checkTokens(["#"], [{offset: 0, type: "symbol"}]);
Expand Down

0 comments on commit 085dda4

Please sign in to comment.