diff --git a/src/bbcbasic.js b/src/bbcbasic.js index c9038f2..d45ac69 100644 --- a/src/bbcbasic.js +++ b/src/bbcbasic.js @@ -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", @@ -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/, diff --git a/test/bbcbasic_test.js b/test/bbcbasic_test.js index 667bef2..e7bb284 100644 --- a/test/bbcbasic_test.js +++ b/test/bbcbasic_test.js @@ -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"}]);