LaravelTest
180 строк · 5.1 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4// Author: Aliaksei Chapyzhenka
5
6(function(mod) {7if (typeof exports == "object" && typeof module == "object") // CommonJS8mod(require("../../lib/codemirror"));9else if (typeof define == "function" && define.amd) // AMD10define(["../../lib/codemirror"], mod);11else // Plain browser env12mod(CodeMirror);13})(function(CodeMirror) {14"use strict";15
16function toWordList(words) {17var ret = [];18words.split(' ').forEach(function(e){19ret.push({name: e});20});21return ret;22}23
24var coreWordList = toWordList(25'INVERT AND OR XOR\
262* 2/ LSHIFT RSHIFT\
270= = 0< < > U< MIN MAX\
282DROP 2DUP 2OVER 2SWAP ?DUP DEPTH DROP DUP OVER ROT SWAP\
29>R R> R@\
30+ - 1+ 1- ABS NEGATE\
31S>D * M* UM*\
32FM/MOD SM/REM UM/MOD */ */MOD / /MOD MOD\
33HERE , @ ! CELL+ CELLS C, C@ C! CHARS 2@ 2!\
34ALIGN ALIGNED +! ALLOT\
35CHAR [CHAR] [ ] BL\
36FIND EXECUTE IMMEDIATE COUNT LITERAL STATE\
37; DOES> >BODY\
38EVALUATE\
39SOURCE >IN\
40<# # #S #> HOLD SIGN BASE >NUMBER HEX DECIMAL\
41FILL MOVE\
42. CR EMIT SPACE SPACES TYPE U. .R U.R\
43ACCEPT\
44TRUE FALSE\
45<> U> 0<> 0>\
46NIP TUCK ROLL PICK\
472>R 2R@ 2R>\
48WITHIN UNUSED MARKER\
49I J\
50TO\
51COMPILE, [COMPILE]\
52SAVE-INPUT RESTORE-INPUT\
53PAD ERASE\
542LITERAL DNEGATE\
55D- D+ D0< D0= D2* D2/ D< D= DMAX DMIN D>S DABS\
56M+ M*/ D. D.R 2ROT DU<\
57CATCH THROW\
58FREE RESIZE ALLOCATE\
59CS-PICK CS-ROLL\
60GET-CURRENT SET-CURRENT FORTH-WORDLIST GET-ORDER SET-ORDER\
61PREVIOUS SEARCH-WORDLIST WORDLIST FIND ALSO ONLY FORTH DEFINITIONS ORDER\
62-TRAILING /STRING SEARCH COMPARE CMOVE CMOVE> BLANK SLITERAL');63
64var immediateWordList = toWordList('IF ELSE THEN BEGIN WHILE REPEAT UNTIL RECURSE [IF] [ELSE] [THEN] ?DO DO LOOP +LOOP UNLOOP LEAVE EXIT AGAIN CASE OF ENDOF ENDCASE');65
66CodeMirror.defineMode('forth', function() {67function searchWordList (wordList, word) {68var i;69for (i = wordList.length - 1; i >= 0; i--) {70if (wordList[i].name === word.toUpperCase()) {71return wordList[i];72}73}74return undefined;75}76return {77startState: function() {78return {79state: '',80base: 10,81coreWordList: coreWordList,82immediateWordList: immediateWordList,83wordList: []84};85},86token: function (stream, stt) {87var mat;88if (stream.eatSpace()) {89return null;90}91if (stt.state === '') { // interpretation92if (stream.match(/^(\]|:NONAME)(\s|$)/i)) {93stt.state = ' compilation';94return 'builtin compilation';95}96mat = stream.match(/^(\:)\s+(\S+)(\s|$)+/);97if (mat) {98stt.wordList.push({name: mat[2].toUpperCase()});99stt.state = ' compilation';100return 'def' + stt.state;101}102mat = stream.match(/^(VARIABLE|2VARIABLE|CONSTANT|2CONSTANT|CREATE|POSTPONE|VALUE|WORD)\s+(\S+)(\s|$)+/i);103if (mat) {104stt.wordList.push({name: mat[2].toUpperCase()});105return 'def' + stt.state;106}107mat = stream.match(/^(\'|\[\'\])\s+(\S+)(\s|$)+/);108if (mat) {109return 'builtin' + stt.state;110}111} else { // compilation112// ; [113if (stream.match(/^(\;|\[)(\s)/)) {114stt.state = '';115stream.backUp(1);116return 'builtin compilation';117}118if (stream.match(/^(\;|\[)($)/)) {119stt.state = '';120return 'builtin compilation';121}122if (stream.match(/^(POSTPONE)\s+\S+(\s|$)+/)) {123return 'builtin';124}125}126
127// dynamic wordlist128mat = stream.match(/^(\S+)(\s+|$)/);129if (mat) {130if (searchWordList(stt.wordList, mat[1]) !== undefined) {131return 'variable' + stt.state;132}133
134// comments135if (mat[1] === '\\') {136stream.skipToEnd();137return 'comment' + stt.state;138}139
140// core words141if (searchWordList(stt.coreWordList, mat[1]) !== undefined) {142return 'builtin' + stt.state;143}144if (searchWordList(stt.immediateWordList, mat[1]) !== undefined) {145return 'keyword' + stt.state;146}147
148if (mat[1] === '(') {149stream.eatWhile(function (s) { return s !== ')'; });150stream.eat(')');151return 'comment' + stt.state;152}153
154// // strings155if (mat[1] === '.(') {156stream.eatWhile(function (s) { return s !== ')'; });157stream.eat(')');158return 'string' + stt.state;159}160if (mat[1] === 'S"' || mat[1] === '."' || mat[1] === 'C"') {161stream.eatWhile(function (s) { return s !== '"'; });162stream.eat('"');163return 'string' + stt.state;164}165
166// numbers167if (mat[1] - 0xfffffffff) {168return 'number' + stt.state;169}170// if (mat[1].match(/^[-+]?[0-9]+\.[0-9]*/)) {171// return 'number' + stt.state;172// }173
174return 'atom' + stt.state;175}176}177};178});179CodeMirror.defineMIME("text/x-forth", "forth");180});181