: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
// Author: Aliaksei Chapyzhenka
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
})(function(CodeMirror) {
function toWordList(words) {
words.split(' ').forEach(function(e){
var coreWordList = toWordList(
2DROP 2DUP 2OVER 2SWAP ?DUP DEPTH DROP DUP OVER ROT SWAP\
FM/MOD SM/REM UM/MOD */ */MOD / /MOD MOD\
HERE , @ ! CELL+ CELLS C, C@ C! CHARS 2@ 2!\
FIND EXECUTE IMMEDIATE COUNT LITERAL STATE\
<# # #S #> HOLD SIGN BASE >NUMBER HEX DECIMAL\
. CR EMIT SPACE SPACES TYPE U. .R U.R\
SAVE-INPUT RESTORE-INPUT\
D- D+ D0< D0= D2* D2/ D< D= DMAX DMIN D>S DABS\
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');
var 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) {
for (i = wordList.length - 1; i >= 0; i--) {
if (wordList[i].name === word.toUpperCase()) {
coreWordList: coreWordList,
immediateWordList: immediateWordList,
token: function (stream, stt) {
if (stt.state === '') { // interpretation
if (stream.match(/^(\]|:NONAME)(\s|$)/i)) {
stt.state = ' compilation';
return 'builtin compilation';
mat = stream.match(/^(\:)\s+(\S+)(\s|$)+/);
stt.wordList.push({name: mat[2].toUpperCase()});
stt.state = ' compilation';
return 'def' + stt.state;
mat = stream.match(/^(VARIABLE|2VARIABLE|CONSTANT|2CONSTANT|CREATE|POSTPONE|VALUE|WORD)\s+(\S+)(\s|$)+/i);
stt.wordList.push({name: mat[2].toUpperCase()});
return 'def' + stt.state;
mat = stream.match(/^(\'|\[\'\])\s+(\S+)(\s|$)+/);
return 'builtin' + stt.state;
if (stream.match(/^(\;|\[)(\s)/)) {
return 'builtin compilation';
if (stream.match(/^(\;|\[)($)/)) {
return 'builtin compilation';
if (stream.match(/^(POSTPONE)\s+\S+(\s|$)+/)) {
mat = stream.match(/^(\S+)(\s+|$)/);
if (searchWordList(stt.wordList, mat[1]) !== undefined) {
return 'variable' + stt.state;
return 'comment' + stt.state;
if (searchWordList(stt.coreWordList, mat[1]) !== undefined) {
return 'builtin' + stt.state;
if (searchWordList(stt.immediateWordList, mat[1]) !== undefined) {
return 'keyword' + stt.state;
stream.eatWhile(function (s) { return s !== ')'; });
return 'comment' + stt.state;
stream.eatWhile(function (s) { return s !== ')'; });
return 'string' + stt.state;
if (mat[1] === 'S"' || mat[1] === '."' || mat[1] === 'C"') {
stream.eatWhile(function (s) { return s !== '"'; });
return 'string' + stt.state;
if (mat[1] - 0xfffffffff) {
return 'number' + stt.state;
// if (mat[1].match(/^[-+]?[0-9]+\.[0-9]*/)) {
// return 'number' + stt.state;
return 'atom' + stt.state;
CodeMirror.defineMIME("text/x-forth", "forth");