ff43d32b529d9bbed755bfef18c832a1171c891d
[myslice.git] / third-party / codemirror-3.15 / mode / z80 / z80.js
1 CodeMirror.defineMode('z80', function() {
2   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;
3   var keywords2 = /^(call|j[pr]|ret[in]?)\b/i;
4   var keywords3 = /^b_?(call|jump)\b/i;
5   var variables1 = /^(af?|bc?|c|de?|e|hl?|l|i[xy]?|r|sp)\b/i;
6   var variables2 = /^(n?[zc]|p[oe]?|m)\b/i;
7   var errors = /^([hl][xy]|i[xy][hl]|slia|sll)\b/i;
8   var numbers = /^([\da-f]+h|[0-7]+o|[01]+b|\d+)\b/i;
9
10   return {
11     startState: function() {
12       return {context: 0};
13     },
14     token: function(stream, state) {
15       if (!stream.column())
16         state.context = 0;
17
18       if (stream.eatSpace())
19         return null;
20
21       var w;
22
23       if (stream.eatWhile(/\w/)) {
24         w = stream.current();
25
26         if (stream.indentation()) {
27           if (state.context == 1 && variables1.test(w))
28             return 'variable-2';
29
30           if (state.context == 2 && variables2.test(w))
31             return 'variable-3';
32
33           if (keywords1.test(w)) {
34             state.context = 1;
35             return 'keyword';
36           } else if (keywords2.test(w)) {
37             state.context = 2;
38             return 'keyword';
39           } else if (keywords3.test(w)) {
40             state.context = 3;
41             return 'keyword';
42           }
43
44           if (errors.test(w))
45             return 'error';
46         } else if (numbers.test(w)) {
47           return 'number';
48         } else {
49           return null;
50         }
51       } else if (stream.eat(';')) {
52         stream.skipToEnd();
53         return 'comment';
54       } else if (stream.eat('"')) {
55         while (w = stream.next()) {
56           if (w == '"')
57             break;
58
59           if (w == '\\')
60             stream.next();
61         }
62         return 'string';
63       } else if (stream.eat('\'')) {
64         if (stream.match(/\\?.'/))
65           return 'number';
66       } else if (stream.eat('.') || stream.sol() && stream.eat('#')) {
67         state.context = 4;
68
69         if (stream.eatWhile(/\w/))
70           return 'def';
71       } else if (stream.eat('$')) {
72         if (stream.eatWhile(/[\da-f]/i))
73           return 'number';
74       } else if (stream.eat('%')) {
75         if (stream.eatWhile(/[01]/))
76           return 'number';
77       } else {
78         stream.next();
79       }
80       return null;
81     }
82   };
83 });
84
85 CodeMirror.defineMIME("text/x-z80", "z80");