PromoCursed/node_modules/.cache/babel-loader/8f6d46a4f0d03407b6c7b6083834bf509e58d96962da86a67044d0207c2cf2cf.json

1 line
16 KiB
JSON
Raw Normal View History

2024-08-20 23:25:37 +04:00
{"ast":null,"code":"import { from, trim, charat, strlen, substr, append, assign } from './Utility.js';\nexport var line = 1;\nexport var column = 1;\nexport var length = 0;\nexport var position = 0;\nexport var character = 0;\nexport var characters = '';\n\n/**\n * @param {string} value\n * @param {object | null} root\n * @param {object | null} parent\n * @param {string} type\n * @param {string[] | string} props\n * @param {object[] | string} children\n * @param {object[]} siblings\n * @param {number} length\n */\nexport function node(value, root, parent, type, props, children, length, siblings) {\n return {\n value: value,\n root: root,\n parent: parent,\n type: type,\n props: props,\n children: children,\n line: line,\n column: column,\n length: length,\n return: '',\n siblings: siblings\n };\n}\n\n/**\n * @param {object} root\n * @param {object} props\n * @return {object}\n */\nexport function copy(root, props) {\n return assign(node('', null, null, '', null, null, 0, root.siblings), root, {\n length: -root.length\n }, props);\n}\n\n/**\n * @param {object} root\n */\nexport function lift(root) {\n while (root.root) root = copy(root.root, {\n children: [root]\n });\n append(root, root.siblings);\n}\n\n/**\n * @return {number}\n */\nexport function char() {\n return character;\n}\n\n/**\n * @return {number}\n */\nexport function prev() {\n character = position > 0 ? charat(characters, --position) : 0;\n if (column--, character === 10) column = 1, line--;\n return character;\n}\n\n/**\n * @return {number}\n */\nexport function next() {\n character = position < length ? charat(characters, position++) : 0;\n if (column++, character === 10) column = 1, line++;\n return character;\n}\n\n/**\n * @return {number}\n */\nexport function peek() {\n return charat(characters, position);\n}\n\n/**\n * @return {number}\n */\nexport function caret() {\n return position;\n}\n\n/**\n * @param {number} begin\n * @param {number} end\n * @return {string}\n */\nexport function slice(begin, end) {\n return substr(characters, begin, end);\n}\n\n/**\n * @param {number} type\n * @return {number}\n */\nexport function token(type) {\n switch (type) {\n // \\0 \\t \\n \\r \\s whitespace token\n case 0:\n case 9:\n case 10:\n case 13:\n case 32:\n return 5;\n // ! + , / > @ ~ isolate token\n case 33:\n case 43:\n case 44:\n case 47:\n case 62:\n case 64:\n case 126:\n // ; { } breakpoint token\n case 59:\n case 123:\n case 125:\n return 4;\n // : accompanied token\n case 58:\n return 3;\n // \" ' ( [ opening delimit token\n case 34:\n case 39:\n case 40:\n case 91:\n return 2;\n // ) ] closing delimit token\n case 41:\n case 93:\n return 1;\n }\n return 0;\n}\n\n/**\n * @param {string} value\n * @return {any[]}\n */\nexport function alloc(value) {\n return line = column = 1, length = strlen(characters = value), position = 0, [];\n}\n\n/**\n * @param {any} value\n * @return {any}\n */\nexport function dealloc(value) {\n return characters = '', value;\n}\n\n/**\n * @param {number} type\n * @return {string}\n */\nexport function delimit(type) {\n return trim(slice(position - 1, delimiter(type === 91 ? type + 2 : type === 40 ? type + 1 : type)));\n}\n\n/**\n * @param {string} value\n * @return {string[]}\n */\nexport function tokenize(value) {\n return dealloc(tokenizer(alloc(value)));\n}\n\n/**\n * @param {number} type\n * @return {string}\n */\nexport function whitespace(type) {\n while (character = peek()) if (character < 33) next();else break;\n return token(type) > 2 || token(character) > 3 ? '' : ' ';\n}\n\n/**\n * @param {string[]} children\n * @return {string[]}\n */\nexport function tokenizer(children) {\n while (next()) switch (token(character)) {\n case 0:\n append(identifier(position - 1), children);\n break;\n case 2:\n append(delimit(character), children);\n break;\n default:\n append(from(character), children);\n }\n return child