@witchcraft/expressit 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +86 -0
- package/dist/ast/builders/array.d.ts +8 -0
- package/dist/ast/builders/array.d.ts.map +1 -0
- package/dist/ast/builders/array.js +31 -0
- package/dist/ast/builders/condition.d.ts +20 -0
- package/dist/ast/builders/condition.d.ts.map +1 -0
- package/dist/ast/builders/condition.js +28 -0
- package/dist/ast/builders/delim.d.ts +11 -0
- package/dist/ast/builders/delim.d.ts.map +1 -0
- package/dist/ast/builders/delim.js +20 -0
- package/dist/ast/builders/error.d.ts +9 -0
- package/dist/ast/builders/error.d.ts.map +1 -0
- package/dist/ast/builders/error.js +16 -0
- package/dist/ast/builders/expression.d.ts +12 -0
- package/dist/ast/builders/expression.d.ts.map +1 -0
- package/dist/ast/builders/expression.js +31 -0
- package/dist/ast/builders/group.d.ts +20 -0
- package/dist/ast/builders/group.d.ts.map +1 -0
- package/dist/ast/builders/group.js +47 -0
- package/dist/ast/builders/index.d.ts +12 -0
- package/dist/ast/builders/index.d.ts.map +1 -0
- package/dist/ast/builders/index.js +24 -0
- package/dist/ast/builders/isFullPos.d.ts +6 -0
- package/dist/ast/builders/isFullPos.d.ts.map +1 -0
- package/dist/ast/builders/isFullPos.js +6 -0
- package/dist/ast/builders/pos.d.ts +21 -0
- package/dist/ast/builders/pos.d.ts.map +1 -0
- package/dist/ast/builders/pos.js +28 -0
- package/dist/ast/builders/token.d.ts +12 -0
- package/dist/ast/builders/token.d.ts.map +1 -0
- package/dist/ast/builders/token.js +26 -0
- package/dist/ast/builders/type.d.ts +6 -0
- package/dist/ast/builders/type.d.ts.map +1 -0
- package/dist/ast/builders/type.js +37 -0
- package/dist/ast/builders/variable.d.ts +17 -0
- package/dist/ast/builders/variable.d.ts.map +1 -0
- package/dist/ast/builders/variable.js +62 -0
- package/dist/ast/classes/ArrayNode.d.ts +18 -0
- package/dist/ast/classes/ArrayNode.d.ts.map +1 -0
- package/dist/ast/classes/ArrayNode.js +55 -0
- package/dist/ast/classes/Condition.d.ts +13 -0
- package/dist/ast/classes/Condition.d.ts.map +1 -0
- package/dist/ast/classes/Condition.js +21 -0
- package/dist/ast/classes/ConditionNode.d.ts +73 -0
- package/dist/ast/classes/ConditionNode.d.ts.map +1 -0
- package/dist/ast/classes/ConditionNode.js +101 -0
- package/dist/ast/classes/ErrorToken.d.ts +27 -0
- package/dist/ast/classes/ErrorToken.d.ts.map +1 -0
- package/dist/ast/classes/ErrorToken.js +47 -0
- package/dist/ast/classes/Expression.d.ts +13 -0
- package/dist/ast/classes/Expression.d.ts.map +1 -0
- package/dist/ast/classes/Expression.js +19 -0
- package/dist/ast/classes/ExpressionNode.d.ts +21 -0
- package/dist/ast/classes/ExpressionNode.d.ts.map +1 -0
- package/dist/ast/classes/ExpressionNode.js +57 -0
- package/dist/ast/classes/GroupNode.d.ts +64 -0
- package/dist/ast/classes/GroupNode.d.ts.map +1 -0
- package/dist/ast/classes/GroupNode.js +69 -0
- package/dist/ast/classes/Node.d.ts +22 -0
- package/dist/ast/classes/Node.d.ts.map +1 -0
- package/dist/ast/classes/Node.js +28 -0
- package/dist/ast/classes/Token.d.ts +27 -0
- package/dist/ast/classes/Token.d.ts.map +1 -0
- package/dist/ast/classes/Token.js +28 -0
- package/dist/ast/classes/ValidToken.d.ts +26 -0
- package/dist/ast/classes/ValidToken.d.ts.map +1 -0
- package/dist/ast/classes/ValidToken.js +49 -0
- package/dist/ast/classes/VariableNode.d.ts +33 -0
- package/dist/ast/classes/VariableNode.d.ts.map +1 -0
- package/dist/ast/classes/VariableNode.js +58 -0
- package/dist/ast/classes/index.d.ts +12 -0
- package/dist/ast/classes/index.d.ts.map +1 -0
- package/dist/ast/classes/index.js +24 -0
- package/dist/ast/handlers.d.ts +42 -0
- package/dist/ast/handlers.d.ts.map +1 -0
- package/dist/ast/handlers.js +150 -0
- package/dist/ast/index.d.ts +4 -0
- package/dist/ast/index.d.ts.map +1 -0
- package/dist/ast/index.js +8 -0
- package/dist/examples/advancedValueComparer.d.ts +3 -0
- package/dist/examples/advancedValueComparer.d.ts.map +1 -0
- package/dist/examples/advancedValueComparer.js +28 -0
- package/dist/examples/shortcutContextParser.d.ts +22 -0
- package/dist/examples/shortcutContextParser.d.ts.map +1 -0
- package/dist/examples/shortcutContextParser.js +126 -0
- package/dist/global.d.js +1 -0
- package/dist/grammar/ParserBase.d.ts +51 -0
- package/dist/grammar/ParserBase.d.ts.map +1 -0
- package/dist/grammar/ParserBase.js +516 -0
- package/dist/grammar/createTokens.d.ts +56 -0
- package/dist/grammar/createTokens.d.ts.map +1 -0
- package/dist/grammar/createTokens.js +843 -0
- package/dist/grammar/index.d.ts +3 -0
- package/dist/grammar/index.d.ts.map +1 -0
- package/dist/grammar/index.js +6 -0
- package/dist/helpers/errors.d.ts +9 -0
- package/dist/helpers/errors.d.ts.map +1 -0
- package/dist/helpers/errors.js +41 -0
- package/dist/helpers/general/applyBoolean.d.ts +3 -0
- package/dist/helpers/general/applyBoolean.d.ts.map +1 -0
- package/dist/helpers/general/applyBoolean.js +17 -0
- package/dist/helpers/general/applyPrefix.d.ts +4 -0
- package/dist/helpers/general/applyPrefix.d.ts.map +1 -0
- package/dist/helpers/general/applyPrefix.js +9 -0
- package/dist/helpers/general/defaultConditionNormalizer.d.ts +3 -0
- package/dist/helpers/general/defaultConditionNormalizer.d.ts.map +1 -0
- package/dist/helpers/general/defaultConditionNormalizer.js +6 -0
- package/dist/helpers/general/defaultKeyParser.d.ts +3 -0
- package/dist/helpers/general/defaultKeyParser.d.ts.map +1 -0
- package/dist/helpers/general/defaultKeyParser.js +8 -0
- package/dist/helpers/general/defaultPrefixApplier.d.ts +3 -0
- package/dist/helpers/general/defaultPrefixApplier.d.ts.map +1 -0
- package/dist/helpers/general/defaultPrefixApplier.js +6 -0
- package/dist/helpers/general/defaultValueComparer.d.ts +3 -0
- package/dist/helpers/general/defaultValueComparer.d.ts.map +1 -0
- package/dist/helpers/general/defaultValueComparer.js +6 -0
- package/dist/helpers/general/index.d.ts +7 -0
- package/dist/helpers/general/index.d.ts.map +1 -0
- package/dist/helpers/general/index.js +14 -0
- package/dist/helpers/index.d.ts +4 -0
- package/dist/helpers/index.d.ts.map +1 -0
- package/dist/helpers/index.js +8 -0
- package/dist/helpers/parser/assignParents.d.ts +4 -0
- package/dist/helpers/parser/assignParents.d.ts.map +1 -0
- package/dist/helpers/parser/assignParents.js +71 -0
- package/dist/helpers/parser/checkParserOpts.d.ts +3 -0
- package/dist/helpers/parser/checkParserOpts.d.ts.map +1 -0
- package/dist/helpers/parser/checkParserOpts.js +126 -0
- package/dist/helpers/parser/extractPosition.d.ts +9 -0
- package/dist/helpers/parser/extractPosition.d.ts.map +1 -0
- package/dist/helpers/parser/extractPosition.js +9 -0
- package/dist/helpers/parser/getUnclosedRightParenCount.d.ts +5 -0
- package/dist/helpers/parser/getUnclosedRightParenCount.d.ts.map +1 -0
- package/dist/helpers/parser/getUnclosedRightParenCount.js +20 -0
- package/dist/helpers/parser/index.d.ts +9 -0
- package/dist/helpers/parser/index.d.ts.map +1 -0
- package/dist/helpers/parser/index.js +18 -0
- package/dist/helpers/parser/parseParserOptions.d.ts +4 -0
- package/dist/helpers/parser/parseParserOptions.d.ts.map +1 -0
- package/dist/helpers/parser/parseParserOptions.js +45 -0
- package/dist/helpers/parser/seal.d.ts +8 -0
- package/dist/helpers/parser/seal.d.ts.map +1 -0
- package/dist/helpers/parser/seal.js +10 -0
- package/dist/helpers/parser/setParent.d.ts +6 -0
- package/dist/helpers/parser/setParent.d.ts.map +1 -0
- package/dist/helpers/parser/setParent.js +4 -0
- package/dist/helpers/parser/unescape.d.ts +3 -0
- package/dist/helpers/parser/unescape.d.ts.map +1 -0
- package/dist/helpers/parser/unescape.js +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/methods/autocomplete.d.ts +18 -0
- package/dist/methods/autocomplete.d.ts.map +1 -0
- package/dist/methods/autocomplete.js +109 -0
- package/dist/methods/autoreplace.d.ts +13 -0
- package/dist/methods/autoreplace.d.ts.map +1 -0
- package/dist/methods/autoreplace.js +36 -0
- package/dist/methods/autosuggest.d.ts +28 -0
- package/dist/methods/autosuggest.d.ts.map +1 -0
- package/dist/methods/autosuggest.js +371 -0
- package/dist/methods/evaluate.d.ts +11 -0
- package/dist/methods/evaluate.d.ts.map +1 -0
- package/dist/methods/evaluate.js +30 -0
- package/dist/methods/getBestIndex.d.ts +19 -0
- package/dist/methods/getBestIndex.d.ts.map +1 -0
- package/dist/methods/getBestIndex.js +53 -0
- package/dist/methods/getIndexes.d.ts +17 -0
- package/dist/methods/getIndexes.d.ts.map +1 -0
- package/dist/methods/getIndexes.js +97 -0
- package/dist/methods/index.d.ts +9 -0
- package/dist/methods/index.d.ts.map +1 -0
- package/dist/methods/index.js +18 -0
- package/dist/methods/normalize.d.ts +12 -0
- package/dist/methods/normalize.d.ts.map +1 -0
- package/dist/methods/normalize.js +99 -0
- package/dist/methods/validate.d.ts +11 -0
- package/dist/methods/validate.d.ts.map +1 -0
- package/dist/methods/validate.js +111 -0
- package/dist/package.js +7 -0
- package/dist/package.json.js +193 -0
- package/dist/parser.d.ts +58 -0
- package/dist/parser.d.ts.map +1 -0
- package/dist/parser.js +136 -0
- package/dist/types/ast.d.ts +70 -0
- package/dist/types/ast.d.ts.map +1 -0
- package/dist/types/ast.js +29 -0
- package/dist/types/autocomplete.d.ts +143 -0
- package/dist/types/autocomplete.d.ts.map +1 -0
- package/dist/types/autocomplete.js +24 -0
- package/dist/types/errors.d.ts +34 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/errors.js +10 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +9 -0
- package/dist/types/parser.d.ts +451 -0
- package/dist/types/parser.d.ts.map +1 -0
- package/dist/types/parser.js +1 -0
- package/dist/utils/extractTokens.d.ts +8 -0
- package/dist/utils/extractTokens.d.ts.map +1 -0
- package/dist/utils/extractTokens.js +50 -0
- package/dist/utils/getCursorInfo.d.ts +7 -0
- package/dist/utils/getCursorInfo.d.ts.map +1 -0
- package/dist/utils/getCursorInfo.js +86 -0
- package/dist/utils/getOppositeDelimiter.d.ts +6 -0
- package/dist/utils/getOppositeDelimiter.d.ts.map +1 -0
- package/dist/utils/getOppositeDelimiter.js +35 -0
- package/dist/utils/getSurroundingErrors.d.ts +25 -0
- package/dist/utils/getSurroundingErrors.d.ts.map +1 -0
- package/dist/utils/getSurroundingErrors.js +37 -0
- package/dist/utils/index.d.ts +10 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +20 -0
- package/dist/utils/isBracket.d.ts +3 -0
- package/dist/utils/isBracket.d.ts.map +1 -0
- package/dist/utils/isBracket.js +7 -0
- package/dist/utils/isDelimiter.d.ts +6 -0
- package/dist/utils/isDelimiter.d.ts.map +1 -0
- package/dist/utils/isDelimiter.js +17 -0
- package/dist/utils/isParen.d.ts +3 -0
- package/dist/utils/isParen.d.ts.map +1 -0
- package/dist/utils/isParen.js +7 -0
- package/dist/utils/isQuote.d.ts +4 -0
- package/dist/utils/isQuote.d.ts.map +1 -0
- package/dist/utils/isQuote.js +7 -0
- package/dist/utils/prettyAst.d.ts +35 -0
- package/dist/utils/prettyAst.d.ts.map +1 -0
- package/dist/utils/prettyAst.js +112 -0
- package/package.json +152 -0
- package/src/ast/builders/array.ts +45 -0
- package/src/ast/builders/condition.ts +56 -0
- package/src/ast/builders/delim.ts +39 -0
- package/src/ast/builders/error.ts +22 -0
- package/src/ast/builders/expression.ts +66 -0
- package/src/ast/builders/group.ts +79 -0
- package/src/ast/builders/index.ts +13 -0
- package/src/ast/builders/isFullPos.ts +10 -0
- package/src/ast/builders/pos.ts +57 -0
- package/src/ast/builders/token.ts +46 -0
- package/src/ast/builders/type.ts +32 -0
- package/src/ast/builders/variable.ts +89 -0
- package/src/ast/classes/ArrayNode.ts +46 -0
- package/src/ast/classes/Condition.ts +22 -0
- package/src/ast/classes/ConditionNode.ts +141 -0
- package/src/ast/classes/ErrorToken.ts +49 -0
- package/src/ast/classes/Expression.ts +26 -0
- package/src/ast/classes/ExpressionNode.ts +62 -0
- package/src/ast/classes/GroupNode.ts +127 -0
- package/src/ast/classes/Node.ts +47 -0
- package/src/ast/classes/Token.ts +59 -0
- package/src/ast/classes/ValidToken.ts +56 -0
- package/src/ast/classes/VariableNode.ts +67 -0
- package/src/ast/classes/index.ts +13 -0
- package/src/ast/handlers.ts +190 -0
- package/src/ast/index.ts +5 -0
- package/src/examples/advancedValueComparer.ts +31 -0
- package/src/examples/shortcutContextParser.ts +140 -0
- package/src/global.d.ts +4 -0
- package/src/grammar/ParserBase.ts +715 -0
- package/src/grammar/createTokens.ts +512 -0
- package/src/grammar/index.ts +4 -0
- package/src/helpers/errors.ts +45 -0
- package/src/helpers/general/applyBoolean.ts +9 -0
- package/src/helpers/general/applyPrefix.ts +7 -0
- package/src/helpers/general/defaultConditionNormalizer.ts +9 -0
- package/src/helpers/general/defaultKeyParser.ts +8 -0
- package/src/helpers/general/defaultPrefixApplier.ts +7 -0
- package/src/helpers/general/defaultValueComparer.ts +7 -0
- package/src/helpers/general/index.ts +8 -0
- package/src/helpers/index.ts +5 -0
- package/src/helpers/parser/assignParents.ts +51 -0
- package/src/helpers/parser/checkParserOpts.ts +143 -0
- package/src/helpers/parser/extractPosition.ts +15 -0
- package/src/helpers/parser/getUnclosedRightParenCount.ts +22 -0
- package/src/helpers/parser/index.ts +10 -0
- package/src/helpers/parser/parseParserOptions.ts +54 -0
- package/src/helpers/parser/seal.ts +14 -0
- package/src/helpers/parser/setParent.ts +5 -0
- package/src/helpers/parser/unescape.ts +4 -0
- package/src/index.ts +7 -0
- package/src/methods/autocomplete.ts +128 -0
- package/src/methods/autoreplace.ts +46 -0
- package/src/methods/autosuggest.ts +543 -0
- package/src/methods/evaluate.ts +37 -0
- package/src/methods/getBestIndex.ts +53 -0
- package/src/methods/getIndexes.ts +99 -0
- package/src/methods/index.ts +10 -0
- package/src/methods/normalize.ts +138 -0
- package/src/methods/validate.ts +141 -0
- package/src/package.js +11 -0
- package/src/parser.ts +183 -0
- package/src/types/ast.ts +148 -0
- package/src/types/autocomplete.ts +152 -0
- package/src/types/errors.ts +40 -0
- package/src/types/index.ts +6 -0
- package/src/types/parser.ts +479 -0
- package/src/utils/extractTokens.ts +67 -0
- package/src/utils/getCursorInfo.ts +106 -0
- package/src/utils/getOppositeDelimiter.ts +36 -0
- package/src/utils/getSurroundingErrors.ts +57 -0
- package/src/utils/index.ts +11 -0
- package/src/utils/isBracket.ts +6 -0
- package/src/utils/isDelimiter.ts +18 -0
- package/src/utils/isParen.ts +6 -0
- package/src/utils/isQuote.ts +6 -0
- package/src/utils/prettyAst.ts +152 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
const name = "@witchcraft/expressit";
|
|
2
|
+
const description = "A blazing fast, customizable, error-tolerant expression parser that creates safe to eval expressions + a few other goodies like autocomplete.";
|
|
3
|
+
const version = "0.0.2";
|
|
4
|
+
const types = "./dist/index.d.ts";
|
|
5
|
+
const type = "module";
|
|
6
|
+
const exports = {
|
|
7
|
+
".": {
|
|
8
|
+
types: "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./ast": {
|
|
12
|
+
types: "./dist/ast/index.d.ts",
|
|
13
|
+
"import": "./dist/ast/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./grammar": {
|
|
16
|
+
types: "./dist/grammar/index.d.ts",
|
|
17
|
+
"import": "./dist/grammar/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./helpers": {
|
|
20
|
+
types: "./dist/helpers/index.d.ts",
|
|
21
|
+
"import": "./dist/helpers/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./methods": {
|
|
24
|
+
types: "./dist/methods/index.d.ts",
|
|
25
|
+
"import": "./dist/methods/index.js"
|
|
26
|
+
},
|
|
27
|
+
"./types": {
|
|
28
|
+
types: "./dist/types/index.d.ts",
|
|
29
|
+
"import": "./dist/types/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./utils": {
|
|
32
|
+
types: "./dist/utils/index.d.ts",
|
|
33
|
+
"import": "./dist/utils/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./examples": {
|
|
36
|
+
types: "./dist/examples/index.d.ts",
|
|
37
|
+
"import": "./dist/examples/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./*": {
|
|
40
|
+
types: "./dist/*",
|
|
41
|
+
"import": "./dist/*"
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const scripts = {
|
|
45
|
+
debug: "ts-node -r tsconfig-paths/register -T --esm",
|
|
46
|
+
build: "vite build",
|
|
47
|
+
"build:dev": "vite build --mode development",
|
|
48
|
+
"build:watch": "vite build --watch --mode production",
|
|
49
|
+
"build:types": "tsc --emitDeclarationOnly -p tsconfig.types.json && npm run build:types:fix",
|
|
50
|
+
"build:types:fix": "tsc-alias -p tsconfig.types.json --debug",
|
|
51
|
+
"lint:eslint": 'eslint "{src,tests,bin}/**/*.{cjs,js,ts}" "*.{cjs,js,ts}" --max-warnings=0 --report-unused-disable-directives',
|
|
52
|
+
"lint:types": "tsc --noEmit --pretty",
|
|
53
|
+
"lint:commits": "commitlint --from $(git rev-list --max-parents=0 HEAD) --to HEAD --verbose",
|
|
54
|
+
"lint:imports": "madge --circular --extensions ts ./src",
|
|
55
|
+
lint: "npm run lint:types && npm run lint:eslint",
|
|
56
|
+
coverage: "vitest --coverage",
|
|
57
|
+
"coverage:dev": "vitest --watch --coverage",
|
|
58
|
+
test: "npm run lint:types && vitest run",
|
|
59
|
+
"test:watch": "vitest --watch",
|
|
60
|
+
"test:inspect-errors": "cross-env INSPECT_ERRORS=true npm run test",
|
|
61
|
+
doc: "typedoc --options typedoc.config.cjs",
|
|
62
|
+
"doc:watch": 'onchange -i "src/**/*.ts" "typedoc.config.cjs" -- npm run doc',
|
|
63
|
+
"doc:serve": "http-server docs --port=5001",
|
|
64
|
+
"doc:dev": 'concurrently "npm run doc:watch" "npm run doc:serve"',
|
|
65
|
+
"doc:check-invalid": "typedoc --options typedoc.config.cjs --listInvalidSymbolLinks",
|
|
66
|
+
"demo:dev": 'cd demo && concurrently "vite" "npm run build:watch"',
|
|
67
|
+
"demo:build": "cd demo && npm run build",
|
|
68
|
+
"actions:debug": "act -r -v -j build",
|
|
69
|
+
"gen:exports": "indexit update -o '${path}.js' -i **/*.d.ts",
|
|
70
|
+
prepare: "husky install && npm run build"
|
|
71
|
+
};
|
|
72
|
+
const dependencies = {
|
|
73
|
+
"@alanscodelog/utils": "^4.0.0-beta.11",
|
|
74
|
+
chevrotain: "^11.0.3"
|
|
75
|
+
};
|
|
76
|
+
const devDependencies = {
|
|
77
|
+
"@alanscodelog/commitlint-config": "^2.0.0",
|
|
78
|
+
"@alanscodelog/eslint-config": "^4.0.3",
|
|
79
|
+
"@alanscodelog/semantic-release-config": "^3.0.0",
|
|
80
|
+
"@alanscodelog/tsconfigs": "^3.2.0",
|
|
81
|
+
"@knodes/typedoc-plugin-pages": "^0.23.4",
|
|
82
|
+
"@types/node": "^20.4.1",
|
|
83
|
+
"@typescript-eslint/eslint-plugin": "^6.7.4",
|
|
84
|
+
"@typescript-eslint/parser": "^6.7.4",
|
|
85
|
+
"@vitest/coverage-c8": "^0.33.0",
|
|
86
|
+
commitlint: "^17.6.6",
|
|
87
|
+
concurrently: "^8.2.0",
|
|
88
|
+
"cross-env": "^7.0.3",
|
|
89
|
+
eslint: "^8.44.0",
|
|
90
|
+
"eslint-import-resolver-typescript": "^3.5.5",
|
|
91
|
+
"eslint-plugin-import": "^2.27.5",
|
|
92
|
+
"eslint-plugin-jsdoc": "^46.4.3",
|
|
93
|
+
"eslint-plugin-simple-import-sort": "^10.0.0",
|
|
94
|
+
"fast-glob": "^3.3.1",
|
|
95
|
+
"http-server": "^14.1.1",
|
|
96
|
+
husky: "^8.0.3",
|
|
97
|
+
indexit: "2.1.0-beta.3",
|
|
98
|
+
madge: "^6.1.0",
|
|
99
|
+
onchange: "^7.1.0",
|
|
100
|
+
"semantic-release": "^22.0.5",
|
|
101
|
+
"ts-node": "^10.9.1",
|
|
102
|
+
"tsc-alias": "^1.8.7",
|
|
103
|
+
typedoc: "~0.23.1",
|
|
104
|
+
typescript: "~5.0.0",
|
|
105
|
+
vite: "^4.4.2",
|
|
106
|
+
"vite-plugin-externalize-deps": "^0.7.0",
|
|
107
|
+
"vite-tsconfig-paths": "^4.2.0",
|
|
108
|
+
vitest: "^0.34.6"
|
|
109
|
+
};
|
|
110
|
+
const author = "Alan <alanscodelog@gmail.com>";
|
|
111
|
+
const repository = "https://github.com/witchcraftjs/expressit";
|
|
112
|
+
const keywords = [
|
|
113
|
+
"boolean",
|
|
114
|
+
"parser",
|
|
115
|
+
"query",
|
|
116
|
+
"evaluator",
|
|
117
|
+
"expression",
|
|
118
|
+
"condition",
|
|
119
|
+
"search"
|
|
120
|
+
];
|
|
121
|
+
const license = "MIT";
|
|
122
|
+
const files = [
|
|
123
|
+
"src",
|
|
124
|
+
"dist"
|
|
125
|
+
];
|
|
126
|
+
const release = {
|
|
127
|
+
"extends": [
|
|
128
|
+
"@alanscodelog/semantic-release-config"
|
|
129
|
+
]
|
|
130
|
+
};
|
|
131
|
+
const commitlint = {
|
|
132
|
+
"extends": [
|
|
133
|
+
"@alanscodelog"
|
|
134
|
+
]
|
|
135
|
+
};
|
|
136
|
+
const browserslist = "defaults and supports es6-module,maintained node versions";
|
|
137
|
+
const engines = {
|
|
138
|
+
node: ">=18.0.0"
|
|
139
|
+
};
|
|
140
|
+
const publishConfig = {
|
|
141
|
+
access: "public"
|
|
142
|
+
};
|
|
143
|
+
const pkg = {
|
|
144
|
+
name,
|
|
145
|
+
description,
|
|
146
|
+
version,
|
|
147
|
+
types,
|
|
148
|
+
type,
|
|
149
|
+
exports,
|
|
150
|
+
scripts,
|
|
151
|
+
dependencies,
|
|
152
|
+
devDependencies,
|
|
153
|
+
author,
|
|
154
|
+
repository,
|
|
155
|
+
keywords,
|
|
156
|
+
license,
|
|
157
|
+
files,
|
|
158
|
+
release,
|
|
159
|
+
commitlint,
|
|
160
|
+
browserslist,
|
|
161
|
+
engines,
|
|
162
|
+
"@comments": {
|
|
163
|
+
scripts: {
|
|
164
|
+
test: "Runs `lint:types` before (so that flags can be passed to the test command) so that we can test type assertions. See expect_type function in @alanscodelog/utils.",
|
|
165
|
+
"lint:commits": "Lints all unpushed commits in the active branch.",
|
|
166
|
+
prepare: "Needed so that if we pull the package from git it will get built and installed properly.",
|
|
167
|
+
"actions:debug": "For debugging github build action locally with nektos/act. Requires act and docker. Note: Cache will never work locally because of https://github.com/nektos/act/issues/285"
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
publishConfig
|
|
171
|
+
};
|
|
172
|
+
export {
|
|
173
|
+
author,
|
|
174
|
+
browserslist,
|
|
175
|
+
commitlint,
|
|
176
|
+
pkg as default,
|
|
177
|
+
dependencies,
|
|
178
|
+
description,
|
|
179
|
+
devDependencies,
|
|
180
|
+
engines,
|
|
181
|
+
exports,
|
|
182
|
+
files,
|
|
183
|
+
keywords,
|
|
184
|
+
license,
|
|
185
|
+
name,
|
|
186
|
+
publishConfig,
|
|
187
|
+
release,
|
|
188
|
+
repository,
|
|
189
|
+
scripts,
|
|
190
|
+
type,
|
|
191
|
+
types,
|
|
192
|
+
version
|
|
193
|
+
};
|
package/dist/parser.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The parser's methods are often long and have a lot of documentation per method, so it's methods have been split into mixins. They can be found in the `./methods` folder.
|
|
3
|
+
*
|
|
4
|
+
* Writing from within any of these methods is like writing a method from here except:
|
|
5
|
+
* - `this` calls are wrapped in `(this as any as Parser<T>)`
|
|
6
|
+
* - private method/property access requires `// @ts-expect-error`.
|
|
7
|
+
* - recursion with hidden parameters requires re-typing this (see evaluate/validate for examples) since otherwise if we only retyped the function it would become unbound from `this`.
|
|
8
|
+
*
|
|
9
|
+
* Docs work like normal (on methods). From the outside, users of the library cannot even tell the class is composed of mixins.
|
|
10
|
+
*/
|
|
11
|
+
import type { Mixin } from "@alanscodelog/utils";
|
|
12
|
+
import { createTokens } from "./grammar/createTokens.js";
|
|
13
|
+
import { ParserBase } from "./grammar/ParserBase.js";
|
|
14
|
+
import { AutocompleteMixin } from "./methods/autocomplete.js";
|
|
15
|
+
import { AutoreplaceMixin } from "./methods/autoreplace.js";
|
|
16
|
+
import { Autosuggest } from "./methods/autosuggest.js";
|
|
17
|
+
import { EvaluateMixin } from "./methods/evaluate.js";
|
|
18
|
+
import { GetBestIndexesMixin } from "./methods/getBestIndex.js";
|
|
19
|
+
import { GetIndexMixin } from "./methods/getIndexes.js";
|
|
20
|
+
import { NormalizeMixin, ValidateMixin } from "./methods/index.js";
|
|
21
|
+
import type { ParserResults } from "./types/ast.js";
|
|
22
|
+
import type { FullParserOptions, ParserOptions } from "./types/parser.js";
|
|
23
|
+
/**
|
|
24
|
+
* Creates the main parser class which handles all functionality (evaluation, validation, etc).
|
|
25
|
+
*/
|
|
26
|
+
export declare class Parser<T extends {} = {}> {
|
|
27
|
+
options: FullParserOptions<T>;
|
|
28
|
+
private readonly rawOptions;
|
|
29
|
+
parser: ParserBase<T>;
|
|
30
|
+
private readonly lexer;
|
|
31
|
+
private readonly tokens;
|
|
32
|
+
info: ReturnType<typeof createTokens>["info"];
|
|
33
|
+
constructor(options?: ParserOptions<T>);
|
|
34
|
+
/**
|
|
35
|
+
* Parses a string.
|
|
36
|
+
*/
|
|
37
|
+
parse(input: string): ParserResults;
|
|
38
|
+
private evaluationOptionsChecked;
|
|
39
|
+
_checkEvaluationOptions(): void;
|
|
40
|
+
private validationOptionsChecked;
|
|
41
|
+
_checkValidationOptions(): void;
|
|
42
|
+
/**
|
|
43
|
+
* Generates a railroad diagram for debugging. Does not 100% represent how things are actually handled internally.
|
|
44
|
+
*
|
|
45
|
+
* Not exposed because it uses the raw chevrotain tokens.
|
|
46
|
+
*
|
|
47
|
+
* **Note: It is not 100% accurate. Some special cases are parsed one way but handled internally differently.**
|
|
48
|
+
*/
|
|
49
|
+
private _generateRailRoadDiagram;
|
|
50
|
+
/**
|
|
51
|
+
* For debugging.
|
|
52
|
+
* Not exposed because it returns the raw chevrotain tokens.
|
|
53
|
+
*/
|
|
54
|
+
private _lex;
|
|
55
|
+
}
|
|
56
|
+
export interface Parser<T extends {} = {}> extends Mixin<AutocompleteMixin<T> | AutoreplaceMixin | Autosuggest<T> | EvaluateMixin<T> | ValidateMixin<T> | NormalizeMixin<T> | GetIndexMixin<T> | GetBestIndexesMixin>, AutocompleteMixin<T>, AutoreplaceMixin, Autosuggest<T>, EvaluateMixin<T>, ValidateMixin<T>, NormalizeMixin<T>, GetIndexMixin<T>, GetBestIndexesMixin {
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAKhD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAKpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AACvD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM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AC,CAAC,CAAC,EAChB,aAAa,CAAG,CAAC,CAAE,EACnB,cAAc,CAAC,CAAC,CAAC,EACjB,aAAa,CAAC,CAAC,CAAC,EAChB,mBAAmB;CAClB"}
|
package/dist/parser.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
7
|
+
import { mixin, isWhitespace } from "@alanscodelog/utils";
|
|
8
|
+
import { createSyntaxDiagramsCode } from "chevrotain";
|
|
9
|
+
import { token } from "./ast/handlers.js";
|
|
10
|
+
import { createTokens } from "./grammar/createTokens.js";
|
|
11
|
+
import { ParserBase } from "./grammar/ParserBase.js";
|
|
12
|
+
import { BooleanParserLibraryError } from "./helpers/errors.js";
|
|
13
|
+
import { checkParserOpts } from "./helpers/parser/checkParserOpts.js";
|
|
14
|
+
import { getUnclosedRightParenCount } from "./helpers/parser/getUnclosedRightParenCount.js";
|
|
15
|
+
import { ERROR_CODES } from "./types/errors.js";
|
|
16
|
+
import { parseParserOptions } from "./helpers/parser/parseParserOptions.js";
|
|
17
|
+
import { seal } from "./helpers/parser/seal.js";
|
|
18
|
+
import { AutocompleteMixin } from "./methods/autocomplete.js";
|
|
19
|
+
import { AutoreplaceMixin } from "./methods/autoreplace.js";
|
|
20
|
+
import { Autosuggest } from "./methods/autosuggest.js";
|
|
21
|
+
import { EvaluateMixin } from "./methods/evaluate.js";
|
|
22
|
+
import { GetBestIndexesMixin } from "./methods/getBestIndex.js";
|
|
23
|
+
import { GetIndexMixin } from "./methods/getIndexes.js";
|
|
24
|
+
import { NormalizeMixin } from "./methods/normalize.js";
|
|
25
|
+
import { ValidateMixin } from "./methods/validate.js";
|
|
26
|
+
class Parser {
|
|
27
|
+
constructor(options) {
|
|
28
|
+
__publicField(this, "options");
|
|
29
|
+
__publicField(this, "rawOptions");
|
|
30
|
+
__publicField(this, "parser");
|
|
31
|
+
__publicField(this, "lexer");
|
|
32
|
+
__publicField(this, "tokens");
|
|
33
|
+
__publicField(this, "info");
|
|
34
|
+
// needed for evaluate and validate so they are only checked on demand
|
|
35
|
+
__publicField(this, "evaluationOptionsChecked", false);
|
|
36
|
+
__publicField(this, "validationOptionsChecked", false);
|
|
37
|
+
this.rawOptions = options ?? {};
|
|
38
|
+
const opts = parseParserOptions(this.rawOptions);
|
|
39
|
+
checkParserOpts(opts);
|
|
40
|
+
this.options = opts;
|
|
41
|
+
const { lexer, tokens, info } = createTokens(opts);
|
|
42
|
+
this.lexer = lexer;
|
|
43
|
+
this.tokens = tokens;
|
|
44
|
+
this.info = info;
|
|
45
|
+
this.parser = new ParserBase(opts, this.tokens, this.info);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Parses a string.
|
|
49
|
+
*/
|
|
50
|
+
parse(input) {
|
|
51
|
+
var _a;
|
|
52
|
+
if (isWhitespace(input)) {
|
|
53
|
+
return token.value(void 0, { start: 0, end: 0 });
|
|
54
|
+
}
|
|
55
|
+
let lexed = this._lex(input);
|
|
56
|
+
const shift = getUnclosedRightParenCount(lexed.tokens, this.tokens);
|
|
57
|
+
if (shift) {
|
|
58
|
+
input = "(".repeat(shift) + input;
|
|
59
|
+
lexed = this._lex(input);
|
|
60
|
+
}
|
|
61
|
+
this.parser.shift = shift;
|
|
62
|
+
this.parser.input = lexed.tokens;
|
|
63
|
+
this.parser.rawInput = input;
|
|
64
|
+
try {
|
|
65
|
+
if (lexed.errors.length > 0)
|
|
66
|
+
throw new Error("Unexpected Lexer Errors");
|
|
67
|
+
this.parser.input = lexed.tokens;
|
|
68
|
+
const res = this.parser.main();
|
|
69
|
+
if (res === void 0) {
|
|
70
|
+
throw new Error("throw");
|
|
71
|
+
}
|
|
72
|
+
if (!((_a = arguments[1]) == null ? void 0 : _a.unsealed))
|
|
73
|
+
seal(res);
|
|
74
|
+
return res;
|
|
75
|
+
} catch (error) {
|
|
76
|
+
if (error.message === "throw")
|
|
77
|
+
error = void 0;
|
|
78
|
+
const err = new BooleanParserLibraryError(ERROR_CODES.PARSER_ERROR, {
|
|
79
|
+
input,
|
|
80
|
+
options: this.rawOptions,
|
|
81
|
+
"parsed options": this.options,
|
|
82
|
+
error,
|
|
83
|
+
"lexed tokens": lexed.tokens,
|
|
84
|
+
"lexer errors": lexed.errors,
|
|
85
|
+
"parser errors": this.parser.errors
|
|
86
|
+
});
|
|
87
|
+
throw err;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
91
|
+
_checkEvaluationOptions() {
|
|
92
|
+
if (!this.evaluationOptionsChecked) {
|
|
93
|
+
checkParserOpts(this.options, true);
|
|
94
|
+
this.evaluationOptionsChecked = true;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
98
|
+
_checkValidationOptions() {
|
|
99
|
+
if (!this.validationOptionsChecked) {
|
|
100
|
+
checkParserOpts(this.options, false, true);
|
|
101
|
+
this.validationOptionsChecked = true;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Generates a railroad diagram for debugging. Does not 100% represent how things are actually handled internally.
|
|
106
|
+
*
|
|
107
|
+
* Not exposed because it uses the raw chevrotain tokens.
|
|
108
|
+
*
|
|
109
|
+
* **Note: It is not 100% accurate. Some special cases are parsed one way but handled internally differently.**
|
|
110
|
+
*/
|
|
111
|
+
_generateRailRoadDiagram() {
|
|
112
|
+
const serialized = this.parser.getSerializedGastProductions();
|
|
113
|
+
const html = createSyntaxDiagramsCode(serialized);
|
|
114
|
+
return html;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* For debugging.
|
|
118
|
+
* Not exposed because it returns the raw chevrotain tokens.
|
|
119
|
+
*/
|
|
120
|
+
_lex(input) {
|
|
121
|
+
return this.lexer.tokenize(input);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
mixin(Parser, [
|
|
125
|
+
AutocompleteMixin,
|
|
126
|
+
AutoreplaceMixin,
|
|
127
|
+
Autosuggest,
|
|
128
|
+
EvaluateMixin,
|
|
129
|
+
ValidateMixin,
|
|
130
|
+
NormalizeMixin,
|
|
131
|
+
GetIndexMixin,
|
|
132
|
+
GetBestIndexesMixin
|
|
133
|
+
]);
|
|
134
|
+
export {
|
|
135
|
+
Parser
|
|
136
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { AnyFunction } from "@alanscodelog/utils";
|
|
2
|
+
import type { ArrayNode } from "../ast/classes/ArrayNode.js";
|
|
3
|
+
import type { ConditionNode } from "../ast/classes/ConditionNode.js";
|
|
4
|
+
import type { ErrorToken } from "../ast/classes/ErrorToken.js";
|
|
5
|
+
import type { ExpressionNode } from "../ast/classes/ExpressionNode.js";
|
|
6
|
+
import type { GroupNode } from "../ast/classes/GroupNode.js";
|
|
7
|
+
import type { ValidToken } from "../ast/classes/ValidToken.js";
|
|
8
|
+
import type { VariableNode } from "../ast/classes/VariableNode.js";
|
|
9
|
+
export type AddParameters<T extends AnyFunction, TExtra extends any[] = [boolean]> = (...args: [...Parameters<T>, ...TExtra]) => ReturnType<T>;
|
|
10
|
+
export declare enum TOKEN_TYPE {
|
|
11
|
+
VALUE = "VALUE",
|
|
12
|
+
AND = "AND",
|
|
13
|
+
OR = "OR",
|
|
14
|
+
NOT = "NOT",
|
|
15
|
+
BACKTICK = "BACKTICK",
|
|
16
|
+
SINGLEQUOTE = "SINGLEQUOTE",
|
|
17
|
+
DOUBLEQUOTE = "DOUBLEQUOTE",
|
|
18
|
+
PARENL = "PARENL",
|
|
19
|
+
PARENR = "PARENR",
|
|
20
|
+
BRACKETL = "BRACKETL",
|
|
21
|
+
BRACKETR = "BRACKETR",
|
|
22
|
+
OP_EXPANDED_SEP = "OP_EXPANDED",
|
|
23
|
+
OP_CUSTOM = "OP_CUSTOM",
|
|
24
|
+
REGEX = "REGEX"
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* @internal
|
|
28
|
+
* Note if the negation operator, `!`, is used as a propertyOperator, this will return the wrong type.
|
|
29
|
+
*/
|
|
30
|
+
export type ExtractTokenType<T extends string> = T extends "`" ? TOKEN_TYPE.BACKTICK : T extends `'` ? TOKEN_TYPE.SINGLEQUOTE : T extends `"` ? TOKEN_TYPE.DOUBLEQUOTE : T extends `/` ? TOKEN_TYPE.REGEX : T extends `(` ? TOKEN_TYPE.PARENL : T extends `)` ? TOKEN_TYPE.PARENR : T extends `[` ? TOKEN_TYPE.BRACKETL : T extends `]` ? TOKEN_TYPE.BRACKETR : T extends `and` ? TOKEN_TYPE.AND : T extends `&&` ? TOKEN_TYPE.AND : T extends `&` ? TOKEN_TYPE.AND : T extends `or` ? TOKEN_TYPE.OR : T extends `||` ? TOKEN_TYPE.OR : T extends `|` ? TOKEN_TYPE.OR : T extends `not` ? TOKEN_TYPE.NOT : T extends `!` ? TOKEN_TYPE.NOT : TOKEN_TYPE.VALUE;
|
|
31
|
+
export type TokenParenTypes = TOKEN_TYPE.PARENL | TOKEN_TYPE.PARENR;
|
|
32
|
+
export type TokenBracketTypes = TOKEN_TYPE.BRACKETL | TOKEN_TYPE.BRACKETR;
|
|
33
|
+
export type TokenDelimiterTypes = TokenParenTypes | TokenQuoteTypes | TokenBracketTypes | TOKEN_TYPE.OP_EXPANDED_SEP;
|
|
34
|
+
export type TokenQuoteTypes = TOKEN_TYPE.BACKTICK | TOKEN_TYPE.SINGLEQUOTE | TOKEN_TYPE.DOUBLEQUOTE | TOKEN_TYPE.REGEX;
|
|
35
|
+
export type TokenBooleanTypes = TOKEN_TYPE.AND | TOKEN_TYPE.OR;
|
|
36
|
+
export type TokenOperatorTypes = TokenBooleanTypes | TOKEN_TYPE.NOT;
|
|
37
|
+
export type TokenPropertyOperatorTypes = TOKEN_TYPE.OP_CUSTOM | TOKEN_TYPE.OP_EXPANDED_SEP;
|
|
38
|
+
export type EmptyObj = Record<any, never>;
|
|
39
|
+
export type FirstConstructorParam<T extends new (...args: any) => any> = ConstructorParameters<T>["0"];
|
|
40
|
+
export type Position = {
|
|
41
|
+
start: number;
|
|
42
|
+
end: number;
|
|
43
|
+
};
|
|
44
|
+
export declare enum AST_TYPE {
|
|
45
|
+
EXPRESSION = "EXPRESSION",
|
|
46
|
+
GROUP = "GROUP",
|
|
47
|
+
ARRAY = "ARRAY",
|
|
48
|
+
CONDITION = "CONDITION",
|
|
49
|
+
VARIABLE = "VARIABLE"
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* For more easily typing tokens that might or might not be valid.
|
|
53
|
+
*
|
|
54
|
+
* Using @see Token does not work well in certain situations and is also more complex because it has so many generics.
|
|
55
|
+
*/
|
|
56
|
+
export type AnyToken<TType extends TOKEN_TYPE = TOKEN_TYPE> = ValidToken<TType> | ErrorToken<TType>;
|
|
57
|
+
export type ParserResults = ExpressionNode | ConditionNode | GroupNode | ErrorToken<TOKEN_TYPE.VALUE>;
|
|
58
|
+
export type Nodes = ExpressionNode | ConditionNode | GroupNode | VariableNode | ArrayNode;
|
|
59
|
+
/**
|
|
60
|
+
* Contains any delimiter tokens some AST nodes ( @see GroupNode and @see VariableNode ) can have.
|
|
61
|
+
*
|
|
62
|
+
* These are usually not important for evaluating an expression but are useful for syntax highlighting.
|
|
63
|
+
*/
|
|
64
|
+
export type NodeDelimiters<TLEFT extends TOKEN_TYPE, TRIGHT extends TOKEN_TYPE = TLEFT> = {
|
|
65
|
+
left: AnyToken<TLEFT>;
|
|
66
|
+
right: AnyToken<TRIGHT>;
|
|
67
|
+
/** Only exists if regexes are enabled and this is a regex value. */
|
|
68
|
+
flags?: ValidToken<TOKEN_TYPE.VALUE>;
|
|
69
|
+
};
|
|
70
|
+
//# source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__PURE__ */ ((TOKEN_TYPE2) => {
|
|
2
|
+
TOKEN_TYPE2["VALUE"] = "VALUE";
|
|
3
|
+
TOKEN_TYPE2["AND"] = "AND";
|
|
4
|
+
TOKEN_TYPE2["OR"] = "OR";
|
|
5
|
+
TOKEN_TYPE2["NOT"] = "NOT";
|
|
6
|
+
TOKEN_TYPE2["BACKTICK"] = "BACKTICK";
|
|
7
|
+
TOKEN_TYPE2["SINGLEQUOTE"] = "SINGLEQUOTE";
|
|
8
|
+
TOKEN_TYPE2["DOUBLEQUOTE"] = "DOUBLEQUOTE";
|
|
9
|
+
TOKEN_TYPE2["PARENL"] = "PARENL";
|
|
10
|
+
TOKEN_TYPE2["PARENR"] = "PARENR";
|
|
11
|
+
TOKEN_TYPE2["BRACKETL"] = "BRACKETL";
|
|
12
|
+
TOKEN_TYPE2["BRACKETR"] = "BRACKETR";
|
|
13
|
+
TOKEN_TYPE2["OP_EXPANDED_SEP"] = "OP_EXPANDED";
|
|
14
|
+
TOKEN_TYPE2["OP_CUSTOM"] = "OP_CUSTOM";
|
|
15
|
+
TOKEN_TYPE2["REGEX"] = "REGEX";
|
|
16
|
+
return TOKEN_TYPE2;
|
|
17
|
+
})(TOKEN_TYPE || {});
|
|
18
|
+
var AST_TYPE = /* @__PURE__ */ ((AST_TYPE2) => {
|
|
19
|
+
AST_TYPE2["EXPRESSION"] = "EXPRESSION";
|
|
20
|
+
AST_TYPE2["GROUP"] = "GROUP";
|
|
21
|
+
AST_TYPE2["ARRAY"] = "ARRAY";
|
|
22
|
+
AST_TYPE2["CONDITION"] = "CONDITION";
|
|
23
|
+
AST_TYPE2["VARIABLE"] = "VARIABLE";
|
|
24
|
+
return AST_TYPE2;
|
|
25
|
+
})(AST_TYPE || {});
|
|
26
|
+
export {
|
|
27
|
+
AST_TYPE,
|
|
28
|
+
TOKEN_TYPE
|
|
29
|
+
};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import type { AnyToken, Position } from "./ast.js";
|
|
2
|
+
import type { ValidToken } from "../ast/classes/ValidToken.js";
|
|
3
|
+
/**
|
|
4
|
+
* Contains information regarding the tokens around a cursor position. Mostly for internally use by @see autosuggest.
|
|
5
|
+
*
|
|
6
|
+
* Notes:
|
|
7
|
+
*
|
|
8
|
+
* - There are no whitespace tokens because whitespace is not tokenized. `prev`, `at`, `next` properties that contain tokens are set looking only at the list of tokens extracted from the ast by @see extractTokens. This is why there is an extra `whitespace` property to tell us whether there is whitespace (i.e. a hole) between the cursor and the next/prev **valid** tokens or if it can't find any, the start/end of the input.
|
|
9
|
+
* - If next/prev are invalid tokens, note that there are cases where more invalid tokens might follow them. To get them we can use @see getSurroundingErrors or we can just find their index in the tokens list and go forward/backward as needed:
|
|
10
|
+
* ```ts
|
|
11
|
+
* let i = tokens.findIndex(t => t === info.next)
|
|
12
|
+
* while (tokens[i] instanceof ErrorToken) {...}
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* Examples:
|
|
16
|
+
*
|
|
17
|
+
* ```js
|
|
18
|
+
* aaaa| bbbb // tokens: ["aaaa", TokenError(operator), "bbbb"]
|
|
19
|
+
* ^
|
|
20
|
+
* {
|
|
21
|
+
* index: 4, // cursor position
|
|
22
|
+
* at: undefined, // it's not inside a token
|
|
23
|
+
* prev: "aaaa",
|
|
24
|
+
* next: TokenError, // operator is missing to the right
|
|
25
|
+
* // closest valid tokens to either side
|
|
26
|
+
* valid: {
|
|
27
|
+
* prev: "aaaa",
|
|
28
|
+
* next: "bbbb",
|
|
29
|
+
* },
|
|
30
|
+
* // whether there is whitespace between the cursor and the next/prev valid tokens or start/end of input
|
|
31
|
+
* whitespace: {
|
|
32
|
+
* prev: false,
|
|
33
|
+
* next: true,
|
|
34
|
+
* }
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
* ```js
|
|
38
|
+
* aaaa || bb|bb && cccc
|
|
39
|
+
* ^
|
|
40
|
+
* {
|
|
41
|
+
* index: 10,
|
|
42
|
+
* at: "bbbb", // it's inside a token
|
|
43
|
+
* prev: "||",
|
|
44
|
+
* next: "&&",
|
|
45
|
+
* valid: {
|
|
46
|
+
* prev: "||",
|
|
47
|
+
* next: "&&",
|
|
48
|
+
* },
|
|
49
|
+
* whitespace: {
|
|
50
|
+
* prev: true,
|
|
51
|
+
* next: true,
|
|
52
|
+
* }
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export type CursorInfo = {
|
|
57
|
+
index: number;
|
|
58
|
+
/**
|
|
59
|
+
* The token the cursor is inside of. By "inside", we mean the ends of the token are before/after the cursor respectively (e.g. `a|a`, but NOT `|aa` or `aa|`). This token, if defined, is always a valid token, since error tokens have no length.
|
|
60
|
+
*
|
|
61
|
+
* Note though that there are cases where one might be inside a variable but not inside a token because quotes are their own tokens (e.g. `"|var"` or `"var|"`).
|
|
62
|
+
*/
|
|
63
|
+
at?: ValidToken;
|
|
64
|
+
/** The first token, valid or invalid, that starts at or after the index position. */
|
|
65
|
+
next?: AnyToken;
|
|
66
|
+
/** The first token (going backwards), valid or invalid, that ends at or before the index position. */
|
|
67
|
+
prev?: AnyToken;
|
|
68
|
+
/** Closest valid tokens. */
|
|
69
|
+
valid: {
|
|
70
|
+
/** Closest prev valid token. */
|
|
71
|
+
next?: ValidToken;
|
|
72
|
+
/** Closest next valid token. */
|
|
73
|
+
prev?: ValidToken;
|
|
74
|
+
};
|
|
75
|
+
/** Whether there is whitespace between the cursor and the next/prev valid tokens or start/end of the input. */
|
|
76
|
+
whitespace: {
|
|
77
|
+
/** Whether there is whitespace between the cursor and the next valid token or the end of the input. */
|
|
78
|
+
next: boolean;
|
|
79
|
+
/** Whether there is whitespace between the cursor and the prev valid token or the start of the input. */
|
|
80
|
+
prev: boolean;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
export declare enum SUGGESTION_TYPE {
|
|
84
|
+
VARIABLE = "VARIABLE",
|
|
85
|
+
ARRAY_VALUE = "ARRAY_VALUE",
|
|
86
|
+
VALUE = "VALUE",
|
|
87
|
+
PREFIX = "PREFIX",
|
|
88
|
+
BOOLEAN_WORD_OP = "BOOLEAN_WORD_OP",
|
|
89
|
+
BOOLEAN_SYMBOL_OP = "BOOLEAN_SYMBOL_OP",
|
|
90
|
+
BACKTICK = "BACKTICK",
|
|
91
|
+
DOUBLEQUOTE = "DOUBLEQUOTE",
|
|
92
|
+
SINGLEQUOTE = "SINGLEQUOTE",
|
|
93
|
+
PARENL = "PARENL",
|
|
94
|
+
PARENR = "PARENR",
|
|
95
|
+
PROPERTY = "PROPERTY",
|
|
96
|
+
EXPANDED_PROPERTY_OPERATOR = "EXPANDED_PROPERTY_OPERATOR",
|
|
97
|
+
CUSTOM_PROPERTY_OPERATOR = "CUSTOM_PROPERTY_OPERATOR",
|
|
98
|
+
PROPERTY_SEP = "PROPERTY_SEP",
|
|
99
|
+
BRAKCETR = "BRAKCETR",
|
|
100
|
+
REGEX = "REGEX",
|
|
101
|
+
REGEX_FLAGS = "REGEX_FLAGS"
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* A suggestion entry that describes a type of suggestion.
|
|
105
|
+
*/
|
|
106
|
+
export type Suggestion = {
|
|
107
|
+
type: SUGGESTION_TYPE;
|
|
108
|
+
/** The range the suggestion should replace / be inserted at. */
|
|
109
|
+
range: Position;
|
|
110
|
+
/** @see CursorInfo */
|
|
111
|
+
cursorInfo: CursorInfo;
|
|
112
|
+
/** Tells us any additional requirements for inserting the suggestion. */
|
|
113
|
+
requires: {
|
|
114
|
+
/**
|
|
115
|
+
* Whether the suggestions requires inserting whitespace before/after to keep the intent of the expression consistent. For example, an unquoted variable needs a space between it and a non-symbol operator.
|
|
116
|
+
*
|
|
117
|
+
* In the case of variables this requirement can be ignored though if you insert a quoted value.
|
|
118
|
+
*/
|
|
119
|
+
whitespace: {
|
|
120
|
+
after: boolean;
|
|
121
|
+
before: boolean;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* If prefixableGroups is enabled, a suggestion can be a prefix suggestion and this tells us whether `()` needs to be inserted at the end in the case it does not already exist.
|
|
125
|
+
*
|
|
126
|
+
* For example, a user might choose to insert a prefix in this situation `a && |` and we want the result to be `a && prefix()` because without the `()` the prefix will probably be an invalid variable name on insertion.
|
|
127
|
+
*
|
|
128
|
+
* The opposite happens with an existing prefix where the user might want to replace it. `a && existing|(...)`. We want the result to be `a && replacement(...)` not `a && replacement()(...)`.
|
|
129
|
+
*/
|
|
130
|
+
group: boolean;
|
|
131
|
+
/** If `prefixableValues` is enabled and a value is prefixed, contains the prefix it was prefixed with. Note that the prefix is included in the range. This way you can choose to suggest/replace just the prefix, just the value or both. */
|
|
132
|
+
prefix: string | false;
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Whether the suggestion was created because there was an error token there and it would fix it.
|
|
136
|
+
*/
|
|
137
|
+
isError: boolean;
|
|
138
|
+
};
|
|
139
|
+
export type Completion = {
|
|
140
|
+
suggestion: Suggestion;
|
|
141
|
+
value: string;
|
|
142
|
+
};
|
|
143
|
+
//# sourceMappingURL=autocomplete.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"autocomplete.d.ts","sourceRoot":"","sources":["../../src/types/autocomplete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAElD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAA;AAG9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,MAAM,MAAM,UAAU,GAAG;IACxB,KAAK,EAAE,MAAM,CAAA;IACb;;;;OAIG;IACH,EAAE,CAAC,EAAE,UAAU,CAAA;IACf,qFAAqF;IACrF,IAAI,CAAC,EAAE,QAAQ,CAAA;IACf,sGAAsG;IACtG,IAAI,CAAC,EAAE,QAAQ,CAAA;IACf,4BAA4B;IAC5B,KAAK,EAAE;QAC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