Mercurial
comparison .cms/lib/codemirror/mode/z80/z80.js @ 0:78edf6b517a0 draft
24.10
author | Coffee CMS <info@coffee-cms.ru> |
---|---|
date | Fri, 11 Oct 2024 22:40:23 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:78edf6b517a0 |
---|---|
1 // CodeMirror, copyright (c) by Marijn Haverbeke and others | |
2 // Distributed under an MIT license: https://codemirror.net/5/LICENSE | |
3 | |
4 (function(mod) { | |
5 if (typeof exports == "object" && typeof module == "object") // CommonJS | |
6 mod(require("../../lib/codemirror")); | |
7 else if (typeof define == "function" && define.amd) // AMD | |
8 define(["../../lib/codemirror"], mod); | |
9 else // Plain browser env | |
10 mod(CodeMirror); | |
11 })(function(CodeMirror) { | |
12 "use strict"; | |
13 | |
14 CodeMirror.defineMode('z80', function(_config, parserConfig) { | |
15 var ez80 = parserConfig.ez80; | |
16 var keywords1, keywords2; | |
17 if (ez80) { | |
18 keywords1 = /^(exx?|(ld|cp)([di]r?)?|[lp]ea|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|[de]i|halt|im|in([di]mr?|ir?|irx|2r?)|ot(dmr?|[id]rx|imr?)|out(0?|[di]r?|[di]2r?)|tst(io)?|slp)(\.([sl]?i)?[sl])?\b/i; | |
19 keywords2 = /^(((call|j[pr]|rst|ret[in]?)(\.([sl]?i)?[sl])?)|(rs|st)mix)\b/i; | |
20 } else { | |
21 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; | |
22 keywords2 = /^(call|j[pr]|ret[in]?|b_?(call|jump))\b/i; | |
23 } | |
24 | |
25 var variables1 = /^(af?|bc?|c|de?|e|hl?|l|i[xy]?|r|sp)\b/i; | |
26 var variables2 = /^(n?[zc]|p[oe]?|m)\b/i; | |
27 var errors = /^([hl][xy]|i[xy][hl]|slia|sll)\b/i; | |
28 var numbers = /^([\da-f]+h|[0-7]+o|[01]+b|\d+d?)\b/i; | |
29 | |
30 return { | |
31 startState: function() { | |
32 return { | |
33 context: 0 | |
34 }; | |
35 }, | |
36 token: function(stream, state) { | |
37 if (!stream.column()) | |
38 state.context = 0; | |
39 | |
40 if (stream.eatSpace()) | |
41 return null; | |
42 | |
43 var w; | |
44 | |
45 if (stream.eatWhile(/\w/)) { | |
46 if (ez80 && stream.eat('.')) { | |
47 stream.eatWhile(/\w/); | |
48 } | |
49 w = stream.current(); | |
50 | |
51 if (stream.indentation()) { | |
52 if ((state.context == 1 || state.context == 4) && variables1.test(w)) { | |
53 state.context = 4; | |
54 return 'var2'; | |
55 } | |
56 | |
57 if (state.context == 2 && variables2.test(w)) { | |
58 state.context = 4; | |
59 return 'var3'; | |
60 } | |
61 | |
62 if (keywords1.test(w)) { | |
63 state.context = 1; | |
64 return 'keyword'; | |
65 } else if (keywords2.test(w)) { | |
66 state.context = 2; | |
67 return 'keyword'; | |
68 } else if (state.context == 4 && numbers.test(w)) { | |
69 return 'number'; | |
70 } | |
71 | |
72 if (errors.test(w)) | |
73 return 'error'; | |
74 } else if (stream.match(numbers)) { | |
75 return 'number'; | |
76 } else { | |
77 return null; | |
78 } | |
79 } else if (stream.eat(';')) { | |
80 stream.skipToEnd(); | |
81 return 'comment'; | |
82 } else if (stream.eat('"')) { | |
83 while (w = stream.next()) { | |
84 if (w == '"') | |
85 break; | |
86 | |
87 if (w == '\\') | |
88 stream.next(); | |
89 } | |
90 return 'string'; | |
91 } else if (stream.eat('\'')) { | |
92 if (stream.match(/\\?.'/)) | |
93 return 'number'; | |
94 } else if (stream.eat('.') || stream.sol() && stream.eat('#')) { | |
95 state.context = 5; | |
96 | |
97 if (stream.eatWhile(/\w/)) | |
98 return 'def'; | |
99 } else if (stream.eat('$')) { | |
100 if (stream.eatWhile(/[\da-f]/i)) | |
101 return 'number'; | |
102 } else if (stream.eat('%')) { | |
103 if (stream.eatWhile(/[01]/)) | |
104 return 'number'; | |
105 } else { | |
106 stream.next(); | |
107 } | |
108 return null; | |
109 } | |
110 }; | |
111 }); | |
112 | |
113 CodeMirror.defineMIME("text/x-z80", "z80"); | |
114 CodeMirror.defineMIME("text/x-ez80", { name: "z80", ez80: true }); | |
115 | |
116 }); |