@lokascript/semantic 1.0.0
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/LICENSE +21 -0
- package/README.md +686 -0
- package/dist/browser-ar.ar.global.js +2 -0
- package/dist/browser-core.core.global.js +2 -0
- package/dist/browser-de.de.global.js +2 -0
- package/dist/browser-east-asian.east-asian.global.js +2 -0
- package/dist/browser-en-tr.en-tr.global.js +2 -0
- package/dist/browser-en.en.global.js +2 -0
- package/dist/browser-es-en.es-en.global.js +2 -0
- package/dist/browser-es.es.global.js +2 -0
- package/dist/browser-fr.fr.global.js +2 -0
- package/dist/browser-id.id.global.js +2 -0
- package/dist/browser-ja.ja.global.js +2 -0
- package/dist/browser-ko.ko.global.js +2 -0
- package/dist/browser-lazy.lazy.global.js +2 -0
- package/dist/browser-priority.priority.global.js +2 -0
- package/dist/browser-pt.pt.global.js +2 -0
- package/dist/browser-qu.qu.global.js +2 -0
- package/dist/browser-sw.sw.global.js +2 -0
- package/dist/browser-tr.tr.global.js +2 -0
- package/dist/browser-western.western.global.js +2 -0
- package/dist/browser-zh.zh.global.js +2 -0
- package/dist/browser.global.js +3 -0
- package/dist/browser.global.js.map +1 -0
- package/dist/index.cjs +35051 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +3426 -0
- package/dist/index.d.ts +3426 -0
- package/dist/index.js +34890 -0
- package/dist/index.js.map +1 -0
- package/dist/languages/ar.d.ts +78 -0
- package/dist/languages/ar.js +1622 -0
- package/dist/languages/ar.js.map +1 -0
- package/dist/languages/de.d.ts +38 -0
- package/dist/languages/de.js +1168 -0
- package/dist/languages/de.js.map +1 -0
- package/dist/languages/en.d.ts +44 -0
- package/dist/languages/en.js +3491 -0
- package/dist/languages/en.js.map +1 -0
- package/dist/languages/es.d.ts +52 -0
- package/dist/languages/es.js +1493 -0
- package/dist/languages/es.js.map +1 -0
- package/dist/languages/fr.d.ts +37 -0
- package/dist/languages/fr.js +1159 -0
- package/dist/languages/fr.js.map +1 -0
- package/dist/languages/id.d.ts +35 -0
- package/dist/languages/id.js +1152 -0
- package/dist/languages/id.js.map +1 -0
- package/dist/languages/ja.d.ts +53 -0
- package/dist/languages/ja.js +1430 -0
- package/dist/languages/ja.js.map +1 -0
- package/dist/languages/ko.d.ts +51 -0
- package/dist/languages/ko.js +1729 -0
- package/dist/languages/ko.js.map +1 -0
- package/dist/languages/pt.d.ts +37 -0
- package/dist/languages/pt.js +1127 -0
- package/dist/languages/pt.js.map +1 -0
- package/dist/languages/qu.d.ts +36 -0
- package/dist/languages/qu.js +1143 -0
- package/dist/languages/qu.js.map +1 -0
- package/dist/languages/sw.d.ts +35 -0
- package/dist/languages/sw.js +1147 -0
- package/dist/languages/sw.js.map +1 -0
- package/dist/languages/tr.d.ts +45 -0
- package/dist/languages/tr.js +1529 -0
- package/dist/languages/tr.js.map +1 -0
- package/dist/languages/zh.d.ts +58 -0
- package/dist/languages/zh.js +1257 -0
- package/dist/languages/zh.js.map +1 -0
- package/dist/types-C4dcj53L.d.ts +600 -0
- package/package.json +202 -0
- package/src/__test-utils__/index.ts +7 -0
- package/src/__test-utils__/test-helpers.ts +8 -0
- package/src/__types__/test-helpers.ts +122 -0
- package/src/analysis/index.ts +479 -0
- package/src/ast-builder/command-mappers.ts +1133 -0
- package/src/ast-builder/expression-parser/index.ts +41 -0
- package/src/ast-builder/expression-parser/parser.ts +563 -0
- package/src/ast-builder/expression-parser/tokenizer.ts +394 -0
- package/src/ast-builder/expression-parser/types.ts +208 -0
- package/src/ast-builder/index.ts +536 -0
- package/src/ast-builder/value-converters.ts +172 -0
- package/src/bridge.ts +275 -0
- package/src/browser-ar.ts +162 -0
- package/src/browser-core.ts +231 -0
- package/src/browser-de.ts +162 -0
- package/src/browser-east-asian.ts +173 -0
- package/src/browser-en-tr.ts +165 -0
- package/src/browser-en.ts +157 -0
- package/src/browser-es-en.ts +200 -0
- package/src/browser-es.ts +170 -0
- package/src/browser-fr.ts +162 -0
- package/src/browser-id.ts +162 -0
- package/src/browser-ja.ts +162 -0
- package/src/browser-ko.ts +162 -0
- package/src/browser-lazy.ts +189 -0
- package/src/browser-priority.ts +214 -0
- package/src/browser-pt.ts +162 -0
- package/src/browser-qu.ts +162 -0
- package/src/browser-sw.ts +162 -0
- package/src/browser-tr.ts +162 -0
- package/src/browser-western.ts +181 -0
- package/src/browser-zh.ts +162 -0
- package/src/browser.ts +268 -0
- package/src/cache/index.ts +14 -0
- package/src/cache/semantic-cache.ts +344 -0
- package/src/core-bridge.ts +372 -0
- package/src/explicit/converter.ts +258 -0
- package/src/explicit/index.ts +18 -0
- package/src/explicit/parser.ts +236 -0
- package/src/explicit/renderer.ts +424 -0
- package/src/generators/command-schemas.ts +1636 -0
- package/src/generators/event-handler-generator.ts +109 -0
- package/src/generators/index.ts +117 -0
- package/src/generators/language-profiles.ts +139 -0
- package/src/generators/pattern-generator.ts +537 -0
- package/src/generators/profiles/arabic.ts +131 -0
- package/src/generators/profiles/bengali.ts +132 -0
- package/src/generators/profiles/chinese.ts +124 -0
- package/src/generators/profiles/english.ts +113 -0
- package/src/generators/profiles/french.ts +125 -0
- package/src/generators/profiles/german.ts +126 -0
- package/src/generators/profiles/hindi.ts +146 -0
- package/src/generators/profiles/index.ts +46 -0
- package/src/generators/profiles/indonesian.ts +125 -0
- package/src/generators/profiles/italian.ts +139 -0
- package/src/generators/profiles/japanese.ts +149 -0
- package/src/generators/profiles/korean.ts +127 -0
- package/src/generators/profiles/marker-templates.ts +288 -0
- package/src/generators/profiles/ms.ts +130 -0
- package/src/generators/profiles/polish.ts +249 -0
- package/src/generators/profiles/portuguese.ts +115 -0
- package/src/generators/profiles/quechua.ts +113 -0
- package/src/generators/profiles/russian.ts +260 -0
- package/src/generators/profiles/spanish.ts +130 -0
- package/src/generators/profiles/swahili.ts +129 -0
- package/src/generators/profiles/thai.ts +132 -0
- package/src/generators/profiles/tl.ts +128 -0
- package/src/generators/profiles/turkish.ts +124 -0
- package/src/generators/profiles/types.ts +165 -0
- package/src/generators/profiles/ukrainian.ts +270 -0
- package/src/generators/profiles/vietnamese.ts +133 -0
- package/src/generators/schema-error-codes.ts +160 -0
- package/src/generators/schema-validator.ts +391 -0
- package/src/index.ts +429 -0
- package/src/language-building-schema.ts +3170 -0
- package/src/language-loader.ts +394 -0
- package/src/languages/_all.ts +65 -0
- package/src/languages/ar.ts +15 -0
- package/src/languages/bn.ts +16 -0
- package/src/languages/de.ts +15 -0
- package/src/languages/en.ts +29 -0
- package/src/languages/es.ts +15 -0
- package/src/languages/fr.ts +15 -0
- package/src/languages/hi.ts +26 -0
- package/src/languages/id.ts +15 -0
- package/src/languages/index.ts +18 -0
- package/src/languages/it.ts +15 -0
- package/src/languages/ja.ts +15 -0
- package/src/languages/ko.ts +15 -0
- package/src/languages/ms.ts +16 -0
- package/src/languages/pl.ts +18 -0
- package/src/languages/pt.ts +15 -0
- package/src/languages/qu.ts +15 -0
- package/src/languages/ru.ts +26 -0
- package/src/languages/sw.ts +15 -0
- package/src/languages/th.ts +16 -0
- package/src/languages/tl.ts +16 -0
- package/src/languages/tr.ts +15 -0
- package/src/languages/uk.ts +26 -0
- package/src/languages/vi.ts +16 -0
- package/src/languages/zh.ts +15 -0
- package/src/parser/index.ts +15 -0
- package/src/parser/pattern-matcher.ts +1181 -0
- package/src/parser/semantic-parser.ts +573 -0
- package/src/parser/utils/index.ts +35 -0
- package/src/parser/utils/marker-resolution.ts +111 -0
- package/src/parser/utils/possessive-keywords.ts +43 -0
- package/src/parser/utils/role-positioning.ts +70 -0
- package/src/parser/utils/type-validation.ts +134 -0
- package/src/patterns/add/ar.ts +71 -0
- package/src/patterns/add/bn.ts +70 -0
- package/src/patterns/add/hi.ts +69 -0
- package/src/patterns/add/index.ts +87 -0
- package/src/patterns/add/it.ts +61 -0
- package/src/patterns/add/ja.ts +93 -0
- package/src/patterns/add/ko.ts +74 -0
- package/src/patterns/add/ms.ts +30 -0
- package/src/patterns/add/pl.ts +62 -0
- package/src/patterns/add/ru.ts +62 -0
- package/src/patterns/add/th.ts +49 -0
- package/src/patterns/add/tl.ts +30 -0
- package/src/patterns/add/tr.ts +71 -0
- package/src/patterns/add/uk.ts +62 -0
- package/src/patterns/add/vi.ts +61 -0
- package/src/patterns/add/zh.ts +71 -0
- package/src/patterns/builders.ts +207 -0
- package/src/patterns/decrement/bn.ts +70 -0
- package/src/patterns/decrement/de.ts +42 -0
- package/src/patterns/decrement/hi.ts +68 -0
- package/src/patterns/decrement/index.ts +79 -0
- package/src/patterns/decrement/it.ts +69 -0
- package/src/patterns/decrement/ms.ts +30 -0
- package/src/patterns/decrement/pl.ts +58 -0
- package/src/patterns/decrement/ru.ts +58 -0
- package/src/patterns/decrement/th.ts +49 -0
- package/src/patterns/decrement/tl.ts +30 -0
- package/src/patterns/decrement/tr.ts +48 -0
- package/src/patterns/decrement/uk.ts +58 -0
- package/src/patterns/decrement/vi.ts +61 -0
- package/src/patterns/decrement/zh.ts +32 -0
- package/src/patterns/en.ts +302 -0
- package/src/patterns/event-handler/ar.ts +151 -0
- package/src/patterns/event-handler/bn.ts +72 -0
- package/src/patterns/event-handler/de.ts +117 -0
- package/src/patterns/event-handler/en.ts +117 -0
- package/src/patterns/event-handler/es.ts +136 -0
- package/src/patterns/event-handler/fr.ts +117 -0
- package/src/patterns/event-handler/hi.ts +64 -0
- package/src/patterns/event-handler/id.ts +117 -0
- package/src/patterns/event-handler/index.ts +119 -0
- package/src/patterns/event-handler/it.ts +54 -0
- package/src/patterns/event-handler/ja.ts +118 -0
- package/src/patterns/event-handler/ko.ts +133 -0
- package/src/patterns/event-handler/ms.ts +30 -0
- package/src/patterns/event-handler/pl.ts +62 -0
- package/src/patterns/event-handler/pt.ts +117 -0
- package/src/patterns/event-handler/qu.ts +66 -0
- package/src/patterns/event-handler/ru.ts +62 -0
- package/src/patterns/event-handler/shared.ts +270 -0
- package/src/patterns/event-handler/sw.ts +117 -0
- package/src/patterns/event-handler/th.ts +53 -0
- package/src/patterns/event-handler/tl.ts +30 -0
- package/src/patterns/event-handler/tr.ts +170 -0
- package/src/patterns/event-handler/uk.ts +62 -0
- package/src/patterns/event-handler/vi.ts +61 -0
- package/src/patterns/event-handler/zh.ts +150 -0
- package/src/patterns/get/ar.ts +49 -0
- package/src/patterns/get/bn.ts +47 -0
- package/src/patterns/get/de.ts +32 -0
- package/src/patterns/get/hi.ts +52 -0
- package/src/patterns/get/index.ts +83 -0
- package/src/patterns/get/it.ts +56 -0
- package/src/patterns/get/ja.ts +53 -0
- package/src/patterns/get/ko.ts +53 -0
- package/src/patterns/get/ms.ts +30 -0
- package/src/patterns/get/pl.ts +57 -0
- package/src/patterns/get/ru.ts +57 -0
- package/src/patterns/get/th.ts +29 -0
- package/src/patterns/get/tl.ts +30 -0
- package/src/patterns/get/uk.ts +57 -0
- package/src/patterns/get/vi.ts +48 -0
- package/src/patterns/grammar-transformed/index.ts +39 -0
- package/src/patterns/grammar-transformed/ja.ts +1713 -0
- package/src/patterns/grammar-transformed/ko.ts +1311 -0
- package/src/patterns/grammar-transformed/tr.ts +1067 -0
- package/src/patterns/hide/ar.ts +67 -0
- package/src/patterns/hide/bn.ts +47 -0
- package/src/patterns/hide/de.ts +36 -0
- package/src/patterns/hide/hi.ts +61 -0
- package/src/patterns/hide/index.ts +91 -0
- package/src/patterns/hide/it.ts +56 -0
- package/src/patterns/hide/ja.ts +69 -0
- package/src/patterns/hide/ko.ts +69 -0
- package/src/patterns/hide/ms.ts +30 -0
- package/src/patterns/hide/pl.ts +57 -0
- package/src/patterns/hide/ru.ts +57 -0
- package/src/patterns/hide/th.ts +29 -0
- package/src/patterns/hide/tl.ts +30 -0
- package/src/patterns/hide/tr.ts +65 -0
- package/src/patterns/hide/uk.ts +57 -0
- package/src/patterns/hide/vi.ts +56 -0
- package/src/patterns/hide/zh.ts +68 -0
- package/src/patterns/increment/bn.ts +70 -0
- package/src/patterns/increment/de.ts +36 -0
- package/src/patterns/increment/hi.ts +68 -0
- package/src/patterns/increment/index.ts +79 -0
- package/src/patterns/increment/it.ts +69 -0
- package/src/patterns/increment/ms.ts +30 -0
- package/src/patterns/increment/pl.ts +58 -0
- package/src/patterns/increment/ru.ts +58 -0
- package/src/patterns/increment/th.ts +49 -0
- package/src/patterns/increment/tl.ts +30 -0
- package/src/patterns/increment/tr.ts +52 -0
- package/src/patterns/increment/uk.ts +58 -0
- package/src/patterns/increment/vi.ts +61 -0
- package/src/patterns/increment/zh.ts +32 -0
- package/src/patterns/index.ts +84 -0
- package/src/patterns/languages/en/control-flow.ts +93 -0
- package/src/patterns/languages/en/fetch.ts +62 -0
- package/src/patterns/languages/en/index.ts +42 -0
- package/src/patterns/languages/en/repeat.ts +67 -0
- package/src/patterns/languages/en/set.ts +48 -0
- package/src/patterns/languages/en/swap.ts +38 -0
- package/src/patterns/languages/en/temporal.ts +57 -0
- package/src/patterns/put/ar.ts +74 -0
- package/src/patterns/put/bn.ts +53 -0
- package/src/patterns/put/en.ts +74 -0
- package/src/patterns/put/es.ts +74 -0
- package/src/patterns/put/hi.ts +69 -0
- package/src/patterns/put/id.ts +96 -0
- package/src/patterns/put/index.ts +99 -0
- package/src/patterns/put/it.ts +56 -0
- package/src/patterns/put/ja.ts +75 -0
- package/src/patterns/put/ko.ts +67 -0
- package/src/patterns/put/ms.ts +30 -0
- package/src/patterns/put/pl.ts +81 -0
- package/src/patterns/put/ru.ts +85 -0
- package/src/patterns/put/th.ts +32 -0
- package/src/patterns/put/tl.ts +30 -0
- package/src/patterns/put/tr.ts +67 -0
- package/src/patterns/put/uk.ts +85 -0
- package/src/patterns/put/vi.ts +72 -0
- package/src/patterns/put/zh.ts +62 -0
- package/src/patterns/registry.ts +163 -0
- package/src/patterns/remove/ar.ts +71 -0
- package/src/patterns/remove/bn.ts +68 -0
- package/src/patterns/remove/hi.ts +69 -0
- package/src/patterns/remove/index.ts +87 -0
- package/src/patterns/remove/it.ts +69 -0
- package/src/patterns/remove/ja.ts +74 -0
- package/src/patterns/remove/ko.ts +78 -0
- package/src/patterns/remove/ms.ts +30 -0
- package/src/patterns/remove/pl.ts +62 -0
- package/src/patterns/remove/ru.ts +62 -0
- package/src/patterns/remove/th.ts +49 -0
- package/src/patterns/remove/tl.ts +30 -0
- package/src/patterns/remove/tr.ts +78 -0
- package/src/patterns/remove/uk.ts +62 -0
- package/src/patterns/remove/vi.ts +61 -0
- package/src/patterns/remove/zh.ts +72 -0
- package/src/patterns/set/ar.ts +84 -0
- package/src/patterns/set/bn.ts +53 -0
- package/src/patterns/set/de.ts +84 -0
- package/src/patterns/set/es.ts +92 -0
- package/src/patterns/set/fr.ts +88 -0
- package/src/patterns/set/hi.ts +56 -0
- package/src/patterns/set/id.ts +84 -0
- package/src/patterns/set/index.ts +107 -0
- package/src/patterns/set/it.ts +56 -0
- package/src/patterns/set/ja.ts +86 -0
- package/src/patterns/set/ko.ts +85 -0
- package/src/patterns/set/ms.ts +30 -0
- package/src/patterns/set/pl.ts +57 -0
- package/src/patterns/set/pt.ts +84 -0
- package/src/patterns/set/ru.ts +57 -0
- package/src/patterns/set/th.ts +31 -0
- package/src/patterns/set/tl.ts +30 -0
- package/src/patterns/set/tr.ts +107 -0
- package/src/patterns/set/uk.ts +57 -0
- package/src/patterns/set/vi.ts +53 -0
- package/src/patterns/set/zh.ts +84 -0
- package/src/patterns/show/ar.ts +67 -0
- package/src/patterns/show/bn.ts +47 -0
- package/src/patterns/show/de.ts +32 -0
- package/src/patterns/show/fr.ts +32 -0
- package/src/patterns/show/hi.ts +61 -0
- package/src/patterns/show/index.ts +95 -0
- package/src/patterns/show/it.ts +56 -0
- package/src/patterns/show/ja.ts +69 -0
- package/src/patterns/show/ko.ts +73 -0
- package/src/patterns/show/ms.ts +30 -0
- package/src/patterns/show/pl.ts +57 -0
- package/src/patterns/show/ru.ts +57 -0
- package/src/patterns/show/th.ts +29 -0
- package/src/patterns/show/tl.ts +30 -0
- package/src/patterns/show/tr.ts +65 -0
- package/src/patterns/show/uk.ts +57 -0
- package/src/patterns/show/vi.ts +56 -0
- package/src/patterns/show/zh.ts +68 -0
- package/src/patterns/take/ar.ts +51 -0
- package/src/patterns/take/index.ts +31 -0
- package/src/patterns/toggle/ar.ts +61 -0
- package/src/patterns/toggle/bn.ts +70 -0
- package/src/patterns/toggle/en.ts +61 -0
- package/src/patterns/toggle/es.ts +61 -0
- package/src/patterns/toggle/hi.ts +80 -0
- package/src/patterns/toggle/index.ts +95 -0
- package/src/patterns/toggle/it.ts +69 -0
- package/src/patterns/toggle/ja.ts +156 -0
- package/src/patterns/toggle/ko.ts +113 -0
- package/src/patterns/toggle/ms.ts +30 -0
- package/src/patterns/toggle/pl.ts +62 -0
- package/src/patterns/toggle/ru.ts +62 -0
- package/src/patterns/toggle/th.ts +50 -0
- package/src/patterns/toggle/tl.ts +30 -0
- package/src/patterns/toggle/tr.ts +88 -0
- package/src/patterns/toggle/uk.ts +62 -0
- package/src/patterns/toggle/vi.ts +61 -0
- package/src/patterns/toggle/zh.ts +99 -0
- package/src/public-api.ts +286 -0
- package/src/registry.ts +441 -0
- package/src/tokenizers/arabic.ts +723 -0
- package/src/tokenizers/base.ts +1300 -0
- package/src/tokenizers/bengali.ts +289 -0
- package/src/tokenizers/chinese.ts +481 -0
- package/src/tokenizers/english.ts +416 -0
- package/src/tokenizers/french.ts +326 -0
- package/src/tokenizers/german.ts +324 -0
- package/src/tokenizers/hindi.ts +319 -0
- package/src/tokenizers/index.ts +127 -0
- package/src/tokenizers/indonesian.ts +306 -0
- package/src/tokenizers/italian.ts +458 -0
- package/src/tokenizers/japanese.ts +447 -0
- package/src/tokenizers/korean.ts +642 -0
- package/src/tokenizers/morphology/arabic-normalizer.ts +242 -0
- package/src/tokenizers/morphology/french-normalizer.ts +268 -0
- package/src/tokenizers/morphology/german-normalizer.ts +256 -0
- package/src/tokenizers/morphology/index.ts +46 -0
- package/src/tokenizers/morphology/italian-normalizer.ts +329 -0
- package/src/tokenizers/morphology/japanese-normalizer.ts +288 -0
- package/src/tokenizers/morphology/korean-normalizer.ts +428 -0
- package/src/tokenizers/morphology/polish-normalizer.ts +264 -0
- package/src/tokenizers/morphology/portuguese-normalizer.ts +310 -0
- package/src/tokenizers/morphology/spanish-normalizer.ts +327 -0
- package/src/tokenizers/morphology/turkish-normalizer.ts +412 -0
- package/src/tokenizers/morphology/types.ts +211 -0
- package/src/tokenizers/ms.ts +198 -0
- package/src/tokenizers/polish.ts +354 -0
- package/src/tokenizers/portuguese.ts +304 -0
- package/src/tokenizers/quechua.ts +339 -0
- package/src/tokenizers/russian.ts +375 -0
- package/src/tokenizers/spanish.ts +403 -0
- package/src/tokenizers/swahili.ts +303 -0
- package/src/tokenizers/thai.ts +236 -0
- package/src/tokenizers/tl.ts +198 -0
- package/src/tokenizers/turkish.ts +411 -0
- package/src/tokenizers/ukrainian.ts +369 -0
- package/src/tokenizers/vietnamese.ts +410 -0
- package/src/types/grammar-types.ts +617 -0
- package/src/types/unified-profile.ts +267 -0
- package/src/types.ts +709 -0
- package/src/utils/confidence-calculator.ts +147 -0
- package/src/validators/command-validator.ts +380 -0
- package/src/validators/index.ts +15 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Expression Parser
|
|
3
|
+
*
|
|
4
|
+
* Internal expression parser for the semantic AST builder.
|
|
5
|
+
* Parses raw expression strings into AST nodes when semantic values
|
|
6
|
+
* cannot be directly converted.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// Types
|
|
12
|
+
export type {
|
|
13
|
+
ExpressionNode,
|
|
14
|
+
LiteralNode,
|
|
15
|
+
TemplateLiteralNode,
|
|
16
|
+
SelectorNode,
|
|
17
|
+
SelectorKind,
|
|
18
|
+
ContextReferenceNode,
|
|
19
|
+
ContextType,
|
|
20
|
+
IdentifierNode,
|
|
21
|
+
PropertyAccessNode,
|
|
22
|
+
MemberExpressionNode,
|
|
23
|
+
PossessiveExpressionNode,
|
|
24
|
+
BinaryExpressionNode,
|
|
25
|
+
UnaryExpressionNode,
|
|
26
|
+
CallExpressionNode,
|
|
27
|
+
ArrayLiteralNode,
|
|
28
|
+
ObjectLiteralNode,
|
|
29
|
+
ObjectPropertyNode,
|
|
30
|
+
TimeExpressionNode,
|
|
31
|
+
ErrorNode,
|
|
32
|
+
AnyExpressionNode,
|
|
33
|
+
ExpressionParseResult,
|
|
34
|
+
} from './types';
|
|
35
|
+
|
|
36
|
+
// Tokenizer
|
|
37
|
+
export { tokenize, TokenType } from './tokenizer';
|
|
38
|
+
export type { Token } from './tokenizer';
|
|
39
|
+
|
|
40
|
+
// Parser
|
|
41
|
+
export { ExpressionParser, parseExpression } from './parser';
|
|
@@ -0,0 +1,563 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Expression Parser
|
|
3
|
+
*
|
|
4
|
+
* Parses expression tokens into AST nodes.
|
|
5
|
+
* Uses recursive descent parsing with operator precedence.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { tokenize, Token, TokenType } from './tokenizer';
|
|
9
|
+
import type {
|
|
10
|
+
ExpressionNode,
|
|
11
|
+
LiteralNode,
|
|
12
|
+
TemplateLiteralNode,
|
|
13
|
+
SelectorNode,
|
|
14
|
+
ContextReferenceNode,
|
|
15
|
+
IdentifierNode,
|
|
16
|
+
PropertyAccessNode,
|
|
17
|
+
PossessiveExpressionNode,
|
|
18
|
+
BinaryExpressionNode,
|
|
19
|
+
UnaryExpressionNode,
|
|
20
|
+
CallExpressionNode,
|
|
21
|
+
ArrayLiteralNode,
|
|
22
|
+
ObjectLiteralNode,
|
|
23
|
+
TimeExpressionNode,
|
|
24
|
+
ExpressionParseResult,
|
|
25
|
+
ContextType,
|
|
26
|
+
SelectorKind,
|
|
27
|
+
} from './types';
|
|
28
|
+
|
|
29
|
+
// =============================================================================
|
|
30
|
+
// Parser Class
|
|
31
|
+
// =============================================================================
|
|
32
|
+
|
|
33
|
+
export class ExpressionParser {
|
|
34
|
+
private tokens: Token[] = [];
|
|
35
|
+
private current = 0;
|
|
36
|
+
|
|
37
|
+
parse(input: string): ExpressionParseResult {
|
|
38
|
+
try {
|
|
39
|
+
this.tokens = tokenize(input);
|
|
40
|
+
this.current = 0;
|
|
41
|
+
|
|
42
|
+
if (this.isAtEnd()) {
|
|
43
|
+
return { success: false, error: 'Empty expression' };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const node = this.parseExpression();
|
|
47
|
+
return { success: true, node, consumed: this.current };
|
|
48
|
+
} catch (e) {
|
|
49
|
+
return {
|
|
50
|
+
success: false,
|
|
51
|
+
error: e instanceof Error ? e.message : 'Parse error',
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// =============================================================================
|
|
57
|
+
// Token Navigation
|
|
58
|
+
// =============================================================================
|
|
59
|
+
|
|
60
|
+
private peek(): Token {
|
|
61
|
+
return this.tokens[this.current] ?? { type: TokenType.EOF, value: '', start: 0, end: 0 };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private previous(): Token {
|
|
65
|
+
return this.tokens[this.current - 1] ?? { type: TokenType.EOF, value: '', start: 0, end: 0 };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private isAtEnd(): boolean {
|
|
69
|
+
return this.peek().type === TokenType.EOF;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private advance(): Token {
|
|
73
|
+
if (!this.isAtEnd()) {
|
|
74
|
+
this.current++;
|
|
75
|
+
}
|
|
76
|
+
return this.previous();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
private check(type: TokenType): boolean {
|
|
80
|
+
return this.peek().type === type;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
private checkValue(value: string): boolean {
|
|
84
|
+
return this.peek().value.toLowerCase() === value.toLowerCase();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private match(...types: TokenType[]): boolean {
|
|
88
|
+
for (const type of types) {
|
|
89
|
+
if (this.check(type)) {
|
|
90
|
+
this.advance();
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// =============================================================================
|
|
98
|
+
// Expression Parsing (Precedence Climbing)
|
|
99
|
+
// =============================================================================
|
|
100
|
+
|
|
101
|
+
private parseExpression(): ExpressionNode {
|
|
102
|
+
return this.parseOr();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
private parseOr(): ExpressionNode {
|
|
106
|
+
let left = this.parseAnd();
|
|
107
|
+
|
|
108
|
+
while (this.checkValue('or')) {
|
|
109
|
+
const operator = this.advance().value;
|
|
110
|
+
const right = this.parseAnd();
|
|
111
|
+
left = this.createBinaryExpression(operator, left, right);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return left;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
private parseAnd(): ExpressionNode {
|
|
118
|
+
let left = this.parseEquality();
|
|
119
|
+
|
|
120
|
+
while (this.checkValue('and')) {
|
|
121
|
+
const operator = this.advance().value;
|
|
122
|
+
const right = this.parseEquality();
|
|
123
|
+
left = this.createBinaryExpression(operator, left, right);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return left;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
private parseEquality(): ExpressionNode {
|
|
130
|
+
let left = this.parseComparison();
|
|
131
|
+
|
|
132
|
+
while (
|
|
133
|
+
this.match(TokenType.COMPARISON) ||
|
|
134
|
+
this.checkValue('is') ||
|
|
135
|
+
this.checkValue('matches') ||
|
|
136
|
+
this.checkValue('contains') ||
|
|
137
|
+
this.checkValue('in')
|
|
138
|
+
) {
|
|
139
|
+
const operator = this.previous().value;
|
|
140
|
+
const right = this.parseComparison();
|
|
141
|
+
left = this.createBinaryExpression(operator, left, right);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return left;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
private parseComparison(): ExpressionNode {
|
|
148
|
+
let left = this.parseAddition();
|
|
149
|
+
|
|
150
|
+
while (this.check(TokenType.COMPARISON)) {
|
|
151
|
+
const operator = this.advance().value;
|
|
152
|
+
const right = this.parseAddition();
|
|
153
|
+
left = this.createBinaryExpression(operator, left, right);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return left;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
private parseAddition(): ExpressionNode {
|
|
160
|
+
let left = this.parseMultiplication();
|
|
161
|
+
|
|
162
|
+
while (this.peek().value === '+' || this.peek().value === '-') {
|
|
163
|
+
const operator = this.advance().value;
|
|
164
|
+
const right = this.parseMultiplication();
|
|
165
|
+
left = this.createBinaryExpression(operator, left, right);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return left;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
private parseMultiplication(): ExpressionNode {
|
|
172
|
+
let left = this.parseUnary();
|
|
173
|
+
|
|
174
|
+
while (this.peek().value === '*' || this.peek().value === '/' || this.peek().value === '%') {
|
|
175
|
+
const operator = this.advance().value;
|
|
176
|
+
const right = this.parseUnary();
|
|
177
|
+
left = this.createBinaryExpression(operator, left, right);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return left;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
private parseUnary(): ExpressionNode {
|
|
184
|
+
if (this.checkValue('not') || this.checkValue('no') || this.peek().value === '-') {
|
|
185
|
+
const operator = this.advance().value;
|
|
186
|
+
const operand = this.parseUnary();
|
|
187
|
+
return this.createUnaryExpression(operator, operand);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return this.parsePostfix();
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
private parsePostfix(): ExpressionNode {
|
|
194
|
+
let expr = this.parsePrimary();
|
|
195
|
+
|
|
196
|
+
while (true) {
|
|
197
|
+
// Property access with dot: expr.property
|
|
198
|
+
if (this.match(TokenType.DOT)) {
|
|
199
|
+
// Accept IDENTIFIER or CONTEXT_VAR as property name
|
|
200
|
+
if (this.check(TokenType.IDENTIFIER) || this.check(TokenType.CONTEXT_VAR)) {
|
|
201
|
+
const property = this.advance().value;
|
|
202
|
+
expr = this.createPropertyAccess(expr, property);
|
|
203
|
+
} else {
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
// Possessive: expr's property
|
|
208
|
+
else if (this.match(TokenType.POSSESSIVE)) {
|
|
209
|
+
// Accept IDENTIFIER or CONTEXT_VAR as property name
|
|
210
|
+
if (this.check(TokenType.IDENTIFIER) || this.check(TokenType.CONTEXT_VAR)) {
|
|
211
|
+
const property = this.advance().value;
|
|
212
|
+
expr = this.createPossessiveExpression(expr, property);
|
|
213
|
+
} else {
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
// Function call: expr(args)
|
|
218
|
+
else if (this.match(TokenType.LPAREN)) {
|
|
219
|
+
const args = this.parseArguments();
|
|
220
|
+
expr = this.createCallExpression(expr, args);
|
|
221
|
+
}
|
|
222
|
+
// Array access: expr[index]
|
|
223
|
+
else if (this.match(TokenType.LBRACKET)) {
|
|
224
|
+
const index = this.parseExpression();
|
|
225
|
+
if (!this.match(TokenType.RBRACKET)) {
|
|
226
|
+
throw new Error('Expected ] after index');
|
|
227
|
+
}
|
|
228
|
+
expr = this.createPropertyAccess(expr, index);
|
|
229
|
+
} else {
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return expr;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
private parsePrimary(): ExpressionNode {
|
|
238
|
+
const token = this.peek();
|
|
239
|
+
|
|
240
|
+
// Literals
|
|
241
|
+
if (this.match(TokenType.NUMBER)) {
|
|
242
|
+
return this.createLiteral(parseFloat(token.value), 'number', token);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (this.match(TokenType.STRING)) {
|
|
246
|
+
const value = token.value.slice(1, -1); // Remove quotes
|
|
247
|
+
return this.createLiteral(value, 'string', token);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (this.match(TokenType.BOOLEAN)) {
|
|
251
|
+
const value =
|
|
252
|
+
token.value === 'true'
|
|
253
|
+
? true
|
|
254
|
+
: token.value === 'false'
|
|
255
|
+
? false
|
|
256
|
+
: token.value === 'null'
|
|
257
|
+
? null
|
|
258
|
+
: undefined;
|
|
259
|
+
return this.createLiteral(value, token.value as any, token);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (this.match(TokenType.TEMPLATE_LITERAL)) {
|
|
263
|
+
const templateNode: TemplateLiteralNode = {
|
|
264
|
+
type: 'templateLiteral',
|
|
265
|
+
value: token.value,
|
|
266
|
+
start: token.start,
|
|
267
|
+
end: token.end,
|
|
268
|
+
line: token.line,
|
|
269
|
+
column: token.column,
|
|
270
|
+
};
|
|
271
|
+
return templateNode;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if (this.match(TokenType.TIME_EXPRESSION)) {
|
|
275
|
+
return this.parseTimeExpression(token);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// Selectors
|
|
279
|
+
if (this.match(TokenType.ID_SELECTOR)) {
|
|
280
|
+
return this.createSelector(token.value, 'id', token);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (this.match(TokenType.CLASS_SELECTOR)) {
|
|
284
|
+
return this.createSelector(token.value, 'class', token);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (this.match(TokenType.ATTRIBUTE_SELECTOR)) {
|
|
288
|
+
return this.createSelector(token.value, 'attribute', token);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (this.match(TokenType.QUERY_SELECTOR)) {
|
|
292
|
+
// Extract selector from <.../>
|
|
293
|
+
const selector = token.value.slice(1, -2);
|
|
294
|
+
return this.createSelector(selector, 'query', token);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// Context references
|
|
298
|
+
if (this.match(TokenType.CONTEXT_VAR)) {
|
|
299
|
+
return this.createContextReference(token.value as ContextType, token);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// Identifiers
|
|
303
|
+
if (this.match(TokenType.IDENTIFIER)) {
|
|
304
|
+
return this.createIdentifier(token.value, token);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// Parenthesized expression
|
|
308
|
+
if (this.match(TokenType.LPAREN)) {
|
|
309
|
+
const expr = this.parseExpression();
|
|
310
|
+
if (!this.match(TokenType.RPAREN)) {
|
|
311
|
+
throw new Error('Expected ) after expression');
|
|
312
|
+
}
|
|
313
|
+
return expr;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// Array literal
|
|
317
|
+
if (this.match(TokenType.LBRACKET)) {
|
|
318
|
+
return this.parseArrayLiteral();
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// Object literal
|
|
322
|
+
if (this.match(TokenType.LBRACE)) {
|
|
323
|
+
return this.parseObjectLiteral();
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
throw new Error(`Unexpected token: ${token.value}`);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
private parseArguments(): ExpressionNode[] {
|
|
330
|
+
const args: ExpressionNode[] = [];
|
|
331
|
+
|
|
332
|
+
if (!this.check(TokenType.RPAREN)) {
|
|
333
|
+
do {
|
|
334
|
+
args.push(this.parseExpression());
|
|
335
|
+
} while (this.match(TokenType.COMMA));
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if (!this.match(TokenType.RPAREN)) {
|
|
339
|
+
throw new Error('Expected ) after arguments');
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
return args;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
private parseArrayLiteral(): ArrayLiteralNode {
|
|
346
|
+
const elements: ExpressionNode[] = [];
|
|
347
|
+
const start = this.previous().start;
|
|
348
|
+
|
|
349
|
+
if (!this.check(TokenType.RBRACKET)) {
|
|
350
|
+
do {
|
|
351
|
+
elements.push(this.parseExpression());
|
|
352
|
+
} while (this.match(TokenType.COMMA));
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
if (!this.match(TokenType.RBRACKET)) {
|
|
356
|
+
throw new Error('Expected ] after array elements');
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
return {
|
|
360
|
+
type: 'arrayLiteral',
|
|
361
|
+
elements,
|
|
362
|
+
start,
|
|
363
|
+
end: this.previous().end,
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
private parseObjectLiteral(): ObjectLiteralNode {
|
|
368
|
+
const properties: Array<{ key: string; value: ExpressionNode }> = [];
|
|
369
|
+
const start = this.previous().start;
|
|
370
|
+
|
|
371
|
+
if (!this.check(TokenType.RBRACE)) {
|
|
372
|
+
do {
|
|
373
|
+
let key: string;
|
|
374
|
+
if (this.check(TokenType.STRING)) {
|
|
375
|
+
key = this.advance().value.slice(1, -1);
|
|
376
|
+
} else if (this.check(TokenType.IDENTIFIER)) {
|
|
377
|
+
key = this.advance().value;
|
|
378
|
+
} else {
|
|
379
|
+
throw new Error('Expected property name');
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
if (!this.match(TokenType.COLON)) {
|
|
383
|
+
throw new Error('Expected : after property name');
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
const value = this.parseExpression();
|
|
387
|
+
properties.push({ key, value });
|
|
388
|
+
} while (this.match(TokenType.COMMA));
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
if (!this.match(TokenType.RBRACE)) {
|
|
392
|
+
throw new Error('Expected } after object properties');
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
return {
|
|
396
|
+
type: 'objectLiteral',
|
|
397
|
+
properties: properties.map(p => ({
|
|
398
|
+
type: 'objectProperty' as const,
|
|
399
|
+
key: p.key,
|
|
400
|
+
value: p.value,
|
|
401
|
+
})),
|
|
402
|
+
start,
|
|
403
|
+
end: this.previous().end,
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
private parseTimeExpression(token: Token): TimeExpressionNode {
|
|
408
|
+
const match = token.value.match(
|
|
409
|
+
/^(\d+(?:\.\d+)?)(ms|s|seconds?|milliseconds?|minutes?|hours?)$/i
|
|
410
|
+
);
|
|
411
|
+
if (!match) {
|
|
412
|
+
throw new Error(`Invalid time expression: ${token.value}`);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
const value = parseFloat(match[1]);
|
|
416
|
+
const unit = match[2].toLowerCase() as TimeExpressionNode['unit'];
|
|
417
|
+
|
|
418
|
+
return {
|
|
419
|
+
type: 'timeExpression',
|
|
420
|
+
value,
|
|
421
|
+
unit,
|
|
422
|
+
raw: token.value,
|
|
423
|
+
start: token.start,
|
|
424
|
+
end: token.end,
|
|
425
|
+
line: token.line,
|
|
426
|
+
column: token.column,
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// =============================================================================
|
|
431
|
+
// Node Factories
|
|
432
|
+
// =============================================================================
|
|
433
|
+
|
|
434
|
+
private createLiteral(
|
|
435
|
+
value: string | number | boolean | null | undefined,
|
|
436
|
+
dataType: LiteralNode['dataType'],
|
|
437
|
+
token: Token
|
|
438
|
+
): LiteralNode {
|
|
439
|
+
return {
|
|
440
|
+
type: 'literal',
|
|
441
|
+
value,
|
|
442
|
+
dataType,
|
|
443
|
+
raw: token.value,
|
|
444
|
+
start: token.start,
|
|
445
|
+
end: token.end,
|
|
446
|
+
line: token.line,
|
|
447
|
+
column: token.column,
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
private createSelector(value: string, kind: SelectorKind, token: Token): SelectorNode {
|
|
452
|
+
return {
|
|
453
|
+
type: 'selector',
|
|
454
|
+
value,
|
|
455
|
+
selector: value,
|
|
456
|
+
selectorType: kind,
|
|
457
|
+
start: token.start,
|
|
458
|
+
end: token.end,
|
|
459
|
+
line: token.line,
|
|
460
|
+
column: token.column,
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
private createContextReference(contextType: ContextType, token: Token): ContextReferenceNode {
|
|
465
|
+
return {
|
|
466
|
+
type: 'contextReference',
|
|
467
|
+
contextType,
|
|
468
|
+
name: token.value,
|
|
469
|
+
start: token.start,
|
|
470
|
+
end: token.end,
|
|
471
|
+
line: token.line,
|
|
472
|
+
column: token.column,
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
private createIdentifier(name: string, token: Token): IdentifierNode {
|
|
477
|
+
return {
|
|
478
|
+
type: 'identifier',
|
|
479
|
+
name,
|
|
480
|
+
start: token.start,
|
|
481
|
+
end: token.end,
|
|
482
|
+
line: token.line,
|
|
483
|
+
column: token.column,
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
private createPropertyAccess(
|
|
488
|
+
object: ExpressionNode,
|
|
489
|
+
property: string | ExpressionNode
|
|
490
|
+
): PropertyAccessNode {
|
|
491
|
+
return {
|
|
492
|
+
type: 'propertyAccess',
|
|
493
|
+
object,
|
|
494
|
+
property: typeof property === 'string' ? property : ((property as any).name ?? ''),
|
|
495
|
+
start: object.start,
|
|
496
|
+
end: this.previous().end,
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
private createPossessiveExpression(
|
|
501
|
+
object: ExpressionNode,
|
|
502
|
+
property: string
|
|
503
|
+
): PossessiveExpressionNode {
|
|
504
|
+
return {
|
|
505
|
+
type: 'possessiveExpression',
|
|
506
|
+
object,
|
|
507
|
+
property,
|
|
508
|
+
start: object.start,
|
|
509
|
+
end: this.previous().end,
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
private createBinaryExpression(
|
|
514
|
+
operator: string,
|
|
515
|
+
left: ExpressionNode,
|
|
516
|
+
right: ExpressionNode
|
|
517
|
+
): BinaryExpressionNode {
|
|
518
|
+
return {
|
|
519
|
+
type: 'binaryExpression',
|
|
520
|
+
operator,
|
|
521
|
+
left,
|
|
522
|
+
right,
|
|
523
|
+
start: left.start,
|
|
524
|
+
end: right.end,
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
private createUnaryExpression(operator: string, operand: ExpressionNode): UnaryExpressionNode {
|
|
529
|
+
return {
|
|
530
|
+
type: 'unaryExpression',
|
|
531
|
+
operator,
|
|
532
|
+
operand,
|
|
533
|
+
prefix: true,
|
|
534
|
+
start: this.previous().start,
|
|
535
|
+
end: operand.end,
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
private createCallExpression(callee: ExpressionNode, args: ExpressionNode[]): CallExpressionNode {
|
|
540
|
+
return {
|
|
541
|
+
type: 'callExpression',
|
|
542
|
+
callee,
|
|
543
|
+
arguments: args,
|
|
544
|
+
start: callee.start,
|
|
545
|
+
end: this.previous().end,
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// =============================================================================
|
|
551
|
+
// Convenience Function
|
|
552
|
+
// =============================================================================
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* Parse an expression string into an AST node.
|
|
556
|
+
*
|
|
557
|
+
* @param input - The expression string to parse
|
|
558
|
+
* @returns The parse result with success status and node or error
|
|
559
|
+
*/
|
|
560
|
+
export function parseExpression(input: string): ExpressionParseResult {
|
|
561
|
+
const parser = new ExpressionParser();
|
|
562
|
+
return parser.parse(input);
|
|
563
|
+
}
|