@hyperfixi/core 3.3.0 → 4.0.1
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 +57 -179
- package/dist/ast-utils/index.cjs +74 -806
- package/dist/ast-utils/index.d.ts +1 -1
- package/dist/ast-utils/index.mjs +74 -805
- package/dist/ast-utils/interchange/engine-positions.d.ts +3 -0
- package/dist/ast-utils/interchange/index.d.ts +1 -2
- package/dist/hyperfixi.js +19 -2
- package/dist/index.d.ts +2 -22
- package/dist/index.mjs +3 -29128
- package/dist/lsp-metadata.cjs +77 -73
- package/dist/lsp-metadata.d.ts +4 -4
- package/dist/lsp-metadata.mjs +77 -73
- package/dist/metadata.cjs +34 -266
- package/dist/metadata.d.ts +31 -26
- package/dist/metadata.mjs +34 -266
- package/dist/multilingual/index.cjs +16 -382
- package/dist/multilingual/index.d.ts +4 -32
- package/dist/multilingual/index.mjs +15 -377
- package/dist/reference/index.cjs +67 -216
- package/dist/reference/index.d.ts +0 -3
- package/dist/reference/index.mjs +68 -216
- package/dist/version.d.ts +1 -1
- package/package.json +13 -179
- package/dist/__test-utils__/context-builders.d.ts +0 -42
- package/dist/__test-utils__/error-testing.d.ts +0 -18
- package/dist/__test-utils__/index.d.ts +0 -6
- package/dist/__test-utils__/mock-types.d.ts +0 -57
- package/dist/__test-utils__/parser-context-mock.d.ts +0 -7
- package/dist/__test-utils__/parser-helpers.d.ts +0 -38
- package/dist/api/hyperscript-api.d.ts +0 -90
- package/dist/api/lokascript-api.d.ts +0 -9
- package/dist/ast/command-slots.d.ts +0 -140
- package/dist/ast/guards.d.ts +0 -15
- package/dist/ast/legacy.d.ts +0 -15
- package/dist/ast/nodes.d.ts +0 -243
- package/dist/ast-utils/interchange/from-core.d.ts +0 -12
- package/dist/ast-utils/interchange/to-core.d.ts +0 -8
- package/dist/behaviors/boosted.d.ts +0 -29
- package/dist/behaviors/history-swap.d.ts +0 -24
- package/dist/behaviors/index.cjs +0 -1155
- package/dist/behaviors/index.d.ts +0 -4
- package/dist/behaviors/index.mjs +0 -1145
- package/dist/bundle-generator/executor-core.d.ts +0 -4
- package/dist/bundle-generator/generator.d.ts +0 -4
- package/dist/bundle-generator/index.cjs +0 -2804
- package/dist/bundle-generator/index.d.ts +0 -6
- package/dist/bundle-generator/index.mjs +0 -2779
- package/dist/bundle-generator/parser-templates.d.ts +0 -6
- package/dist/bundle-generator/template-capabilities.d.ts +0 -12
- package/dist/bundle-generator/templates.d.ts +0 -12
- package/dist/bundle-generator/types.d.ts +0 -34
- package/dist/chunks/bridge-CI9SOl8u.js +0 -2
- package/dist/chunks/browser-modular-7CpI5VF2.js +0 -2
- package/dist/chunks/index-BwXDEK0m.js +0 -2
- package/dist/chunks/index-DQi2o8Lk.js +0 -2
- package/dist/chunks/index-uCOQ8Qn0.js +0 -2
- package/dist/commands/advanced/js.d.ts +0 -40
- package/dist/commands/animation/measure.d.ts +0 -43
- package/dist/commands/animation/settle.d.ts +0 -38
- package/dist/commands/animation/start-view-transition.d.ts +0 -38
- package/dist/commands/animation/take.d.ts +0 -41
- package/dist/commands/animation/transition.d.ts +0 -49
- package/dist/commands/async/fetch.d.ts +0 -61
- package/dist/commands/async/wait.d.ts +0 -51
- package/dist/commands/behaviors/install.d.ts +0 -40
- package/dist/commands/content/append.d.ts +0 -26
- package/dist/commands/content/insertion-base.d.ts +0 -60
- package/dist/commands/content/prepend.d.ts +0 -26
- package/dist/commands/control-flow/break.d.ts +0 -29
- package/dist/commands/control-flow/continue.d.ts +0 -29
- package/dist/commands/control-flow/exit.d.ts +0 -29
- package/dist/commands/control-flow/halt.d.ts +0 -39
- package/dist/commands/control-flow/if.d.ts +0 -58
- package/dist/commands/control-flow/repeat.d.ts +0 -50
- package/dist/commands/control-flow/return.d.ts +0 -33
- package/dist/commands/control-flow/signal-base.d.ts +0 -18
- package/dist/commands/control-flow/throw.d.ts +0 -34
- package/dist/commands/control-flow/unless.d.ts +0 -3
- package/dist/commands/data/clear.d.ts +0 -37
- package/dist/commands/data/decrement.d.ts +0 -3
- package/dist/commands/data/default.d.ts +0 -60
- package/dist/commands/data/get.d.ts +0 -35
- package/dist/commands/data/increment.d.ts +0 -42
- package/dist/commands/data/set.d.ts +0 -76
- package/dist/commands/decorators/index.d.ts +0 -14
- package/dist/commands/dom/add.d.ts +0 -44
- package/dist/commands/dom/close.d.ts +0 -32
- package/dist/commands/dom/dom-modification-base.d.ts +0 -48
- package/dist/commands/dom/empty.d.ts +0 -32
- package/dist/commands/dom/hide.d.ts +0 -28
- package/dist/commands/dom/make.d.ts +0 -34
- package/dist/commands/dom/open.d.ts +0 -34
- package/dist/commands/dom/process-partials.d.ts +0 -51
- package/dist/commands/dom/put.d.ts +0 -42
- package/dist/commands/dom/remove.d.ts +0 -46
- package/dist/commands/dom/reset.d.ts +0 -32
- package/dist/commands/dom/select.d.ts +0 -32
- package/dist/commands/dom/show.d.ts +0 -29
- package/dist/commands/dom/swap.d.ts +0 -65
- package/dist/commands/dom/toggle.d.ts +0 -69
- package/dist/commands/dom/visibility-base.d.ts +0 -22
- package/dist/commands/events/send.d.ts +0 -3
- package/dist/commands/events/trigger.d.ts +0 -49
- package/dist/commands/execution/blur.d.ts +0 -32
- package/dist/commands/execution/call.d.ts +0 -35
- package/dist/commands/execution/focus.d.ts +0 -32
- package/dist/commands/execution/pseudo-command.d.ts +0 -41
- package/dist/commands/helpers/attribute-manipulation.d.ts +0 -11
- package/dist/commands/helpers/attribute-target.d.ts +0 -9
- package/dist/commands/helpers/batch-dom-operations.d.ts +0 -12
- package/dist/commands/helpers/body-ops.d.ts +0 -10
- package/dist/commands/helpers/class-manipulation.d.ts +0 -11
- package/dist/commands/helpers/condition-helpers.d.ts +0 -4
- package/dist/commands/helpers/dom-mutation.d.ts +0 -16
- package/dist/commands/helpers/duration-parsing.d.ts +0 -8
- package/dist/commands/helpers/element-property-access.d.ts +0 -7
- package/dist/commands/helpers/element-resolution.d.ts +0 -16
- package/dist/commands/helpers/error-helpers.d.ts +0 -17
- package/dist/commands/helpers/event-helpers.d.ts +0 -13
- package/dist/commands/helpers/event-waiting.d.ts +0 -37
- package/dist/commands/helpers/index.d.ts +0 -32
- package/dist/commands/helpers/input-validator.d.ts +0 -23
- package/dist/commands/helpers/loop-executor.d.ts +0 -56
- package/dist/commands/helpers/numeric-target-parser.d.ts +0 -21
- package/dist/commands/helpers/property-target.d.ts +0 -20
- package/dist/commands/helpers/selector-type-detection.d.ts +0 -24
- package/dist/commands/helpers/slots.d.ts +0 -5
- package/dist/commands/helpers/smart-element.d.ts +0 -16
- package/dist/commands/helpers/style-manipulation.d.ts +0 -16
- package/dist/commands/helpers/target-elements.d.ts +0 -5
- package/dist/commands/helpers/temporal-modifiers.d.ts +0 -15
- package/dist/commands/helpers/url-argument-parser.d.ts +0 -13
- package/dist/commands/helpers/url-validation.d.ts +0 -7
- package/dist/commands/helpers/variable-access.d.ts +0 -13
- package/dist/commands/helpers/visibility-target-parser.d.ts +0 -15
- package/dist/commands/helpers/write-target.d.ts +0 -42
- package/dist/commands/index.cjs +0 -24168
- package/dist/commands/index.d.ts +0 -171
- package/dist/commands/index.mjs +0 -23981
- package/dist/commands/manifest.d.ts +0 -17
- package/dist/commands/navigation/go.d.ts +0 -58
- package/dist/commands/navigation/push-url.d.ts +0 -48
- package/dist/commands/navigation/replace-url.d.ts +0 -3
- package/dist/commands/navigation/scroll-to.d.ts +0 -43
- package/dist/commands/templates/render.d.ts +0 -47
- package/dist/commands/utility/beep.d.ts +0 -41
- package/dist/commands/utility/breakpoint.d.ts +0 -32
- package/dist/commands/utility/copy.d.ts +0 -41
- package/dist/commands/utility/log.d.ts +0 -36
- package/dist/commands/utility/pick.d.ts +0 -47
- package/dist/commands/utility/tell.d.ts +0 -39
- package/dist/compatibility/browser-bundle-classic.d.ts +0 -17
- package/dist/compatibility/browser-bundle-hybrid-complete.d.ts +0 -22
- package/dist/compatibility/browser-bundle-hybrid-hx.d.ts +0 -43
- package/dist/compatibility/browser-bundle-lite.d.ts +0 -15
- package/dist/compatibility/browser-bundle-modular.d.ts +0 -18
- package/dist/compatibility/browser-bundle-multilingual.d.ts +0 -19
- package/dist/compatibility/browser-bundle-semantic-complete.d.ts +0 -24
- package/dist/compatibility/browser-bundle-textshelf-minimal.d.ts +0 -16
- package/dist/compatibility/browser-bundle-textshelf-profile.d.ts +0 -18
- package/dist/compatibility/browser-modular.d.ts +0 -42
- package/dist/compatibility/browser-tests/helpers/semantic-page.d.ts +0 -3
- package/dist/compatibility/browser-tests/test-utils.d.ts +0 -21
- package/dist/compatibility/bundle-shell.d.ts +0 -13
- package/dist/compatibility/bundle-sources.d.ts +0 -4
- package/dist/compatibility/eval-hyperscript.d.ts +0 -16
- package/dist/compatibility/hyperscript-adapter.d.ts +0 -38
- package/dist/core/ast-property-utils.d.ts +0 -2
- package/dist/core/context.d.ts +0 -19
- package/dist/core/dom.d.ts +0 -15
- package/dist/core/evaluator-types.d.ts +0 -5
- package/dist/core/events.d.ts +0 -48
- package/dist/core/executor.d.ts +0 -34
- package/dist/core/expression-evaluator.d.ts +0 -6
- package/dist/core/expression-registry.d.ts +0 -8
- package/dist/core/scope-hooks.d.ts +0 -24
- package/dist/debug/debug-controller.d.ts +0 -62
- package/dist/debug/index.d.ts +0 -5
- package/dist/dom/attribute-processor.d.ts +0 -75
- package/dist/dom/detect-language.d.ts +0 -3
- package/dist/dom/minimal-attribute-processor.d.ts +0 -20
- package/dist/expressions/base-expression.d.ts +0 -27
- package/dist/expressions/bundles/common-expressions.d.ts +0 -10
- package/dist/expressions/bundles/core-expressions.d.ts +0 -8
- package/dist/expressions/bundles/full-expressions.d.ts +0 -11
- package/dist/expressions/bundles/index.d.ts +0 -7
- package/dist/expressions/collection/index.d.ts +0 -10
- package/dist/expressions/conversion/index.d.ts +0 -31
- package/dist/expressions/expression-tiers.d.ts +0 -13
- package/dist/expressions/index.cjs +0 -4331
- package/dist/expressions/index.d.ts +0 -13
- package/dist/expressions/index.mjs +0 -4312
- package/dist/expressions/logical/index.d.ts +0 -61
- package/dist/expressions/mathematical/index.d.ts +0 -80
- package/dist/expressions/positional/index.d.ts +0 -31
- package/dist/expressions/properties/index.d.ts +0 -27
- package/dist/expressions/property-access-utils.d.ts +0 -23
- package/dist/expressions/references/index.d.ts +0 -39
- package/dist/expressions/shared/comparison-utils.d.ts +0 -10
- package/dist/expressions/shared/index.d.ts +0 -10
- package/dist/expressions/shared/number-utils.d.ts +0 -8
- package/dist/expressions/shared/tracking.d.ts +0 -20
- package/dist/expressions/shared/validation-utils.d.ts +0 -13
- package/dist/expressions/special/index.d.ts +0 -78
- package/dist/expressions/type-helpers.d.ts +0 -11
- package/dist/expressions/type-registry.d.ts +0 -57
- package/dist/expressions/validation-helpers.d.ts +0 -15
- package/dist/htmx/hcon.d.ts +0 -9
- package/dist/htmx/htmx-attribute-processor.d.ts +0 -120
- package/dist/htmx/htmx-translator.d.ts +0 -22
- package/dist/htmx/i18n-hooks.d.ts +0 -18
- package/dist/htmx/i18n-orchestrator.d.ts +0 -16
- package/dist/htmx/index.d.ts +0 -3
- package/dist/htmx/lang-resolver.d.ts +0 -3
- package/dist/htmx/sse.d.ts +0 -60
- package/dist/htmx/ws.d.ts +0 -59
- package/dist/hyperfixi-browser-classic-i18n.js +0 -2
- package/dist/hyperfixi-browser.js +0 -2
- package/dist/hyperfixi-classic-i18n.js +0 -2
- package/dist/hyperfixi-hx-v4.js +0 -1
- package/dist/hyperfixi-hx.js +0 -1
- package/dist/hyperfixi-hybrid-complete.js +0 -1
- package/dist/hyperfixi-hybrid-hx.js +0 -1
- package/dist/hyperfixi-multilingual.js +0 -2
- package/dist/hyperfixi.mjs +0 -2
- package/dist/i18n/error-catalog.d.ts +0 -12
- package/dist/index.cjs +0 -29159
- package/dist/index.min.js +0 -2
- package/dist/lib/dom-globals-shim.d.ts +0 -2
- package/dist/lib/index.d.ts +0 -4
- package/dist/lib/morph-adapter.d.ts +0 -9
- package/dist/lib/swap-executor.d.ts +0 -12
- package/dist/lib/view-transitions.d.ts +0 -7
- package/dist/lokascript-browser-classic-i18n.js +0 -2
- package/dist/lokascript-browser.js +0 -2
- package/dist/lokascript-hybrid-complete.js +0 -1
- package/dist/lokascript-hybrid-hx.js +0 -1
- package/dist/lokascript-multilingual.js +0 -2
- package/dist/lse/index.cjs +0 -84
- package/dist/lse/index.d.ts +0 -15
- package/dist/lse/index.mjs +0 -71
- package/dist/multilingual/bridge.d.ts +0 -38
- package/dist/multilingual/schema-roles.d.ts +0 -3
- package/dist/parser/__types__/test-helpers.d.ts +0 -25
- package/dist/parser/command-grammar.d.ts +0 -14
- package/dist/parser/command-node-builder.d.ts +0 -46
- package/dist/parser/command-parsers/animation-commands.d.ts +0 -6
- package/dist/parser/command-parsers/async-commands.d.ts +0 -5
- package/dist/parser/command-parsers/control-flow-commands.d.ts +0 -7
- package/dist/parser/command-parsers/declared-commands.d.ts +0 -6
- package/dist/parser/command-parsers/dom-commands.d.ts +0 -11
- package/dist/parser/command-parsers/event-commands.d.ts +0 -4
- package/dist/parser/command-parsers/navigation-commands.d.ts +0 -6
- package/dist/parser/command-parsers/utility-commands.d.ts +0 -14
- package/dist/parser/command-parsers/variable-commands.d.ts +0 -12
- package/dist/parser/error-handler.d.ts +0 -34
- package/dist/parser/extensions.d.ts +0 -43
- package/dist/parser/full-parser.cjs +0 -7943
- package/dist/parser/full-parser.d.ts +0 -4
- package/dist/parser/full-parser.mjs +0 -7940
- package/dist/parser/helpers/ast-helpers.d.ts +0 -24
- package/dist/parser/helpers/parsing-helpers.d.ts +0 -19
- package/dist/parser/helpers/token-helpers.d.ts +0 -28
- package/dist/parser/hybrid/aliases.cjs +0 -44
- package/dist/parser/hybrid/aliases.d.ts +0 -7
- package/dist/parser/hybrid/aliases.mjs +0 -37
- package/dist/parser/hybrid/ast-types.cjs +0 -3
- package/dist/parser/hybrid/ast-types.d.ts +0 -97
- package/dist/parser/hybrid/ast-types.mjs +0 -2
- package/dist/parser/hybrid/index.cjs +0 -1185
- package/dist/parser/hybrid/index.d.ts +0 -6
- package/dist/parser/hybrid/index.mjs +0 -1175
- package/dist/parser/hybrid/parser-core.cjs +0 -1171
- package/dist/parser/hybrid/parser-core.d.ts +0 -69
- package/dist/parser/hybrid/parser-core.mjs +0 -1169
- package/dist/parser/hybrid/tokenizer.cjs +0 -255
- package/dist/parser/hybrid/tokenizer.d.ts +0 -9
- package/dist/parser/hybrid/tokenizer.mjs +0 -252
- package/dist/parser/hybrid-parser.cjs +0 -1249
- package/dist/parser/hybrid-parser.d.ts +0 -10
- package/dist/parser/hybrid-parser.mjs +0 -1242
- package/dist/parser/parser-constants.d.ts +0 -100
- package/dist/parser/parser-interface.d.ts +0 -12
- package/dist/parser/parser-types.d.ts +0 -164
- package/dist/parser/parser.d.ts +0 -165
- package/dist/parser/pratt-parser.d.ts +0 -41
- package/dist/parser/regex-parser.cjs +0 -422
- package/dist/parser/regex-parser.d.ts +0 -4
- package/dist/parser/regex-parser.mjs +0 -419
- package/dist/parser/runtime.d.ts +0 -14
- package/dist/parser/semantic-integration.d.ts +0 -17
- package/dist/parser/token-consumer.d.ts +0 -34
- package/dist/parser/token-predicates.d.ts +0 -77
- package/dist/parser/tokenizer.d.ts +0 -28
- package/dist/parser/types.d.ts +0 -105
- package/dist/performance/expression-cache.d.ts +0 -78
- package/dist/performance/integration.d.ts +0 -40
- package/dist/performance/production-monitor.d.ts +0 -67
- package/dist/registry/browser-types.cjs +0 -81
- package/dist/registry/browser-types.d.ts +0 -20
- package/dist/registry/browser-types.mjs +0 -76
- package/dist/registry/environment.cjs +0 -36
- package/dist/registry/environment.d.ts +0 -19
- package/dist/registry/environment.mjs +0 -30
- package/dist/registry/event-source-registry.d.ts +0 -54
- package/dist/registry/examples/server-commands.d.ts +0 -6
- package/dist/registry/examples/server-event-source.d.ts +0 -32
- package/dist/registry/index.cjs +0 -14055
- package/dist/registry/index.d.ts +0 -39
- package/dist/registry/index.mjs +0 -14039
- package/dist/registry/runtime-integration.d.ts +0 -23
- package/dist/registry/universal-types.cjs +0 -91
- package/dist/registry/universal-types.d.ts +0 -35
- package/dist/registry/universal-types.mjs +0 -86
- package/dist/runtime/cleanup-registry.d.ts +0 -47
- package/dist/runtime/command-adapter.d.ts +0 -69
- package/dist/runtime/environment.d.ts +0 -75
- package/dist/runtime/plugin.d.ts +0 -14
- package/dist/runtime/runtime-base.d.ts +0 -100
- package/dist/runtime/runtime-factory.d.ts +0 -29
- package/dist/runtime/runtime.d.ts +0 -20
- package/dist/runtime/temporal-modifiers.d.ts +0 -37
- package/dist/test-setup.d.ts +0 -28
- package/dist/test-utilities.d.ts +0 -39
- package/dist/types/base-types.d.ts +0 -231
- package/dist/types/code-fix.d.ts +0 -39
- package/dist/types/command-metadata.d.ts +0 -57
- package/dist/types/command-types.d.ts +0 -262
- package/dist/types/context-types.d.ts +0 -106
- package/dist/types/core-context.d.ts +0 -22
- package/dist/types/core.d.ts +0 -143
- package/dist/types/error-codes.d.ts +0 -207
- package/dist/types/expression-types.d.ts +0 -155
- package/dist/types/hooks.d.ts +0 -45
- package/dist/types/index.d.ts +0 -32
- package/dist/types/program.d.ts +0 -8
- package/dist/types/result.d.ts +0 -73
- package/dist/types/template-types.d.ts +0 -162
- package/dist/types/type-guards.d.ts +0 -24
- package/dist/types/unified-types.d.ts +0 -91
- package/dist/utils/beep.d.ts +0 -8
- package/dist/utils/debug-events.d.ts +0 -41
- package/dist/utils/debug.d.ts +0 -35
- package/dist/utils/dom-utils.d.ts +0 -16
- package/dist/utils/element-check.d.ts +0 -8
- package/dist/utils/keyboard-shortcuts.d.ts +0 -18
- package/dist/utils/performance.d.ts +0 -40
- package/dist/validation/command-pattern-validator.d.ts +0 -53
- package/dist/validation/common-validators.d.ts +0 -24
- package/dist/validation/lightweight-validators.d.ts +0 -113
- package/dist/validation/partial-validation-types.d.ts +0 -50
- package/dist/validation/partial-validator.d.ts +0 -6
- package/dist/validation/partial-warning-formatter.d.ts +0 -6
- package/dist/validation/validate-cli.d.ts +0 -41
- package/vocab/htmx/ar.js +0 -62
- package/vocab/htmx/bn.js +0 -65
- package/vocab/htmx/de.js +0 -83
- package/vocab/htmx/en.js +0 -24
- package/vocab/htmx/es.js +0 -79
- package/vocab/htmx/fr.js +0 -79
- package/vocab/htmx/he.js +0 -61
- package/vocab/htmx/hi.js +0 -81
- package/vocab/htmx/id.js +0 -76
- package/vocab/htmx/it.js +0 -79
- package/vocab/htmx/ja.js +0 -85
- package/vocab/htmx/ko.js +0 -81
- package/vocab/htmx/ms.js +0 -58
- package/vocab/htmx/pl.js +0 -80
- package/vocab/htmx/pt.js +0 -81
- package/vocab/htmx/qu.js +0 -83
- package/vocab/htmx/ru.js +0 -82
- package/vocab/htmx/sw.js +0 -79
- package/vocab/htmx/th.js +0 -67
- package/vocab/htmx/tl.js +0 -56
- package/vocab/htmx/tr.js +0 -86
- package/vocab/htmx/uk.js +0 -82
- package/vocab/htmx/vi.js +0 -59
- package/vocab/htmx/zh.js +0 -79
|
@@ -1,1185 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const KEYWORDS = new Set([
|
|
4
|
-
'on',
|
|
5
|
-
'from',
|
|
6
|
-
'to',
|
|
7
|
-
'into',
|
|
8
|
-
'before',
|
|
9
|
-
'after',
|
|
10
|
-
'in',
|
|
11
|
-
'of',
|
|
12
|
-
'at',
|
|
13
|
-
'with',
|
|
14
|
-
'if',
|
|
15
|
-
'else',
|
|
16
|
-
'unless',
|
|
17
|
-
'end',
|
|
18
|
-
'then',
|
|
19
|
-
'and',
|
|
20
|
-
'or',
|
|
21
|
-
'not',
|
|
22
|
-
'repeat',
|
|
23
|
-
'times',
|
|
24
|
-
'for',
|
|
25
|
-
'each',
|
|
26
|
-
'while',
|
|
27
|
-
'until',
|
|
28
|
-
'toggle',
|
|
29
|
-
'add',
|
|
30
|
-
'remove',
|
|
31
|
-
'put',
|
|
32
|
-
'set',
|
|
33
|
-
'get',
|
|
34
|
-
'call',
|
|
35
|
-
'return',
|
|
36
|
-
'append',
|
|
37
|
-
'prepend',
|
|
38
|
-
'log',
|
|
39
|
-
'send',
|
|
40
|
-
'trigger',
|
|
41
|
-
'wait',
|
|
42
|
-
'settle',
|
|
43
|
-
'fetch',
|
|
44
|
-
'as',
|
|
45
|
-
'show',
|
|
46
|
-
'hide',
|
|
47
|
-
'take',
|
|
48
|
-
'increment',
|
|
49
|
-
'decrement',
|
|
50
|
-
'focus',
|
|
51
|
-
'blur',
|
|
52
|
-
'go',
|
|
53
|
-
'transition',
|
|
54
|
-
'over',
|
|
55
|
-
'the',
|
|
56
|
-
'a',
|
|
57
|
-
'an',
|
|
58
|
-
'my',
|
|
59
|
-
'its',
|
|
60
|
-
'me',
|
|
61
|
-
'it',
|
|
62
|
-
'you',
|
|
63
|
-
'first',
|
|
64
|
-
'last',
|
|
65
|
-
'next',
|
|
66
|
-
'previous',
|
|
67
|
-
'closest',
|
|
68
|
-
'parent',
|
|
69
|
-
'true',
|
|
70
|
-
'false',
|
|
71
|
-
'null',
|
|
72
|
-
'undefined',
|
|
73
|
-
'is',
|
|
74
|
-
'matches',
|
|
75
|
-
'contains',
|
|
76
|
-
'includes',
|
|
77
|
-
'exists',
|
|
78
|
-
'has',
|
|
79
|
-
'init',
|
|
80
|
-
'every',
|
|
81
|
-
'by',
|
|
82
|
-
'halt',
|
|
83
|
-
'via',
|
|
84
|
-
'values',
|
|
85
|
-
'default',
|
|
86
|
-
'event',
|
|
87
|
-
]);
|
|
88
|
-
function tokenize(code) {
|
|
89
|
-
const tokens = [];
|
|
90
|
-
let pos = 0;
|
|
91
|
-
while (pos < code.length) {
|
|
92
|
-
if (/\s/.test(code[pos])) {
|
|
93
|
-
pos++;
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
|
-
if (code.slice(pos, pos + 2) === '--') {
|
|
97
|
-
while (pos < code.length && code[pos] !== '\n')
|
|
98
|
-
pos++;
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
const start = pos;
|
|
102
|
-
if (code[pos] === '<' && /[a-zA-Z]/.test(code[pos + 1] || '')) {
|
|
103
|
-
pos++;
|
|
104
|
-
while (pos < code.length && code[pos] !== '>')
|
|
105
|
-
pos++;
|
|
106
|
-
if (code[pos] === '>')
|
|
107
|
-
pos++;
|
|
108
|
-
const val = code.slice(start, pos);
|
|
109
|
-
if (val.endsWith('/>') || val.endsWith('>')) {
|
|
110
|
-
const normalized = val.slice(1).replace(/\/?>$/, '');
|
|
111
|
-
tokens.push({ type: 'selector', value: normalized, pos: start });
|
|
112
|
-
continue;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
if (code.slice(pos, pos + 2) === "'s" && !/[a-zA-Z]/.test(code[pos + 2] || '')) {
|
|
116
|
-
tokens.push({ type: 'operator', value: "'s", pos: start });
|
|
117
|
-
pos += 2;
|
|
118
|
-
continue;
|
|
119
|
-
}
|
|
120
|
-
if (code[pos] === '"' || code[pos] === "'") {
|
|
121
|
-
const quote = code[pos++];
|
|
122
|
-
while (pos < code.length && code[pos] !== quote) {
|
|
123
|
-
if (code[pos] === '\\')
|
|
124
|
-
pos++;
|
|
125
|
-
pos++;
|
|
126
|
-
}
|
|
127
|
-
pos++;
|
|
128
|
-
tokens.push({ type: 'string', value: code.slice(start, pos), pos: start });
|
|
129
|
-
continue;
|
|
130
|
-
}
|
|
131
|
-
if (/\d/.test(code[pos]) || (code[pos] === '-' && /\d/.test(code[pos + 1] || ''))) {
|
|
132
|
-
if (code[pos] === '-')
|
|
133
|
-
pos++;
|
|
134
|
-
while (pos < code.length && /[\d.]/.test(code[pos]))
|
|
135
|
-
pos++;
|
|
136
|
-
if (code.slice(pos, pos + 2) === 'ms')
|
|
137
|
-
pos += 2;
|
|
138
|
-
else if (code[pos] === 's' && !/[a-zA-Z]/.test(code[pos + 1] || ''))
|
|
139
|
-
pos++;
|
|
140
|
-
else if (code.slice(pos, pos + 2) === 'px')
|
|
141
|
-
pos += 2;
|
|
142
|
-
tokens.push({ type: 'number', value: code.slice(start, pos), pos: start });
|
|
143
|
-
continue;
|
|
144
|
-
}
|
|
145
|
-
if (code[pos] === ':') {
|
|
146
|
-
pos++;
|
|
147
|
-
while (pos < code.length && /[\w]/.test(code[pos]))
|
|
148
|
-
pos++;
|
|
149
|
-
tokens.push({ type: 'localVar', value: code.slice(start, pos), pos: start });
|
|
150
|
-
continue;
|
|
151
|
-
}
|
|
152
|
-
if (code[pos] === '$') {
|
|
153
|
-
pos++;
|
|
154
|
-
while (pos < code.length && /[\w]/.test(code[pos]))
|
|
155
|
-
pos++;
|
|
156
|
-
tokens.push({ type: 'globalVar', value: code.slice(start, pos), pos: start });
|
|
157
|
-
continue;
|
|
158
|
-
}
|
|
159
|
-
if (code[pos] === '@') {
|
|
160
|
-
pos++;
|
|
161
|
-
while (pos < code.length && /[\w-]/.test(code[pos]))
|
|
162
|
-
pos++;
|
|
163
|
-
tokens.push({ type: 'selector', value: code.slice(start, pos), pos: start });
|
|
164
|
-
continue;
|
|
165
|
-
}
|
|
166
|
-
if (code[pos] === '#' || code[pos] === '.') {
|
|
167
|
-
if (code[pos] === '.') {
|
|
168
|
-
const afterDot = code.slice(pos + 1).match(/^(once|prevent|stop|debounce|throttle)\b/i);
|
|
169
|
-
if (afterDot) {
|
|
170
|
-
tokens.push({ type: 'symbol', value: '.', pos: start });
|
|
171
|
-
pos++;
|
|
172
|
-
continue;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
pos++;
|
|
176
|
-
while (pos < code.length && /[\w-]/.test(code[pos]))
|
|
177
|
-
pos++;
|
|
178
|
-
tokens.push({ type: 'selector', value: code.slice(start, pos), pos: start });
|
|
179
|
-
continue;
|
|
180
|
-
}
|
|
181
|
-
if (code[pos] === '[') {
|
|
182
|
-
let lookahead = pos + 1;
|
|
183
|
-
while (lookahead < code.length && /\s/.test(code[lookahead]))
|
|
184
|
-
lookahead++;
|
|
185
|
-
const nextChar = code[lookahead] || '';
|
|
186
|
-
const isArrayLiteral = /['"\d\[\]:\$\-]/.test(nextChar) || nextChar === '';
|
|
187
|
-
if (isArrayLiteral) {
|
|
188
|
-
tokens.push({ type: 'symbol', value: '[', pos: start });
|
|
189
|
-
pos++;
|
|
190
|
-
continue;
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
pos++;
|
|
194
|
-
let depth = 1;
|
|
195
|
-
while (pos < code.length && depth > 0) {
|
|
196
|
-
if (code[pos] === '[')
|
|
197
|
-
depth++;
|
|
198
|
-
if (code[pos] === ']')
|
|
199
|
-
depth--;
|
|
200
|
-
pos++;
|
|
201
|
-
}
|
|
202
|
-
tokens.push({ type: 'selector', value: code.slice(start, pos), pos: start });
|
|
203
|
-
continue;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
if (code[pos] === ']') {
|
|
207
|
-
tokens.push({ type: 'symbol', value: ']', pos: start });
|
|
208
|
-
pos++;
|
|
209
|
-
continue;
|
|
210
|
-
}
|
|
211
|
-
if (code.slice(pos, pos + 2) === "'s") {
|
|
212
|
-
tokens.push({ type: 'operator', value: "'s", pos: start });
|
|
213
|
-
pos += 2;
|
|
214
|
-
continue;
|
|
215
|
-
}
|
|
216
|
-
const twoChar = code.slice(pos, pos + 2);
|
|
217
|
-
if (['==', '!=', '<=', '>=', '&&', '||'].includes(twoChar)) {
|
|
218
|
-
tokens.push({ type: 'operator', value: twoChar, pos: start });
|
|
219
|
-
pos += 2;
|
|
220
|
-
continue;
|
|
221
|
-
}
|
|
222
|
-
if (code[pos] === '*' && /[a-zA-Z]/.test(code[pos + 1] || '')) {
|
|
223
|
-
pos++;
|
|
224
|
-
while (pos < code.length && /[\w-]/.test(code[pos]))
|
|
225
|
-
pos++;
|
|
226
|
-
tokens.push({ type: 'styleProperty', value: code.slice(start, pos), pos: start });
|
|
227
|
-
continue;
|
|
228
|
-
}
|
|
229
|
-
if ('+-*/%<>!'.includes(code[pos])) {
|
|
230
|
-
tokens.push({ type: 'operator', value: code[pos], pos: start });
|
|
231
|
-
pos++;
|
|
232
|
-
continue;
|
|
233
|
-
}
|
|
234
|
-
if ('()[]{},.'.includes(code[pos])) {
|
|
235
|
-
tokens.push({ type: 'symbol', value: code[pos], pos: start });
|
|
236
|
-
pos++;
|
|
237
|
-
continue;
|
|
238
|
-
}
|
|
239
|
-
if (/[a-zA-Z_]/.test(code[pos])) {
|
|
240
|
-
while (pos < code.length && /[\w-]/.test(code[pos]))
|
|
241
|
-
pos++;
|
|
242
|
-
const value = code.slice(start, pos);
|
|
243
|
-
const type = KEYWORDS.has(value.toLowerCase()) ? 'keyword' : 'identifier';
|
|
244
|
-
tokens.push({ type, value, pos: start });
|
|
245
|
-
continue;
|
|
246
|
-
}
|
|
247
|
-
pos++;
|
|
248
|
-
}
|
|
249
|
-
tokens.push({ type: 'eof', value: '', pos: code.length });
|
|
250
|
-
return tokens;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
const COMMAND_ALIASES = {
|
|
254
|
-
flip: 'toggle',
|
|
255
|
-
switch: 'toggle',
|
|
256
|
-
display: 'show',
|
|
257
|
-
reveal: 'show',
|
|
258
|
-
conceal: 'hide',
|
|
259
|
-
increase: 'increment',
|
|
260
|
-
decrease: 'decrement',
|
|
261
|
-
fire: 'trigger',
|
|
262
|
-
dispatch: 'send',
|
|
263
|
-
navigate: 'go',
|
|
264
|
-
goto: 'go',
|
|
265
|
-
};
|
|
266
|
-
const EVENT_ALIASES = {
|
|
267
|
-
clicked: 'click',
|
|
268
|
-
pressed: 'keydown',
|
|
269
|
-
changed: 'change',
|
|
270
|
-
submitted: 'submit',
|
|
271
|
-
loaded: 'load',
|
|
272
|
-
};
|
|
273
|
-
function normalizeCommand(name) {
|
|
274
|
-
const lower = name.toLowerCase();
|
|
275
|
-
return COMMAND_ALIASES[lower] || lower;
|
|
276
|
-
}
|
|
277
|
-
function normalizeEvent(name) {
|
|
278
|
-
const lower = name.toLowerCase();
|
|
279
|
-
return EVENT_ALIASES[lower] || lower;
|
|
280
|
-
}
|
|
281
|
-
function addCommandAliases(aliases) {
|
|
282
|
-
Object.assign(COMMAND_ALIASES, aliases);
|
|
283
|
-
}
|
|
284
|
-
function addEventAliases(aliases) {
|
|
285
|
-
Object.assign(EVENT_ALIASES, aliases);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
class HybridParser {
|
|
289
|
-
constructor(code) {
|
|
290
|
-
this.pos = 0;
|
|
291
|
-
this.cmdMap = {
|
|
292
|
-
toggle: () => this.parseToggle(),
|
|
293
|
-
add: () => this.parseAdd(),
|
|
294
|
-
remove: () => this.parseRemove(),
|
|
295
|
-
put: () => this.parsePut(),
|
|
296
|
-
append: () => this.parseInsertion('append'),
|
|
297
|
-
prepend: () => this.parseInsertion('prepend'),
|
|
298
|
-
set: () => this.parseSet(),
|
|
299
|
-
get: () => this.parseGet(),
|
|
300
|
-
call: () => this.parseCall(),
|
|
301
|
-
log: () => this.parseLog(),
|
|
302
|
-
send: () => this.parseSend('to'),
|
|
303
|
-
trigger: () => this.parseSend('on'),
|
|
304
|
-
wait: () => this.parseWait(),
|
|
305
|
-
show: () => this.parseShow(),
|
|
306
|
-
hide: () => this.parseHide(),
|
|
307
|
-
take: () => this.parseTake(),
|
|
308
|
-
empty: () => this.parseEmpty(),
|
|
309
|
-
increment: () => this.parseIncDec('increment'),
|
|
310
|
-
decrement: () => this.parseIncDec('decrement'),
|
|
311
|
-
focus: () => this.parseFocusBlur('focus'),
|
|
312
|
-
blur: () => this.parseFocusBlur('blur'),
|
|
313
|
-
go: () => this.parseGo(),
|
|
314
|
-
return: () => this.parseReturn(),
|
|
315
|
-
transition: () => this.parseTransition(),
|
|
316
|
-
halt: () => this.parseHalt(),
|
|
317
|
-
copy: () => this.parseCopy(),
|
|
318
|
-
beep: () => this.parseBeep(),
|
|
319
|
-
push: () => this.parseUrlCommand('push'),
|
|
320
|
-
replace: () => this.parseUrlCommand('replace'),
|
|
321
|
-
morph: () => this.parseMorph(),
|
|
322
|
-
js: () => this.parseJs(),
|
|
323
|
-
throw: () => this.parseThrow(),
|
|
324
|
-
break: () => this.parseBare('break'),
|
|
325
|
-
continue: () => this.parseBare('continue'),
|
|
326
|
-
exit: () => this.parseBare('exit'),
|
|
327
|
-
};
|
|
328
|
-
this.source = code;
|
|
329
|
-
this.tokens = tokenize(code);
|
|
330
|
-
}
|
|
331
|
-
peek(offset = 0) {
|
|
332
|
-
return this.tokens[Math.min(this.pos + offset, this.tokens.length - 1)];
|
|
333
|
-
}
|
|
334
|
-
advance() {
|
|
335
|
-
return this.tokens[this.pos++];
|
|
336
|
-
}
|
|
337
|
-
match(...values) {
|
|
338
|
-
const token = this.peek();
|
|
339
|
-
return values.some(v => token.value.toLowerCase() === v.toLowerCase());
|
|
340
|
-
}
|
|
341
|
-
matchType(...types) {
|
|
342
|
-
return types.includes(this.peek().type);
|
|
343
|
-
}
|
|
344
|
-
expect(value) {
|
|
345
|
-
if (!this.match(value) && normalizeCommand(this.peek().value) !== value) {
|
|
346
|
-
throw new Error(`Expected '${value}', got '${this.peek().value}'`);
|
|
347
|
-
}
|
|
348
|
-
return this.advance();
|
|
349
|
-
}
|
|
350
|
-
isAtEnd() {
|
|
351
|
-
return this.peek().type === 'eof';
|
|
352
|
-
}
|
|
353
|
-
parse() {
|
|
354
|
-
if (this.match('on'))
|
|
355
|
-
return this.parseEventHandler();
|
|
356
|
-
if (this.match('init')) {
|
|
357
|
-
this.advance();
|
|
358
|
-
return { type: 'event', event: 'init', modifiers: {}, body: this.parseCommandSequence() };
|
|
359
|
-
}
|
|
360
|
-
if (this.match('every'))
|
|
361
|
-
return this.parseEveryHandler();
|
|
362
|
-
return { type: 'sequence', commands: this.parseCommandSequence() };
|
|
363
|
-
}
|
|
364
|
-
parseEventHandler() {
|
|
365
|
-
this.expect('on');
|
|
366
|
-
const eventName = this.advance().value;
|
|
367
|
-
const modifiers = {};
|
|
368
|
-
let filter;
|
|
369
|
-
while (this.peek().value === '.') {
|
|
370
|
-
this.advance();
|
|
371
|
-
const mod = this.advance().value.toLowerCase();
|
|
372
|
-
if (mod === 'once')
|
|
373
|
-
modifiers.once = true;
|
|
374
|
-
else if (mod === 'prevent')
|
|
375
|
-
modifiers.prevent = true;
|
|
376
|
-
else if (mod === 'stop')
|
|
377
|
-
modifiers.stop = true;
|
|
378
|
-
else if (mod === 'debounce' || mod === 'throttle') {
|
|
379
|
-
if (this.peek().value === '(') {
|
|
380
|
-
this.advance();
|
|
381
|
-
const num = this.advance().value;
|
|
382
|
-
this.expect(')');
|
|
383
|
-
if (mod === 'debounce')
|
|
384
|
-
modifiers.debounce = parseInt(num) || 100;
|
|
385
|
-
else
|
|
386
|
-
modifiers.throttle = parseInt(num) || 100;
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
if (this.match('from')) {
|
|
391
|
-
this.advance();
|
|
392
|
-
filter = this.parseExpression();
|
|
393
|
-
}
|
|
394
|
-
return {
|
|
395
|
-
type: 'event',
|
|
396
|
-
event: normalizeEvent(eventName),
|
|
397
|
-
filter,
|
|
398
|
-
modifiers,
|
|
399
|
-
body: this.parseCommandSequence(),
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
parseEveryHandler() {
|
|
403
|
-
this.expect('every');
|
|
404
|
-
const interval = this.advance().value;
|
|
405
|
-
return {
|
|
406
|
-
type: 'event',
|
|
407
|
-
event: `interval:${interval}`,
|
|
408
|
-
modifiers: {},
|
|
409
|
-
body: this.parseCommandSequence(),
|
|
410
|
-
};
|
|
411
|
-
}
|
|
412
|
-
parseCommandSequence() {
|
|
413
|
-
const commands = [];
|
|
414
|
-
while (!this.isAtEnd() && !this.match('end', 'else')) {
|
|
415
|
-
const cmd = this.parseCommand();
|
|
416
|
-
if (cmd)
|
|
417
|
-
commands.push(cmd);
|
|
418
|
-
if (this.match('then', 'and'))
|
|
419
|
-
this.advance();
|
|
420
|
-
}
|
|
421
|
-
return commands;
|
|
422
|
-
}
|
|
423
|
-
parseCommand() {
|
|
424
|
-
if (this.match('if', 'unless'))
|
|
425
|
-
return this.parseIf();
|
|
426
|
-
if (this.match('repeat'))
|
|
427
|
-
return this.parseRepeat();
|
|
428
|
-
if (this.match('for'))
|
|
429
|
-
return this.parseFor();
|
|
430
|
-
if (this.match('while'))
|
|
431
|
-
return this.parseWhile();
|
|
432
|
-
if (this.match('fetch'))
|
|
433
|
-
return this.parseFetchBlock();
|
|
434
|
-
const normalized = normalizeCommand(this.peek().value);
|
|
435
|
-
if (this.cmdMap[normalized]) {
|
|
436
|
-
return this.cmdMap[normalized]();
|
|
437
|
-
}
|
|
438
|
-
if (this.match('catch', 'finally')) {
|
|
439
|
-
throw new Error(`'${this.peek().value}' needs the full parser (use hyperfixi.js)`);
|
|
440
|
-
}
|
|
441
|
-
const stray = this.peek();
|
|
442
|
-
if (!this.isAtEnd() &&
|
|
443
|
-
(stray.type === 'identifier' || stray.type === 'keyword') &&
|
|
444
|
-
!this.match('then', 'and', 'end', 'else')) {
|
|
445
|
-
throw new Error(`'${stray.value}' needs the full parser (use hyperfixi.js)`);
|
|
446
|
-
}
|
|
447
|
-
if (!this.isAtEnd() && !this.match('then', 'and', 'end', 'else')) {
|
|
448
|
-
this.advance();
|
|
449
|
-
}
|
|
450
|
-
return null;
|
|
451
|
-
}
|
|
452
|
-
parseIf() {
|
|
453
|
-
const isUnless = this.match('unless');
|
|
454
|
-
this.advance();
|
|
455
|
-
const condition = this.parseExpression();
|
|
456
|
-
const body = this.parseCommandSequence();
|
|
457
|
-
let elseBody;
|
|
458
|
-
if (this.match('else')) {
|
|
459
|
-
this.advance();
|
|
460
|
-
elseBody = this.parseCommandSequence();
|
|
461
|
-
}
|
|
462
|
-
if (this.match('end'))
|
|
463
|
-
this.advance();
|
|
464
|
-
return {
|
|
465
|
-
type: 'if',
|
|
466
|
-
condition: isUnless ? { type: 'unary', operator: 'not', operand: condition } : condition,
|
|
467
|
-
body,
|
|
468
|
-
elseBody,
|
|
469
|
-
};
|
|
470
|
-
}
|
|
471
|
-
parseRepeat() {
|
|
472
|
-
this.expect('repeat');
|
|
473
|
-
let count;
|
|
474
|
-
if (!this.match('until', 'while', 'forever')) {
|
|
475
|
-
count = this.parseExpression();
|
|
476
|
-
if (this.match('times'))
|
|
477
|
-
this.advance();
|
|
478
|
-
}
|
|
479
|
-
const body = this.parseCommandSequence();
|
|
480
|
-
if (this.match('end'))
|
|
481
|
-
this.advance();
|
|
482
|
-
return { type: 'repeat', condition: count, body };
|
|
483
|
-
}
|
|
484
|
-
parseFor() {
|
|
485
|
-
this.expect('for');
|
|
486
|
-
if (this.match('each'))
|
|
487
|
-
this.advance();
|
|
488
|
-
const variable = this.advance().value;
|
|
489
|
-
this.expect('in');
|
|
490
|
-
const iterable = this.parseExpression();
|
|
491
|
-
const body = this.parseCommandSequence();
|
|
492
|
-
if (this.match('end'))
|
|
493
|
-
this.advance();
|
|
494
|
-
return { type: 'for', condition: { type: 'forCondition', variable, iterable }, body };
|
|
495
|
-
}
|
|
496
|
-
parseWhile() {
|
|
497
|
-
this.expect('while');
|
|
498
|
-
const condition = this.parseExpression();
|
|
499
|
-
const body = this.parseCommandSequence();
|
|
500
|
-
if (this.match('end'))
|
|
501
|
-
this.advance();
|
|
502
|
-
return { type: 'while', condition, body };
|
|
503
|
-
}
|
|
504
|
-
parseNakedUrl() {
|
|
505
|
-
const tok = this.peek();
|
|
506
|
-
const isSlash = tok.type === 'operator' && tok.value === '/';
|
|
507
|
-
const isScheme = (tok.value === 'http' || tok.value === 'https') &&
|
|
508
|
-
this.source.slice(tok.pos + tok.value.length, tok.pos + tok.value.length + 3) === '://';
|
|
509
|
-
if (!isSlash && !isScheme)
|
|
510
|
-
return null;
|
|
511
|
-
let end = tok.pos;
|
|
512
|
-
while (end < this.source.length && !/\s/.test(this.source[end]))
|
|
513
|
-
end++;
|
|
514
|
-
while (!this.isAtEnd() && this.peek().pos < end)
|
|
515
|
-
this.advance();
|
|
516
|
-
return { type: 'literal', value: this.source.slice(tok.pos, end) };
|
|
517
|
-
}
|
|
518
|
-
parseFetchBlock() {
|
|
519
|
-
this.expect('fetch');
|
|
520
|
-
const url = this.parseNakedUrl() ?? this.parseExpression();
|
|
521
|
-
let responseType = { type: 'literal', value: 'text' };
|
|
522
|
-
let options;
|
|
523
|
-
let method;
|
|
524
|
-
if (this.match('{')) {
|
|
525
|
-
this.pos--;
|
|
526
|
-
options = this.parseExpression();
|
|
527
|
-
}
|
|
528
|
-
for (let i = 0; i < 3; i++) {
|
|
529
|
-
if (this.match('via') && !method) {
|
|
530
|
-
this.advance();
|
|
531
|
-
method = this.parseExpression();
|
|
532
|
-
continue;
|
|
533
|
-
}
|
|
534
|
-
if (this.match('as')) {
|
|
535
|
-
this.advance();
|
|
536
|
-
if (this.match('a') || this.match('an'))
|
|
537
|
-
this.advance();
|
|
538
|
-
responseType = this.parseExpression();
|
|
539
|
-
continue;
|
|
540
|
-
}
|
|
541
|
-
if (this.match('with') && !options) {
|
|
542
|
-
this.advance();
|
|
543
|
-
options = this.parseExpression();
|
|
544
|
-
continue;
|
|
545
|
-
}
|
|
546
|
-
break;
|
|
547
|
-
}
|
|
548
|
-
if (this.match('then'))
|
|
549
|
-
this.advance();
|
|
550
|
-
const body = this.parseCommandSequence();
|
|
551
|
-
return {
|
|
552
|
-
type: 'fetch',
|
|
553
|
-
condition: { type: 'fetchConfig', url, responseType, options, method },
|
|
554
|
-
body,
|
|
555
|
-
};
|
|
556
|
-
}
|
|
557
|
-
parseToggle() {
|
|
558
|
-
this.expect('toggle');
|
|
559
|
-
const what = this.parseExpression();
|
|
560
|
-
let target;
|
|
561
|
-
if (this.match('on')) {
|
|
562
|
-
this.advance();
|
|
563
|
-
target = this.parseExpression();
|
|
564
|
-
}
|
|
565
|
-
return { type: 'command', name: 'toggle', args: [what], target };
|
|
566
|
-
}
|
|
567
|
-
parseAdd() {
|
|
568
|
-
this.expect('add');
|
|
569
|
-
const what = this.parseExpression();
|
|
570
|
-
let target;
|
|
571
|
-
if (this.match('to')) {
|
|
572
|
-
this.advance();
|
|
573
|
-
target = this.parseExpression();
|
|
574
|
-
}
|
|
575
|
-
return { type: 'command', name: 'add', args: [what], target };
|
|
576
|
-
}
|
|
577
|
-
parseRemove() {
|
|
578
|
-
this.expect('remove');
|
|
579
|
-
if (this.matchType('selector') && /^[.@]/.test(this.peek().value)) {
|
|
580
|
-
const what = this.parseExpression();
|
|
581
|
-
let target;
|
|
582
|
-
if (this.match('from')) {
|
|
583
|
-
this.advance();
|
|
584
|
-
target = this.parseExpression();
|
|
585
|
-
}
|
|
586
|
-
return { type: 'command', name: 'removeClass', args: [what], target };
|
|
587
|
-
}
|
|
588
|
-
const target = this.parseExpression();
|
|
589
|
-
return { type: 'command', name: 'remove', args: [], target };
|
|
590
|
-
}
|
|
591
|
-
parsePut() {
|
|
592
|
-
this.expect('put');
|
|
593
|
-
const content = this.parseExpression();
|
|
594
|
-
let modifier = 'into';
|
|
595
|
-
if (this.match('into', 'before', 'after', 'at')) {
|
|
596
|
-
modifier = this.advance().value;
|
|
597
|
-
if (modifier === 'at') {
|
|
598
|
-
const pos = this.advance().value;
|
|
599
|
-
this.expect('of');
|
|
600
|
-
modifier = `at ${pos} of`;
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
const target = this.parseExpression();
|
|
604
|
-
return { type: 'command', name: 'put', args: [content], target, modifier };
|
|
605
|
-
}
|
|
606
|
-
parseInsertion(name) {
|
|
607
|
-
this.expect(name);
|
|
608
|
-
const content = this.parseExpression();
|
|
609
|
-
let target;
|
|
610
|
-
if (this.match('to')) {
|
|
611
|
-
this.advance();
|
|
612
|
-
target = this.parseExpression();
|
|
613
|
-
}
|
|
614
|
-
return { type: 'command', name, args: [content], target };
|
|
615
|
-
}
|
|
616
|
-
parseSet() {
|
|
617
|
-
this.expect('set');
|
|
618
|
-
const target = this.parseExpression();
|
|
619
|
-
if (this.match('to')) {
|
|
620
|
-
this.advance();
|
|
621
|
-
const value = this.parseExpression();
|
|
622
|
-
return { type: 'command', name: 'set', args: [target, value] };
|
|
623
|
-
}
|
|
624
|
-
return { type: 'command', name: 'set', args: [target] };
|
|
625
|
-
}
|
|
626
|
-
parseGet() {
|
|
627
|
-
this.expect('get');
|
|
628
|
-
return { type: 'command', name: 'get', args: [this.parseExpression()] };
|
|
629
|
-
}
|
|
630
|
-
parseCall() {
|
|
631
|
-
this.expect('call');
|
|
632
|
-
return { type: 'command', name: 'call', args: [this.parseExpression()] };
|
|
633
|
-
}
|
|
634
|
-
parseLog() {
|
|
635
|
-
this.expect('log');
|
|
636
|
-
const args = [];
|
|
637
|
-
while (!this.isAtEnd() && !this.match('then', 'and', 'end', 'else')) {
|
|
638
|
-
args.push(this.parseExpression());
|
|
639
|
-
if (this.match(','))
|
|
640
|
-
this.advance();
|
|
641
|
-
else
|
|
642
|
-
break;
|
|
643
|
-
}
|
|
644
|
-
return { type: 'command', name: 'log', args };
|
|
645
|
-
}
|
|
646
|
-
parseSend(marker) {
|
|
647
|
-
this.advance();
|
|
648
|
-
const first = this.advance();
|
|
649
|
-
let event = first.value;
|
|
650
|
-
let end = first.pos + first.value.length;
|
|
651
|
-
while (!this.isAtEnd() && this.peek().type === 'localVar' && this.peek().pos === end) {
|
|
652
|
-
const piece = this.advance();
|
|
653
|
-
event += piece.value;
|
|
654
|
-
end = piece.pos + piece.value.length;
|
|
655
|
-
}
|
|
656
|
-
let target;
|
|
657
|
-
if (this.match(marker)) {
|
|
658
|
-
this.advance();
|
|
659
|
-
target = this.parseExpression();
|
|
660
|
-
}
|
|
661
|
-
return { type: 'command', name: 'send', args: [{ type: 'literal', value: event }], target };
|
|
662
|
-
}
|
|
663
|
-
parseWait() {
|
|
664
|
-
this.expect('wait');
|
|
665
|
-
if (this.match('for')) {
|
|
666
|
-
this.advance();
|
|
667
|
-
const event = this.advance().value;
|
|
668
|
-
let target;
|
|
669
|
-
if (this.match('from')) {
|
|
670
|
-
this.advance();
|
|
671
|
-
target = this.parseExpression();
|
|
672
|
-
}
|
|
673
|
-
return {
|
|
674
|
-
type: 'command',
|
|
675
|
-
name: 'waitFor',
|
|
676
|
-
args: [{ type: 'literal', value: event }],
|
|
677
|
-
target,
|
|
678
|
-
};
|
|
679
|
-
}
|
|
680
|
-
return { type: 'command', name: 'wait', args: [this.parseExpression()] };
|
|
681
|
-
}
|
|
682
|
-
parseShow() {
|
|
683
|
-
this.expect('show');
|
|
684
|
-
let target;
|
|
685
|
-
const modifiers = {};
|
|
686
|
-
if (!this.isAtEnd() && !this.match('then', 'and', 'end', 'else', 'when', 'where')) {
|
|
687
|
-
target = this.parseExpression();
|
|
688
|
-
}
|
|
689
|
-
if (!this.isAtEnd() && this.match('when', 'where')) {
|
|
690
|
-
const keyword = this.advance().value;
|
|
691
|
-
modifiers[keyword] = this.parseExpression();
|
|
692
|
-
}
|
|
693
|
-
return { type: 'command', name: 'show', args: [], target, modifiers };
|
|
694
|
-
}
|
|
695
|
-
parseHide() {
|
|
696
|
-
this.expect('hide');
|
|
697
|
-
let target;
|
|
698
|
-
const modifiers = {};
|
|
699
|
-
if (!this.isAtEnd() && !this.match('then', 'and', 'end', 'else', 'when', 'where')) {
|
|
700
|
-
target = this.parseExpression();
|
|
701
|
-
}
|
|
702
|
-
if (!this.isAtEnd() && this.match('when', 'where')) {
|
|
703
|
-
const keyword = this.advance().value;
|
|
704
|
-
modifiers[keyword] = this.parseExpression();
|
|
705
|
-
}
|
|
706
|
-
return { type: 'command', name: 'hide', args: [], target, modifiers };
|
|
707
|
-
}
|
|
708
|
-
parseTake() {
|
|
709
|
-
this.expect('take');
|
|
710
|
-
const what = this.parseExpression();
|
|
711
|
-
let from;
|
|
712
|
-
if (this.match('from')) {
|
|
713
|
-
this.advance();
|
|
714
|
-
from = this.parseExpression();
|
|
715
|
-
}
|
|
716
|
-
return { type: 'command', name: 'take', args: [what], target: from };
|
|
717
|
-
}
|
|
718
|
-
parseIncDec(name) {
|
|
719
|
-
this.advance();
|
|
720
|
-
const target = this.parseExpression();
|
|
721
|
-
let amount = { type: 'literal', value: 1 };
|
|
722
|
-
if (this.match('by')) {
|
|
723
|
-
this.advance();
|
|
724
|
-
amount = this.parseExpression();
|
|
725
|
-
}
|
|
726
|
-
return { type: 'command', name, args: [target, amount] };
|
|
727
|
-
}
|
|
728
|
-
parseFocusBlur(name) {
|
|
729
|
-
this.advance();
|
|
730
|
-
let target;
|
|
731
|
-
if (!this.isAtEnd() && !this.match('then', 'and', 'end', 'else')) {
|
|
732
|
-
target = this.parseExpression();
|
|
733
|
-
}
|
|
734
|
-
return { type: 'command', name, args: [], target };
|
|
735
|
-
}
|
|
736
|
-
parseGo() {
|
|
737
|
-
this.expect('go');
|
|
738
|
-
if (this.match('to'))
|
|
739
|
-
this.advance();
|
|
740
|
-
if (this.match('url'))
|
|
741
|
-
this.advance();
|
|
742
|
-
const dest = this.parseExpression();
|
|
743
|
-
return { type: 'command', name: 'go', args: [dest] };
|
|
744
|
-
}
|
|
745
|
-
parseReturn() {
|
|
746
|
-
this.expect('return');
|
|
747
|
-
let value;
|
|
748
|
-
if (!this.isAtEnd() && !this.match('then', 'and', 'end', 'else')) {
|
|
749
|
-
value = this.parseExpression();
|
|
750
|
-
}
|
|
751
|
-
return { type: 'command', name: 'return', args: value ? [value] : [] };
|
|
752
|
-
}
|
|
753
|
-
parseEmpty() {
|
|
754
|
-
this.expect('empty');
|
|
755
|
-
let target;
|
|
756
|
-
if (!this.isAtEnd() && !this.match('then', 'and', 'end', 'else')) {
|
|
757
|
-
target = this.parseExpression();
|
|
758
|
-
}
|
|
759
|
-
return { type: 'command', name: 'empty', args: [], target };
|
|
760
|
-
}
|
|
761
|
-
parseCopy() {
|
|
762
|
-
this.expect('copy');
|
|
763
|
-
return { type: 'command', name: 'copy', args: [this.parseExpression()] };
|
|
764
|
-
}
|
|
765
|
-
parseBeep() {
|
|
766
|
-
this.advance();
|
|
767
|
-
if (this.match('!'))
|
|
768
|
-
this.advance();
|
|
769
|
-
const args = [];
|
|
770
|
-
while (!this.isAtEnd() && !this.match('then', 'and', 'end', 'else')) {
|
|
771
|
-
args.push(this.parseExpression());
|
|
772
|
-
if (this.match(','))
|
|
773
|
-
this.advance();
|
|
774
|
-
else
|
|
775
|
-
break;
|
|
776
|
-
}
|
|
777
|
-
return { type: 'command', name: 'beep', args };
|
|
778
|
-
}
|
|
779
|
-
parseUrlCommand(name) {
|
|
780
|
-
this.advance();
|
|
781
|
-
if (this.match('url'))
|
|
782
|
-
this.advance();
|
|
783
|
-
const url = this.parseExpression();
|
|
784
|
-
const modifiers = {};
|
|
785
|
-
if (this.match('with')) {
|
|
786
|
-
this.advance();
|
|
787
|
-
if (this.match('title')) {
|
|
788
|
-
this.advance();
|
|
789
|
-
modifiers.title = this.parseExpression();
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
return { type: 'command', name, args: [url], modifiers };
|
|
793
|
-
}
|
|
794
|
-
parseMorph() {
|
|
795
|
-
this.expect('morph');
|
|
796
|
-
let modifier;
|
|
797
|
-
if (this.match('over')) {
|
|
798
|
-
this.advance();
|
|
799
|
-
modifier = 'over';
|
|
800
|
-
}
|
|
801
|
-
const target = this.parseExpression();
|
|
802
|
-
if (this.match('with', 'to', 'into'))
|
|
803
|
-
this.advance();
|
|
804
|
-
const content = this.parseExpression();
|
|
805
|
-
return { type: 'command', name: 'morph', args: [content], target, modifier };
|
|
806
|
-
}
|
|
807
|
-
parseJs() {
|
|
808
|
-
this.advance();
|
|
809
|
-
if (this.match('(')) {
|
|
810
|
-
while (!this.isAtEnd() && !this.match(')'))
|
|
811
|
-
this.advance();
|
|
812
|
-
if (this.match(')'))
|
|
813
|
-
this.advance();
|
|
814
|
-
}
|
|
815
|
-
const start = this.peek().pos;
|
|
816
|
-
while (!this.isAtEnd() && !this.match('end'))
|
|
817
|
-
this.advance();
|
|
818
|
-
const stop = this.peek().pos;
|
|
819
|
-
if (this.match('end'))
|
|
820
|
-
this.advance();
|
|
821
|
-
const code = this.source.slice(start, stop).trim();
|
|
822
|
-
return { type: 'command', name: 'js', args: [{ type: 'literal', value: code }] };
|
|
823
|
-
}
|
|
824
|
-
parseThrow() {
|
|
825
|
-
this.expect('throw');
|
|
826
|
-
let value;
|
|
827
|
-
if (!this.isAtEnd() && !this.match('then', 'and', 'end', 'else')) {
|
|
828
|
-
value = this.parseExpression();
|
|
829
|
-
}
|
|
830
|
-
return { type: 'command', name: 'throw', args: value ? [value] : [] };
|
|
831
|
-
}
|
|
832
|
-
parseBare(name) {
|
|
833
|
-
this.advance();
|
|
834
|
-
return { type: 'command', name, args: [] };
|
|
835
|
-
}
|
|
836
|
-
parseHalt() {
|
|
837
|
-
this.expect('halt');
|
|
838
|
-
if (this.match('the'))
|
|
839
|
-
this.advance();
|
|
840
|
-
if (this.match('event', 'default'))
|
|
841
|
-
this.advance();
|
|
842
|
-
return { type: 'command', name: 'halt', args: [] };
|
|
843
|
-
}
|
|
844
|
-
parseTransition() {
|
|
845
|
-
this.expect('transition');
|
|
846
|
-
let target;
|
|
847
|
-
if (this.match('my', 'its')) {
|
|
848
|
-
const ref = this.advance().value;
|
|
849
|
-
target = { type: 'identifier', value: ref === 'my' ? 'me' : 'it' };
|
|
850
|
-
}
|
|
851
|
-
else if (this.matchType('selector')) {
|
|
852
|
-
const expr = this.parseExpression();
|
|
853
|
-
if (expr.type === 'possessive') {
|
|
854
|
-
return this.parseTransitionRest(expr.object, expr.property);
|
|
855
|
-
}
|
|
856
|
-
target = expr;
|
|
857
|
-
}
|
|
858
|
-
const propToken = this.peek();
|
|
859
|
-
let property;
|
|
860
|
-
if (propToken.type === 'styleProperty') {
|
|
861
|
-
property = this.advance().value;
|
|
862
|
-
}
|
|
863
|
-
else if (propToken.type === 'identifier' || propToken.type === 'keyword') {
|
|
864
|
-
property = this.advance().value;
|
|
865
|
-
}
|
|
866
|
-
else {
|
|
867
|
-
property = 'opacity';
|
|
868
|
-
}
|
|
869
|
-
return this.parseTransitionRest(target, property);
|
|
870
|
-
}
|
|
871
|
-
parseTransitionRest(target, property) {
|
|
872
|
-
let toValue = { type: 'literal', value: 1 };
|
|
873
|
-
if (this.match('to')) {
|
|
874
|
-
this.advance();
|
|
875
|
-
toValue = this.parseExpression();
|
|
876
|
-
}
|
|
877
|
-
let duration = { type: 'literal', value: 300 };
|
|
878
|
-
if (this.match('over')) {
|
|
879
|
-
this.advance();
|
|
880
|
-
duration = this.parseExpression();
|
|
881
|
-
}
|
|
882
|
-
return {
|
|
883
|
-
type: 'command',
|
|
884
|
-
name: 'transition',
|
|
885
|
-
args: [{ type: 'literal', value: property }, toValue, duration],
|
|
886
|
-
target,
|
|
887
|
-
};
|
|
888
|
-
}
|
|
889
|
-
parseExpression() {
|
|
890
|
-
return this.parseOr();
|
|
891
|
-
}
|
|
892
|
-
parseOr() {
|
|
893
|
-
let left = this.parseAnd();
|
|
894
|
-
while (this.match('or', '||')) {
|
|
895
|
-
this.advance();
|
|
896
|
-
left = { type: 'binary', operator: 'or', left, right: this.parseAnd() };
|
|
897
|
-
}
|
|
898
|
-
return left;
|
|
899
|
-
}
|
|
900
|
-
parseAnd() {
|
|
901
|
-
let left = this.parseEquality();
|
|
902
|
-
while (this.match('and', '&&') && !this.isCommandKeyword(this.peek(1))) {
|
|
903
|
-
this.advance();
|
|
904
|
-
left = { type: 'binary', operator: 'and', left, right: this.parseEquality() };
|
|
905
|
-
}
|
|
906
|
-
return left;
|
|
907
|
-
}
|
|
908
|
-
isCommandKeyword(token) {
|
|
909
|
-
const cmds = [
|
|
910
|
-
'toggle',
|
|
911
|
-
'add',
|
|
912
|
-
'remove',
|
|
913
|
-
'set',
|
|
914
|
-
'put',
|
|
915
|
-
'log',
|
|
916
|
-
'send',
|
|
917
|
-
'wait',
|
|
918
|
-
'show',
|
|
919
|
-
'hide',
|
|
920
|
-
'increment',
|
|
921
|
-
'decrement',
|
|
922
|
-
'focus',
|
|
923
|
-
'blur',
|
|
924
|
-
'go',
|
|
925
|
-
];
|
|
926
|
-
return cmds.includes(normalizeCommand(token.value));
|
|
927
|
-
}
|
|
928
|
-
parseEquality() {
|
|
929
|
-
let left = this.parseComparison();
|
|
930
|
-
while (this.match('==', '!=', 'is', 'matches', 'contains', 'includes', 'has')) {
|
|
931
|
-
const op = this.advance().value;
|
|
932
|
-
if (op.toLowerCase() === 'is' && this.match('not')) {
|
|
933
|
-
this.advance();
|
|
934
|
-
left = { type: 'binary', operator: 'is not', left, right: this.parseComparison() };
|
|
935
|
-
}
|
|
936
|
-
else {
|
|
937
|
-
left = { type: 'binary', operator: op, left, right: this.parseComparison() };
|
|
938
|
-
}
|
|
939
|
-
}
|
|
940
|
-
return left;
|
|
941
|
-
}
|
|
942
|
-
parseComparison() {
|
|
943
|
-
let left = this.parseAdditive();
|
|
944
|
-
while (this.match('<', '>', '<=', '>=')) {
|
|
945
|
-
const op = this.advance().value;
|
|
946
|
-
left = { type: 'binary', operator: op, left, right: this.parseAdditive() };
|
|
947
|
-
}
|
|
948
|
-
return left;
|
|
949
|
-
}
|
|
950
|
-
parseAdditive() {
|
|
951
|
-
let left = this.parseMultiplicative();
|
|
952
|
-
while (this.match('+', '-')) {
|
|
953
|
-
const op = this.advance().value;
|
|
954
|
-
left = { type: 'binary', operator: op, left, right: this.parseMultiplicative() };
|
|
955
|
-
}
|
|
956
|
-
return left;
|
|
957
|
-
}
|
|
958
|
-
parseMultiplicative() {
|
|
959
|
-
let left = this.parseUnary();
|
|
960
|
-
while (this.match('*', '/', '%')) {
|
|
961
|
-
const op = this.advance().value;
|
|
962
|
-
left = { type: 'binary', operator: op, left, right: this.parseUnary() };
|
|
963
|
-
}
|
|
964
|
-
return left;
|
|
965
|
-
}
|
|
966
|
-
parseUnary() {
|
|
967
|
-
if (this.match('beep') && this.peek(1).value === '!') {
|
|
968
|
-
throw new Error(`'beep!' needs the full parser (use hyperfixi.js)`);
|
|
969
|
-
}
|
|
970
|
-
if (this.match('not', '!')) {
|
|
971
|
-
this.advance();
|
|
972
|
-
return { type: 'unary', operator: 'not', operand: this.parseUnary() };
|
|
973
|
-
}
|
|
974
|
-
if (this.match('-') && this.peek(1).type === 'number') {
|
|
975
|
-
this.advance();
|
|
976
|
-
const num = this.advance();
|
|
977
|
-
return { type: 'literal', value: -parseFloat(num.value) };
|
|
978
|
-
}
|
|
979
|
-
return this.parsePostfix();
|
|
980
|
-
}
|
|
981
|
-
parsePostfix() {
|
|
982
|
-
let left = this.parsePrimary();
|
|
983
|
-
while (true) {
|
|
984
|
-
if (this.match("'s")) {
|
|
985
|
-
this.advance();
|
|
986
|
-
const next = this.peek();
|
|
987
|
-
const prop = next.type === 'styleProperty' ? this.advance().value : this.advance().value;
|
|
988
|
-
left = { type: 'possessive', object: left, property: prop };
|
|
989
|
-
}
|
|
990
|
-
else if (this.peek().type === 'styleProperty') {
|
|
991
|
-
const prop = this.advance().value;
|
|
992
|
-
left = { type: 'possessive', object: left, property: prop };
|
|
993
|
-
}
|
|
994
|
-
else if (this.peek().value === '.') {
|
|
995
|
-
this.advance();
|
|
996
|
-
const prop = this.advance().value;
|
|
997
|
-
left = { type: 'member', object: left, property: prop };
|
|
998
|
-
}
|
|
999
|
-
else if (this.peek().type === 'selector' && this.peek().value.startsWith('.')) {
|
|
1000
|
-
const prop = this.advance().value.slice(1);
|
|
1001
|
-
left = { type: 'member', object: left, property: prop };
|
|
1002
|
-
}
|
|
1003
|
-
else if (this.peek().value === '(') {
|
|
1004
|
-
this.advance();
|
|
1005
|
-
const args = [];
|
|
1006
|
-
while (!this.match(')')) {
|
|
1007
|
-
args.push(this.parseExpression());
|
|
1008
|
-
if (this.match(','))
|
|
1009
|
-
this.advance();
|
|
1010
|
-
}
|
|
1011
|
-
this.expect(')');
|
|
1012
|
-
left = { type: 'call', callee: left, args };
|
|
1013
|
-
}
|
|
1014
|
-
else if (this.peek().value === '[' && left.type !== 'selector') {
|
|
1015
|
-
this.advance();
|
|
1016
|
-
const index = this.parseExpression();
|
|
1017
|
-
this.expect(']');
|
|
1018
|
-
left = { type: 'member', object: left, property: index, computed: true };
|
|
1019
|
-
}
|
|
1020
|
-
else {
|
|
1021
|
-
break;
|
|
1022
|
-
}
|
|
1023
|
-
}
|
|
1024
|
-
return left;
|
|
1025
|
-
}
|
|
1026
|
-
parsePrimary() {
|
|
1027
|
-
const token = this.peek();
|
|
1028
|
-
if (token.value === '(') {
|
|
1029
|
-
this.advance();
|
|
1030
|
-
const expr = this.parseExpression();
|
|
1031
|
-
this.expect(')');
|
|
1032
|
-
return expr;
|
|
1033
|
-
}
|
|
1034
|
-
if (token.value === '{')
|
|
1035
|
-
return this.parseObjectLiteral();
|
|
1036
|
-
if (token.value === '[')
|
|
1037
|
-
return this.parseArrayLiteral();
|
|
1038
|
-
if (token.type === 'number') {
|
|
1039
|
-
this.advance();
|
|
1040
|
-
const val = token.value;
|
|
1041
|
-
if (val.endsWith('ms'))
|
|
1042
|
-
return { type: 'literal', value: parseInt(val), unit: 'ms' };
|
|
1043
|
-
if (val.endsWith('s'))
|
|
1044
|
-
return { type: 'literal', value: parseFloat(val) * 1000, unit: 'ms' };
|
|
1045
|
-
return { type: 'literal', value: parseFloat(val) };
|
|
1046
|
-
}
|
|
1047
|
-
if (token.type === 'string') {
|
|
1048
|
-
this.advance();
|
|
1049
|
-
return { type: 'literal', value: token.value.slice(1, -1) };
|
|
1050
|
-
}
|
|
1051
|
-
if (this.match('true')) {
|
|
1052
|
-
this.advance();
|
|
1053
|
-
return { type: 'literal', value: true };
|
|
1054
|
-
}
|
|
1055
|
-
if (this.match('false')) {
|
|
1056
|
-
this.advance();
|
|
1057
|
-
return { type: 'literal', value: false };
|
|
1058
|
-
}
|
|
1059
|
-
if (this.match('null')) {
|
|
1060
|
-
this.advance();
|
|
1061
|
-
return { type: 'literal', value: null };
|
|
1062
|
-
}
|
|
1063
|
-
if (this.match('undefined')) {
|
|
1064
|
-
this.advance();
|
|
1065
|
-
return { type: 'literal', value: undefined };
|
|
1066
|
-
}
|
|
1067
|
-
if (token.type === 'localVar') {
|
|
1068
|
-
this.advance();
|
|
1069
|
-
return { type: 'variable', name: token.value, scope: 'local' };
|
|
1070
|
-
}
|
|
1071
|
-
if (token.type === 'globalVar') {
|
|
1072
|
-
this.advance();
|
|
1073
|
-
return { type: 'variable', name: token.value, scope: 'global' };
|
|
1074
|
-
}
|
|
1075
|
-
if (token.type === 'selector') {
|
|
1076
|
-
this.advance();
|
|
1077
|
-
return { type: 'selector', value: token.value };
|
|
1078
|
-
}
|
|
1079
|
-
if (this.match('my')) {
|
|
1080
|
-
this.advance();
|
|
1081
|
-
const next = this.peek();
|
|
1082
|
-
if ((next.type === 'identifier' || next.type === 'keyword') && !this.isCommandKeyword(next)) {
|
|
1083
|
-
const prop = this.advance().value;
|
|
1084
|
-
return { type: 'possessive', object: { type: 'identifier', value: 'me' }, property: prop };
|
|
1085
|
-
}
|
|
1086
|
-
return { type: 'identifier', value: 'me' };
|
|
1087
|
-
}
|
|
1088
|
-
if (this.match('its')) {
|
|
1089
|
-
this.advance();
|
|
1090
|
-
const next = this.peek();
|
|
1091
|
-
if ((next.type === 'identifier' || next.type === 'keyword') && !this.isCommandKeyword(next)) {
|
|
1092
|
-
const prop = this.advance().value;
|
|
1093
|
-
return { type: 'possessive', object: { type: 'identifier', value: 'it' }, property: prop };
|
|
1094
|
-
}
|
|
1095
|
-
return { type: 'identifier', value: 'it' };
|
|
1096
|
-
}
|
|
1097
|
-
if (this.match('me')) {
|
|
1098
|
-
this.advance();
|
|
1099
|
-
return { type: 'identifier', value: 'me' };
|
|
1100
|
-
}
|
|
1101
|
-
if (this.match('it')) {
|
|
1102
|
-
this.advance();
|
|
1103
|
-
return { type: 'identifier', value: 'it' };
|
|
1104
|
-
}
|
|
1105
|
-
if (this.match('you')) {
|
|
1106
|
-
this.advance();
|
|
1107
|
-
return { type: 'identifier', value: 'you' };
|
|
1108
|
-
}
|
|
1109
|
-
if (this.match('the', 'a', 'an')) {
|
|
1110
|
-
this.advance();
|
|
1111
|
-
if (this.match('first', 'last', 'next', 'previous', 'closest', 'parent')) {
|
|
1112
|
-
const position = this.advance().value;
|
|
1113
|
-
const target = this.parsePositionalTarget();
|
|
1114
|
-
return { type: 'positional', position, target };
|
|
1115
|
-
}
|
|
1116
|
-
return this.parsePrimary();
|
|
1117
|
-
}
|
|
1118
|
-
if (this.match('first', 'last', 'next', 'previous', 'closest', 'parent')) {
|
|
1119
|
-
const position = this.advance().value;
|
|
1120
|
-
const target = this.parsePositionalTarget();
|
|
1121
|
-
return { type: 'positional', position, target };
|
|
1122
|
-
}
|
|
1123
|
-
if (this.match('values')) {
|
|
1124
|
-
this.advance();
|
|
1125
|
-
if (this.match('of')) {
|
|
1126
|
-
this.advance();
|
|
1127
|
-
const target = this.parseExpression();
|
|
1128
|
-
return { type: 'valuesOf', target };
|
|
1129
|
-
}
|
|
1130
|
-
return { type: 'identifier', value: token.value };
|
|
1131
|
-
}
|
|
1132
|
-
if (token.type === 'identifier' || token.type === 'keyword') {
|
|
1133
|
-
this.advance();
|
|
1134
|
-
return { type: 'identifier', value: token.value };
|
|
1135
|
-
}
|
|
1136
|
-
this.advance();
|
|
1137
|
-
return { type: 'identifier', value: token.value };
|
|
1138
|
-
}
|
|
1139
|
-
parseObjectLiteral() {
|
|
1140
|
-
this.expect('{');
|
|
1141
|
-
const properties = [];
|
|
1142
|
-
while (!this.match('}')) {
|
|
1143
|
-
const key = this.advance().value;
|
|
1144
|
-
this.expect(':');
|
|
1145
|
-
const value = this.parseExpression();
|
|
1146
|
-
properties.push({ key, value });
|
|
1147
|
-
if (this.match(','))
|
|
1148
|
-
this.advance();
|
|
1149
|
-
}
|
|
1150
|
-
this.expect('}');
|
|
1151
|
-
return { type: 'object', properties };
|
|
1152
|
-
}
|
|
1153
|
-
parseArrayLiteral() {
|
|
1154
|
-
this.expect('[');
|
|
1155
|
-
const elements = [];
|
|
1156
|
-
while (!this.match(']')) {
|
|
1157
|
-
elements.push(this.parseExpression());
|
|
1158
|
-
if (this.match(','))
|
|
1159
|
-
this.advance();
|
|
1160
|
-
}
|
|
1161
|
-
this.expect(']');
|
|
1162
|
-
return { type: 'array', elements };
|
|
1163
|
-
}
|
|
1164
|
-
parsePositionalTarget() {
|
|
1165
|
-
const token = this.peek();
|
|
1166
|
-
if (token.type === 'selector') {
|
|
1167
|
-
return { type: 'selector', value: this.advance().value };
|
|
1168
|
-
}
|
|
1169
|
-
if (token.type === 'identifier' || token.type === 'keyword') {
|
|
1170
|
-
return { type: 'identifier', value: this.advance().value };
|
|
1171
|
-
}
|
|
1172
|
-
return this.parseExpression();
|
|
1173
|
-
}
|
|
1174
|
-
}
|
|
1175
|
-
|
|
1176
|
-
exports.COMMAND_ALIASES = COMMAND_ALIASES;
|
|
1177
|
-
exports.EVENT_ALIASES = EVENT_ALIASES;
|
|
1178
|
-
exports.HybridParser = HybridParser;
|
|
1179
|
-
exports.KEYWORDS = KEYWORDS;
|
|
1180
|
-
exports.addCommandAliases = addCommandAliases;
|
|
1181
|
-
exports.addEventAliases = addEventAliases;
|
|
1182
|
-
exports.normalizeCommand = normalizeCommand;
|
|
1183
|
-
exports.normalizeEvent = normalizeEvent;
|
|
1184
|
-
exports.tokenize = tokenize;
|
|
1185
|
-
//# sourceMappingURL=index.cjs.map
|