"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const Utility = require("./src-Utility.cjs");
exports.line = 1;
exports.column = 1;
exports.length = 0;
exports.position = 0;
exports.character = 0;
exports.characters = "";
function node(value, root, parent, type, props, children, length, siblings) {
  return { value, root, parent, type, props, children, line: exports.line, column: exports.column, length, return: "", siblings };
}
function char() {
  return exports.character;
}
function prev() {
  exports.character = exports.position > 0 ? Utility.charat(exports.characters, --exports.position) : 0;
  if (exports.column--, exports.character === 10)
    exports.column = 1, exports.line--;
  return exports.character;
}
function next() {
  exports.character = exports.position < exports.length ? Utility.charat(exports.characters, exports.position++) : 0;
  if (exports.column++, exports.character === 10)
    exports.column = 1, exports.line++;
  return exports.character;
}
function peek() {
  return Utility.charat(exports.characters, exports.position);
}
function caret() {
  return exports.position;
}
function slice(begin, end) {
  return Utility.substr(exports.characters, begin, end);
}
function token(type) {
  switch (type) {
    // \0 \t \n \r \s whitespace token
    case 0:
    case 9:
    case 10:
    case 13:
    case 32:
      return 5;
    // ! + , / > @ ~ isolate token
    case 33:
    case 43:
    case 44:
    case 47:
    case 62:
    case 64:
    case 126:
    // ; { } breakpoint token
    case 59:
    case 123:
    case 125:
      return 4;
    // : accompanied token
    case 58:
      return 3;
    // " ' ( [ opening delimit token
    case 34:
    case 39:
    case 40:
    case 91:
      return 2;
    // ) ] closing delimit token
    case 41:
    case 93:
      return 1;
  }
  return 0;
}
function alloc(value) {
  return exports.line = exports.column = 1, exports.length = Utility.strlen(exports.characters = value), exports.position = 0, [];
}
function dealloc(value) {
  return exports.characters = "", value;
}
function delimit(type) {
  return Utility.trim(slice(exports.position - 1, delimiter(type === 91 ? type + 2 : type === 40 ? type + 1 : type)));
}
function whitespace(type) {
  while (exports.character = peek())
    if (exports.character < 33)
      next();
    else
      break;
  return token(type) > 2 || token(exports.character) > 3 ? "" : " ";
}
function escaping(index, count) {
  while (--count && next())
    if (exports.character < 48 || exports.character > 102 || exports.character > 57 && exports.character < 65 || exports.character > 70 && exports.character < 97)
      break;
  return slice(index, caret() + (count < 6 && peek() == 32 && next() == 32));
}
function delimiter(type) {
  while (next())
    switch (exports.character) {
      // ] ) " '
      case type:
        return exports.position;
      // " '
      case 34:
      case 39:
        if (type !== 34 && type !== 39)
          delimiter(exports.character);
        break;
      // (
      case 40:
        if (type === 41)
          delimiter(type);
        break;
      // \
      case 92:
        next();
        break;
    }
  return exports.position;
}
function commenter(type, index) {
  while (next())
    if (type + exports.character === 47 + 10)
      break;
    else if (type + exports.character === 42 + 42 && peek() === 47)
      break;
  return "/*" + slice(index, exports.position - 1) + "*" + Utility.from(type === 47 ? type : next());
}
function identifier(index) {
  while (!token(peek()))
    next();
  return slice(index, exports.position);
}
exports.alloc = alloc;
exports.caret = caret;
exports.char = char;
exports.commenter = commenter;
exports.dealloc = dealloc;
exports.delimit = delimit;
exports.delimiter = delimiter;
exports.escaping = escaping;
exports.identifier = identifier;
exports.next = next;
exports.node = node;
exports.peek = peek;
exports.prev = prev;
exports.slice = slice;
exports.token = token;
exports.whitespace = whitespace;
//# sourceMappingURL=src-Tokenizer.cjs.map
