From 929c33e0e0319a266bbf5e9d115d2348b1b83da1 Mon Sep 17 00:00:00 2001 From: Michael Schmidt Date: Mon, 22 Nov 2021 13:02:28 +0100 Subject: [PATCH] Asm6502: Use standard tokens and minor improvements (#3184) --- components/prism-asm6502.js | 23 +- components/prism-asm6502.min.js | 2 +- tests/languages/asm6502/number_feature.test | 15 +- tests/languages/asm6502/opcode_feature.test | 224 +++++++++--------- .../asm6502/punctuation_feature.test | 10 + tests/languages/asm6502/register_feature.test | 17 +- 6 files changed, 151 insertions(+), 140 deletions(-) create mode 100644 tests/languages/asm6502/punctuation_feature.test diff --git a/components/prism-asm6502.js b/components/prism-asm6502.js index 6ac8382cf3..2ff65836a6 100644 --- a/components/prism-asm6502.js +++ b/components/prism-asm6502.js @@ -2,27 +2,28 @@ Prism.languages.asm6502 = { 'comment': /;.*/, 'directive': { pattern: /\.\w+(?= )/, - alias: 'keyword' + alias: 'property' }, 'string': /(["'`])(?:\\.|(?!\1)[^\\\r\n])*\1/, - 'opcode': { + 'op-code': { pattern: /\b(?:ADC|AND|ASL|BCC|BCS|BEQ|BIT|BMI|BNE|BPL|BRK|BVC|BVS|CLC|CLD|CLI|CLV|CMP|CPX|CPY|DEC|DEX|DEY|EOR|INC|INX|INY|JMP|JSR|LDA|LDX|LDY|LSR|NOP|ORA|PHA|PHP|PLA|PLP|ROL|ROR|RTI|RTS|SBC|SEC|SED|SEI|STA|STX|STY|TAX|TAY|TSX|TXA|TXS|TYA|adc|and|asl|bcc|bcs|beq|bit|bmi|bne|bpl|brk|bvc|bvs|clc|cld|cli|clv|cmp|cpx|cpy|dec|dex|dey|eor|inc|inx|iny|jmp|jsr|lda|ldx|ldy|lsr|nop|ora|pha|php|pla|plp|rol|ror|rti|rts|sbc|sec|sed|sei|sta|stx|sty|tax|tay|tsx|txa|txs|tya)\b/, - alias: 'property' + alias: 'keyword' }, - 'hexnumber': { - pattern: /#?\$[\da-f]{2,4}\b/i, - alias: 'string' + 'hex-number': { + pattern: /#?\$[\da-f]{1,4}\b/i, + alias: 'number' }, - 'binarynumber': { + 'binary-number': { pattern: /#?%[01]+\b/, - alias: 'string' + alias: 'number' }, - 'decimalnumber': { + 'decimal-number': { pattern: /#?\b\d+\b/, - alias: 'string' + alias: 'number' }, 'register': { pattern: /\b[xya]\b/i, alias: 'variable' - } + }, + 'punctuation': /[(),:]/ }; diff --git a/components/prism-asm6502.min.js b/components/prism-asm6502.min.js index 7f0189aade..255cdc1938 100644 --- a/components/prism-asm6502.min.js +++ b/components/prism-asm6502.min.js @@ -1 +1 @@ -Prism.languages.asm6502={comment:/;.*/,directive:{pattern:/\.\w+(?= )/,alias:"keyword"},string:/(["'`])(?:\\.|(?!\1)[^\\\r\n])*\1/,opcode:{pattern:/\b(?:ADC|AND|ASL|BCC|BCS|BEQ|BIT|BMI|BNE|BPL|BRK|BVC|BVS|CLC|CLD|CLI|CLV|CMP|CPX|CPY|DEC|DEX|DEY|EOR|INC|INX|INY|JMP|JSR|LDA|LDX|LDY|LSR|NOP|ORA|PHA|PHP|PLA|PLP|ROL|ROR|RTI|RTS|SBC|SEC|SED|SEI|STA|STX|STY|TAX|TAY|TSX|TXA|TXS|TYA|adc|and|asl|bcc|bcs|beq|bit|bmi|bne|bpl|brk|bvc|bvs|clc|cld|cli|clv|cmp|cpx|cpy|dec|dex|dey|eor|inc|inx|iny|jmp|jsr|lda|ldx|ldy|lsr|nop|ora|pha|php|pla|plp|rol|ror|rti|rts|sbc|sec|sed|sei|sta|stx|sty|tax|tay|tsx|txa|txs|tya)\b/,alias:"property"},hexnumber:{pattern:/#?\$[\da-f]{2,4}\b/i,alias:"string"},binarynumber:{pattern:/#?%[01]+\b/,alias:"string"},decimalnumber:{pattern:/#?\b\d+\b/,alias:"string"},register:{pattern:/\b[xya]\b/i,alias:"variable"}}; \ No newline at end of file +Prism.languages.asm6502={comment:/;.*/,directive:{pattern:/\.\w+(?= )/,alias:"property"},string:/(["'`])(?:\\.|(?!\1)[^\\\r\n])*\1/,"op-code":{pattern:/\b(?:ADC|AND|ASL|BCC|BCS|BEQ|BIT|BMI|BNE|BPL|BRK|BVC|BVS|CLC|CLD|CLI|CLV|CMP|CPX|CPY|DEC|DEX|DEY|EOR|INC|INX|INY|JMP|JSR|LDA|LDX|LDY|LSR|NOP|ORA|PHA|PHP|PLA|PLP|ROL|ROR|RTI|RTS|SBC|SEC|SED|SEI|STA|STX|STY|TAX|TAY|TSX|TXA|TXS|TYA|adc|and|asl|bcc|bcs|beq|bit|bmi|bne|bpl|brk|bvc|bvs|clc|cld|cli|clv|cmp|cpx|cpy|dec|dex|dey|eor|inc|inx|iny|jmp|jsr|lda|ldx|ldy|lsr|nop|ora|pha|php|pla|plp|rol|ror|rti|rts|sbc|sec|sed|sei|sta|stx|sty|tax|tay|tsx|txa|txs|tya)\b/,alias:"keyword"},"hex-number":{pattern:/#?\$[\da-f]{1,4}\b/i,alias:"number"},"binary-number":{pattern:/#?%[01]+\b/,alias:"number"},"decimal-number":{pattern:/#?\b\d+\b/,alias:"number"},register:{pattern:/\b[xya]\b/i,alias:"variable"},punctuation:/[(),:]/}; \ No newline at end of file diff --git a/tests/languages/asm6502/number_feature.test b/tests/languages/asm6502/number_feature.test index 55262f67bd..7b5fd3b020 100644 --- a/tests/languages/asm6502/number_feature.test +++ b/tests/languages/asm6502/number_feature.test @@ -1,18 +1,17 @@ LDA #127 STA $8000 +STA #$1 LDX #%10001010 -------------------------- +---------------------------------------------------- [ - ["opcode", "LDA"], - ["decimalnumber", "#127"], - ["opcode", "STA"], - ["hexnumber", "$8000"], - ["opcode", "LDX"], - ["binarynumber", "#%10001010"] + ["op-code", "LDA"], ["decimal-number", "#127"], + ["op-code", "STA"], ["hex-number", "$8000"], + ["op-code", "STA"], ["hex-number", "#$1"], + ["op-code", "LDX"], ["binary-number", "#%10001010"] ] -------------------------- +---------------------------------------------------- Check for numbers diff --git a/tests/languages/asm6502/opcode_feature.test b/tests/languages/asm6502/opcode_feature.test index 8410fd2cbe..178d0179d6 100644 --- a/tests/languages/asm6502/opcode_feature.test +++ b/tests/languages/asm6502/opcode_feature.test @@ -114,118 +114,118 @@ TYA ---------------------------------------------------- [ - ["opcode", "adc"], - ["opcode", "and"], - ["opcode", "asl"], - ["opcode", "bcc"], - ["opcode", "bcs"], - ["opcode", "beq"], - ["opcode", "bit"], - ["opcode", "bmi"], - ["opcode", "bne"], - ["opcode", "bpl"], - ["opcode", "brk"], - ["opcode", "bvc"], - ["opcode", "bvs"], - ["opcode", "clc"], - ["opcode", "cld"], - ["opcode", "cli"], - ["opcode", "clv"], - ["opcode", "cmp"], - ["opcode", "cpx"], - ["opcode", "cpy"], - ["opcode", "dec"], - ["opcode", "dex"], - ["opcode", "dey"], - ["opcode", "eor"], - ["opcode", "inc"], - ["opcode", "inx"], - ["opcode", "iny"], - ["opcode", "jmp"], - ["opcode", "jsr"], - ["opcode", "lda"], - ["opcode", "ldx"], - ["opcode", "ldy"], - ["opcode", "lsr"], - ["opcode", "nop"], - ["opcode", "ora"], - ["opcode", "pha"], - ["opcode", "php"], - ["opcode", "pla"], - ["opcode", "plp"], - ["opcode", "rol"], - ["opcode", "ror"], - ["opcode", "rti"], - ["opcode", "rts"], - ["opcode", "sbc"], - ["opcode", "sec"], - ["opcode", "sed"], - ["opcode", "sei"], - ["opcode", "sta"], - ["opcode", "stx"], - ["opcode", "sty"], - ["opcode", "tax"], - ["opcode", "tay"], - ["opcode", "tsx"], - ["opcode", "txa"], - ["opcode", "txs"], - ["opcode", "tya"], - ["opcode", "ADC"], - ["opcode", "AND"], - ["opcode", "ASL"], - ["opcode", "BCC"], - ["opcode", "BCS"], - ["opcode", "BEQ"], - ["opcode", "BIT"], - ["opcode", "BMI"], - ["opcode", "BNE"], - ["opcode", "BPL"], - ["opcode", "BRK"], - ["opcode", "BVC"], - ["opcode", "BVS"], - ["opcode", "CLC"], - ["opcode", "CLD"], - ["opcode", "CLI"], - ["opcode", "CLV"], - ["opcode", "CMP"], - ["opcode", "CPX"], - ["opcode", "CPY"], - ["opcode", "DEC"], - ["opcode", "DEX"], - ["opcode", "DEY"], - ["opcode", "EOR"], - ["opcode", "INC"], - ["opcode", "INX"], - ["opcode", "INY"], - ["opcode", "JMP"], - ["opcode", "JSR"], - ["opcode", "LDA"], - ["opcode", "LDX"], - ["opcode", "LDY"], - ["opcode", "LSR"], - ["opcode", "NOP"], - ["opcode", "ORA"], - ["opcode", "PHA"], - ["opcode", "PHP"], - ["opcode", "PLA"], - ["opcode", "PLP"], - ["opcode", "ROL"], - ["opcode", "ROR"], - ["opcode", "RTI"], - ["opcode", "RTS"], - ["opcode", "SBC"], - ["opcode", "SEC"], - ["opcode", "SED"], - ["opcode", "SEI"], - ["opcode", "STA"], - ["opcode", "STX"], - ["opcode", "STY"], - ["opcode", "TAX"], - ["opcode", "TAY"], - ["opcode", "TSX"], - ["opcode", "TXA"], - ["opcode", "TXS"], - ["opcode", "TYA"] + ["op-code", "adc"], + ["op-code", "and"], + ["op-code", "asl"], + ["op-code", "bcc"], + ["op-code", "bcs"], + ["op-code", "beq"], + ["op-code", "bit"], + ["op-code", "bmi"], + ["op-code", "bne"], + ["op-code", "bpl"], + ["op-code", "brk"], + ["op-code", "bvc"], + ["op-code", "bvs"], + ["op-code", "clc"], + ["op-code", "cld"], + ["op-code", "cli"], + ["op-code", "clv"], + ["op-code", "cmp"], + ["op-code", "cpx"], + ["op-code", "cpy"], + ["op-code", "dec"], + ["op-code", "dex"], + ["op-code", "dey"], + ["op-code", "eor"], + ["op-code", "inc"], + ["op-code", "inx"], + ["op-code", "iny"], + ["op-code", "jmp"], + ["op-code", "jsr"], + ["op-code", "lda"], + ["op-code", "ldx"], + ["op-code", "ldy"], + ["op-code", "lsr"], + ["op-code", "nop"], + ["op-code", "ora"], + ["op-code", "pha"], + ["op-code", "php"], + ["op-code", "pla"], + ["op-code", "plp"], + ["op-code", "rol"], + ["op-code", "ror"], + ["op-code", "rti"], + ["op-code", "rts"], + ["op-code", "sbc"], + ["op-code", "sec"], + ["op-code", "sed"], + ["op-code", "sei"], + ["op-code", "sta"], + ["op-code", "stx"], + ["op-code", "sty"], + ["op-code", "tax"], + ["op-code", "tay"], + ["op-code", "tsx"], + ["op-code", "txa"], + ["op-code", "txs"], + ["op-code", "tya"], + ["op-code", "ADC"], + ["op-code", "AND"], + ["op-code", "ASL"], + ["op-code", "BCC"], + ["op-code", "BCS"], + ["op-code", "BEQ"], + ["op-code", "BIT"], + ["op-code", "BMI"], + ["op-code", "BNE"], + ["op-code", "BPL"], + ["op-code", "BRK"], + ["op-code", "BVC"], + ["op-code", "BVS"], + ["op-code", "CLC"], + ["op-code", "CLD"], + ["op-code", "CLI"], + ["op-code", "CLV"], + ["op-code", "CMP"], + ["op-code", "CPX"], + ["op-code", "CPY"], + ["op-code", "DEC"], + ["op-code", "DEX"], + ["op-code", "DEY"], + ["op-code", "EOR"], + ["op-code", "INC"], + ["op-code", "INX"], + ["op-code", "INY"], + ["op-code", "JMP"], + ["op-code", "JSR"], + ["op-code", "LDA"], + ["op-code", "LDX"], + ["op-code", "LDY"], + ["op-code", "LSR"], + ["op-code", "NOP"], + ["op-code", "ORA"], + ["op-code", "PHA"], + ["op-code", "PHP"], + ["op-code", "PLA"], + ["op-code", "PLP"], + ["op-code", "ROL"], + ["op-code", "ROR"], + ["op-code", "RTI"], + ["op-code", "RTS"], + ["op-code", "SBC"], + ["op-code", "SEC"], + ["op-code", "SED"], + ["op-code", "SEI"], + ["op-code", "STA"], + ["op-code", "STX"], + ["op-code", "STY"], + ["op-code", "TAX"], + ["op-code", "TAY"], + ["op-code", "TSX"], + ["op-code", "TXA"], + ["op-code", "TXS"], + ["op-code", "TYA"] ] ---------------------------------------------------- diff --git a/tests/languages/asm6502/punctuation_feature.test b/tests/languages/asm6502/punctuation_feature.test new file mode 100644 index 0000000000..b0a75ee6f6 --- /dev/null +++ b/tests/languages/asm6502/punctuation_feature.test @@ -0,0 +1,10 @@ +( ) , : + +---------------------------------------------------- + +[ + ["punctuation", "("], + ["punctuation", ")"], + ["punctuation", ","], + ["punctuation", ":"] +] diff --git a/tests/languages/asm6502/register_feature.test b/tests/languages/asm6502/register_feature.test index 91ec7c42be..10002bedc0 100644 --- a/tests/languages/asm6502/register_feature.test +++ b/tests/languages/asm6502/register_feature.test @@ -1,17 +1,18 @@ LDA $8000,x ASL A -------------------------- +---------------------------------------------------- [ - ["opcode", "LDA"], - ["hexnumber", "$8000"], - ",", - ["register", "x"], - ["opcode", "ASL"], - ["register", "A"] + ["op-code", "LDA"], + ["hex-number", "$8000"], + ["punctuation", ","], + ["register", "x"], + + ["op-code", "ASL"], + ["register", "A"] ] -------------------------- +---------------------------------------------------- Check for registers