Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for 6502 assembly #1245

Merged
merged 2 commits into from
Dec 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions components.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ var components = {
"title": "AsciiDoc",
"owner": "Golmote"
},
"asm6502": {
"title": "6502 Assembly",
"owner": "kzurawel"
},
"aspnet": {
"title": "ASP.NET (C#)",
"require": "markup",
Expand Down
28 changes: 28 additions & 0 deletions components/prism-asm6502.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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-fA-F]{2,4}/,
alias: 'string'
},
'binarynumber': {
pattern: /#?%[01]+/,
alias: 'string'
},
'decimalnumber': {
pattern: /#?\d+/,
alias: 'string'
},
'register': {
pattern: /\b[xyaXYA]\b/,
alias: 'variable'
}
};
1 change: 1 addition & 0 deletions components/prism-asm6502.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions examples/prism-asm6502.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<h1>6502 Assembly</h1>
<p>To use this language, use the class "language-asm6502".</p>

<h2>Comments</h2>
<pre><code>; This is a comment</code></pre>

<h2>Labels</h2>
<pre><code>label1: ; a label</code></pre>

<h2>Opcodes</h2>
<pre><code>
SEI
CLC

; lowercase
inx
bne label1
</code></pre>

<h2>Assembler directives</h2>
<pre><code>
.segment CODE
.word $07d3
</code></pre>

<h2>Registers</h2>
<pre><code>
ASL A ; "A"
LDA label1,x ; "x"
</code></pre>

<h2>Strings</h2>
<pre><code>
.include "header.asm"
</code></pre>

<h2>Numbers</h2>
<pre><code>
LDA #127
STA $80f0
LDY #%01011000
</code></pre>
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if (!Prism.plugins.toolbar) {
}

// The languages map is built automatically with gulp
var Languages = /*languages_placeholder[*/{"html":"HTML","xml":"XML","svg":"SVG","mathml":"MathML","css":"CSS","clike":"C-like","javascript":"JavaScript","abap":"ABAP","actionscript":"ActionScript","apacheconf":"Apache Configuration","apl":"APL","applescript":"AppleScript","asciidoc":"AsciiDoc","aspnet":"ASP.NET (C#)","autohotkey":"AutoHotkey","autoit":"AutoIt","basic":"BASIC","csharp":"C#","cpp":"C++","coffeescript":"CoffeeScript","css-extras":"CSS Extras","django":"Django/Jinja2","fsharp":"F#","glsl":"GLSL","graphql":"GraphQL","http":"HTTP","inform7":"Inform 7","json":"JSON","latex":"LaTeX","livescript":"LiveScript","lolcode":"LOLCODE","matlab":"MATLAB","mel":"MEL","n4js":"N4JS","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","opencl":"OpenCL","parigp":"PARI/GP","php":"PHP","php-extras":"PHP Extras","powershell":"PowerShell","properties":".properties","protobuf":"Protocol Buffers","jsx":"React JSX","renpy":"Ren'py","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","typescript":"TypeScript","vbnet":"VB.Net","vhdl":"VHDL","vim":"vim","wiki":"Wiki markup","xojo":"Xojo (REALbasic)","yaml":"YAML"}/*]*/;
var Languages = /*languages_placeholder[*/{"html":"HTML","xml":"XML","svg":"SVG","mathml":"MathML","css":"CSS","clike":"C-like","javascript":"JavaScript","abap":"ABAP","actionscript":"ActionScript","apacheconf":"Apache Configuration","apl":"APL","applescript":"AppleScript","asciidoc":"AsciiDoc","asm6502":"6502 Assembly","aspnet":"ASP.NET (C#)","autohotkey":"AutoHotkey","autoit":"AutoIt","basic":"BASIC","csharp":"C#","cpp":"C++","coffeescript":"CoffeeScript","css-extras":"CSS Extras","django":"Django/Jinja2","fsharp":"F#","glsl":"GLSL","graphql":"GraphQL","http":"HTTP","inform7":"Inform 7","json":"JSON","latex":"LaTeX","livescript":"LiveScript","lolcode":"LOLCODE","matlab":"MATLAB","mel":"MEL","n4js":"N4JS","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","opencl":"OpenCL","parigp":"PARI/GP","php":"PHP","php-extras":"PHP Extras","powershell":"PowerShell","properties":".properties","protobuf":"Protocol Buffers","jsx":"React JSX","renpy":"Ren'py","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","typescript":"TypeScript","vbnet":"VB.Net","vhdl":"VHDL","vim":"vim","wiki":"Wiki markup","xojo":"Xojo (REALbasic)","yaml":"YAML"}/*]*/;
Prism.plugins.toolbar.registerButton('show-language', function(env) {
var pre = env.element.parentNode;
if (!pre || !/pre/i.test(pre.nodeName)) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions tests/languages/asm6502/comment_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
;
; foo bar baz

-------------------------

[
["comment", ";"],
["comment", "; foo bar baz"]
]

-------------------------

Check for comments
12 changes: 12 additions & 0 deletions tests/languages/asm6502/directive_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.segment CODE

-------------------------

[
["directive", ".segment"],
" CODE"
]

-------------------------

Check for directives
18 changes: 18 additions & 0 deletions tests/languages/asm6502/number_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
LDA #127
STA $8000
LDX #%10001010

-------------------------

[
["opcode", "LDA"],
["decimalnumber", "#127"],
["opcode", "STA"],
["hexnumber", "$8000"],
["opcode", "LDX"],
["binarynumber", "#%10001010"]
]

-------------------------

Check for numbers
17 changes: 17 additions & 0 deletions tests/languages/asm6502/opcode_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
LDA
BNE
inx
clc

-------------------------------------

[
["opcode", "LDA"],
["opcode", "BNE"],
["opcode", "inx"],
["opcode", "clc"]
]

-------------------------------------

Check for opcodes
17 changes: 17 additions & 0 deletions tests/languages/asm6502/register_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
LDA $8000,x
ASL A

-------------------------

[
["opcode", "LDA"],
["hexnumber", "$8000"],
",",
["register", "x"],
["opcode", "ASL"],
["register", "A"]
]

-------------------------

Check for registers
12 changes: 12 additions & 0 deletions tests/languages/asm6502/string_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.include "header.asm"

-------------------------

[
["directive", ".include"],
["string", "\"header.asm\""]
]

-------------------------

Check for strings