forked from phcode-dev/staging.phcode.dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathforth.js
More file actions
1 lines (1 loc) · 3.23 KB
/
Copy pathforth.js
File metadata and controls
1 lines (1 loc) · 3.23 KB
1
!function(mod){"object"==typeof exports&&"object"==typeof module?mod(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],mod):mod(CodeMirror)}(function(CodeMirror){"use strict";function toWordList(words){var ret=[];return words.split(" ").forEach(function(e){ret.push({name:e})}),ret}var coreWordList=toWordList("INVERT AND OR XOR 2* 2/ LSHIFT RSHIFT 0= = 0< < > U< MIN MAX 2DROP 2DUP 2OVER 2SWAP ?DUP DEPTH DROP DUP OVER ROT SWAP >R R> R@ + - 1+ 1- ABS NEGATE S>D * M* UM* FM/MOD SM/REM UM/MOD */ */MOD / /MOD MOD HERE , @ ! CELL+ CELLS C, C@ C! CHARS 2@ 2! ALIGN ALIGNED +! ALLOT CHAR [CHAR] [ ] BL FIND EXECUTE IMMEDIATE COUNT LITERAL STATE ; DOES> >BODY EVALUATE SOURCE >IN <# # #S #> HOLD SIGN BASE >NUMBER HEX DECIMAL FILL MOVE . CR EMIT SPACE SPACES TYPE U. .R U.R ACCEPT TRUE FALSE <> U> 0<> 0> NIP TUCK ROLL PICK 2>R 2R@ 2R> WITHIN UNUSED MARKER I J TO COMPILE, [COMPILE] SAVE-INPUT RESTORE-INPUT PAD ERASE 2LITERAL DNEGATE D- D+ D0< D0= D2* D2/ D< D= DMAX DMIN D>S DABS M+ M*/ D. D.R 2ROT DU< CATCH THROW FREE RESIZE ALLOCATE CS-PICK CS-ROLL GET-CURRENT SET-CURRENT FORTH-WORDLIST GET-ORDER SET-ORDER PREVIOUS SEARCH-WORDLIST WORDLIST FIND ALSO ONLY FORTH DEFINITIONS ORDER -TRAILING /STRING SEARCH COMPARE CMOVE CMOVE> BLANK SLITERAL"),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");CodeMirror.defineMode("forth",function(){function searchWordList(wordList,word){var i;for(i=wordList.length-1;i>=0;i--)if(wordList[i].name===word.toUpperCase())return wordList[i]}return{startState:function(){return{state:"",base:10,coreWordList:coreWordList,immediateWordList:immediateWordList,wordList:[]}},token:function(stream,stt){var mat;if(stream.eatSpace())return null;if(""===stt.state){if(stream.match(/^(\]|:NONAME)(\s|$)/i))return stt.state=" compilation","builtin compilation";if(mat=stream.match(/^(\:)\s+(\S+)(\s|$)+/))return stt.wordList.push({name:mat[2].toUpperCase()}),stt.state=" compilation","def"+stt.state;if(mat=stream.match(/^(VARIABLE|2VARIABLE|CONSTANT|2CONSTANT|CREATE|POSTPONE|VALUE|WORD)\s+(\S+)(\s|$)+/i))return stt.wordList.push({name:mat[2].toUpperCase()}),"def"+stt.state;if(mat=stream.match(/^(\'|\[\'\])\s+(\S+)(\s|$)+/))return"builtin"+stt.state}else{if(stream.match(/^(\;|\[)(\s)/))return stt.state="",stream.backUp(1),"builtin compilation";if(stream.match(/^(\;|\[)($)/))return stt.state="","builtin compilation";if(stream.match(/^(POSTPONE)\s+\S+(\s|$)+/))return"builtin"}return(mat=stream.match(/^(\S+)(\s+|$)/))?void 0!==searchWordList(stt.wordList,mat[1])?"variable"+stt.state:"\\"===mat[1]?(stream.skipToEnd(),"comment"+stt.state):void 0!==searchWordList(stt.coreWordList,mat[1])?"builtin"+stt.state:void 0!==searchWordList(stt.immediateWordList,mat[1])?"keyword"+stt.state:"("===mat[1]?(stream.eatWhile(function(s){return")"!==s}),stream.eat(")"),"comment"+stt.state):".("===mat[1]?(stream.eatWhile(function(s){return")"!==s}),stream.eat(")"),"string"+stt.state):'S"'===mat[1]||'."'===mat[1]||'C"'===mat[1]?(stream.eatWhile(function(s){return'"'!==s}),stream.eat('"'),"string"+stt.state):mat[1]-68719476735?"number"+stt.state:"atom"+stt.state:void 0}}}),CodeMirror.defineMIME("text/x-forth","forth")});