reqon-dsl 0.2.0 → 0.3.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/CHANGELOG.md +7 -0
- package/README.md +22 -0
- package/dist/ast/nodes.d.ts +83 -4
- package/dist/ast/nodes.js +14 -0
- package/dist/auth/circuit-breaker.js +7 -6
- package/dist/auth/rate-limiter.d.ts +4 -0
- package/dist/auth/rate-limiter.js +9 -16
- package/dist/cli.d.ts +13 -0
- package/dist/cli.js +84 -4
- package/dist/config/constants.d.ts +141 -0
- package/dist/config/constants.js +128 -0
- package/dist/config/index.d.ts +4 -0
- package/dist/config/index.js +4 -0
- package/dist/control/index.d.ts +2 -0
- package/dist/control/index.js +1 -0
- package/dist/control/server.d.ts +88 -0
- package/dist/control/server.js +238 -0
- package/dist/control/types.d.ts +55 -0
- package/dist/control/types.js +7 -0
- package/dist/debug/cli-debugger.d.ts +17 -0
- package/dist/debug/cli-debugger.js +180 -0
- package/dist/debug/controller.d.ts +94 -0
- package/dist/debug/controller.js +45 -0
- package/dist/debug/index.d.ts +6 -0
- package/dist/debug/index.js +5 -0
- package/dist/errors/index.d.ts +67 -0
- package/dist/errors/index.js +89 -1
- package/dist/execution/index.d.ts +1 -1
- package/dist/execution/state.d.ts +24 -0
- package/dist/index.d.ts +21 -1
- package/dist/index.js +33 -2
- package/dist/interpreter/context.d.ts +14 -0
- package/dist/interpreter/context.js +15 -0
- package/dist/interpreter/evaluator.d.ts +63 -1
- package/dist/interpreter/evaluator.js +186 -39
- package/dist/interpreter/executor.d.ts +70 -14
- package/dist/interpreter/executor.js +503 -174
- package/dist/interpreter/fetch-handler.d.ts +9 -0
- package/dist/interpreter/fetch-handler.js +133 -24
- package/dist/interpreter/http.d.ts +5 -0
- package/dist/interpreter/http.js +26 -12
- package/dist/interpreter/index.d.ts +3 -1
- package/dist/interpreter/index.js +2 -0
- package/dist/interpreter/pagination.d.ts +11 -2
- package/dist/interpreter/pagination.js +95 -31
- package/dist/interpreter/signals.d.ts +8 -0
- package/dist/interpreter/signals.js +12 -0
- package/dist/interpreter/source-manager.d.ts +75 -0
- package/dist/interpreter/source-manager.js +157 -0
- package/dist/interpreter/step-handlers/apply-handler.d.ts +29 -0
- package/dist/interpreter/step-handlers/apply-handler.js +79 -0
- package/dist/interpreter/step-handlers/for-handler.d.ts +13 -0
- package/dist/interpreter/step-handlers/for-handler.js +71 -4
- package/dist/interpreter/step-handlers/index.d.ts +4 -2
- package/dist/interpreter/step-handlers/index.js +4 -2
- package/dist/interpreter/step-handlers/match-handler.d.ts +9 -0
- package/dist/interpreter/step-handlers/match-handler.js +43 -16
- package/dist/interpreter/step-handlers/pause-handler.d.ts +52 -0
- package/dist/interpreter/step-handlers/pause-handler.js +87 -0
- package/dist/interpreter/step-handlers/store-handler.d.ts +11 -1
- package/dist/interpreter/step-handlers/store-handler.js +45 -13
- package/dist/interpreter/step-handlers/types.d.ts +3 -0
- package/dist/interpreter/step-handlers/validate-handler.d.ts +2 -1
- package/dist/interpreter/step-handlers/validate-handler.js +4 -2
- package/dist/interpreter/step-handlers/webhook-handler.d.ts +3 -0
- package/dist/interpreter/step-handlers/webhook-handler.js +18 -2
- package/dist/interpreter/store-manager.d.ts +46 -0
- package/dist/interpreter/store-manager.js +66 -0
- package/dist/lexer/index.d.ts +11 -4
- package/dist/lexer/index.js +11 -4
- package/dist/lexer/tokens.d.ts +17 -1
- package/dist/lexer/tokens.js +36 -0
- package/dist/mcp/index.d.ts +11 -0
- package/dist/mcp/index.js +11 -0
- package/dist/mcp/server.d.ts +17 -0
- package/dist/mcp/server.js +451 -0
- package/dist/oas/index.d.ts +2 -0
- package/dist/oas/index.js +1 -0
- package/dist/oas/mock-generator.d.ts +12 -0
- package/dist/oas/mock-generator.js +187 -0
- package/dist/observability/events.d.ts +244 -0
- package/dist/observability/events.js +90 -0
- package/dist/observability/index.d.ts +15 -0
- package/dist/observability/index.js +12 -0
- package/dist/observability/logger.d.ts +106 -0
- package/dist/observability/logger.js +259 -0
- package/dist/observability/otel.d.ts +135 -0
- package/dist/observability/otel.js +386 -0
- package/dist/parser/action-parser.d.ts +105 -0
- package/dist/parser/action-parser.js +645 -0
- package/dist/parser/expressions.d.ts +13 -0
- package/dist/parser/expressions.js +72 -2
- package/dist/parser/fetch-parser.d.ts +27 -0
- package/dist/parser/fetch-parser.js +269 -0
- package/dist/parser/index.d.ts +17 -0
- package/dist/parser/index.js +17 -0
- package/dist/parser/parser.d.ts +44 -46
- package/dist/parser/parser.js +122 -1070
- package/dist/parser/pipeline-parser.d.ts +12 -0
- package/dist/parser/pipeline-parser.js +52 -0
- package/dist/parser/schedule-parser.d.ts +7 -0
- package/dist/parser/schedule-parser.js +137 -0
- package/dist/parser/source-parser.d.ts +9 -0
- package/dist/parser/source-parser.js +151 -0
- package/dist/pause/index.d.ts +14 -0
- package/dist/pause/index.js +11 -0
- package/dist/pause/manager.d.ts +118 -0
- package/dist/pause/manager.js +245 -0
- package/dist/pause/state.d.ts +93 -0
- package/dist/pause/state.js +103 -0
- package/dist/pause/store.d.ts +61 -0
- package/dist/pause/store.js +156 -0
- package/dist/plugin.d.ts +9 -12
- package/dist/plugin.js +10 -13
- package/dist/stores/factory.d.ts +1 -1
- package/dist/stores/factory.js +3 -2
- package/dist/stores/file.d.ts +26 -0
- package/dist/stores/file.js +64 -10
- package/dist/stores/index.d.ts +16 -1
- package/dist/stores/index.js +16 -1
- package/dist/stores/memory.d.ts +4 -0
- package/dist/stores/memory.js +11 -0
- package/dist/stores/types.d.ts +17 -0
- package/dist/stores/types.js +12 -0
- package/dist/trace/index.d.ts +16 -0
- package/dist/trace/index.js +12 -0
- package/dist/trace/recorder.d.ts +71 -0
- package/dist/trace/recorder.js +144 -0
- package/dist/trace/replay.d.ts +132 -0
- package/dist/trace/replay.js +264 -0
- package/dist/trace/state.d.ts +102 -0
- package/dist/trace/state.js +86 -0
- package/dist/trace/store.d.ts +69 -0
- package/dist/trace/store.js +225 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/type-guards.d.ts +58 -0
- package/dist/utils/type-guards.js +92 -0
- package/dist/webhook/server.js +7 -6
- package/package.json +55 -6
- package/.claude/settings.local.json +0 -31
- package/.claude/skills/api-integration.md +0 -125
- package/.claude/skills/database-schema.md +0 -51
- package/.claude/skills/dsl-design.md +0 -80
- package/.claude/skills/property-testing.md +0 -143
- package/.claude/skills/reqon/SKILL.md +0 -44
- package/.claude/skills/reqon/references/examples.md +0 -206
- package/.claude/skills/reqon/references/syntax.md +0 -263
- package/.claude/skills/vscode-extension.md +0 -113
- package/.github/dependabot.yml +0 -32
- package/.github/pull_request_template.md +0 -21
- package/.github/workflows/ci.yml +0 -174
- package/.github/workflows/release.yml +0 -73
- package/CLAUDE.md +0 -72
- package/CONTRIBUTING.md +0 -161
- package/TODO.md +0 -51
- package/dist/auth/auth.test.d.ts +0 -1
- package/dist/auth/auth.test.js +0 -255
- package/dist/errors/errors.test.d.ts +0 -1
- package/dist/errors/errors.test.js +0 -165
- package/dist/execution/execution.test.d.ts +0 -1
- package/dist/execution/execution.test.js +0 -246
- package/dist/integration.test.d.ts +0 -1
- package/dist/integration.test.js +0 -168
- package/dist/interpreter/evaluator.test.d.ts +0 -1
- package/dist/interpreter/evaluator.test.js +0 -512
- package/dist/interpreter/http.test.d.ts +0 -1
- package/dist/interpreter/http.test.js +0 -299
- package/dist/interpreter/progress.test.d.ts +0 -1
- package/dist/interpreter/progress.test.js +0 -216
- package/dist/interpreter/schema-matcher.test.d.ts +0 -1
- package/dist/interpreter/schema-matcher.test.js +0 -122
- package/dist/lexer/lexer.d.ts +0 -24
- package/dist/lexer/lexer.js +0 -264
- package/dist/lexer/lexer.test.d.ts +0 -1
- package/dist/lexer/lexer.test.js +0 -259
- package/dist/loader/loader.test.d.ts +0 -1
- package/dist/loader/loader.test.js +0 -287
- package/dist/oas/oas.test.d.ts +0 -1
- package/dist/oas/oas.test.js +0 -218
- package/dist/parser/expressions.test.d.ts +0 -1
- package/dist/parser/expressions.test.js +0 -378
- package/dist/parser/match.test.d.ts +0 -1
- package/dist/parser/match.test.js +0 -254
- package/dist/parser/parser.test.d.ts +0 -1
- package/dist/parser/parser.test.js +0 -333
- package/dist/parser/schedule.test.d.ts +0 -1
- package/dist/parser/schedule.test.js +0 -241
- package/dist/scheduler/cron-parser.test.d.ts +0 -1
- package/dist/scheduler/cron-parser.test.js +0 -188
- package/dist/stores/file.test.d.ts +0 -1
- package/dist/stores/file.test.js +0 -165
- package/dist/stores/memory.test.d.ts +0 -1
- package/dist/stores/memory.test.js +0 -157
- package/dist/stores/stores.test.d.ts +0 -1
- package/dist/stores/stores.test.js +0 -158
- package/dist/sync/sync.test.d.ts +0 -1
- package/dist/sync/sync.test.js +0 -221
- package/docusaurus/README.md +0 -41
- package/docusaurus/docs/advanced/execution-state.md +0 -283
- package/docusaurus/docs/advanced/extending-reqon.md +0 -388
- package/docusaurus/docs/advanced/multi-file-missions.md +0 -250
- package/docusaurus/docs/advanced/parallel-execution.md +0 -353
- package/docusaurus/docs/api-reference.md +0 -443
- package/docusaurus/docs/authentication/api-key.md +0 -339
- package/docusaurus/docs/authentication/basic.md +0 -276
- package/docusaurus/docs/authentication/bearer.md +0 -282
- package/docusaurus/docs/authentication/oauth2.md +0 -317
- package/docusaurus/docs/authentication/overview.md +0 -251
- package/docusaurus/docs/cli.md +0 -229
- package/docusaurus/docs/core-concepts/actions.md +0 -286
- package/docusaurus/docs/core-concepts/missions.md +0 -264
- package/docusaurus/docs/core-concepts/schemas.md +0 -353
- package/docusaurus/docs/core-concepts/sources.md +0 -339
- package/docusaurus/docs/core-concepts/stores.md +0 -332
- package/docusaurus/docs/dsl-syntax/expressions.md +0 -361
- package/docusaurus/docs/dsl-syntax/fetch.md +0 -293
- package/docusaurus/docs/dsl-syntax/for-loops.md +0 -324
- package/docusaurus/docs/dsl-syntax/map.md +0 -345
- package/docusaurus/docs/dsl-syntax/match.md +0 -387
- package/docusaurus/docs/dsl-syntax/pipelines.md +0 -397
- package/docusaurus/docs/dsl-syntax/validate.md +0 -401
- package/docusaurus/docs/error-handling/dead-letter-queues.md +0 -399
- package/docusaurus/docs/error-handling/flow-control.md +0 -337
- package/docusaurus/docs/error-handling/retry-strategies.md +0 -368
- package/docusaurus/docs/examples.md +0 -488
- package/docusaurus/docs/getting-started.md +0 -256
- package/docusaurus/docs/http/circuit-breaker.md +0 -401
- package/docusaurus/docs/http/incremental-sync.md +0 -394
- package/docusaurus/docs/http/pagination.md +0 -361
- package/docusaurus/docs/http/rate-limiting.md +0 -383
- package/docusaurus/docs/http/requests.md +0 -328
- package/docusaurus/docs/http/retry.md +0 -402
- package/docusaurus/docs/intro.md +0 -90
- package/docusaurus/docs/openapi/loading-specs.md +0 -305
- package/docusaurus/docs/openapi/operation-calls.md +0 -314
- package/docusaurus/docs/openapi/overview.md +0 -212
- package/docusaurus/docs/openapi/response-validation.md +0 -344
- package/docusaurus/docs/scheduling/cron.md +0 -305
- package/docusaurus/docs/scheduling/daemon-mode.md +0 -317
- package/docusaurus/docs/scheduling/intervals.md +0 -289
- package/docusaurus/docs/scheduling/overview.md +0 -231
- package/docusaurus/docs/stores/custom-adapters.md +0 -376
- package/docusaurus/docs/stores/file.md +0 -236
- package/docusaurus/docs/stores/memory.md +0 -193
- package/docusaurus/docs/stores/overview.md +0 -274
- package/docusaurus/docs/stores/postgrest.md +0 -316
- package/docusaurus/docusaurus.config.ts +0 -148
- package/docusaurus/package-lock.json +0 -18029
- package/docusaurus/package.json +0 -47
- package/docusaurus/sidebars.ts +0 -155
- package/docusaurus/src/components/HomepageFeatures/index.tsx +0 -105
- package/docusaurus/src/components/HomepageFeatures/styles.module.css +0 -12
- package/docusaurus/src/css/custom.css +0 -169
- package/docusaurus/src/pages/index.module.css +0 -48
- package/docusaurus/src/pages/index.tsx +0 -110
- package/docusaurus/src/pages/markdown-page.md +0 -7
- package/docusaurus/static/.nojekyll +0 -0
- package/docusaurus/static/img/docusaurus-social-card.jpg +0 -0
- package/docusaurus/static/img/docusaurus.png +0 -0
- package/docusaurus/static/img/favicon.ico +0 -0
- package/docusaurus/static/img/logo.svg +0 -10
- package/docusaurus/static/img/undraw_docusaurus_mountain.svg +0 -171
- package/docusaurus/static/img/undraw_docusaurus_react.svg +0 -170
- package/docusaurus/static/img/undraw_docusaurus_tree.svg +0 -40
- package/docusaurus/tsconfig.json +0 -8
- package/examples/README.md +0 -112
- package/examples/error-handling/README.md +0 -150
- package/examples/error-handling/payment-processor.vague +0 -287
- package/examples/github-sync/README.md +0 -74
- package/examples/github-sync/fetch-issues.vague +0 -47
- package/examples/github-sync/fetch-prs.vague +0 -40
- package/examples/github-sync/mission.vague +0 -101
- package/examples/github-sync/normalize.vague +0 -70
- package/examples/jsonplaceholder/README.md +0 -28
- package/examples/jsonplaceholder/posts.vague +0 -48
- package/examples/petstore/README.md +0 -35
- package/examples/petstore/openapi.yaml +0 -97
- package/examples/petstore/sync.vague +0 -52
- package/examples/temporal-comparison/README.md +0 -297
- package/examples/temporal-comparison/reconciliation.vague +0 -355
- package/examples/temporal-comparison/temporal/activities/index.ts +0 -8
- package/examples/temporal-comparison/temporal/activities/shipstation.ts +0 -225
- package/examples/temporal-comparison/temporal/activities/shopify.ts +0 -257
- package/examples/temporal-comparison/temporal/activities/storage.ts +0 -198
- package/examples/temporal-comparison/temporal/activities/stripe.ts +0 -169
- package/examples/temporal-comparison/temporal/activities/validation.ts +0 -205
- package/examples/temporal-comparison/temporal/client/schedule.ts +0 -218
- package/examples/temporal-comparison/temporal/config/retry.ts +0 -63
- package/examples/temporal-comparison/temporal/types/index.ts +0 -129
- package/examples/temporal-comparison/temporal/workers/main.ts +0 -130
- package/examples/temporal-comparison/temporal/workflows/orderReconciliation.ts +0 -262
- package/examples/xero/README.md +0 -88
- package/examples/xero/invoices.vague +0 -189
- package/src/api-integration.test.ts +0 -954
- package/src/ast/index.ts +0 -1
- package/src/ast/nodes.ts +0 -310
- package/src/auth/auth.test.ts +0 -326
- package/src/auth/circuit-breaker.test.ts +0 -390
- package/src/auth/circuit-breaker.ts +0 -379
- package/src/auth/credentials.test.ts +0 -273
- package/src/auth/credentials.ts +0 -246
- package/src/auth/index.ts +0 -40
- package/src/auth/oauth2-provider.ts +0 -177
- package/src/auth/rate-limiter.ts +0 -459
- package/src/auth/token-store.ts +0 -177
- package/src/auth/types.ts +0 -159
- package/src/benchmark/e2e.bench.ts +0 -288
- package/src/benchmark/evaluator.bench.ts +0 -331
- package/src/benchmark/fixtures.ts +0 -295
- package/src/benchmark/index.ts +0 -108
- package/src/benchmark/lexer.bench.ts +0 -69
- package/src/benchmark/parser.bench.ts +0 -103
- package/src/benchmark/resilience.bench.ts +0 -193
- package/src/benchmark/store.bench.ts +0 -147
- package/src/benchmark/utils.ts +0 -230
- package/src/cli.ts +0 -313
- package/src/errors/errors.test.ts +0 -234
- package/src/errors/index.ts +0 -223
- package/src/execution/execution.test.ts +0 -307
- package/src/execution/index.ts +0 -21
- package/src/execution/state.ts +0 -207
- package/src/execution/store.ts +0 -188
- package/src/index.ts +0 -169
- package/src/integration.test.ts +0 -192
- package/src/interpreter/context.ts +0 -57
- package/src/interpreter/evaluator.test.ts +0 -796
- package/src/interpreter/evaluator.ts +0 -245
- package/src/interpreter/executor.ts +0 -946
- package/src/interpreter/fetch-handler.ts +0 -302
- package/src/interpreter/http.test.ts +0 -423
- package/src/interpreter/http.ts +0 -308
- package/src/interpreter/index.ts +0 -32
- package/src/interpreter/pagination.ts +0 -207
- package/src/interpreter/progress.test.ts +0 -276
- package/src/interpreter/schema-matcher.test.ts +0 -160
- package/src/interpreter/schema-matcher.ts +0 -168
- package/src/interpreter/signals.ts +0 -73
- package/src/interpreter/step-handlers/for-handler.ts +0 -65
- package/src/interpreter/step-handlers/index.ts +0 -17
- package/src/interpreter/step-handlers/map-handler.ts +0 -24
- package/src/interpreter/step-handlers/match-handler.ts +0 -101
- package/src/interpreter/step-handlers/store-handler.ts +0 -78
- package/src/interpreter/step-handlers/types.ts +0 -17
- package/src/interpreter/step-handlers/validate-handler.ts +0 -30
- package/src/interpreter/step-handlers/webhook-handler.ts +0 -142
- package/src/lexer/index.ts +0 -18
- package/src/lexer/lexer.test.ts +0 -316
- package/src/lexer/tokens.ts +0 -179
- package/src/loader/index.ts +0 -288
- package/src/loader/loader.test.ts +0 -360
- package/src/oas/index.ts +0 -4
- package/src/oas/loader.ts +0 -126
- package/src/oas/oas.test.ts +0 -254
- package/src/oas/validator.ts +0 -299
- package/src/parser/base.ts +0 -124
- package/src/parser/expressions.test.ts +0 -525
- package/src/parser/expressions.ts +0 -314
- package/src/parser/index.ts +0 -3
- package/src/parser/match.test.ts +0 -296
- package/src/parser/parser.test.ts +0 -739
- package/src/parser/parser.ts +0 -1469
- package/src/parser/schedule.test.ts +0 -287
- package/src/parser/webhook.test.ts +0 -248
- package/src/plugin.ts +0 -83
- package/src/scheduler/cron-parser.test.ts +0 -236
- package/src/scheduler/cron-parser.ts +0 -236
- package/src/scheduler/index.ts +0 -10
- package/src/scheduler/scheduler.ts +0 -443
- package/src/scheduler/types.ts +0 -71
- package/src/stores/factory.ts +0 -104
- package/src/stores/file.test.ts +0 -276
- package/src/stores/file.ts +0 -211
- package/src/stores/index.ts +0 -6
- package/src/stores/memory.test.ts +0 -238
- package/src/stores/memory.ts +0 -63
- package/src/stores/postgrest.test.ts +0 -488
- package/src/stores/postgrest.ts +0 -263
- package/src/stores/stores.test.ts +0 -197
- package/src/stores/types.ts +0 -58
- package/src/sync/index.ts +0 -16
- package/src/sync/state.ts +0 -126
- package/src/sync/store.ts +0 -139
- package/src/sync/sync.test.ts +0 -271
- package/src/utils/async.ts +0 -10
- package/src/utils/file.ts +0 -106
- package/src/utils/index.ts +0 -14
- package/src/utils/logger.ts +0 -53
- package/src/utils/path.ts +0 -47
- package/src/webhook/index.ts +0 -15
- package/src/webhook/server.test.ts +0 -253
- package/src/webhook/server.ts +0 -389
- package/src/webhook/store.ts +0 -239
- package/src/webhook/types.ts +0 -93
- package/tsconfig.json +0 -17
- package/vitest.config.ts +0 -39
package/src/parser/base.ts
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { TokenType, type Token } from 'vague-lang';
|
|
2
|
-
import { ReqonTokenType } from '../lexer/tokens.js';
|
|
3
|
-
import { ParseError, type ErrorContext } from '../errors/index.js';
|
|
4
|
-
|
|
5
|
-
// Token type can be Vague's TokenType, Reqon's ReqonTokenType, or a plugin string
|
|
6
|
-
type AnyTokenType = TokenType | ReqonTokenType | string;
|
|
7
|
-
|
|
8
|
-
export class ReqonParserBase {
|
|
9
|
-
protected tokens: Token[];
|
|
10
|
-
protected pos = 0;
|
|
11
|
-
protected source?: string;
|
|
12
|
-
protected filePath?: string;
|
|
13
|
-
|
|
14
|
-
constructor(tokens: Token[], source?: string, filePath?: string) {
|
|
15
|
-
this.tokens = tokens.filter((t) => t.type !== TokenType.NEWLINE);
|
|
16
|
-
this.source = source;
|
|
17
|
-
this.filePath = filePath;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
protected peek(): Token {
|
|
21
|
-
return this.tokens[this.pos];
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
protected peekNext(): Token | undefined {
|
|
25
|
-
return this.tokens[this.pos + 1];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
protected check(type: AnyTokenType): boolean {
|
|
29
|
-
return !this.isAtEnd() && this.peek().type === type;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
protected checkAny(...types: AnyTokenType[]): boolean {
|
|
33
|
-
return types.some((t) => this.check(t));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
protected match(type: AnyTokenType): boolean {
|
|
37
|
-
if (this.check(type)) {
|
|
38
|
-
this.advance();
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
protected matchAny(...types: AnyTokenType[]): AnyTokenType | null {
|
|
45
|
-
for (const type of types) {
|
|
46
|
-
if (this.check(type)) {
|
|
47
|
-
this.advance();
|
|
48
|
-
return type;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
protected advance(): Token {
|
|
55
|
-
if (!this.isAtEnd()) this.pos++;
|
|
56
|
-
return this.tokens[this.pos - 1];
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
protected consume(type: AnyTokenType, message: string): Token {
|
|
60
|
-
if (this.check(type)) return this.advance();
|
|
61
|
-
throw this.error(message);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Consume an identifier, allowing HTTP method tokens to be used as identifiers.
|
|
66
|
-
* This is needed because 'get', 'post', etc. are valid variable/store names.
|
|
67
|
-
*/
|
|
68
|
-
protected consumeIdentifier(message: string): Token {
|
|
69
|
-
const token = this.peek();
|
|
70
|
-
// Accept both regular identifiers and HTTP method tokens as identifiers
|
|
71
|
-
if (
|
|
72
|
-
token.type === TokenType.IDENTIFIER ||
|
|
73
|
-
token.type === ReqonTokenType.GET ||
|
|
74
|
-
token.type === ReqonTokenType.POST ||
|
|
75
|
-
token.type === ReqonTokenType.PUT ||
|
|
76
|
-
token.type === ReqonTokenType.PATCH ||
|
|
77
|
-
token.type === ReqonTokenType.DELETE
|
|
78
|
-
) {
|
|
79
|
-
return this.advance();
|
|
80
|
-
}
|
|
81
|
-
throw this.error(message);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Check if current token is an identifier (including HTTP methods as identifiers)
|
|
86
|
-
*/
|
|
87
|
-
protected checkIdentifier(): boolean {
|
|
88
|
-
const type = this.peek().type;
|
|
89
|
-
return (
|
|
90
|
-
type === TokenType.IDENTIFIER ||
|
|
91
|
-
type === ReqonTokenType.GET ||
|
|
92
|
-
type === ReqonTokenType.POST ||
|
|
93
|
-
type === ReqonTokenType.PUT ||
|
|
94
|
-
type === ReqonTokenType.PATCH ||
|
|
95
|
-
type === ReqonTokenType.DELETE
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
protected isAtEnd(): boolean {
|
|
100
|
-
return this.peek().type === TokenType.EOF;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
protected error(message: string): ParseError {
|
|
104
|
-
const token = this.peek();
|
|
105
|
-
const context: ErrorContext | undefined = this.source
|
|
106
|
-
? { source: this.source, filePath: this.filePath }
|
|
107
|
-
: undefined;
|
|
108
|
-
|
|
109
|
-
return new ParseError(
|
|
110
|
-
message,
|
|
111
|
-
{ line: token.line, column: token.column },
|
|
112
|
-
context,
|
|
113
|
-
token.value
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
protected savePosition(): number {
|
|
118
|
-
return this.pos;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
protected restorePosition(saved: number): void {
|
|
122
|
-
this.pos = saved;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
@@ -1,525 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { ReqonLexer } from '../lexer/index.js';
|
|
3
|
-
import { ReqonExpressionParser } from './expressions.js';
|
|
4
|
-
import type { ReqonToken } from '../lexer/tokens.js';
|
|
5
|
-
|
|
6
|
-
describe('ReqonExpressionParser', () => {
|
|
7
|
-
function parseExpr(source: string) {
|
|
8
|
-
const lexer = new ReqonLexer(source);
|
|
9
|
-
const tokens = lexer.tokenize();
|
|
10
|
-
const parser = new TestableExpressionParser(tokens);
|
|
11
|
-
return parser.parseExpression();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// Create a testable subclass that exposes parseExpression
|
|
15
|
-
class TestableExpressionParser extends ReqonExpressionParser {
|
|
16
|
-
constructor(tokens: ReqonToken[]) {
|
|
17
|
-
super(tokens);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
describe('literals', () => {
|
|
22
|
-
it('parses number literals', () => {
|
|
23
|
-
const expr = parseExpr('42');
|
|
24
|
-
|
|
25
|
-
expect(expr.type).toBe('Literal');
|
|
26
|
-
if (expr.type === 'Literal') {
|
|
27
|
-
expect(expr.value).toBe(42);
|
|
28
|
-
expect(expr.dataType).toBe('number');
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('parses decimal number literals', () => {
|
|
33
|
-
const expr = parseExpr('3.14');
|
|
34
|
-
|
|
35
|
-
expect(expr.type).toBe('Literal');
|
|
36
|
-
if (expr.type === 'Literal') {
|
|
37
|
-
expect(expr.value).toBe(3.14);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('parses string literals', () => {
|
|
42
|
-
const expr = parseExpr('"hello world"');
|
|
43
|
-
|
|
44
|
-
expect(expr.type).toBe('Literal');
|
|
45
|
-
if (expr.type === 'Literal') {
|
|
46
|
-
expect(expr.value).toBe('hello world');
|
|
47
|
-
expect(expr.dataType).toBe('string');
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('parses true literal', () => {
|
|
52
|
-
const expr = parseExpr('true');
|
|
53
|
-
|
|
54
|
-
expect(expr.type).toBe('Literal');
|
|
55
|
-
if (expr.type === 'Literal') {
|
|
56
|
-
expect(expr.value).toBe(true);
|
|
57
|
-
expect(expr.dataType).toBe('boolean');
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('parses false literal', () => {
|
|
62
|
-
const expr = parseExpr('false');
|
|
63
|
-
|
|
64
|
-
expect(expr.type).toBe('Literal');
|
|
65
|
-
if (expr.type === 'Literal') {
|
|
66
|
-
expect(expr.value).toBe(false);
|
|
67
|
-
expect(expr.dataType).toBe('boolean');
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('parses null literal', () => {
|
|
72
|
-
const expr = parseExpr('null');
|
|
73
|
-
|
|
74
|
-
expect(expr.type).toBe('Literal');
|
|
75
|
-
if (expr.type === 'Literal') {
|
|
76
|
-
expect(expr.value).toBe(null);
|
|
77
|
-
expect(expr.dataType).toBe('null');
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
describe('identifiers', () => {
|
|
83
|
-
it('parses simple identifiers', () => {
|
|
84
|
-
const expr = parseExpr('myVariable');
|
|
85
|
-
|
|
86
|
-
expect(expr.type).toBe('Identifier');
|
|
87
|
-
if (expr.type === 'Identifier') {
|
|
88
|
-
expect(expr.name).toBe('myVariable');
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('parses dot-prefixed field shorthand', () => {
|
|
93
|
-
const expr = parseExpr('.fieldName');
|
|
94
|
-
|
|
95
|
-
expect(expr.type).toBe('Identifier');
|
|
96
|
-
if (expr.type === 'Identifier') {
|
|
97
|
-
expect(expr.name).toBe('fieldName');
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
describe('binary arithmetic expressions', () => {
|
|
103
|
-
it('parses addition', () => {
|
|
104
|
-
const expr = parseExpr('1 + 2');
|
|
105
|
-
|
|
106
|
-
expect(expr.type).toBe('BinaryExpression');
|
|
107
|
-
if (expr.type === 'BinaryExpression') {
|
|
108
|
-
expect(expr.operator).toBe('+');
|
|
109
|
-
expect(expr.left).toMatchObject({ type: 'Literal', value: 1 });
|
|
110
|
-
expect(expr.right).toMatchObject({ type: 'Literal', value: 2 });
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('parses subtraction', () => {
|
|
115
|
-
const expr = parseExpr('10 - 5');
|
|
116
|
-
|
|
117
|
-
expect(expr.type).toBe('BinaryExpression');
|
|
118
|
-
if (expr.type === 'BinaryExpression') {
|
|
119
|
-
expect(expr.operator).toBe('-');
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it('parses multiplication', () => {
|
|
124
|
-
const expr = parseExpr('3 * 4');
|
|
125
|
-
|
|
126
|
-
expect(expr.type).toBe('BinaryExpression');
|
|
127
|
-
if (expr.type === 'BinaryExpression') {
|
|
128
|
-
expect(expr.operator).toBe('*');
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it('parses division', () => {
|
|
133
|
-
const expr = parseExpr('20 / 4');
|
|
134
|
-
|
|
135
|
-
expect(expr.type).toBe('BinaryExpression');
|
|
136
|
-
if (expr.type === 'BinaryExpression') {
|
|
137
|
-
expect(expr.operator).toBe('/');
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it('respects operator precedence (multiplication before addition)', () => {
|
|
142
|
-
const expr = parseExpr('1 + 2 * 3');
|
|
143
|
-
|
|
144
|
-
expect(expr.type).toBe('BinaryExpression');
|
|
145
|
-
if (expr.type === 'BinaryExpression') {
|
|
146
|
-
expect(expr.operator).toBe('+');
|
|
147
|
-
expect(expr.left).toMatchObject({ type: 'Literal', value: 1 });
|
|
148
|
-
expect(expr.right.type).toBe('BinaryExpression');
|
|
149
|
-
if (expr.right.type === 'BinaryExpression') {
|
|
150
|
-
expect(expr.right.operator).toBe('*');
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it('respects parentheses', () => {
|
|
156
|
-
const expr = parseExpr('(1 + 2) * 3');
|
|
157
|
-
|
|
158
|
-
expect(expr.type).toBe('BinaryExpression');
|
|
159
|
-
if (expr.type === 'BinaryExpression') {
|
|
160
|
-
expect(expr.operator).toBe('*');
|
|
161
|
-
expect(expr.left.type).toBe('BinaryExpression');
|
|
162
|
-
expect(expr.right).toMatchObject({ type: 'Literal', value: 3 });
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
describe('comparison expressions', () => {
|
|
168
|
-
it('parses equality', () => {
|
|
169
|
-
const expr = parseExpr('x == 5');
|
|
170
|
-
|
|
171
|
-
expect(expr.type).toBe('BinaryExpression');
|
|
172
|
-
if (expr.type === 'BinaryExpression') {
|
|
173
|
-
expect(expr.operator).toBe('==');
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
it('parses less than', () => {
|
|
178
|
-
const expr = parseExpr('x < 10');
|
|
179
|
-
|
|
180
|
-
expect(expr.type).toBe('BinaryExpression');
|
|
181
|
-
if (expr.type === 'BinaryExpression') {
|
|
182
|
-
expect(expr.operator).toBe('<');
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it('parses greater than', () => {
|
|
187
|
-
const expr = parseExpr('x > 0');
|
|
188
|
-
|
|
189
|
-
expect(expr.type).toBe('BinaryExpression');
|
|
190
|
-
if (expr.type === 'BinaryExpression') {
|
|
191
|
-
expect(expr.operator).toBe('>');
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
it('parses less than or equal', () => {
|
|
196
|
-
const expr = parseExpr('x <= 100');
|
|
197
|
-
|
|
198
|
-
expect(expr.type).toBe('BinaryExpression');
|
|
199
|
-
if (expr.type === 'BinaryExpression') {
|
|
200
|
-
expect(expr.operator).toBe('<=');
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
it('parses greater than or equal', () => {
|
|
205
|
-
const expr = parseExpr('x >= 0');
|
|
206
|
-
|
|
207
|
-
expect(expr.type).toBe('BinaryExpression');
|
|
208
|
-
if (expr.type === 'BinaryExpression') {
|
|
209
|
-
expect(expr.operator).toBe('>=');
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
describe('logical expressions', () => {
|
|
215
|
-
it('parses and expression', () => {
|
|
216
|
-
const expr = parseExpr('a and b');
|
|
217
|
-
|
|
218
|
-
expect(expr.type).toBe('LogicalExpression');
|
|
219
|
-
if (expr.type === 'LogicalExpression') {
|
|
220
|
-
expect(expr.operator).toBe('and');
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
it('parses or expression', () => {
|
|
225
|
-
const expr = parseExpr('a or b');
|
|
226
|
-
|
|
227
|
-
expect(expr.type).toBe('LogicalExpression');
|
|
228
|
-
if (expr.type === 'LogicalExpression') {
|
|
229
|
-
expect(expr.operator).toBe('or');
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
it('parses not expression', () => {
|
|
234
|
-
const expr = parseExpr('not a');
|
|
235
|
-
|
|
236
|
-
expect(expr.type).toBe('NotExpression');
|
|
237
|
-
if (expr.type === 'NotExpression') {
|
|
238
|
-
expect(expr.operand).toMatchObject({ type: 'Identifier', name: 'a' });
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
it('parses combined logical expressions', () => {
|
|
243
|
-
const expr = parseExpr('a and b or c');
|
|
244
|
-
|
|
245
|
-
// 'or' has lower precedence, so it's the root
|
|
246
|
-
expect(expr.type).toBe('LogicalExpression');
|
|
247
|
-
if (expr.type === 'LogicalExpression') {
|
|
248
|
-
expect(expr.operator).toBe('or');
|
|
249
|
-
expect(expr.left.type).toBe('LogicalExpression');
|
|
250
|
-
if (expr.left.type === 'LogicalExpression') {
|
|
251
|
-
expect(expr.left.operator).toBe('and');
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
it('parses double negation', () => {
|
|
257
|
-
const expr = parseExpr('not not a');
|
|
258
|
-
|
|
259
|
-
expect(expr.type).toBe('NotExpression');
|
|
260
|
-
if (expr.type === 'NotExpression') {
|
|
261
|
-
expect(expr.operand.type).toBe('NotExpression');
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
describe('ternary expressions', () => {
|
|
267
|
-
it('parses simple ternary', () => {
|
|
268
|
-
const expr = parseExpr('true ? 1 : 0');
|
|
269
|
-
|
|
270
|
-
expect(expr.type).toBe('TernaryExpression');
|
|
271
|
-
if (expr.type === 'TernaryExpression') {
|
|
272
|
-
expect(expr.condition).toMatchObject({ type: 'Literal', value: true });
|
|
273
|
-
expect(expr.consequent).toMatchObject({ type: 'Literal', value: 1 });
|
|
274
|
-
expect(expr.alternate).toMatchObject({ type: 'Literal', value: 0 });
|
|
275
|
-
}
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
it('parses nested ternary', () => {
|
|
279
|
-
const expr = parseExpr('a ? b ? 1 : 2 : 3');
|
|
280
|
-
|
|
281
|
-
expect(expr.type).toBe('TernaryExpression');
|
|
282
|
-
if (expr.type === 'TernaryExpression') {
|
|
283
|
-
expect(expr.consequent.type).toBe('TernaryExpression');
|
|
284
|
-
}
|
|
285
|
-
});
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
describe('unary expressions', () => {
|
|
289
|
-
it('parses negative number', () => {
|
|
290
|
-
const expr = parseExpr('-5');
|
|
291
|
-
|
|
292
|
-
expect(expr.type).toBe('UnaryExpression');
|
|
293
|
-
if (expr.type === 'UnaryExpression') {
|
|
294
|
-
expect(expr.operator).toBe('-');
|
|
295
|
-
expect(expr.operand).toMatchObject({ type: 'Literal', value: 5 });
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
it('parses positive number', () => {
|
|
300
|
-
const expr = parseExpr('+5');
|
|
301
|
-
|
|
302
|
-
expect(expr.type).toBe('UnaryExpression');
|
|
303
|
-
if (expr.type === 'UnaryExpression') {
|
|
304
|
-
expect(expr.operator).toBe('+');
|
|
305
|
-
}
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
it('parses double negative', () => {
|
|
309
|
-
const expr = parseExpr('--x');
|
|
310
|
-
|
|
311
|
-
expect(expr.type).toBe('UnaryExpression');
|
|
312
|
-
if (expr.type === 'UnaryExpression') {
|
|
313
|
-
expect(expr.operand.type).toBe('UnaryExpression');
|
|
314
|
-
}
|
|
315
|
-
});
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
describe('member access (qualified names)', () => {
|
|
319
|
-
it('parses single property access', () => {
|
|
320
|
-
const expr = parseExpr('obj.prop');
|
|
321
|
-
|
|
322
|
-
expect(expr.type).toBe('QualifiedName');
|
|
323
|
-
if (expr.type === 'QualifiedName') {
|
|
324
|
-
expect(expr.parts).toEqual(['obj', 'prop']);
|
|
325
|
-
}
|
|
326
|
-
});
|
|
327
|
-
|
|
328
|
-
it('parses chained property access', () => {
|
|
329
|
-
const expr = parseExpr('a.b.c.d');
|
|
330
|
-
|
|
331
|
-
expect(expr.type).toBe('QualifiedName');
|
|
332
|
-
if (expr.type === 'QualifiedName') {
|
|
333
|
-
expect(expr.parts).toEqual(['a', 'b', 'c', 'd']);
|
|
334
|
-
}
|
|
335
|
-
});
|
|
336
|
-
});
|
|
337
|
-
|
|
338
|
-
describe('function calls', () => {
|
|
339
|
-
it('parses function call without arguments', () => {
|
|
340
|
-
const expr = parseExpr('fn()');
|
|
341
|
-
|
|
342
|
-
expect(expr.type).toBe('CallExpression');
|
|
343
|
-
if (expr.type === 'CallExpression') {
|
|
344
|
-
expect(expr.callee).toBe('fn');
|
|
345
|
-
expect(expr.arguments).toEqual([]);
|
|
346
|
-
}
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
it('parses function call with single argument', () => {
|
|
350
|
-
const expr = parseExpr('length(items)');
|
|
351
|
-
|
|
352
|
-
expect(expr.type).toBe('CallExpression');
|
|
353
|
-
if (expr.type === 'CallExpression') {
|
|
354
|
-
expect(expr.callee).toBe('length');
|
|
355
|
-
expect(expr.arguments).toHaveLength(1);
|
|
356
|
-
}
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
it('parses function call with multiple arguments', () => {
|
|
360
|
-
const expr = parseExpr('func(1, 2, 3)');
|
|
361
|
-
|
|
362
|
-
expect(expr.type).toBe('CallExpression');
|
|
363
|
-
if (expr.type === 'CallExpression') {
|
|
364
|
-
expect(expr.arguments).toHaveLength(3);
|
|
365
|
-
}
|
|
366
|
-
});
|
|
367
|
-
});
|
|
368
|
-
|
|
369
|
-
describe('match expressions', () => {
|
|
370
|
-
it('parses simple match expression', () => {
|
|
371
|
-
const expr = parseExpr('match x { 1 => "one", 2 => "two" }');
|
|
372
|
-
|
|
373
|
-
expect(expr.type).toBe('MatchExpression');
|
|
374
|
-
if (expr.type === 'MatchExpression') {
|
|
375
|
-
expect(expr.arms).toHaveLength(2);
|
|
376
|
-
expect(expr.arms[0].pattern).toMatchObject({ type: 'Literal', value: 1 });
|
|
377
|
-
expect(expr.arms[0].result).toMatchObject({ type: 'Literal', value: 'one' });
|
|
378
|
-
}
|
|
379
|
-
});
|
|
380
|
-
|
|
381
|
-
it('parses match with wildcard', () => {
|
|
382
|
-
const expr = parseExpr('match status { "A" => "active", _ => "other" }');
|
|
383
|
-
|
|
384
|
-
expect(expr.type).toBe('MatchExpression');
|
|
385
|
-
if (expr.type === 'MatchExpression') {
|
|
386
|
-
expect(expr.arms).toHaveLength(2);
|
|
387
|
-
expect(expr.arms[1].pattern).toMatchObject({ type: 'Identifier', name: '_' });
|
|
388
|
-
}
|
|
389
|
-
});
|
|
390
|
-
});
|
|
391
|
-
|
|
392
|
-
describe('any of expressions', () => {
|
|
393
|
-
it('parses any of expression', () => {
|
|
394
|
-
const expr = parseExpr('any of items');
|
|
395
|
-
|
|
396
|
-
expect(expr.type).toBe('AnyOfExpression');
|
|
397
|
-
if (expr.type === 'AnyOfExpression') {
|
|
398
|
-
expect(expr.collection).toMatchObject({ type: 'Identifier', name: 'items' });
|
|
399
|
-
expect(expr.condition).toBeUndefined();
|
|
400
|
-
}
|
|
401
|
-
});
|
|
402
|
-
|
|
403
|
-
it('parses any of with where condition', () => {
|
|
404
|
-
const expr = parseExpr('any of items where active');
|
|
405
|
-
|
|
406
|
-
expect(expr.type).toBe('AnyOfExpression');
|
|
407
|
-
if (expr.type === 'AnyOfExpression') {
|
|
408
|
-
expect(expr.condition).toBeDefined();
|
|
409
|
-
}
|
|
410
|
-
});
|
|
411
|
-
});
|
|
412
|
-
|
|
413
|
-
describe('range expressions', () => {
|
|
414
|
-
it('parses range expression', () => {
|
|
415
|
-
const expr = parseExpr('1..10');
|
|
416
|
-
|
|
417
|
-
expect(expr.type).toBe('RangeExpression');
|
|
418
|
-
if (expr.type === 'RangeExpression') {
|
|
419
|
-
expect(expr.min).toMatchObject({ type: 'Literal', value: 1 });
|
|
420
|
-
expect(expr.max).toMatchObject({ type: 'Literal', value: 10 });
|
|
421
|
-
}
|
|
422
|
-
});
|
|
423
|
-
|
|
424
|
-
it('parses open-ended range', () => {
|
|
425
|
-
const expr = parseExpr('5..');
|
|
426
|
-
|
|
427
|
-
expect(expr.type).toBe('RangeExpression');
|
|
428
|
-
if (expr.type === 'RangeExpression') {
|
|
429
|
-
expect(expr.min).toMatchObject({ type: 'Literal', value: 5 });
|
|
430
|
-
expect(expr.max).toBeUndefined();
|
|
431
|
-
}
|
|
432
|
-
});
|
|
433
|
-
});
|
|
434
|
-
|
|
435
|
-
describe('is type checking expressions', () => {
|
|
436
|
-
it('parses is array', () => {
|
|
437
|
-
const expr = parseExpr('items is array');
|
|
438
|
-
|
|
439
|
-
expect(expr.type).toBe('IsExpression');
|
|
440
|
-
if (expr.type === 'IsExpression') {
|
|
441
|
-
expect((expr as any).operand).toMatchObject({ type: 'Identifier', name: 'items' });
|
|
442
|
-
expect((expr as any).typeCheck).toBe('array');
|
|
443
|
-
}
|
|
444
|
-
});
|
|
445
|
-
|
|
446
|
-
it('parses is string', () => {
|
|
447
|
-
const expr = parseExpr('.name is string');
|
|
448
|
-
|
|
449
|
-
expect(expr.type).toBe('IsExpression');
|
|
450
|
-
if (expr.type === 'IsExpression') {
|
|
451
|
-
expect((expr as any).typeCheck).toBe('string');
|
|
452
|
-
}
|
|
453
|
-
});
|
|
454
|
-
|
|
455
|
-
it('parses is number', () => {
|
|
456
|
-
const expr = parseExpr('value is number');
|
|
457
|
-
|
|
458
|
-
expect(expr.type).toBe('IsExpression');
|
|
459
|
-
if (expr.type === 'IsExpression') {
|
|
460
|
-
expect((expr as any).typeCheck).toBe('number');
|
|
461
|
-
}
|
|
462
|
-
});
|
|
463
|
-
|
|
464
|
-
it('parses is object', () => {
|
|
465
|
-
const expr = parseExpr('data is object');
|
|
466
|
-
|
|
467
|
-
expect(expr.type).toBe('IsExpression');
|
|
468
|
-
if (expr.type === 'IsExpression') {
|
|
469
|
-
expect((expr as any).typeCheck).toBe('object');
|
|
470
|
-
}
|
|
471
|
-
});
|
|
472
|
-
|
|
473
|
-
it('parses is boolean', () => {
|
|
474
|
-
const expr = parseExpr('flag is boolean');
|
|
475
|
-
|
|
476
|
-
expect(expr.type).toBe('IsExpression');
|
|
477
|
-
if (expr.type === 'IsExpression') {
|
|
478
|
-
expect((expr as any).typeCheck).toBe('boolean');
|
|
479
|
-
}
|
|
480
|
-
});
|
|
481
|
-
|
|
482
|
-
it('parses is with property access', () => {
|
|
483
|
-
const expr = parseExpr('response.items is array');
|
|
484
|
-
|
|
485
|
-
expect(expr.type).toBe('IsExpression');
|
|
486
|
-
if (expr.type === 'IsExpression') {
|
|
487
|
-
expect((expr as any).operand.type).toBe('QualifiedName');
|
|
488
|
-
expect((expr as any).typeCheck).toBe('array');
|
|
489
|
-
}
|
|
490
|
-
});
|
|
491
|
-
});
|
|
492
|
-
|
|
493
|
-
describe('complex expressions', () => {
|
|
494
|
-
it('parses complex arithmetic with comparisons', () => {
|
|
495
|
-
const expr = parseExpr('(a + b) * 2 > 100');
|
|
496
|
-
|
|
497
|
-
expect(expr.type).toBe('BinaryExpression');
|
|
498
|
-
if (expr.type === 'BinaryExpression') {
|
|
499
|
-
expect(expr.operator).toBe('>');
|
|
500
|
-
}
|
|
501
|
-
});
|
|
502
|
-
|
|
503
|
-
it('parses logical expression with comparisons', () => {
|
|
504
|
-
const expr = parseExpr('x > 0 and x < 100');
|
|
505
|
-
|
|
506
|
-
expect(expr.type).toBe('LogicalExpression');
|
|
507
|
-
if (expr.type === 'LogicalExpression') {
|
|
508
|
-
expect(expr.operator).toBe('and');
|
|
509
|
-
expect(expr.left.type).toBe('BinaryExpression');
|
|
510
|
-
expect(expr.right.type).toBe('BinaryExpression');
|
|
511
|
-
}
|
|
512
|
-
});
|
|
513
|
-
|
|
514
|
-
it('parses ternary with function call', () => {
|
|
515
|
-
const expr = parseExpr('length(items) > 0 ? first(items) : null');
|
|
516
|
-
|
|
517
|
-
expect(expr.type).toBe('TernaryExpression');
|
|
518
|
-
if (expr.type === 'TernaryExpression') {
|
|
519
|
-
expect(expr.condition.type).toBe('BinaryExpression');
|
|
520
|
-
expect(expr.consequent.type).toBe('CallExpression');
|
|
521
|
-
expect(expr.alternate).toMatchObject({ type: 'Literal', value: null });
|
|
522
|
-
}
|
|
523
|
-
});
|
|
524
|
-
});
|
|
525
|
-
});
|