LaravelTest
116 строк · 3.5 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4(function(mod) {5if (typeof exports == "object" && typeof module == "object") // CommonJS6mod(require("../../lib/codemirror"));7else if (typeof define == "function" && define.amd) // AMD8define(["../../lib/codemirror"], mod);9else // Plain browser env10mod(CodeMirror);11})(function(CodeMirror) {12"use strict";13
14CodeMirror.defineMode('z80', function(_config, parserConfig) {15var ez80 = parserConfig.ez80;16var keywords1, keywords2;17if (ez80) {18keywords1 = /^(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;19keywords2 = /^(((call|j[pr]|rst|ret[in]?)(\.([sl]?i)?[sl])?)|(rs|st)mix)\b/i;20} else {21keywords1 = /^(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;22keywords2 = /^(call|j[pr]|ret[in]?|b_?(call|jump))\b/i;23}24
25var variables1 = /^(af?|bc?|c|de?|e|hl?|l|i[xy]?|r|sp)\b/i;26var variables2 = /^(n?[zc]|p[oe]?|m)\b/i;27var errors = /^([hl][xy]|i[xy][hl]|slia|sll)\b/i;28var numbers = /^([\da-f]+h|[0-7]+o|[01]+b|\d+d?)\b/i;29
30return {31startState: function() {32return {33context: 034};35},36token: function(stream, state) {37if (!stream.column())38state.context = 0;39
40if (stream.eatSpace())41return null;42
43var w;44
45if (stream.eatWhile(/\w/)) {46if (ez80 && stream.eat('.')) {47stream.eatWhile(/\w/);48}49w = stream.current();50
51if (stream.indentation()) {52if ((state.context == 1 || state.context == 4) && variables1.test(w)) {53state.context = 4;54return 'var2';55}56
57if (state.context == 2 && variables2.test(w)) {58state.context = 4;59return 'var3';60}61
62if (keywords1.test(w)) {63state.context = 1;64return 'keyword';65} else if (keywords2.test(w)) {66state.context = 2;67return 'keyword';68} else if (state.context == 4 && numbers.test(w)) {69return 'number';70}71
72if (errors.test(w))73return 'error';74} else if (stream.match(numbers)) {75return 'number';76} else {77return null;78}79} else if (stream.eat(';')) {80stream.skipToEnd();81return 'comment';82} else if (stream.eat('"')) {83while (w = stream.next()) {84if (w == '"')85break;86
87if (w == '\\')88stream.next();89}90return 'string';91} else if (stream.eat('\'')) {92if (stream.match(/\\?.'/))93return 'number';94} else if (stream.eat('.') || stream.sol() && stream.eat('#')) {95state.context = 5;96
97if (stream.eatWhile(/\w/))98return 'def';99} else if (stream.eat('$')) {100if (stream.eatWhile(/[\da-f]/i))101return 'number';102} else if (stream.eat('%')) {103if (stream.eatWhile(/[01]/))104return 'number';105} else {106stream.next();107}108return null;109}110};111});112
113CodeMirror.defineMIME("text/x-z80", "z80");114CodeMirror.defineMIME("text/x-ez80", { name: "z80", ez80: true });115
116});117