function toWordList(e) {
  var r = [];
  return e.split(" ").forEach(function(e2) {
    r.push({ name: e2 });
  }), r;
}
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");
function searchWordList(e, r) {
  var i;
  for (i = e.length - 1; i >= 0; i--) if (e[i].name === r.toUpperCase()) return e[i];
}
const forth = {
  name: "forth",
  startState: function() {
    return {
      state: "",
      base: 10,
      coreWordList,
      immediateWordList,
      wordList: []
    };
  },
  token: function(e, r) {
    var i;
    if (e.eatSpace()) return null;
    if (r.state === "") {
      if (e.match(/^(\]|:NONAME)(\s|$)/i)) return r.state = " compilation", "builtin";
      if (i = e.match(/^(\:)\s+(\S+)(\s|$)+/), i) return r.wordList.push({ name: i[2].toUpperCase() }), r.state = " compilation", "def";
      if (i = e.match(/^(VARIABLE|2VARIABLE|CONSTANT|2CONSTANT|CREATE|POSTPONE|VALUE|WORD)\s+(\S+)(\s|$)+/i), i) return r.wordList.push({ name: i[2].toUpperCase() }), "def";
      if (i = e.match(/^(\'|\[\'\])\s+(\S+)(\s|$)+/), i) return "builtin";
    } else {
      if (e.match(/^(\;|\[)(\s)/)) return r.state = "", e.backUp(1), "builtin";
      if (e.match(/^(\;|\[)($)/)) return r.state = "", "builtin";
      if (e.match(/^(POSTPONE)\s+\S+(\s|$)+/)) return "builtin";
    }
    if (i = e.match(/^(\S+)(\s+|$)/), i) return searchWordList(r.wordList, i[1]) === void 0 ? i[1] === "\\" ? (e.skipToEnd(), "comment") : searchWordList(r.coreWordList, i[1]) === void 0 ? searchWordList(r.immediateWordList, i[1]) === void 0 ? i[1] === "(" ? (e.eatWhile(function(e2) {
      return e2 !== ")";
    }), e.eat(")"), "comment") : i[1] === ".(" ? (e.eatWhile(function(e2) {
      return e2 !== ")";
    }), e.eat(")"), "string") : i[1] === 'S"' || i[1] === '."' || i[1] === 'C"' ? (e.eatWhile(function(e2) {
      return e2 !== '"';
    }), e.eat('"'), "string") : i[1] - 68719476735 ? "number" : "atom" : "keyword" : "builtin" : "variable";
  }
};
export {
  forth as t
};
