From 63fabf3ee30fb52b3f051bb17fbed5ea440575a9 Mon Sep 17 00:00:00 2001 From: Deep Thought <ti.42.plus@gmail.com> Date: Mon, 12 Nov 2012 09:38:59 +0100 Subject: [PATCH] Add z80 mode --- doc/compress.html | 1 + doc/realworld.html | 1 + index.html | 1 + mode/z80/index.html | 39 +++++++++++++++ mode/z80/z80.js | 113 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 155 insertions(+) create mode 100644 mode/z80/index.html create mode 100644 mode/z80/z80.js diff --git a/doc/compress.html b/doc/compress.html index 36c5702e..cdb339de 100644 --- a/doc/compress.html +++ b/doc/compress.html @@ -114,6 +114,7 @@ <option value="http://codemirror.net/mode/xml/xml.js">xml.js</option> <option value="http://codemirror.net/mode/xquery/xquery.js">xquery.js</option> <option value="http://codemirror.net/mode/yaml/yaml.js">yaml.js</option> + <option value="http://codemirror.net/mode/z80/z80.js">z80.js</option> </optgroup> <optgroup label="Utilities and add-ons"> <option value="http://codemirror.net/lib/util/overlay.js">overlay.js</option> diff --git a/doc/realworld.html b/doc/realworld.html index c08e7252..ed6b8203 100644 --- a/doc/realworld.html +++ b/doc/realworld.html @@ -53,6 +53,7 @@ <li><a href="http://www.chris-granger.com/2012/04/12/light-table---a-new-ide-concept/">Light Table</a> (experimental IDE)</li> <li><a href="http://www.mergely.com/">Mergely</a> (interactive diffing)</li> <li><a href="https://notex.ch">NoTex</a> (rST authoring)</li> + <li><a href="http://clrhome.org/asm/">ORG</a> (z80 assembly IDE)</li> <li><a href="https://github.com/mamacdon/orion-codemirror">Orion-CodeMirror integration</a> (running CodeMirror modes in Orion)</li> <li><a href="http://paperjs.org/">Paper.js</a> (graphics scripting)</li> <li><a href="http://prose.io/">Prose.io</a> (github content editor)</li> diff --git a/index.html b/index.html index 542f2eff..6f69d4f2 100644 --- a/index.html +++ b/index.html @@ -87,6 +87,7 @@ <li><a href="mode/xml/index.html">XML/HTML</a></li> <li><a href="mode/xquery/index.html">XQuery</a></li> <li><a href="mode/yaml/index.html">YAML</a></li> + <li><a href="mode/z80/index.html">Z80</a></li> </ul> </div><div class="left2 blk"> diff --git a/mode/z80/index.html b/mode/z80/index.html new file mode 100644 index 00000000..133c870e --- /dev/null +++ b/mode/z80/index.html @@ -0,0 +1,39 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <title>CodeMirror: Z80 assembly mode</title> + <link rel="stylesheet" href="../../lib/codemirror.css"> + <script src="../../lib/codemirror.js"></script> + <script src="z80.js"></script> + <link rel="stylesheet" href="../../doc/docs.css"> + <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> + </head> + <body> + <h1>CodeMirror: Z80 assembly mode</h1> + +<div><textarea id="code" name="code"> +#include "ti83plus.inc" +#define progStart $9D95 +.org progStart-2 +.db $BB,$6D + bcall(_ClrLCDFull) + ld HL, 0 + ld (PenCol), HL + ld HL, Message + bcall(_PutS) ; Displays the string + bcall(_NewLine) + ret +Message: +.db "Hello world!",0 +</textarea></div> + + <script> + var editor = CodeMirror.fromTextArea(document.getElementById("code"), { + lineNumbers: true + }); + </script> + + <p><strong>MIME type defined:</strong> <code>text/x-z80</code>.</p> + </body> +</html> diff --git a/mode/z80/z80.js b/mode/z80/z80.js new file mode 100644 index 00000000..c026790d --- /dev/null +++ b/mode/z80/z80.js @@ -0,0 +1,113 @@ +CodeMirror.defineMode('z80', function() +{ + var keywords1 = /^(exx?|(ld|cp|in)([di]r?)?|pop|push|ad[cd]|cpl|daa|dec|inc|neg|sbc|sub|and|bit|[cs]cf|x?or|res|set|r[lr]c?a?|r[lr]d|s[lr]a|srl|djnz|nop|rst|[de]i|halt|im|ot[di]r|out[di]?)\b/i; + var keywords2 = /^(call|j[pr]|ret[in]?)\b/i; + var keywords3 = /^b_?(call|jump)\b/i; + var variables1 = /^(af?|bc?|c|de?|e|hl?|l|i[xy]?|r|sp)\b/i; + var variables2 = /^(n?[zc]|p[oe]?|m)\b/i; + var errors = /^([hl][xy]|i[xy][hl]|slia|sll)\b/i; + var numbers = /^([\da-f]+h|[0-7]+o|[01]+b|\d+)\b/i; + + return {startState: function() + { + return {context: 0}; + }, token: function(stream, state) + { + if (!stream.column()) + state.context = 0; + + if (stream.eatSpace()) + return null; + + var w; + + if (stream.eatWhile(/\w/)) + { + w = stream.current(); + + if (stream.indentation()) + { + if (state.context == 1 && variables1.test(w)) + return 'variable-2'; + + if (state.context == 2 && variables2.test(w)) + return 'variable-3'; + + if (keywords1.test(w)) + { + state.context = 1; + return 'keyword'; + } + else if (keywords2.test(w)) + { + state.context = 2; + return 'keyword'; + } + else if (keywords3.test(w)) + { + state.context = 3; + return 'keyword'; + } + + if (errors.test(w)) + return 'error'; + } + else if (numbers.test(w)) + { + return 'number'; + } + else + { + return null; + } + } + else if (stream.eat(';')) + { + stream.skipToEnd(); + return 'comment'; + } + else if (stream.eat('"')) + { + while (w = stream.next()) + { + if (w == '"') + break; + + if (w == '\\') + stream.next(); + } + + return 'string'; + } + else if (stream.eat('\'')) + { + if (stream.match(/\\?.'/)) + return 'number'; + } + else if (stream.eat('.') || stream.sol() && stream.eat('#')) + { + state.context = 4; + + if (stream.eatWhile(/\w/)) + return 'def'; + } + else if (stream.eat('$')) + { + if (stream.eatWhile(/[\da-f]/i)) + return 'number'; + } + else if (stream.eat('%')) + { + if (stream.eatWhile(/[01]/)) + return 'number'; + } + else + { + stream.next(); + } + + return null; + }}; +}); + +CodeMirror.defineMIME("text/x-z80", "z80"); -- GitLab