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