diff --git a/.DS_Store b/.DS_Store index e80b5c16..e1a9c940 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/.cursor/rules/edgev2-leave-edge-untouched.mdc b/.cursor/rules/edgev2-leave-edge-untouched.mdc new file mode 100644 index 00000000..e0b0ed53 --- /dev/null +++ b/.cursor/rules/edgev2-leave-edge-untouched.mdc @@ -0,0 +1,22 @@ +--- +description: When working on edgeV2, never modify the legacy edge/ engine +alwaysApply: true +--- + +# EdgeV2 vs Edge Engine + +When working on **edgeV2**, leave the legacy **edge** engine untouched. + +## Do + +- Implement, fix, and refactor only under `packages/lib/src/engines/edgeV2/` +- Prefer copying or adapting patterns from `edge/` into `edgeV2/` when needed +- Read `edge/` for reference only + +## Do not + +- Edit, delete, or refactor files under `packages/lib/src/engines/edge/` +- "Keep them in sync" by changing both engines +- Fix bugs in `edge/` unless the user explicitly asks to change the legacy engine + +If a change seems to require touching `edge/`, stop and ask first. diff --git a/.ollie/audit.jsonl b/.ollie/audit.jsonl deleted file mode 100644 index 3aadd1fc..00000000 --- a/.ollie/audit.jsonl +++ /dev/null @@ -1,4 +0,0 @@ -{"tool":"run_command","args":{"cwd":"/path/to/your/repo","command":"git log -- packages/lib/src/index.ts"},"result":"confirmed","durationMs":6,"error":"ENOENT: no such file or directory, posix_spawn 'sh'","timestamp":"2026-03-10T03:00:37.484Z","sessionId":"mmk0ufx5-vsp7h0"} -{"tool":"run_command","args":{"command":"echo"},"result":"confirmed","durationMs":15,"output":"{\n \"stdout\": \"\\n\",\n \"stderr\": \"\",\n \"exitCode\": 0\n}","timestamp":"2026-03-10T03:04:27.681Z","sessionId":"mmk1045d-ceglup"} -{"tool":"run_command","args":{"command":"git","args":{"0":"log","1":"--","2":"packages/lib/src/index.ts"}},"result":"confirmed","durationMs":34,"output":"{\n \"stdout\": \"usage: git [-v | --version] [-h | --help] [-C ] [-c =]\\n [--exec-path[=]] [--html-path] [--man-path] [--info-path]\\n [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--no-lazy-fetch]\\n [--no-optional-locks] [--no-advice] [--bare] [--git-dir=]\\n [--work-tree=] [--namespace=] [--config-env==]\\n []\\n\\nThese are common Git commands used in various situations:\\n\\nstart a working area (see also: git help tutorial)\\n clone Clone a repository into a new directory\\n init Create an empty Git repository or reinitialize an existing one\\n\\nwork on the current change (see also: git help everyday)\\n add Add file contents to the index\\n mv Move or rename a file, a directory, or a symlink\\n restore Restore working tree files\\n rm Remove files from the working tree and from the index\\n\\nexamine the history an... [truncated, 1368 more chars]","timestamp":"2026-03-10T03:05:54.802Z","sessionId":"mmk11jf9-0c4bmp"} -{"tool":"run_command","args":{"command":"git log -- packages/lib/src/index.ts","cwd":"/Users/vieira/vieirin/goal-controller"},"result":"confirmed","durationMs":43,"output":"{\n \"stdout\": \"commit [REDACTED]\\nAuthor: Vieira Neto \\nDate: Wed Feb 11 13:04:38 2026 -0300\\n\\n refactor: extract GoalTree into separate package (#6)\\n \\n * refactor: extract GoalTree into separate package\\n \\n - Move GoalTree module from packages/lib to packages/goal-tree\\n - Update imports across the codebase to use the new package\\n - Remove deleted files from lib (creation.ts, dependencyResolver.ts, etc.)\\n - Add goal-tree as workspace dependency\\n - Update sleecTemplateEngine to use new GoalTree package\\n - Fix implicit any type errors in callback functions\\n \\n * update edge properties to live within the type\\n \\n * refactor: move maxRetries to properties.edge for GoalNode and Task consistency\\n \\n - Move maxRetries from GoalNode.properties to GoalNode.properties.edge\\n - Both GoalNode and Task now have maxRetries in properties.edge\\n - Add isGoalNode and isTask type guards to nodeUtils.ts\\n - Expo... [truncated, 9170 more chars]","timestamp":"2026-03-10T03:18:38.699Z","sessionId":"mmk196dc-vzd3yq"} diff --git a/dissertationExamples/dualGoalOrAny.txt b/dissertationExamples/dualGoalOrAny.txt index 7050715a..31c3ca91 100644 --- a/dissertationExamples/dualGoalOrAny.txt +++ b/dissertationExamples/dualGoalOrAny.txt @@ -12,7 +12,7 @@ "nodes": [ { "id": "d201ecf8-634a-425e-8e6e-f59885442511", - "text": "G0: Collect sample [+]", + "text": "G0: Collect sample [T0?T1]", "type": "istar.Goal", "x": 373, "y": 152, diff --git a/dissertationExamples/goalModel TAS 1.txt b/dissertationExamples/goalModel TAS 1.txt index 6764db12..3ebb2713 100644 --- a/dissertationExamples/goalModel TAS 1.txt +++ b/dissertationExamples/goalModel TAS 1.txt @@ -113,7 +113,7 @@ }, { "id": "ef565838-6961-4f79-87eb-b9db1e57c409", - "text": "G10: Administer medicine [+]", + "text": "G10: Administer medicine [G11?G12]", "type": "istar.Goal", "x": 607, "y": 355, @@ -351,7 +351,7 @@ }, { "id": "67c420f7-9c2d-4911-bdc5-bae573c73eb6", - "text": "G2: Track patient location [+]", + "text": "G2: Track patient location [T2?T3]", "type": "istar.Goal", "x": 665, "y": 170, diff --git a/dissertationExamples/goalModel TAS 2.txt b/dissertationExamples/goalModel TAS 2.txt index 506b1f97..954598d9 100644 --- a/dissertationExamples/goalModel TAS 2.txt +++ b/dissertationExamples/goalModel TAS 2.txt @@ -113,7 +113,7 @@ }, { "id": "ef565838-6961-4f79-87eb-b9db1e57c409", - "text": "G10: Administer medicine [+]", + "text": "G10: Administer medicine [G11?G12]", "type": "istar.Goal", "x": 607, "y": 355, @@ -354,7 +354,7 @@ }, { "id": "67c420f7-9c2d-4911-bdc5-bae573c73eb6", - "text": "G2: Track patient location [+]", + "text": "G2: Track patient location [T2?T3]", "type": "istar.Goal", "x": 665, "y": 170, diff --git a/dissertationExamples/goalModel(16).txt b/dissertationExamples/goalModel(16).txt index 043d85b5..aef99031 100644 --- a/dissertationExamples/goalModel(16).txt +++ b/dissertationExamples/goalModel(16).txt @@ -328,7 +328,7 @@ }, { "id": "e1d797d6-5d27-4b65-a6fd-7ce9597c007a", - "text": "G13: Prepare sample [+]", + "text": "G13: Prepare sample [G3?G4]", "type": "istar.Goal", "x": 471, "y": 302, diff --git a/dissertationExamples/goalModelTAS_new.txt b/dissertationExamples/goalModelTAS_new.txt index 75d66996..e8e5b230 100644 --- a/dissertationExamples/goalModelTAS_new.txt +++ b/dissertationExamples/goalModelTAS_new.txt @@ -113,7 +113,7 @@ }, { "id": "ef565838-6961-4f79-87eb-b9db1e57c409", - "text": "G10: Administer medicine [+]", + "text": "G10: Administer medicine [G11?G12]", "type": "istar.Goal", "x": 712, "y": 353, @@ -351,7 +351,7 @@ }, { "id": "67c420f7-9c2d-4911-bdc5-bae573c73eb6", - "text": "G2: Track patient location [+]", + "text": "G2: Track patient location [T2?T3]", "type": "istar.Goal", "x": 771, "y": 168, diff --git a/examples/EDGEV2.txt b/examples/EDGEV2.txt new file mode 100644 index 00000000..7884b1fa --- /dev/null +++ b/examples/EDGEV2.txt @@ -0,0 +1,158 @@ +// edgeV2 PRISM sketch — names aligned to packages/lib/src/engines/edgeV2 +// +// Types (GoalExecutionDetail / Relation): +// relationToChildren: 'and' | 'or' +// executionDetail.type: 'sequence' | 'interleaved' | 'anyOrder' | 'alternative' | 'choice' | 'degradation' +// (also in types but unused here: 'decisionMaking') +// +// Module vars (template/common.ts): +// stateVariable(id) → g_state : [0..1] // 0 not pursued, 1 pursued +// chosenVariable(id) → g_chosen : [0..n] // OR + choice only +// goalFailedVariable(c) → g_failed : [0..N] // degradation + child maxRetries +// +// Decision consts (decisionVariables.ts): +// decisionVariableName(id) → decision_G // every goal +// selectionDecisionVariableName(id) → _decision_G // OR goals + AND anyOrder +// +// Formulas / transitions: +// achieved is a formula (not a module var): g_achieved +// labels: pursue_G, skip_G, achieved_G +// achievability: G_achievable + + +// ─── AND + sequence ───────────────────────────────────────────────────────── +// relationToChildren: 'and' +// executionDetail: { type: 'sequence', sequence: ['G1', 'G2'] } + +module G0 + g0_state : [0..1] init 0; // stateVariable('G0') — 0 not pursued, 1 currently pursued + + [pursue_G0] !g0_achieved & g0_state=0 & GUARD -> (g0_state'=1); // triggering the goal from upper layer + [pursue_G1] !g0_achieved & g0_state=1 & G0_achievable*10.0 > decision_G0 -> true; // decide whether to pursue a child or skip + [pursue_G2] !g0_achieved & g0_state=1 & G0_achievable*10.0 > decision_G0 & g1_achieved -> true; // sequence: G1 must be achieved first + + [skip_G0] !g0_achieved & g0_state=1 & g1_state=0 & g2_state=0 & G0_achievable*10.0 <= decision_G0 -> (g0_state'=0); // skip only when no child is pursued + + [achieved_G0] g0_state=1 & g0_achieved & g1_state=0 & g2_state=0 -> (g0_state'=0); + +endmodule + +formula g0_achieved = (g1_achieved & g2_achieved); + + +// ─── AND any order ────────────────────────────────────────────────────────── +// relationToChildren: 'and' +// executionDetail: { type: 'anyOrder', anyOrder: ['G1', 'G2'] } // notation: [G1+G2] +// decision: decision_G0 + _decision_G0 (child selection among idle siblings) + +module G0 + g0_state : [0..1] init 0; // 0 not pursued, 1 currently pursued + + [pursue_G0] !g0_achieved & g0_state=0 & GUARD -> (g0_state'=1); // triggering the goal from upper layer + [pursue_G1] !g0_achieved & g0_state=1 & G0_achievable*10.0 > decision_G0 & g2_state!=1 & (g2_state=1 | (G1_achievable/(G1_achievable+G2_achievable))*10.0 > _decision_G0) -> true; + [pursue_G2] !g0_achieved & g0_state=1 & G0_achievable*10.0 > decision_G0 & g1_state!=1 & (g1_state=1 | (G1_achievable/(G1_achievable+G2_achievable))*10.0 <= _decision_G0) -> true; + + [skip_G0] !g0_achieved & g0_state=1 & g1_state=0 & g2_state=0 & G0_achievable*10.0 <= decision_G0 -> (g0_state'=0); + + [achieved_G0] g0_state=1 & g0_achieved & g1_state=0 & g2_state=0 -> (g0_state'=0); + +endmodule + +formula g0_achieved = (g1_achieved & g2_achieved); +formula G0_achievable = G1_achievable * G2_achievable; + + +// ─── AND + interleaved ────────────────────────────────────────────────────── +// relationToChildren: 'and' +// executionDetail: { type: 'interleaved', interleaved: ['G1', 'G2'] } + +module G0 + g0_state : [0..1] init 0; // 0 not pursued, 1 currently pursued + + [pursue_G0] !g0_achieved & g0_state=0 & GUARD -> (g0_state'=1); // triggering the goal from upper layer + [pursue_G1] !g0_achieved & g0_state=1 & G1_achievable*10.0 > decision_G1 -> true; + [pursue_G2] !g0_achieved & g0_state=1 & G2_achievable*10.0 > decision_G2 -> true; // skip G0 if neither child should be pursued (avoids pursue-skip livelock) + + [skip_G0] g0_state=1 & g1_state=0 & g2_state=0 & !g0_achieved & !(G2_achievable*10.0 > decision_G2 | G1_achievable*10.0 > decision_G1) -> (g0_state'=0); + + [achieved_G0] g0_state=1 & g0_achieved & g1_state=0 & g2_state=0 -> (g0_state'=0); + +endmodule + +formula g0_achieved = (g1_achieved & g2_achieved); + + +// ─── OR + alternative ─────────────────────────────────────────────────────── +// relationToChildren: 'or' +// executionDetail: { type: 'alternative', alternative: ['G1', 'G2'] } +// decision: decision_G0 + _decision_G0 (OR) + +module G0 + g0_state : [0..1] init 0; // 0 not pursued, 1 currently pursued + + [pursue_G0] !g0_achieved & g0_state=0 & GUARD -> (g0_state'=1); // triggering the goal from upper layer + [pursue_G1] !g0_achieved & g0_state=1 & G0_achievable*10.0 > decision_G0 & g2_state=0 & (G1_achievable/(G1_achievable+G2_achievable))*10.0 > _decision_G0 -> true; + [pursue_G2] !g0_achieved & g0_state=1 & G0_achievable*10.0 > decision_G0 & g1_state=0 & (G1_achievable/(G1_achievable+G2_achievable))*10.0 <= _decision_G0 -> true; + + [skip_G0] !g0_achieved & g0_state=1 & g1_state=0 & g2_state=0 & G0_achievable*10.0 <= decision_G0 -> (g0_state'=0); + + [achieved_G0] g0_state=1 & g1_state=0 & g2_state=0 & g0_achieved -> (g0_state'=0); + +endmodule + +formula g0_achieved = (g1_achieved | g2_achieved); + + +// ─── OR + choice ("choose once") ──────────────────────────────────────────── +// relationToChildren: 'or' +// executionDetail: { type: 'choice' } +// module vars: stateVariable + chosenVariable (n = #pursueable children) + +module G0 + g0_state : [0..1] init 0; // 0 not pursued, 1 currently pursued + g0_chosen : [0..2] init 0; // 0 not chosen, 1 chose G1, 2 chose G2 + + [pursue_G0] !g0_achieved & g0_state=0 & GUARD -> (g0_state'=1); // triggering the goal from upper layer + [pursue_G1] !g0_achieved & g0_state=1 & g0_chosen=0 & G0_achievable*10.0 > decision_G0 & g2_state=0 & (G1_achievable/(G1_achievable+G2_achievable))*10.0 > _decision_G0 -> (g0_chosen'=1); + [pursue_G2] !g0_achieved & g0_state=1 & g0_chosen=0 & G0_achievable*10.0 > decision_G0 & g1_state=0 & (G1_achievable/(G1_achievable+G2_achievable))*10.0 <= _decision_G0 -> (g0_chosen'=2); + + [pursue_G1] !g0_achieved & g0_state=1 & g0_chosen=1 & G1_achievable*10.0 > decision_G1 -> true; + [pursue_G2] !g0_achieved & g0_state=1 & g0_chosen=2 & G2_achievable*10.0 > decision_G2 -> true; + + [skip_G0] !g0_achieved & g0_state=1 & g1_state=0 & g2_state=0 & g0_chosen=0 & G0_achievable*10.0 <= decision_G0 -> (g0_state'=0); + [skip_G0] !g0_achieved & g0_state=1 & g1_state=0 & g0_chosen=1 & G1_achievable*10.0 <= decision_G1 -> (g0_state'=0); // skip when g0_chosen=1 + [skip_G0] !g0_achieved & g0_state=1 & g2_state=0 & g0_chosen=2 & G2_achievable*10.0 <= decision_G2 -> (g0_state'=0); + + [achieved_G0] g0_state=1 & g1_state=0 & g2_state=0 & g0_achieved -> (g0_state'=0); + +endmodule + +formula g0_achieved = (g1_achieved | g2_achieved); + + +// ─── OR + degradation ─────────────────────────────────────────────────────── +// relationToChildren: 'or' +// executionDetail: { type: 'degradation', degradationList: ['G1', 'G2'], retryMap?: { G1: N } } +// module vars: stateVariable + goalFailedVariable(child) for childrenWithMaxRetries +// Note: older sketches used parent g0_failed; codegen uses per-child g1_failed (below). + +module G0 + g0_state : [0..1] init 0; // 0 not pursued, 1 currently pursued + g1_failed : [0..N] init 0; // goalFailedVariable('G1') — retry G1 up to N times + + [pursue_G0] !g0_achieved & g0_state=0 & GUARD -> (g0_state'=1); // triggering the goal from upper layer + + [pursue_G1] !g0_achieved & g0_state=1 & g1_failed decision_G1 -> (g1_failed'=g1_failed+1); // retry G1 up to N + [skip_G0] !g0_achieved & g0_state=1 & g1_state=0 & g1_failed (g0_state'=0); + + [pursue_G1] !g0_achieved & g0_state=1 & g1_failed=N & G0_achievable*10.0 > decision_G0 & g2_state=0 & (G1_achievable/(G1_achievable+G2_achievable))*10.0 > _decision_G0 -> true; + [pursue_G2] !g0_achieved & g0_state=1 & g1_failed=N & G0_achievable*10.0 > decision_G0 & g1_state=0 & (G1_achievable/(G1_achievable+G2_achievable))*10.0 <= _decision_G0 -> true; + + [skip_G0] !g0_achieved & g0_state=1 & g1_state=0 & g1_failed (g0_state'=0); + [skip_G0] !g0_achieved & g0_state=1 & g1_state=0 & g2_state=0 & g1_failed=N & G0_achievable*10.0 <= decision_G0 -> (g0_state'=0); + + [achieved_G0] !g0_achieved & g0_state=1 & g1_state=0 & g2_state=0 & g0_achieved -> (g0_state'=0); + +endmodule + +formula g0_achieved = (g1_achieved | g2_achieved); diff --git a/examples/experiments/10-minimalMaintainResource.txt b/examples/experiments/10-minimalMaintainResource.txt index 97ca1d8c..f22ab3b0 100644 --- a/examples/experiments/10-minimalMaintainResource.txt +++ b/examples/experiments/10-minimalMaintainResource.txt @@ -43,7 +43,7 @@ }, { "id": "ee59bf52-abc8-4d5e-8148-f8cd0ab0d52c", - "text": "G3: Configure Flight Profile [+]", + "text": "G3: Configure Flight Profile [G9?G10?G11]", "type": "istar.Goal", "x": 813, "y": 305, diff --git a/examples/experiments/4-interleavedChoicePDegradation.txt b/examples/experiments/4-interleavedChoicePDegradation.txt index ccd3daaa..c4fc27fe 100644 --- a/examples/experiments/4-interleavedChoicePDegradation.txt +++ b/examples/experiments/4-interleavedChoicePDegradation.txt @@ -32,7 +32,7 @@ }, { "id": "912c8be2-1e4d-4b6a-b45c-9169f9fba033", - "text": "G2: Configure flight [+]", + "text": "G2: Configure flight [G7?G8]", "type": "istar.Goal", "x": 627, "y": 282, diff --git a/examples/experiments/5-allAnnotations.txt b/examples/experiments/5-allAnnotations.txt index 53b93e33..8d1c4824 100644 --- a/examples/experiments/5-allAnnotations.txt +++ b/examples/experiments/5-allAnnotations.txt @@ -62,7 +62,7 @@ }, { "id": "ee59bf52-abc8-4d5e-8148-f8cd0ab0d52c", - "text": "G3: Configure Flight Profile [+]", + "text": "G3: Configure Flight Profile [G9?G10?G11]", "type": "istar.Goal", "x": 813, "y": 304, diff --git a/examples/experiments/6-allnotationsReduced.txt b/examples/experiments/6-allnotationsReduced.txt index e54a51c8..6f1366f6 100644 --- a/examples/experiments/6-allnotationsReduced.txt +++ b/examples/experiments/6-allnotationsReduced.txt @@ -62,7 +62,7 @@ }, { "id": "ee59bf52-abc8-4d5e-8148-f8cd0ab0d52c", - "text": "G3: Configure Flight Profile [+]", + "text": "G3: Configure Flight Profile [G9?G10?G11]", "type": "istar.Goal", "x": 813, "y": 304, diff --git a/examples/experiments/7-minimalAll.txt b/examples/experiments/7-minimalAll.txt index 640efc32..02b85911 100644 --- a/examples/experiments/7-minimalAll.txt +++ b/examples/experiments/7-minimalAll.txt @@ -42,7 +42,7 @@ }, { "id": "ee59bf52-abc8-4d5e-8148-f8cd0ab0d52c", - "text": "G3: Configure Flight Profile [+]", + "text": "G3: Configure Flight Profile [G9?G10?G11]", "type": "istar.Goal", "x": 813, "y": 304, diff --git a/examples/experiments/8-minimalMaintain.txt b/examples/experiments/8-minimalMaintain.txt index b287e182..1a41b262 100644 --- a/examples/experiments/8-minimalMaintain.txt +++ b/examples/experiments/8-minimalMaintain.txt @@ -42,7 +42,7 @@ }, { "id": "ee59bf52-abc8-4d5e-8148-f8cd0ab0d52c", - "text": "G3: Configure Flight Profile [+]", + "text": "G3: Configure Flight Profile [G9?G10?G11]", "type": "istar.Goal", "x": 813, "y": 305, diff --git a/examples/experiments/9-minimalMaintainContext copy.txt b/examples/experiments/9-minimalMaintainContext copy.txt index 1d3bb889..2130f440 100644 --- a/examples/experiments/9-minimalMaintainContext copy.txt +++ b/examples/experiments/9-minimalMaintainContext copy.txt @@ -42,7 +42,7 @@ }, { "id": "ee59bf52-abc8-4d5e-8148-f8cd0ab0d52c", - "text": "G3: Configure Flight Profile [+]", + "text": "G3: Configure Flight Profile [G9?G10?G11]", "type": "istar.Goal", "x": 813, "y": 305, diff --git a/examples/experiments/9-minimalMaintainContext.txt b/examples/experiments/9-minimalMaintainContext.txt index 9eeef509..6cef91b3 100644 --- a/examples/experiments/9-minimalMaintainContext.txt +++ b/examples/experiments/9-minimalMaintainContext.txt @@ -43,7 +43,7 @@ }, { "id": "ee59bf52-abc8-4d5e-8148-f8cd0ab0d52c", - "text": "G3: Configure Flight Profile [+]", + "text": "G3: Configure Flight Profile [G9?G10?G11]", "type": "istar.Goal", "x": 813, "y": 305, diff --git a/examples/experiments/goalModel_TAS_3.txt b/examples/experiments/goalModel_TAS_3.txt index 0bda989c..8552bfca 100644 --- a/examples/experiments/goalModel_TAS_3.txt +++ b/examples/experiments/goalModel_TAS_3.txt @@ -103,7 +103,7 @@ }, { "id": "1300f48c-890f-41f9-9d53-faf08becfcce", - "text": "G11: Analyse data [+]", + "text": "G11: Analyse data [G14?G15]", "type": "istar.Goal", "x": 411, "y": 355, @@ -113,7 +113,7 @@ }, { "id": "ef565838-6961-4f79-87eb-b9db1e57c409", - "text": "G12: Administer medicine [G16|G17]", + "text": "G12: Administer medicine [G16?G17]", "type": "istar.Goal", "x": 605, "y": 355, @@ -201,7 +201,7 @@ }, { "id": "c6de8c50-a3a9-4dbd-b9c1-e2c8315ae1f6", - "text": "G19: Trigger Alarm Service [+]", + "text": "G19: Trigger Alarm Service [G20?G21]", "type": "istar.Goal", "x": 1037, "y": 345, diff --git a/examples/experiments/labSamplesWithSideEffect.txt b/examples/experiments/labSamplesWithSideEffect.txt index 93f28ad0..2a704472 100644 --- a/examples/experiments/labSamplesWithSideEffect.txt +++ b/examples/experiments/labSamplesWithSideEffect.txt @@ -303,7 +303,7 @@ }, { "id": "e1d797d6-5d27-4b65-a6fd-7ce9597c007a", - "text": "G13: Prepare sample [+]", + "text": "G13: Prepare sample [G3?G4]", "type": "istar.Goal", "x": 470, "y": 302, diff --git a/examples/experiments/props/10-minimalMaintainResource.props b/examples/experiments/props/10-minimalMaintainResource.props index eb4d587a..45d1805f 100644 --- a/examples/experiments/props/10-minimalMaintainResource.props +++ b/examples/experiments/props/10-minimalMaintainResource.props @@ -89,7 +89,7 @@ P>=1 [ G (G2_achieved=1 => G6_achieved=1) ]; // ====================================================== -// Choice semantics for G3: Configure Flight Profile [+] +// Choice semantics for G3: Configure Flight Profile [G9?G10?G11] // Branches: G9, G10, G11 with battery-dependent guards on R0 // ====================================================== diff --git a/examples/experiments/props/4-interleavedChoicePDegradation.props b/examples/experiments/props/4-interleavedChoicePDegradation.props index 3b9dcf72..7f8d0b0f 100644 --- a/examples/experiments/props/4-interleavedChoicePDegradation.props +++ b/examples/experiments/props/4-interleavedChoicePDegradation.props @@ -1,5 +1,5 @@ // ====================================================== -// CHOICE OR (+) — G2: Configure flight [+] +// CHOICE OR (?) — G2: Configure flight [G7?G8] // Children: G7 (Standard Mode) and G8 (High-Priority) // Encoding: G2_chosen ∈ {0,1,2}, set by pursue_G7 / pursue_G8 // ====================================================== @@ -114,7 +114,7 @@ P>=1 [ G ( (G1_achieved=1) => (G5_achieved=1 & G6_achieved=1) ) ]; -// G2 — Choice OR [+] (already partly covered above): +// G2 — Choice OR [G7?G8] (already partly covered above): // When G2 completes, exactly one branch has been achieved. // (Given the model, “at most one” + “at least one” gives exactly one.) P>=1 [ diff --git a/examples/experiments/props/6-allnotationsReduced.props b/examples/experiments/props/6-allnotationsReduced.props index e3be98ba..39a383b7 100644 --- a/examples/experiments/props/6-allnotationsReduced.props +++ b/examples/experiments/props/6-allnotationsReduced.props @@ -52,7 +52,7 @@ P>0 [ F ( G2_pursued=1 & G8_pursued=1 & G7_pursued=0 ) ]; // ============================== -// G3 – choice OR [+], non-idempotent +// G3 – choice OR [?], non-idempotent // ============================== // Each profile is selectable diff --git a/examples/experiments/props/7-minimalAll.props b/examples/experiments/props/7-minimalAll.props index f25f02ce..6f6356f1 100644 --- a/examples/experiments/props/7-minimalAll.props +++ b/examples/experiments/props/7-minimalAll.props @@ -71,7 +71,7 @@ P>=1 [ G ( ((T11_pursued=1 | T11_achieved=1) P>=1 [ G ( G14_achieved=1 => (T10_achieved=1 & T11_achieved=1) ) ]; // ===================================================================== -// Choice OR : G3: Configure Flight Profile [+] +// Choice OR : G3: Configure Flight Profile [G9?G10?G11] // (G9, G10, G11) are mutually exclusive, with a sticky choice via G3_chosen. // ===================================================================== diff --git a/examples/experiments/props/8-minimalMaintain.props b/examples/experiments/props/8-minimalMaintain.props index 531f652e..42977a27 100644 --- a/examples/experiments/props/8-minimalMaintain.props +++ b/examples/experiments/props/8-minimalMaintain.props @@ -78,7 +78,7 @@ P>0 [ F (G2_pursued=1 & G7_pursued=1) ]; // ====================================================== -// Choice semantics for G3: Configure Flight Profile [+] +// Choice semantics for G3: Configure Flight Profile [G9?G10?G11] // Branches: G9, G10, G11 // ====================================================== diff --git a/examples/experiments/props/9-minimalMaintainContext.props b/examples/experiments/props/9-minimalMaintainContext.props index c87c0df6..2bc37798 100644 --- a/examples/experiments/props/9-minimalMaintainContext.props +++ b/examples/experiments/props/9-minimalMaintainContext.props @@ -63,7 +63,7 @@ P>0 [ F (G2_pursued=1 & G7_pursued=1 & G6_pursued=0) ]; // ====================================================== // 3. Choice semantics -// - G3: [+] over G9, G10, G11 +// - G3: [G9?G10?G11] over G9, G10, G11 // ====================================================== // At most one of G9, G10, G11 can be pursued at a time diff --git a/examples/experiments/props/goalModel_TAS_3.props b/examples/experiments/props/goalModel_TAS_3.props index 22cce946..769b8896 100644 --- a/examples/experiments/props/goalModel_TAS_3.props +++ b/examples/experiments/props/goalModel_TAS_3.props @@ -148,7 +148,7 @@ P>=1 [ G ( G9_achieved=1 // --------------------------------------------------------------------- -// Choice OR: G11: Analyse data [+] with branches G14 (remote) / G15 (local) +// Choice OR: G11: Analyse data [G14?G15] with branches G14 (remote) / G15 (local) // - Mutually exclusive, sticky choice via G11_chosen. // --------------------------------------------------------------------- @@ -167,7 +167,7 @@ P>=1 [ G ( (G11_pursued=1 & G11_achieved=0 & G11_chosen=2) // --------------------------------------------------------------------- -// Choice OR: G19: Trigger Alarm Service [+] with G20/G21 +// Choice OR: G19: Trigger Alarm Service [G20?G21] with G20/G21 // - Mutually exclusive alarm modes with sticky choice via G19_chosen. // --------------------------------------------------------------------- diff --git a/examples/goalModel_TAS_3_.expected.txt b/examples/goalModel_TAS_3_.expected.txt new file mode 100644 index 00000000..160c6379 --- /dev/null +++ b/examples/goalModel_TAS_3_.expected.txt @@ -0,0 +1,484 @@ +// EDGEV2 expected output for goalModel_TAS_3_.txt +// Generated 2026-07-11 following patterns from EDGEV2.txt +// +// Legend: +// [S] = sequence, [I] = interleaved, [A] = alternative, [C] = choice, [D] = degradation +// assertions shown as GUARD_; maintain formulas inline + + +dtmc + +// ─── Decision variables ───────────────────────────────────────────────────── +// Every goal gets decision_G; OR goals also get _decision_G +const int decision_G0; +const int decision_G1; +const int _decision_G1; +const int decision_G2; +const int _decision_G2; +const int decision_G3; +const int decision_G4; +const int decision_G5; +const int decision_G6; +const int decision_G7; +const int decision_G8; +const int decision_G9; +const int decision_G10; +const int decision_G11; +const int _decision_G11; +const int decision_G12; +const int _decision_G12; +const int decision_G13; +const int decision_G14; +const int decision_G15; +const int decision_G16; +const int decision_G17; +const int decision_G18; +const int decision_G19; +const int _decision_G19; +const int decision_G20; +const int decision_G21; + + +// ═══════════════════════════════════════════════════════════════════════════════ +// G0: Provide Health Support (AND + sequence [G1;G2]) +// ═══════════════════════════════════════════════════════════════════════════════ +module G0 + g0_state : [0..1] init 0; + + [pursue_G0] !g0_achieved & g0_state=0 -> (g0_state'=1); + [pursue_G1] !g0_achieved & g0_state=1 & G0_achievable*10.0 > decision_G0 -> true; + [pursue_G2] !g0_achieved & g0_state=1 & G0_achievable*10.0 > decision_G0 & g1_achieved -> true; + + [skip_G0] !g0_achieved & g0_state=1 & g1_state=0 & g2_state=0 -> (g0_state'=0); + + [achieved_G0] g0_state=1 & g0_achieved & g1_state=0 & g2_state=0 -> (g0_state'=0); + +endmodule + +formula g0_achieved = (g1_achieved & g2_achieved); +formula G0_achievable = G1_achievable * G2_achievable; + + +// ═══════════════════════════════════════════════════════════════════════════════ +// G1: Support in emergency (OR + degradation [G4@2->G3]) +// ═══════════════════════════════════════════════════════════════════════════════ +module G1 + g1_state : [0..1] init 0; + g4_failed : [0..2] init 0; // retry G4 up to 2 times before falling back to G3 + + [pursue_G1] !g1_achieved & g1_state=0 -> (g1_state'=1); + + // ── Retry G4 ── + [pursue_G4] !g1_achieved & g1_state=1 & g4_failed<2 & G4_achievable*10.0 > decision_G4 -> (g4_failed'=g4_failed+1); + + // ── Fallback: G4 exhausted → try G3 ── + [pursue_G4] !g1_achieved & g1_state=1 & g4_failed=2 & G1_achievable*10.0 > decision_G1 & g3_state=0 & (G4_achievable/(G4_achievable+G3_achievable))*10.0 > _decision_G1 -> true; + [pursue_G3] !g1_achieved & g1_state=1 & g4_failed=2 & G1_achievable*10.0 > decision_G1 & g4_state=0 & (G4_achievable/(G4_achievable+G3_achievable))*10.0 <= _decision_G1 -> true; + + // ── Skip ── + [skip_G1] !g1_achieved & g1_state=1 & g4_state=0 & g3_state=0 -> (g1_state'=0); + + [achieved_G1] g1_state=1 & g1_achieved & g4_state=0 & g3_state=0 -> (g1_state'=0); + +endmodule + +formula g1_achieved = (g4_achieved | g3_achieved); +formula G1_achievable = G4_achievable + G3_achievable - (G4_achievable * G3_achievable); + + +// ═══════════════════════════════════════════════════════════════════════════════ +// G2: Track patient location (maintain, OR + alternative [G5|G6]) +// ═══════════════════════════════════════════════════════════════════════════════ +module G2 + g2_state : [0..1] init 0; + + [pursue_G2] !g2_achieved & g2_state=0 & patientTracking -> (g2_state'=1); + [pursue_G5] !g2_achieved & g2_state=1 & G2_achievable*10.0 > decision_G2 & g6_state=0 & (G5_achievable/(G5_achievable+G6_achievable))*10.0 > _decision_G2 -> true; + [pursue_G6] !g2_achieved & g2_state=1 & G2_achievable*10.0 > decision_G2 & g5_state=0 & (G5_achievable/(G5_achievable+G6_achievable))*10.0 <= _decision_G2 -> true; + + [skip_G2] !g2_achieved & g2_state=1 & g5_state=0 & g6_state=0 -> (g2_state'=0); + + [achieved_G2] g2_state=1 & g2_achieved & g5_state=0 & g6_state=0 -> (g2_state'=0); + +endmodule + +formula g2_achieved = highPrecision; +formula G2_achievable = G5_achievable + G6_achievable - (G5_achievable * G6_achievable); + + +// ═══════════════════════════════════════════════════════════════════════════════ +// G3: Self-diagnosed emergency support service (AND) +// ═══════════════════════════════════════════════════════════════════════════════ +module G3 + g3_state : [0..1] init 0; + + [pursue_G3] !g3_achieved & g3_state=0 & privacyEnabled -> (g3_state'=1); + [pursue_G7] !g3_achieved & g3_state=1 & G3_achievable*10.0 > decision_G3 -> true; + + [skip_G3] !g3_achieved & g3_state=1 & g7_state=0 -> (g3_state'=0); + + [achieved_G3] g3_state=1 & g3_achieved & g7_state=0 -> (g3_state'=0); + +endmodule + +formula g3_achieved = g7_achieved; +formula G3_achievable = G7_achievable; + + +// ═══════════════════════════════════════════════════════════════════════════════ +// G4: Automated life support service (maintain, AND + sequence [G8;G9]) +// ═══════════════════════════════════════════════════════════════════════════════ +module G4 + g4_state : [0..1] init 0; + + [pursue_G4] !g4_achieved & g4_state=0 & (enoughBattery & highReliability) -> (g4_state'=1); + [pursue_G8] !g4_achieved & g4_state=1 & G4_achievable*10.0 > decision_G4 -> true; + [pursue_G9] !g4_achieved & g4_state=1 & G4_achievable*10.0 > decision_G4 & g8_achieved -> true; + + [skip_G4] !g4_achieved & g4_state=1 & g8_state=0 & g9_state=0 -> (g4_state'=0); + + [achieved_G4] g4_state=1 & g4_achieved & g8_state=0 & g9_state=0 -> (g4_state'=0); + +endmodule + +formula g4_achieved = inEmergency; +formula G4_achievable = G8_achievable * G9_achievable; + + +// ═══════════════════════════════════════════════════════════════════════════════ +// G5: Manual Tracking (AND) +// ═══════════════════════════════════════════════════════════════════════════════ +module G5 + g5_state : [0..1] init 0; + + [pursue_G5] !g5_achieved & g5_state=0 & privacyEnabled -> (g5_state'=1); + [pursue_T2] !g5_achieved & g5_state=1 & G5_achievable*10.0 > decision_G5 -> true; + + [skip_G5] !g5_achieved & g5_state=1 & T2_pursued=0 -> (g5_state'=0); + + [achieved_G5] g5_state=1 & g5_achieved & T2_pursued=0 -> (g5_state'=0); + +endmodule + +formula g5_achieved = T2_achieved; +formula G5_achievable = T2_achievable; + + +// ═══════════════════════════════════════════════════════════════════════════════ +// G6: Automatic Tracking (AND) +// ═══════════════════════════════════════════════════════════════════════════════ +module G6 + g6_state : [0..1] init 0; + + [pursue_G6] !g6_achieved & g6_state=0 & !privacyEnabled -> (g6_state'=1); + [pursue_T3] !g6_achieved & g6_state=1 & G6_achievable*10.0 > decision_G6 -> true; + + [skip_G6] !g6_achieved & g6_state=1 & T3_pursued=0 -> (g6_state'=0); + + [achieved_G6] g6_state=1 & g6_achieved & T3_pursued=0 -> (g6_state'=0); + +endmodule + +formula g6_achieved = T3_achieved; +formula G6_achievable = T3_achievable; + + +// ═══════════════════════════════════════════════════════════════════════════════ +// G7: Allow push button (AND) +// ═══════════════════════════════════════════════════════════════════════════════ +module G7 + g7_state : [0..1] init 0; + + [pursue_G7] !g7_achieved & g7_state=0 -> (g7_state'=1); + [pursue_T1] !g7_achieved & g7_state=1 & G7_achievable*10.0 > decision_G7 -> true; + + [skip_G7] !g7_achieved & g7_state=1 & T1_pursued=0 -> (g7_state'=0); + + [achieved_G7] g7_state=1 & g7_achieved & T1_pursued=0 -> (g7_state'=0); + +endmodule + +formula g7_achieved = T1_achieved; +formula G7_achievable = T1_achievable; + + +// ═══════════════════════════════════════════════════════════════════════════════ +// G8: Detect patient's health status (maintain, AND + sequence [G10;G11]) +// ═══════════════════════════════════════════════════════════════════════════════ +module G8 + g8_state : [0..1] init 0; + + [pursue_G8] !g8_achieved & g8_state=0 & sensorAvailable -> (g8_state'=1); + [pursue_G10] !g8_achieved & g8_state=1 & G8_achievable*10.0 > decision_G8 -> true; + [pursue_G11] !g8_achieved & g8_state=1 & G8_achievable*10.0 > decision_G8 & g10_achieved -> true; + + [skip_G8] !g8_achieved & g8_state=1 & g10_state=0 & g11_state=0 -> (g8_state'=0); + + [achieved_G8] g8_state=1 & g8_achieved & g10_state=0 & g11_state=0 -> (g8_state'=0); + +endmodule + +formula g8_achieved = (enoughBattery & highReliability); +formula G8_achievable = G10_achievable * G11_achievable; + + +// ═══════════════════════════════════════════════════════════════════════════════ +// G9: Enact treatment (AND + sequence [G12;G13]) +// ═══════════════════════════════════════════════════════════════════════════════ +module G9 + g9_state : [0..1] init 0; + + [pursue_G9] !g9_achieved & g9_state=0 -> (g9_state'=1); + [pursue_G12] !g9_achieved & g9_state=1 & G9_achievable*10.0 > decision_G9 -> true; + [pursue_G13] !g9_achieved & g9_state=1 & G9_achievable*10.0 > decision_G9 & g12_achieved -> true; + + [skip_G9] !g9_achieved & g9_state=1 & g12_state=0 & g13_state=0 -> (g9_state'=0); + + [achieved_G9] g9_state=1 & g9_achieved & g12_state=0 & g13_state=0 -> (g9_state'=0); + +endmodule + +formula g9_achieved = (g12_achieved & g13_achieved); +formula G9_achievable = G12_achievable * G13_achievable; + + +// ═══════════════════════════════════════════════════════════════════════════════ +// G10: Read vital signs (AND) +// ═══════════════════════════════════════════════════════════════════════════════ +module G10 + g10_state : [0..1] init 0; + + [pursue_G10] !g10_achieved & g10_state=0 -> (g10_state'=1); + [pursue_T4] !g10_achieved & g10_state=1 & G10_achievable*10.0 > decision_G10 -> true; + + [skip_G10] !g10_achieved & g10_state=1 & T4_pursued=0 -> (g10_state'=0); + + [achieved_G10] g10_state=1 & g10_achieved & T4_pursued=0 -> (g10_state'=0); + +endmodule + +formula g10_achieved = T4_achieved; +formula G10_achievable = T4_achievable; + + +// ═══════════════════════════════════════════════════════════════════════════════ +// G11: Analyse data (OR + alternative [G14|G15]) +// ═══════════════════════════════════════════════════════════════════════════════ +module G11 + g11_state : [0..1] init 0; + + [pursue_G11] !g11_achieved & g11_state=0 -> (g11_state'=1); + [pursue_G14] !g11_achieved & g11_state=1 & G11_achievable*10.0 > decision_G11 & g15_state=0 & (G14_achievable/(G14_achievable+G15_achievable))*10.0 > _decision_G11 -> true; + [pursue_G15] !g11_achieved & g11_state=1 & G11_achievable*10.0 > decision_G11 & g14_state=0 & (G14_achievable/(G14_achievable+G15_achievable))*10.0 <= _decision_G11 -> true; + + [skip_G11] !g11_achieved & g11_state=1 & g14_state=0 & g15_state=0 -> (g11_state'=0); + + [achieved_G11] g11_state=1 & g11_achieved & g14_state=0 & g15_state=0 -> (g11_state'=0); + +endmodule + +formula g11_achieved = (g14_achieved | g15_achieved); +formula G11_achievable = G14_achievable + G15_achievable - (G14_achievable * G15_achievable); + + +// ═══════════════════════════════════════════════════════════════════════════════ +// G12: Administer medicine (OR + choice [G16?G17]) +// ═══════════════════════════════════════════════════════════════════════════════ +module G12 + g12_state : [0..1] init 0; + g12_chosen : [0..2] init 0; // 0 not chosen, 1→G16, 2→G17 + + [pursue_G12] !g12_achieved & g12_state=0 & (pharmacyAvailable & atHome) -> (g12_state'=1); + + // ── Choose once ── + [pursue_G16] !g12_achieved & g12_state=1 & g12_chosen=0 & G12_achievable*10.0 > decision_G12 & g17_state=0 & (G16_achievable/(G16_achievable+G17_achievable))*10.0 > _decision_G12 -> (g12_chosen'=1); + [pursue_G17] !g12_achieved & g12_state=1 & g12_chosen=0 & G12_achievable*10.0 > decision_G12 & g16_state=0 & (G16_achievable/(G16_achievable+G17_achievable))*10.0 <= _decision_G12 -> (g12_chosen'=2); + + // ── Continue chosen ── + [pursue_G16] !g12_achieved & g12_state=1 & g12_chosen=1 & G16_achievable*10.0 > decision_G16 -> true; + [pursue_G17] !g12_achieved & g12_state=1 & g12_chosen=2 & G17_achievable*10.0 > decision_G17 -> true; + + // ── Skip ── + [skip_G12] !g12_achieved & g12_state=1 & g16_state=0 & g17_state=0 & g12_chosen=0 -> (g12_state'=0); + [skip_G12] !g12_achieved & g12_state=1 & g16_state=0 & g12_chosen=1 -> (g12_state'=0); + [skip_G12] !g12_achieved & g12_state=1 & g17_state=0 & g12_chosen=2 -> (g12_state'=0); + + [achieved_G12] g12_state=1 & g12_achieved & g16_state=0 & g17_state=0 -> (g12_state'=0); + +endmodule + +formula g12_achieved = (g16_achieved | g17_achieved); +formula G12_achievable = G16_achievable + G17_achievable - (G16_achievable * G17_achievable); + + +// ═══════════════════════════════════════════════════════════════════════════════ +// G13: Analyse side effect (AND + sequence [G18;G19]) +// ═══════════════════════════════════════════════════════════════════════════════ +module G13 + g13_state : [0..1] init 0; + + [pursue_G13] !g13_achieved & g13_state=0 -> (g13_state'=1); + [pursue_G18] !g13_achieved & g13_state=1 & G13_achievable*10.0 > decision_G13 -> true; + [pursue_G19] !g13_achieved & g13_state=1 & G13_achievable*10.0 > decision_G13 & g18_achieved -> true; + + [skip_G13] !g13_achieved & g13_state=1 & g18_state=0 & g19_state=0 -> (g13_state'=0); + + [achieved_G13] g13_state=1 & g13_achieved & g18_state=0 & g19_state=0 -> (g13_state'=0); + +endmodule + +formula g13_achieved = (g18_achieved & g19_achieved); +formula G13_achievable = G18_achievable * G19_achievable; + + +// ═══════════════════════════════════════════════════════════════════════════════ +// G14: Remote analysis (AND) +// ═══════════════════════════════════════════════════════════════════════════════ +module G14 + g14_state : [0..1] init 0; + + [pursue_G14] !g14_achieved & g14_state=0 -> (g14_state'=1); + [pursue_T5] !g14_achieved & g14_state=1 & G14_achievable*10.0 > decision_G14 -> true; + + [skip_G14] !g14_achieved & g14_state=1 & T5_pursued=0 -> (g14_state'=0); + + [achieved_G14] g14_state=1 & g14_achieved & T5_pursued=0 -> (g14_state'=0); + +endmodule + +formula g14_achieved = T5_achieved; +formula G14_achievable = T5_achievable; + + +// ═══════════════════════════════════════════════════════════════════════════════ +// G15: Local analysis (AND) +// ═══════════════════════════════════════════════════════════════════════════════ +module G15 + g15_state : [0..1] init 0; + + [pursue_G15] !g15_achieved & g15_state=0 -> (g15_state'=1); + [pursue_T6] !g15_achieved & g15_state=1 & G15_achievable*10.0 > decision_G15 -> true; + + [skip_G15] !g15_achieved & g15_state=1 & T6_pursued=0 -> (g15_state'=0); + + [achieved_G15] g15_state=1 & g15_achieved & T6_pursued=0 -> (g15_state'=0); + +endmodule + +formula g15_achieved = T6_achieved; +formula G15_achievable = T6_achievable; + + +// ═══════════════════════════════════════════════════════════════════════════════ +// G16: Change drug (AND) +// ═══════════════════════════════════════════════════════════════════════════════ +module G16 + g16_state : [0..1] init 0; + + [pursue_G16] !g16_achieved & g16_state=0 -> (g16_state'=1); + [pursue_T7] !g16_achieved & g16_state=1 & G16_achievable*10.0 > decision_G16 -> true; + + [skip_G16] !g16_achieved & g16_state=1 & T7_pursued=0 -> (g16_state'=0); + + [achieved_G16] g16_state=1 & g16_achieved & T7_pursued=0 -> (g16_state'=0); + +endmodule + +formula g16_achieved = T7_achieved; +formula G16_achievable = T7_achievable; + + +// ═══════════════════════════════════════════════════════════════════════════════ +// G17: Change dose (AND) +// ═══════════════════════════════════════════════════════════════════════════════ +module G17 + g17_state : [0..1] init 0; + + [pursue_G17] !g17_achieved & g17_state=0 -> (g17_state'=1); + [pursue_T8] !g17_achieved & g17_state=1 & G17_achievable*10.0 > decision_G17 -> true; + + [skip_G17] !g17_achieved & g17_state=1 & T8_pursued=0 -> (g17_state'=0); + + [achieved_G17] g17_state=1 & g17_achieved & T8_pursued=0 -> (g17_state'=0); + +endmodule + +formula g17_achieved = T8_achieved; +formula G17_achievable = T8_achievable; + + +// ═══════════════════════════════════════════════════════════════════════════════ +// G18: Monitor side effects (maintain, AND) +// ═══════════════════════════════════════════════════════════════════════════════ +module G18 + g18_state : [0..1] init 0; + + [pursue_G18] !g18_achieved & g18_state=0 & medicationApplied -> (g18_state'=1); + [pursue_T9] !g18_achieved & g18_state=1 & G18_achievable*10.0 > decision_G18 -> true; + + [skip_G18] !g18_achieved & g18_state=1 & T9_pursued=0 -> (g18_state'=0); + + [achieved_G18] g18_state=1 & g18_achieved & T9_pursued=0 -> (g18_state'=0); + +endmodule + +formula g18_achieved = inSideEffectWindow; +formula G18_achievable = T9_achievable; + + +// ═══════════════════════════════════════════════════════════════════════════════ +// G19: Trigger Alarm Service (OR + alternative [G20|G21]) +// ═══════════════════════════════════════════════════════════════════════════════ +module G19 + g19_state : [0..1] init 0; + + [pursue_G19] !g19_achieved & g19_state=0 & inEmergency -> (g19_state'=1); + [pursue_G20] !g19_achieved & g19_state=1 & G19_achievable*10.0 > decision_G19 & g21_state=0 & (G20_achievable/(G20_achievable+G21_achievable))*10.0 > _decision_G19 -> true; + [pursue_G21] !g19_achieved & g19_state=1 & G19_achievable*10.0 > decision_G19 & g20_state=0 & (G20_achievable/(G20_achievable+G21_achievable))*10.0 <= _decision_G19 -> true; + + [skip_G19] !g19_achieved & g19_state=1 & g20_state=0 & g21_state=0 -> (g19_state'=0); + + [achieved_G19] g19_state=1 & g19_achieved & g20_state=0 & g21_state=0 -> (g19_state'=0); + +endmodule + +formula g19_achieved = (g20_achieved | g21_achieved); +formula G19_achievable = G20_achievable + G21_achievable - (G20_achievable * G21_achievable); + + +// ═══════════════════════════════════════════════════════════════════════════════ +// G20: Trigger SMS Service (AND) +// ═══════════════════════════════════════════════════════════════════════════════ +module G20 + g20_state : [0..1] init 0; + + [pursue_G20] !g20_achieved & g20_state=0 -> (g20_state'=1); + [pursue_T10] !g20_achieved & g20_state=1 & G20_achievable*10.0 > decision_G20 -> true; + + [skip_G20] !g20_achieved & g20_state=1 & T10_pursued=0 -> (g20_state'=0); + + [achieved_G20] g20_state=1 & g20_achieved & T10_pursued=0 -> (g20_state'=0); + +endmodule + +formula g20_achieved = T10_achieved; +formula G20_achievable = T10_achievable; + + +// ═══════════════════════════════════════════════════════════════════════════════ +// G21: Trigger alarm service (AND) +// ═══════════════════════════════════════════════════════════════════════════════ +module G21 + g21_state : [0..1] init 0; + + [pursue_G21] !g21_achieved & g21_state=0 & networkAvailable -> (g21_state'=1); + [pursue_T11] !g21_achieved & g21_state=1 & G21_achievable*10.0 > decision_G21 -> true; + + [skip_G21] !g21_achieved & g21_state=1 & T11_pursued=0 -> (g21_state'=0); + + [achieved_G21] g21_state=1 & g21_achieved & T11_pursued=0 -> (g21_state'=0); + +endmodule + +formula g21_achieved = T11_achieved; +formula G21_achievable = T11_achievable; diff --git a/examples/goalModel_TAS_3_.txt b/examples/goalModel_TAS_3_.txt index 0bda989c..8552bfca 100644 --- a/examples/goalModel_TAS_3_.txt +++ b/examples/goalModel_TAS_3_.txt @@ -103,7 +103,7 @@ }, { "id": "1300f48c-890f-41f9-9d53-faf08becfcce", - "text": "G11: Analyse data [+]", + "text": "G11: Analyse data [G14?G15]", "type": "istar.Goal", "x": 411, "y": 355, @@ -113,7 +113,7 @@ }, { "id": "ef565838-6961-4f79-87eb-b9db1e57c409", - "text": "G12: Administer medicine [G16|G17]", + "text": "G12: Administer medicine [G16?G17]", "type": "istar.Goal", "x": 605, "y": 355, @@ -201,7 +201,7 @@ }, { "id": "c6de8c50-a3a9-4dbd-b9c1-e2c8315ae1f6", - "text": "G19: Trigger Alarm Service [+]", + "text": "G19: Trigger Alarm Service [G20?G21]", "type": "istar.Goal", "x": 1037, "y": 345, diff --git a/examples/labSamplesWithSideEffect_.txt b/examples/labSamplesWithSideEffect_.txt index 93f28ad0..2a704472 100644 --- a/examples/labSamplesWithSideEffect_.txt +++ b/examples/labSamplesWithSideEffect_.txt @@ -303,7 +303,7 @@ }, { "id": "e1d797d6-5d27-4b65-a6fd-7ce9597c007a", - "text": "G13: Prepare sample [+]", + "text": "G13: Prepare sample [G3?G4]", "type": "istar.Goal", "x": 470, "y": 302, diff --git a/examples/props/goalModel_TAS_3.props b/examples/props/goalModel_TAS_3.props index 22cce946..769b8896 100644 --- a/examples/props/goalModel_TAS_3.props +++ b/examples/props/goalModel_TAS_3.props @@ -148,7 +148,7 @@ P>=1 [ G ( G9_achieved=1 // --------------------------------------------------------------------- -// Choice OR: G11: Analyse data [+] with branches G14 (remote) / G15 (local) +// Choice OR: G11: Analyse data [G14?G15] with branches G14 (remote) / G15 (local) // - Mutually exclusive, sticky choice via G11_chosen. // --------------------------------------------------------------------- @@ -167,7 +167,7 @@ P>=1 [ G ( (G11_pursued=1 & G11_achieved=0 & G11_chosen=2) // --------------------------------------------------------------------- -// Choice OR: G19: Trigger Alarm Service [+] with G20/G21 +// Choice OR: G19: Trigger Alarm Service [G20?G21] with G20/G21 // - Mutually exclusive alarm modes with sticky choice via G19_chosen. // --------------------------------------------------------------------- diff --git a/examples/simpleChoice.txt b/examples/simpleChoice.txt index d4f5b925..55bafa33 100644 --- a/examples/simpleChoice.txt +++ b/examples/simpleChoice.txt @@ -12,7 +12,7 @@ "nodes": [ { "id": "117b97d7-775b-41a9-8fec-9e923edde772", - "text": "G1: Goal [+]", + "text": "G1: Goal [G2?G3]", "type": "istar.Goal", "x": 311, "y": 205, diff --git a/packages/goal-tree/src/antlr/RTRegexLexer.ts b/packages/goal-tree/src/antlr/RTRegexLexer.ts index df27ffe5..d015b90c 100644 --- a/packages/goal-tree/src/antlr/RTRegexLexer.ts +++ b/packages/goal-tree/src/antlr/RTRegexLexer.ts @@ -1,216 +1,138 @@ -// Generated from grammar/RTRegex.g4 by ANTLR 4.13.2 +// Generated from RTRegex.g4 by ANTLR 4.13.2 // noinspection ES6UnusedImports,JSUnusedGlobalSymbols,JSUnusedLocalSymbols import { - ATN, - ATNDeserializer, - CharStream, - DecisionState, - DFA, - Lexer, - LexerATNSimulator, - RuleContext, - PredictionContextCache, - Token, -} from 'antlr4'; + ATN, + ATNDeserializer, + CharStream, + DecisionState, DFA, + Lexer, + LexerATNSimulator, + RuleContext, + PredictionContextCache, + Token +} from "antlr4"; export default class RTRegexLexer extends Lexer { - public static readonly T__0 = 1; - public static readonly T__1 = 2; - public static readonly T__2 = 3; - public static readonly T__3 = 4; - public static readonly T__4 = 5; - public static readonly T__5 = 6; - public static readonly T__6 = 7; - public static readonly T__7 = 8; - public static readonly T__8 = 9; - public static readonly DIGIT_SUBID = 10; - public static readonly FLOAT = 11; - public static readonly SEQ = 12; - public static readonly INT = 13; - public static readonly TASK = 14; - public static readonly GOAL = 15; - public static readonly SKIPP = 16; - public static readonly X = 17; - public static readonly NEWLINE = 18; - public static readonly WORD = 19; - public static readonly SUBID = 20; - public static readonly WS = 21; - public static readonly EOF = Token.EOF; + public static readonly T__0 = 1; + public static readonly T__1 = 2; + public static readonly T__2 = 3; + public static readonly T__3 = 4; + public static readonly T__4 = 5; + public static readonly T__5 = 6; + public static readonly T__6 = 7; + public static readonly T__7 = 8; + public static readonly T__8 = 9; + public static readonly T__9 = 10; + public static readonly DIGIT_SUBID = 11; + public static readonly FLOAT = 12; + public static readonly SEQ = 13; + public static readonly INT = 14; + public static readonly TASK = 15; + public static readonly GOAL = 16; + public static readonly SKIPP = 17; + public static readonly X = 18; + public static readonly NEWLINE = 19; + public static readonly WORD = 20; + public static readonly SUBID = 21; + public static readonly WS = 22; + public static readonly EOF = Token.EOF; - public static readonly channelNames: string[] = [ - 'DEFAULT_TOKEN_CHANNEL', - 'HIDDEN', - ]; - public static readonly literalNames: (string | null)[] = [ - null, - "'R'", - "','", - "'['", - "']'", - "':'", - "'@'", - "'|'", - "'->'", - "'+'", - null, - null, - "';'", - "'#'", - "'T'", - "'G'", - "'skip'", - "'X'", - ]; - public static readonly symbolicNames: (string | null)[] = [ - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - 'DIGIT_SUBID', - 'FLOAT', - 'SEQ', - 'INT', - 'TASK', - 'GOAL', - 'SKIPP', - 'X', - 'NEWLINE', - 'WORD', - 'SUBID', - 'WS', - ]; - public static readonly modeNames: string[] = ['DEFAULT_MODE']; + public static readonly channelNames: string[] = [ "DEFAULT_TOKEN_CHANNEL", "HIDDEN" ]; + public static readonly literalNames: (string | null)[] = [ null, "'R'", + "','", "'['", + "']'", "':'", + "'@'", "'|'", + "'?'", "'+'", + "'->'", null, + null, "';'", + "'#'", "'T'", + "'G'", "'skip'", + "'X'" ]; + public static readonly symbolicNames: (string | null)[] = [ null, null, + null, null, + null, null, + null, null, + null, null, + null, "DIGIT_SUBID", + "FLOAT", "SEQ", + "INT", "TASK", + "GOAL", "SKIPP", + "X", "NEWLINE", + "WORD", "SUBID", + "WS" ]; + public static readonly modeNames: string[] = [ "DEFAULT_MODE", ]; - public static readonly ruleNames: string[] = [ - 'T__0', - 'T__1', - 'T__2', - 'T__3', - 'T__4', - 'T__5', - 'T__6', - 'T__7', - 'T__8', - 'DIGIT_SUBID', - 'FLOAT', - 'SEQ', - 'INT', - 'TASK', - 'GOAL', - 'SKIPP', - 'X', - 'NEWLINE', - 'WORD', - 'SUBID', - 'WS', - 'DIGIT', - ]; + public static readonly ruleNames: string[] = [ + "T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6", "T__7", "T__8", + "T__9", "DIGIT_SUBID", "FLOAT", "SEQ", "INT", "TASK", "GOAL", "SKIPP", + "X", "NEWLINE", "WORD", "SUBID", "WS", "DIGIT", + ]; - constructor(input: CharStream) { - super(input); - this._interp = new LexerATNSimulator( - this, - RTRegexLexer._ATN, - RTRegexLexer.DecisionsToDFA, - new PredictionContextCache(), - ); - } - public get grammarFileName(): string { - return 'RTRegex.g4'; - } + constructor(input: CharStream) { + super(input); + this._interp = new LexerATNSimulator(this, RTRegexLexer._ATN, RTRegexLexer.DecisionsToDFA, new PredictionContextCache()); + } - public get literalNames(): (string | null)[] { - return RTRegexLexer.literalNames; - } - public get symbolicNames(): (string | null)[] { - return RTRegexLexer.symbolicNames; - } - public get ruleNames(): string[] { - return RTRegexLexer.ruleNames; - } + public get grammarFileName(): string { return "RTRegex.g4"; } - public get serializedATN(): number[] { - return RTRegexLexer._serializedATN; - } + public get literalNames(): (string | null)[] { return RTRegexLexer.literalNames; } + public get symbolicNames(): (string | null)[] { return RTRegexLexer.symbolicNames; } + public get ruleNames(): string[] { return RTRegexLexer.ruleNames; } - public get channelNames(): string[] { - return RTRegexLexer.channelNames; - } + public get serializedATN(): number[] { return RTRegexLexer._serializedATN; } - public get modeNames(): string[] { - return RTRegexLexer.modeNames; - } + public get channelNames(): string[] { return RTRegexLexer.channelNames; } - public static readonly _serializedATN: number[] = [ - 4, 0, 21, 117, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, - 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, - 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, - 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 2, 20, 7, 20, 2, 21, 7, - 21, 1, 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, - 1, 6, 1, 6, 1, 7, 1, 7, 1, 7, 1, 8, 1, 8, 1, 9, 1, 9, 1, 9, 1, 10, 4, 10, - 69, 8, 10, 11, 10, 12, 10, 70, 1, 10, 3, 10, 74, 8, 10, 1, 10, 5, 10, 77, 8, - 10, 10, 10, 12, 10, 80, 9, 10, 1, 11, 1, 11, 1, 12, 1, 12, 1, 13, 1, 13, 1, - 14, 1, 14, 1, 15, 1, 15, 1, 15, 1, 15, 1, 15, 1, 16, 1, 16, 1, 17, 4, 17, - 98, 8, 17, 11, 17, 12, 17, 99, 1, 18, 4, 18, 103, 8, 18, 11, 18, 12, 18, - 104, 1, 19, 1, 19, 1, 20, 4, 20, 110, 8, 20, 11, 20, 12, 20, 111, 1, 20, 1, - 20, 1, 21, 1, 21, 0, 0, 22, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, - 8, 17, 9, 19, 10, 21, 11, 23, 12, 25, 13, 27, 14, 29, 15, 31, 16, 33, 17, - 35, 18, 37, 19, 39, 20, 41, 21, 43, 0, 1, 0, 5, 2, 0, 10, 10, 13, 13, 5, 0, - 32, 32, 39, 39, 45, 45, 65, 90, 97, 122, 1, 0, 97, 122, 1, 0, 9, 9, 1, 0, - 48, 57, 121, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, - 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, - 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 0, 23, 1, - 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, 27, 1, 0, 0, 0, 0, 29, 1, 0, 0, 0, 0, 31, 1, - 0, 0, 0, 0, 33, 1, 0, 0, 0, 0, 35, 1, 0, 0, 0, 0, 37, 1, 0, 0, 0, 0, 39, 1, - 0, 0, 0, 0, 41, 1, 0, 0, 0, 1, 45, 1, 0, 0, 0, 3, 47, 1, 0, 0, 0, 5, 49, 1, - 0, 0, 0, 7, 51, 1, 0, 0, 0, 9, 53, 1, 0, 0, 0, 11, 55, 1, 0, 0, 0, 13, 57, - 1, 0, 0, 0, 15, 59, 1, 0, 0, 0, 17, 62, 1, 0, 0, 0, 19, 64, 1, 0, 0, 0, 21, - 68, 1, 0, 0, 0, 23, 81, 1, 0, 0, 0, 25, 83, 1, 0, 0, 0, 27, 85, 1, 0, 0, 0, - 29, 87, 1, 0, 0, 0, 31, 89, 1, 0, 0, 0, 33, 94, 1, 0, 0, 0, 35, 97, 1, 0, 0, - 0, 37, 102, 1, 0, 0, 0, 39, 106, 1, 0, 0, 0, 41, 109, 1, 0, 0, 0, 43, 115, - 1, 0, 0, 0, 45, 46, 5, 82, 0, 0, 46, 2, 1, 0, 0, 0, 47, 48, 5, 44, 0, 0, 48, - 4, 1, 0, 0, 0, 49, 50, 5, 91, 0, 0, 50, 6, 1, 0, 0, 0, 51, 52, 5, 93, 0, 0, - 52, 8, 1, 0, 0, 0, 53, 54, 5, 58, 0, 0, 54, 10, 1, 0, 0, 0, 55, 56, 5, 64, - 0, 0, 56, 12, 1, 0, 0, 0, 57, 58, 5, 124, 0, 0, 58, 14, 1, 0, 0, 0, 59, 60, - 5, 45, 0, 0, 60, 61, 5, 62, 0, 0, 61, 16, 1, 0, 0, 0, 62, 63, 5, 43, 0, 0, - 63, 18, 1, 0, 0, 0, 64, 65, 3, 43, 21, 0, 65, 66, 3, 39, 19, 0, 66, 20, 1, - 0, 0, 0, 67, 69, 3, 43, 21, 0, 68, 67, 1, 0, 0, 0, 69, 70, 1, 0, 0, 0, 70, - 68, 1, 0, 0, 0, 70, 71, 1, 0, 0, 0, 71, 73, 1, 0, 0, 0, 72, 74, 5, 46, 0, 0, - 73, 72, 1, 0, 0, 0, 73, 74, 1, 0, 0, 0, 74, 78, 1, 0, 0, 0, 75, 77, 3, 43, - 21, 0, 76, 75, 1, 0, 0, 0, 77, 80, 1, 0, 0, 0, 78, 76, 1, 0, 0, 0, 78, 79, - 1, 0, 0, 0, 79, 22, 1, 0, 0, 0, 80, 78, 1, 0, 0, 0, 81, 82, 5, 59, 0, 0, 82, - 24, 1, 0, 0, 0, 83, 84, 5, 35, 0, 0, 84, 26, 1, 0, 0, 0, 85, 86, 5, 84, 0, - 0, 86, 28, 1, 0, 0, 0, 87, 88, 5, 71, 0, 0, 88, 30, 1, 0, 0, 0, 89, 90, 5, - 115, 0, 0, 90, 91, 5, 107, 0, 0, 91, 92, 5, 105, 0, 0, 92, 93, 5, 112, 0, 0, - 93, 32, 1, 0, 0, 0, 94, 95, 5, 88, 0, 0, 95, 34, 1, 0, 0, 0, 96, 98, 7, 0, - 0, 0, 97, 96, 1, 0, 0, 0, 98, 99, 1, 0, 0, 0, 99, 97, 1, 0, 0, 0, 99, 100, - 1, 0, 0, 0, 100, 36, 1, 0, 0, 0, 101, 103, 7, 1, 0, 0, 102, 101, 1, 0, 0, 0, - 103, 104, 1, 0, 0, 0, 104, 102, 1, 0, 0, 0, 104, 105, 1, 0, 0, 0, 105, 38, - 1, 0, 0, 0, 106, 107, 7, 2, 0, 0, 107, 40, 1, 0, 0, 0, 108, 110, 7, 3, 0, 0, - 109, 108, 1, 0, 0, 0, 110, 111, 1, 0, 0, 0, 111, 109, 1, 0, 0, 0, 111, 112, - 1, 0, 0, 0, 112, 113, 1, 0, 0, 0, 113, 114, 6, 20, 0, 0, 114, 42, 1, 0, 0, - 0, 115, 116, 7, 4, 0, 0, 116, 44, 1, 0, 0, 0, 7, 0, 70, 73, 78, 99, 104, - 111, 1, 6, 0, 0, - ]; + public get modeNames(): string[] { return RTRegexLexer.modeNames; } - private static __ATN: ATN; - public static get _ATN(): ATN { - if (!RTRegexLexer.__ATN) { - RTRegexLexer.__ATN = new ATNDeserializer().deserialize( - RTRegexLexer._serializedATN, - ); - } + public static readonly _serializedATN: number[] = [4,0,22,121,6,-1,2,0, + 7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7,6,2,7,7,7,2,8,7,8,2,9, + 7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,13,7,13,2,14,7,14,2,15,7,15,2,16,7, + 16,2,17,7,17,2,18,7,18,2,19,7,19,2,20,7,20,2,21,7,21,2,22,7,22,1,0,1,0, + 1,1,1,1,1,2,1,2,1,3,1,3,1,4,1,4,1,5,1,5,1,6,1,6,1,7,1,7,1,8,1,8,1,9,1,9, + 1,9,1,10,1,10,1,10,1,11,4,11,73,8,11,11,11,12,11,74,1,11,3,11,78,8,11,1, + 11,5,11,81,8,11,10,11,12,11,84,9,11,1,12,1,12,1,13,1,13,1,14,1,14,1,15, + 1,15,1,16,1,16,1,16,1,16,1,16,1,17,1,17,1,18,4,18,102,8,18,11,18,12,18, + 103,1,19,4,19,107,8,19,11,19,12,19,108,1,20,1,20,1,21,4,21,114,8,21,11, + 21,12,21,115,1,21,1,21,1,22,1,22,0,0,23,1,1,3,2,5,3,7,4,9,5,11,6,13,7,15, + 8,17,9,19,10,21,11,23,12,25,13,27,14,29,15,31,16,33,17,35,18,37,19,39,20, + 41,21,43,22,45,0,1,0,5,2,0,10,10,13,13,5,0,32,32,39,39,45,45,65,90,97,122, + 1,0,97,122,1,0,9,9,1,0,48,57,125,0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0, + 7,1,0,0,0,0,9,1,0,0,0,0,11,1,0,0,0,0,13,1,0,0,0,0,15,1,0,0,0,0,17,1,0,0, + 0,0,19,1,0,0,0,0,21,1,0,0,0,0,23,1,0,0,0,0,25,1,0,0,0,0,27,1,0,0,0,0,29, + 1,0,0,0,0,31,1,0,0,0,0,33,1,0,0,0,0,35,1,0,0,0,0,37,1,0,0,0,0,39,1,0,0, + 0,0,41,1,0,0,0,0,43,1,0,0,0,1,47,1,0,0,0,3,49,1,0,0,0,5,51,1,0,0,0,7,53, + 1,0,0,0,9,55,1,0,0,0,11,57,1,0,0,0,13,59,1,0,0,0,15,61,1,0,0,0,17,63,1, + 0,0,0,19,65,1,0,0,0,21,68,1,0,0,0,23,72,1,0,0,0,25,85,1,0,0,0,27,87,1,0, + 0,0,29,89,1,0,0,0,31,91,1,0,0,0,33,93,1,0,0,0,35,98,1,0,0,0,37,101,1,0, + 0,0,39,106,1,0,0,0,41,110,1,0,0,0,43,113,1,0,0,0,45,119,1,0,0,0,47,48,5, + 82,0,0,48,2,1,0,0,0,49,50,5,44,0,0,50,4,1,0,0,0,51,52,5,91,0,0,52,6,1,0, + 0,0,53,54,5,93,0,0,54,8,1,0,0,0,55,56,5,58,0,0,56,10,1,0,0,0,57,58,5,64, + 0,0,58,12,1,0,0,0,59,60,5,124,0,0,60,14,1,0,0,0,61,62,5,63,0,0,62,16,1, + 0,0,0,63,64,5,43,0,0,64,18,1,0,0,0,65,66,5,45,0,0,66,67,5,62,0,0,67,20, + 1,0,0,0,68,69,3,45,22,0,69,70,3,41,20,0,70,22,1,0,0,0,71,73,3,45,22,0,72, + 71,1,0,0,0,73,74,1,0,0,0,74,72,1,0,0,0,74,75,1,0,0,0,75,77,1,0,0,0,76,78, + 5,46,0,0,77,76,1,0,0,0,77,78,1,0,0,0,78,82,1,0,0,0,79,81,3,45,22,0,80,79, + 1,0,0,0,81,84,1,0,0,0,82,80,1,0,0,0,82,83,1,0,0,0,83,24,1,0,0,0,84,82,1, + 0,0,0,85,86,5,59,0,0,86,26,1,0,0,0,87,88,5,35,0,0,88,28,1,0,0,0,89,90,5, + 84,0,0,90,30,1,0,0,0,91,92,5,71,0,0,92,32,1,0,0,0,93,94,5,115,0,0,94,95, + 5,107,0,0,95,96,5,105,0,0,96,97,5,112,0,0,97,34,1,0,0,0,98,99,5,88,0,0, + 99,36,1,0,0,0,100,102,7,0,0,0,101,100,1,0,0,0,102,103,1,0,0,0,103,101,1, + 0,0,0,103,104,1,0,0,0,104,38,1,0,0,0,105,107,7,1,0,0,106,105,1,0,0,0,107, + 108,1,0,0,0,108,106,1,0,0,0,108,109,1,0,0,0,109,40,1,0,0,0,110,111,7,2, + 0,0,111,42,1,0,0,0,112,114,7,3,0,0,113,112,1,0,0,0,114,115,1,0,0,0,115, + 113,1,0,0,0,115,116,1,0,0,0,116,117,1,0,0,0,117,118,6,21,0,0,118,44,1,0, + 0,0,119,120,7,4,0,0,120,46,1,0,0,0,7,0,74,77,82,103,108,115,1,6,0,0]; - return RTRegexLexer.__ATN; - } + private static __ATN: ATN; + public static get _ATN(): ATN { + if (!RTRegexLexer.__ATN) { + RTRegexLexer.__ATN = new ATNDeserializer().deserialize(RTRegexLexer._serializedATN); + } - static DecisionsToDFA = RTRegexLexer._ATN.decisionToState.map( - (ds: DecisionState, index: number) => new DFA(ds, index), - ); -} + return RTRegexLexer.__ATN; + } + + + static DecisionsToDFA = RTRegexLexer._ATN.decisionToState.map( (ds: DecisionState, index: number) => new DFA(ds, index) ); +} \ No newline at end of file diff --git a/packages/goal-tree/src/antlr/RTRegexListener.ts b/packages/goal-tree/src/antlr/RTRegexListener.ts index 5277ca36..1db0fa09 100644 --- a/packages/goal-tree/src/antlr/RTRegexListener.ts +++ b/packages/goal-tree/src/antlr/RTRegexListener.ts @@ -1,228 +1,244 @@ -// Generated from grammar/RTRegex.g4 by ANTLR 4.13.2 +// Generated from RTRegex.g4 by ANTLR 4.13.2 -import { ParseTreeListener } from 'antlr4'; +import {ParseTreeListener} from "antlr4"; + + +import { PrintExprContext } from "./RTRegexParser.js"; +import { BlankContext } from "./RTRegexParser.js"; +import { GAnyOrderContext } from "./RTRegexParser.js"; +import { GIdContext } from "./RTRegexParser.js"; +import { NameOnlyContext } from "./RTRegexParser.js"; +import { GInterleavedContext } from "./RTRegexParser.js"; +import { GChoiceContext } from "./RTRegexParser.js"; +import { GArgsContext } from "./RTRegexParser.js"; +import { NameContinuedContext } from "./RTRegexParser.js"; +import { GAlternativeContext } from "./RTRegexParser.js"; +import { GDegradationContext } from "./RTRegexParser.js"; +import { GSkipContext } from "./RTRegexParser.js"; +import { NotationStartContext } from "./RTRegexParser.js"; +import { GRetryContext } from "./RTRegexParser.js"; +import { GSequenceContext } from "./RTRegexParser.js"; +import { GIdContinuedContext } from "./RTRegexParser.js"; +import { IdContext } from "./RTRegexParser.js"; +import { WordContext } from "./RTRegexParser.js"; -import { PrintExprContext } from './RTRegexParser.js'; -import { BlankContext } from './RTRegexParser.js'; -import { GIdContext } from './RTRegexParser.js'; -import { NameOnlyContext } from './RTRegexParser.js'; -import { GInterleavedContext } from './RTRegexParser.js'; -import { GChoiceContext } from './RTRegexParser.js'; -import { GArgsContext } from './RTRegexParser.js'; -import { NameContinuedContext } from './RTRegexParser.js'; -import { GAlternativeContext } from './RTRegexParser.js'; -import { GDegradationContext } from './RTRegexParser.js'; -import { GSkipContext } from './RTRegexParser.js'; -import { NotationStartContext } from './RTRegexParser.js'; -import { GRetryContext } from './RTRegexParser.js'; -import { GSequenceContext } from './RTRegexParser.js'; -import { GIdContinuedContext } from './RTRegexParser.js'; -import { IdContext } from './RTRegexParser.js'; -import { WordContext } from './RTRegexParser.js'; /** * This interface defines a complete listener for a parse tree produced by * `RTRegexParser`. */ export default class RTRegexListener extends ParseTreeListener { - /** - * Enter a parse tree produced by the `printExpr` - * labeled alternative in `RTRegexParser.rt`. - * @param ctx the parse tree - */ - enterPrintExpr?: (ctx: PrintExprContext) => void; - /** - * Exit a parse tree produced by the `printExpr` - * labeled alternative in `RTRegexParser.rt`. - * @param ctx the parse tree - */ - exitPrintExpr?: (ctx: PrintExprContext) => void; - /** - * Enter a parse tree produced by the `blank` - * labeled alternative in `RTRegexParser.rt`. - * @param ctx the parse tree - */ - enterBlank?: (ctx: BlankContext) => void; - /** - * Exit a parse tree produced by the `blank` - * labeled alternative in `RTRegexParser.rt`. - * @param ctx the parse tree - */ - exitBlank?: (ctx: BlankContext) => void; - /** - * Enter a parse tree produced by the `gId` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - enterGId?: (ctx: GIdContext) => void; - /** - * Exit a parse tree produced by the `gId` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - exitGId?: (ctx: GIdContext) => void; - /** - * Enter a parse tree produced by the `nameOnly` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - enterNameOnly?: (ctx: NameOnlyContext) => void; - /** - * Exit a parse tree produced by the `nameOnly` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - exitNameOnly?: (ctx: NameOnlyContext) => void; - /** - * Enter a parse tree produced by the `gInterleaved` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - enterGInterleaved?: (ctx: GInterleavedContext) => void; - /** - * Exit a parse tree produced by the `gInterleaved` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - exitGInterleaved?: (ctx: GInterleavedContext) => void; - /** - * Enter a parse tree produced by the `gChoice` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - enterGChoice?: (ctx: GChoiceContext) => void; - /** - * Exit a parse tree produced by the `gChoice` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - exitGChoice?: (ctx: GChoiceContext) => void; - /** - * Enter a parse tree produced by the `gArgs` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - enterGArgs?: (ctx: GArgsContext) => void; - /** - * Exit a parse tree produced by the `gArgs` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - exitGArgs?: (ctx: GArgsContext) => void; - /** - * Enter a parse tree produced by the `nameContinued` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - enterNameContinued?: (ctx: NameContinuedContext) => void; - /** - * Exit a parse tree produced by the `nameContinued` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - exitNameContinued?: (ctx: NameContinuedContext) => void; - /** - * Enter a parse tree produced by the `gAlternative` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - enterGAlternative?: (ctx: GAlternativeContext) => void; - /** - * Exit a parse tree produced by the `gAlternative` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - exitGAlternative?: (ctx: GAlternativeContext) => void; - /** - * Enter a parse tree produced by the `gDegradation` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - enterGDegradation?: (ctx: GDegradationContext) => void; - /** - * Exit a parse tree produced by the `gDegradation` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - exitGDegradation?: (ctx: GDegradationContext) => void; - /** - * Enter a parse tree produced by the `gSkip` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - enterGSkip?: (ctx: GSkipContext) => void; - /** - * Exit a parse tree produced by the `gSkip` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - exitGSkip?: (ctx: GSkipContext) => void; - /** - * Enter a parse tree produced by the `notationStart` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - enterNotationStart?: (ctx: NotationStartContext) => void; - /** - * Exit a parse tree produced by the `notationStart` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - exitNotationStart?: (ctx: NotationStartContext) => void; - /** - * Enter a parse tree produced by the `gRetry` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - enterGRetry?: (ctx: GRetryContext) => void; - /** - * Exit a parse tree produced by the `gRetry` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - exitGRetry?: (ctx: GRetryContext) => void; - /** - * Enter a parse tree produced by the `gSequence` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - enterGSequence?: (ctx: GSequenceContext) => void; - /** - * Exit a parse tree produced by the `gSequence` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - exitGSequence?: (ctx: GSequenceContext) => void; - /** - * Enter a parse tree produced by the `gIdContinued` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - enterGIdContinued?: (ctx: GIdContinuedContext) => void; - /** - * Exit a parse tree produced by the `gIdContinued` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - exitGIdContinued?: (ctx: GIdContinuedContext) => void; - /** - * Enter a parse tree produced by `RTRegexParser.id`. - * @param ctx the parse tree - */ - enterId?: (ctx: IdContext) => void; - /** - * Exit a parse tree produced by `RTRegexParser.id`. - * @param ctx the parse tree - */ - exitId?: (ctx: IdContext) => void; - /** - * Enter a parse tree produced by `RTRegexParser.word`. - * @param ctx the parse tree - */ - enterWord?: (ctx: WordContext) => void; - /** - * Exit a parse tree produced by `RTRegexParser.word`. - * @param ctx the parse tree - */ - exitWord?: (ctx: WordContext) => void; + /** + * Enter a parse tree produced by the `printExpr` + * labeled alternative in `RTRegexParser.rt`. + * @param ctx the parse tree + */ + enterPrintExpr?: (ctx: PrintExprContext) => void; + /** + * Exit a parse tree produced by the `printExpr` + * labeled alternative in `RTRegexParser.rt`. + * @param ctx the parse tree + */ + exitPrintExpr?: (ctx: PrintExprContext) => void; + /** + * Enter a parse tree produced by the `blank` + * labeled alternative in `RTRegexParser.rt`. + * @param ctx the parse tree + */ + enterBlank?: (ctx: BlankContext) => void; + /** + * Exit a parse tree produced by the `blank` + * labeled alternative in `RTRegexParser.rt`. + * @param ctx the parse tree + */ + exitBlank?: (ctx: BlankContext) => void; + /** + * Enter a parse tree produced by the `gAnyOrder` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + enterGAnyOrder?: (ctx: GAnyOrderContext) => void; + /** + * Exit a parse tree produced by the `gAnyOrder` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + exitGAnyOrder?: (ctx: GAnyOrderContext) => void; + /** + * Enter a parse tree produced by the `gId` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + enterGId?: (ctx: GIdContext) => void; + /** + * Exit a parse tree produced by the `gId` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + exitGId?: (ctx: GIdContext) => void; + /** + * Enter a parse tree produced by the `nameOnly` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + enterNameOnly?: (ctx: NameOnlyContext) => void; + /** + * Exit a parse tree produced by the `nameOnly` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + exitNameOnly?: (ctx: NameOnlyContext) => void; + /** + * Enter a parse tree produced by the `gInterleaved` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + enterGInterleaved?: (ctx: GInterleavedContext) => void; + /** + * Exit a parse tree produced by the `gInterleaved` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + exitGInterleaved?: (ctx: GInterleavedContext) => void; + /** + * Enter a parse tree produced by the `gChoice` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + enterGChoice?: (ctx: GChoiceContext) => void; + /** + * Exit a parse tree produced by the `gChoice` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + exitGChoice?: (ctx: GChoiceContext) => void; + /** + * Enter a parse tree produced by the `gArgs` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + enterGArgs?: (ctx: GArgsContext) => void; + /** + * Exit a parse tree produced by the `gArgs` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + exitGArgs?: (ctx: GArgsContext) => void; + /** + * Enter a parse tree produced by the `nameContinued` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + enterNameContinued?: (ctx: NameContinuedContext) => void; + /** + * Exit a parse tree produced by the `nameContinued` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + exitNameContinued?: (ctx: NameContinuedContext) => void; + /** + * Enter a parse tree produced by the `gAlternative` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + enterGAlternative?: (ctx: GAlternativeContext) => void; + /** + * Exit a parse tree produced by the `gAlternative` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + exitGAlternative?: (ctx: GAlternativeContext) => void; + /** + * Enter a parse tree produced by the `gDegradation` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + enterGDegradation?: (ctx: GDegradationContext) => void; + /** + * Exit a parse tree produced by the `gDegradation` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + exitGDegradation?: (ctx: GDegradationContext) => void; + /** + * Enter a parse tree produced by the `gSkip` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + enterGSkip?: (ctx: GSkipContext) => void; + /** + * Exit a parse tree produced by the `gSkip` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + exitGSkip?: (ctx: GSkipContext) => void; + /** + * Enter a parse tree produced by the `notationStart` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + enterNotationStart?: (ctx: NotationStartContext) => void; + /** + * Exit a parse tree produced by the `notationStart` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + exitNotationStart?: (ctx: NotationStartContext) => void; + /** + * Enter a parse tree produced by the `gRetry` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + enterGRetry?: (ctx: GRetryContext) => void; + /** + * Exit a parse tree produced by the `gRetry` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + exitGRetry?: (ctx: GRetryContext) => void; + /** + * Enter a parse tree produced by the `gSequence` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + enterGSequence?: (ctx: GSequenceContext) => void; + /** + * Exit a parse tree produced by the `gSequence` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + exitGSequence?: (ctx: GSequenceContext) => void; + /** + * Enter a parse tree produced by the `gIdContinued` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + enterGIdContinued?: (ctx: GIdContinuedContext) => void; + /** + * Exit a parse tree produced by the `gIdContinued` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + exitGIdContinued?: (ctx: GIdContinuedContext) => void; + /** + * Enter a parse tree produced by `RTRegexParser.id`. + * @param ctx the parse tree + */ + enterId?: (ctx: IdContext) => void; + /** + * Exit a parse tree produced by `RTRegexParser.id`. + * @param ctx the parse tree + */ + exitId?: (ctx: IdContext) => void; + /** + * Enter a parse tree produced by `RTRegexParser.word`. + * @param ctx the parse tree + */ + enterWord?: (ctx: WordContext) => void; + /** + * Exit a parse tree produced by `RTRegexParser.word`. + * @param ctx the parse tree + */ + exitWord?: (ctx: WordContext) => void; } + diff --git a/packages/goal-tree/src/antlr/RTRegexParser.ts b/packages/goal-tree/src/antlr/RTRegexParser.ts index bf65d1c7..a43e7326 100644 --- a/packages/goal-tree/src/antlr/RTRegexParser.ts +++ b/packages/goal-tree/src/antlr/RTRegexParser.ts @@ -1,1078 +1,1006 @@ -// Generated from grammar/RTRegex.g4 by ANTLR 4.13.2 +// Generated from RTRegex.g4 by ANTLR 4.13.2 // noinspection ES6UnusedImports,JSUnusedGlobalSymbols,JSUnusedLocalSymbols import { - ATN, - ATNDeserializer, - DecisionState, - DFA, - FailedPredicateException, - RecognitionException, - NoViableAltException, - BailErrorStrategy, - Parser, - ParserATNSimulator, - RuleContext, - ParserRuleContext, - PredictionMode, - PredictionContextCache, - TerminalNode, - RuleNode, - Token, - TokenStream, - Interval, - IntervalSet, + ATN, + ATNDeserializer, DecisionState, DFA, FailedPredicateException, + RecognitionException, NoViableAltException, BailErrorStrategy, + Parser, ParserATNSimulator, + RuleContext, ParserRuleContext, PredictionMode, PredictionContextCache, + TerminalNode, RuleNode, + Token, TokenStream, + Interval, IntervalSet } from 'antlr4'; -import RTRegexListener from './RTRegexListener.js'; +import RTRegexListener from "./RTRegexListener.js"; // for running tests with parameters, TODO: discuss strategy for typed parameters in CI // eslint-disable-next-line no-unused-vars type int = number; export default class RTRegexParser extends Parser { - public static readonly T__0 = 1; - public static readonly T__1 = 2; - public static readonly T__2 = 3; - public static readonly T__3 = 4; - public static readonly T__4 = 5; - public static readonly T__5 = 6; - public static readonly T__6 = 7; - public static readonly T__7 = 8; - public static readonly T__8 = 9; - public static readonly DIGIT_SUBID = 10; - public static readonly FLOAT = 11; - public static readonly SEQ = 12; - public static readonly INT = 13; - public static readonly TASK = 14; - public static readonly GOAL = 15; - public static readonly SKIPP = 16; - public static readonly X = 17; - public static readonly NEWLINE = 18; - public static readonly WORD = 19; - public static readonly SUBID = 20; - public static readonly WS = 21; - public static override readonly EOF = Token.EOF; - public static readonly RULE_rt = 0; - public static readonly RULE_expr = 1; - public static readonly RULE_id = 2; - public static readonly RULE_word = 3; - public static readonly literalNames: (string | null)[] = [ - null, - "'R'", - "','", - "'['", - "']'", - "':'", - "'@'", - "'|'", - "'->'", - "'+'", - null, - null, - "';'", - "'#'", - "'T'", - "'G'", - "'skip'", - "'X'", - ]; - public static readonly symbolicNames: (string | null)[] = [ - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - 'DIGIT_SUBID', - 'FLOAT', - 'SEQ', - 'INT', - 'TASK', - 'GOAL', - 'SKIPP', - 'X', - 'NEWLINE', - 'WORD', - 'SUBID', - 'WS', - ]; - // tslint:disable:no-trailing-whitespace - public static readonly ruleNames: string[] = ['rt', 'expr', 'id', 'word']; - public get grammarFileName(): string { - return 'RTRegex.g4'; - } - public get literalNames(): (string | null)[] { - return RTRegexParser.literalNames; - } - public get symbolicNames(): (string | null)[] { - return RTRegexParser.symbolicNames; - } - public get ruleNames(): string[] { - return RTRegexParser.ruleNames; - } - public get serializedATN(): number[] { - return RTRegexParser._serializedATN; - } + public static readonly T__0 = 1; + public static readonly T__1 = 2; + public static readonly T__2 = 3; + public static readonly T__3 = 4; + public static readonly T__4 = 5; + public static readonly T__5 = 6; + public static readonly T__6 = 7; + public static readonly T__7 = 8; + public static readonly T__8 = 9; + public static readonly T__9 = 10; + public static readonly DIGIT_SUBID = 11; + public static readonly FLOAT = 12; + public static readonly SEQ = 13; + public static readonly INT = 14; + public static readonly TASK = 15; + public static readonly GOAL = 16; + public static readonly SKIPP = 17; + public static readonly X = 18; + public static readonly NEWLINE = 19; + public static readonly WORD = 20; + public static readonly SUBID = 21; + public static readonly WS = 22; + public static override readonly EOF = Token.EOF; + public static readonly RULE_rt = 0; + public static readonly RULE_expr = 1; + public static readonly RULE_id = 2; + public static readonly RULE_word = 3; + public static readonly literalNames: (string | null)[] = [ null, "'R'", + "','", "'['", + "']'", "':'", + "'@'", "'|'", + "'?'", "'+'", + "'->'", null, + null, "';'", + "'#'", "'T'", + "'G'", "'skip'", + "'X'" ]; + public static readonly symbolicNames: (string | null)[] = [ null, null, + null, null, + null, null, + null, null, + null, null, + null, "DIGIT_SUBID", + "FLOAT", "SEQ", + "INT", "TASK", + "GOAL", "SKIPP", + "X", "NEWLINE", + "WORD", "SUBID", + "WS" ]; + // tslint:disable:no-trailing-whitespace + public static readonly ruleNames: string[] = [ + "rt", "expr", "id", "word", + ]; + public get grammarFileName(): string { return "RTRegex.g4"; } + public get literalNames(): (string | null)[] { return RTRegexParser.literalNames; } + public get symbolicNames(): (string | null)[] { return RTRegexParser.symbolicNames; } + public get ruleNames(): string[] { return RTRegexParser.ruleNames; } + public get serializedATN(): number[] { return RTRegexParser._serializedATN; } - protected createFailedPredicateException( - predicate?: string, - message?: string, - ): FailedPredicateException { - return new FailedPredicateException(this, predicate, message); - } + protected createFailedPredicateException(predicate?: string, message?: string): FailedPredicateException { + return new FailedPredicateException(this, predicate, message); + } - constructor(input: TokenStream) { - super(input); - this._interp = new ParserATNSimulator( - this, - RTRegexParser._ATN, - RTRegexParser.DecisionsToDFA, - new PredictionContextCache(), - ); - } - // @RuleVersion(0) - public rt(): RtContext { - let localctx: RtContext = new RtContext(this, this._ctx, this.state); - this.enterRule(localctx, 0, RTRegexParser.RULE_rt); - try { - this.state = 12; - this._errHandler.sync(this); - switch (this._input.LA(1)) { - case 1: - case 3: - case 5: - case 9: - case 14: - case 15: - case 16: - localctx = new PrintExprContext(this, localctx); - this.enterOuterAlt(localctx, 1); - { - this.state = 8; - this.expr(0); - this.state = 9; - this.match(RTRegexParser.EOF); - } - break; - case -1: - localctx = new BlankContext(this, localctx); - this.enterOuterAlt(localctx, 2); - { - this.state = 11; - this.match(RTRegexParser.EOF); - } - break; - default: - throw new NoViableAltException(this); - } - } catch (re) { - if (re instanceof RecognitionException) { - localctx.exception = re; - this._errHandler.reportError(this, re); - this._errHandler.recover(this, re); - } else { - throw re; - } - } finally { - this.exitRule(); - } - return localctx; - } + constructor(input: TokenStream) { + super(input); + this._interp = new ParserATNSimulator(this, RTRegexParser._ATN, RTRegexParser.DecisionsToDFA, new PredictionContextCache()); + } + // @RuleVersion(0) + public rt(): RtContext { + let localctx: RtContext = new RtContext(this, this._ctx, this.state); + this.enterRule(localctx, 0, RTRegexParser.RULE_rt); + try { + this.state = 12; + this._errHandler.sync(this); + switch (this._input.LA(1)) { + case 1: + case 3: + case 5: + case 15: + case 16: + case 17: + localctx = new PrintExprContext(this, localctx); + this.enterOuterAlt(localctx, 1); + { + this.state = 8; + this.expr(0); + this.state = 9; + this.match(RTRegexParser.EOF); + } + break; + case -1: + localctx = new BlankContext(this, localctx); + this.enterOuterAlt(localctx, 2); + { + this.state = 11; + this.match(RTRegexParser.EOF); + } + break; + default: + throw new NoViableAltException(this); + } + } + catch (re) { + if (re instanceof RecognitionException) { + localctx.exception = re; + this._errHandler.reportError(this, re); + this._errHandler.recover(this, re); + } else { + throw re; + } + } + finally { + this.exitRule(); + } + return localctx; + } - public expr(): ExprContext; - public expr(_p: number): ExprContext; - // @RuleVersion(0) - public expr(_p?: number): ExprContext { - if (_p === undefined) { - _p = 0; - } + public expr(): ExprContext; + public expr(_p: number): ExprContext; + // @RuleVersion(0) + public expr(_p?: number): ExprContext { + if (_p === undefined) { + _p = 0; + } - let _parentctx: ParserRuleContext = this._ctx; - let _parentState: number = this.state; - let localctx: ExprContext = new ExprContext(this, this._ctx, _parentState); - let _prevctx: ExprContext = localctx; - let _startState: number = 2; - this.enterRecursionRule(localctx, 2, RTRegexParser.RULE_expr, _p); - let _la: number; - try { - let _alt: number; - this.enterOuterAlt(localctx, 1); - { - this.state = 40; - this._errHandler.sync(this); - switch (this._interp.adaptivePredict(this._input, 1, this._ctx)) { - case 1: - { - localctx = new GIdContext(this, localctx); - this._ctx = localctx; - _prevctx = localctx; + let _parentctx: ParserRuleContext = this._ctx; + let _parentState: number = this.state; + let localctx: ExprContext = new ExprContext(this, this._ctx, _parentState); + let _prevctx: ExprContext = localctx; + let _startState: number = 2; + this.enterRecursionRule(localctx, 2, RTRegexParser.RULE_expr, _p); + let _la: number; + try { + let _alt: number; + this.enterOuterAlt(localctx, 1); + { + this.state = 39; + this._errHandler.sync(this); + switch ( this._interp.adaptivePredict(this._input, 1, this._ctx) ) { + case 1: + { + localctx = new GIdContext(this, localctx); + this._ctx = localctx; + _prevctx = localctx; - this.state = 15; - (localctx as GIdContext)._t = this._input.LT(1); - _la = this._input.LA(1); - if (!((_la & ~0x1f) === 0 && ((1 << _la) & 49154) !== 0)) { - (localctx as GIdContext)._t = - this._errHandler.recoverInline(this); - } else { - this._errHandler.reportMatch(this); - this.consume(); - } - this.state = 16; - this.id(); - } - break; - case 2: - { - localctx = new GIdContinuedContext(this, localctx); - this._ctx = localctx; - _prevctx = localctx; - this.state = 17; - (localctx as GIdContinuedContext)._t = this._input.LT(1); - _la = this._input.LA(1); - if (!((_la & ~0x1f) === 0 && ((1 << _la) & 49154) !== 0)) { - (localctx as GIdContinuedContext)._t = - this._errHandler.recoverInline(this); - } else { - this._errHandler.reportMatch(this); - this.consume(); - } - this.state = 18; - this.id(); - this.state = 19; - this.expr(12); - } - break; - case 3: - { - localctx = new GArgsContext(this, localctx); - this._ctx = localctx; - _prevctx = localctx; - this.state = 21; - (localctx as GArgsContext)._t = this._input.LT(1); - _la = this._input.LA(1); - if (!((_la & ~0x1f) === 0 && ((1 << _la) & 49154) !== 0)) { - (localctx as GArgsContext)._t = - this._errHandler.recoverInline(this); - } else { - this._errHandler.reportMatch(this); - this.consume(); - } - this.state = 22; - this.id(); - this.state = 23; - this.match(RTRegexParser.T__1); - this.state = 24; - this.expr(11); - } - break; - case 4: - { - localctx = new NotationStartContext(this, localctx); - this._ctx = localctx; - _prevctx = localctx; - this.state = 26; - this.match(RTRegexParser.T__2); - this.state = 27; - this.expr(0); - this.state = 28; - this.match(RTRegexParser.T__3); - } - break; - case 5: - { - localctx = new NameContinuedContext(this, localctx); - this._ctx = localctx; - _prevctx = localctx; - this.state = 30; - this.match(RTRegexParser.T__4); - this.state = 31; - this.word(); - this.state = 32; - this.expr(9); - } - break; - case 6: - { - localctx = new NameOnlyContext(this, localctx); - this._ctx = localctx; - _prevctx = localctx; - this.state = 34; - this.match(RTRegexParser.T__4); - this.state = 35; - this.word(); - this.state = 36; - this.match(RTRegexParser.EOF); - } - break; - case 7: - { - localctx = new GChoiceContext(this, localctx); - this._ctx = localctx; - _prevctx = localctx; - this.state = 38; - (localctx as GChoiceContext)._op = this.match(RTRegexParser.T__8); - } - break; - case 8: - { - localctx = new GSkipContext(this, localctx); - this._ctx = localctx; - _prevctx = localctx; - this.state = 39; - this.match(RTRegexParser.SKIPP); - } - break; - } - this._ctx.stop = this._input.LT(-1); - this.state = 59; - this._errHandler.sync(this); - _alt = this._interp.adaptivePredict(this._input, 3, this._ctx); - while (_alt !== 2 && _alt !== ATN.INVALID_ALT_NUMBER) { - if (_alt === 1) { - if (this._parseListeners != null) { - this.triggerExitRuleEvent(); - } - _prevctx = localctx; - { - this.state = 57; - this._errHandler.sync(this); - switch (this._interp.adaptivePredict(this._input, 2, this._ctx)) { - case 1: - { - localctx = new GAlternativeContext( - this, - new ExprContext(this, _parentctx, _parentState), - ); - this.pushNewRecursionContext( - localctx, - _startState, - RTRegexParser.RULE_expr, - ); - this.state = 42; - if (!this.precpred(this._ctx, 6)) { - throw this.createFailedPredicateException( - 'this.precpred(this._ctx, 6)', - ); - } - this.state = 43; - (localctx as GAlternativeContext)._op = this.match( - RTRegexParser.T__6, - ); - this.state = 44; - this.expr(7); - } - break; - case 2: - { - localctx = new GInterleavedContext( - this, - new ExprContext(this, _parentctx, _parentState), - ); - this.pushNewRecursionContext( - localctx, - _startState, - RTRegexParser.RULE_expr, - ); - this.state = 45; - if (!this.precpred(this._ctx, 5)) { - throw this.createFailedPredicateException( - 'this.precpred(this._ctx, 5)', - ); - } - this.state = 46; - (localctx as GInterleavedContext)._op = this.match( - RTRegexParser.INT, - ); - this.state = 47; - this.expr(6); - } - break; - case 3: - { - localctx = new GSequenceContext( - this, - new ExprContext(this, _parentctx, _parentState), - ); - this.pushNewRecursionContext( - localctx, - _startState, - RTRegexParser.RULE_expr, - ); - this.state = 48; - if (!this.precpred(this._ctx, 4)) { - throw this.createFailedPredicateException( - 'this.precpred(this._ctx, 4)', - ); - } - this.state = 49; - (localctx as GSequenceContext)._op = this.match( - RTRegexParser.SEQ, - ); - this.state = 50; - this.expr(5); - } - break; - case 4: - { - localctx = new GDegradationContext( - this, - new ExprContext(this, _parentctx, _parentState), - ); - this.pushNewRecursionContext( - localctx, - _startState, - RTRegexParser.RULE_expr, - ); - this.state = 51; - if (!this.precpred(this._ctx, 3)) { - throw this.createFailedPredicateException( - 'this.precpred(this._ctx, 3)', - ); - } - this.state = 52; - (localctx as GDegradationContext)._op = this.match( - RTRegexParser.T__7, - ); - this.state = 53; - this.expr(4); - } - break; - case 5: - { - localctx = new GRetryContext( - this, - new ExprContext(this, _parentctx, _parentState), - ); - this.pushNewRecursionContext( - localctx, - _startState, - RTRegexParser.RULE_expr, - ); - this.state = 54; - if (!this.precpred(this._ctx, 7)) { - throw this.createFailedPredicateException( - 'this.precpred(this._ctx, 7)', - ); - } - this.state = 55; - (localctx as GRetryContext)._op = this.match( - RTRegexParser.T__5, - ); - this.state = 56; - this.match(RTRegexParser.FLOAT); - } - break; - } - } - } - this.state = 61; - this._errHandler.sync(this); - _alt = this._interp.adaptivePredict(this._input, 3, this._ctx); - } - } - } catch (re) { - if (re instanceof RecognitionException) { - localctx.exception = re; - this._errHandler.reportError(this, re); - this._errHandler.recover(this, re); - } else { - throw re; - } - } finally { - this.unrollRecursionContexts(_parentctx); - } - return localctx; - } - // @RuleVersion(0) - public id(): IdContext { - let localctx: IdContext = new IdContext(this, this._ctx, this.state); - this.enterRule(localctx, 4, RTRegexParser.RULE_id); - try { - this.state = 67; - this._errHandler.sync(this); - switch (this._interp.adaptivePredict(this._input, 4, this._ctx)) { - case 1: - this.enterOuterAlt(localctx, 1); - { - this.state = 62; - this.match(RTRegexParser.FLOAT); - } - break; - case 2: - this.enterOuterAlt(localctx, 2); - { - this.state = 63; - this.match(RTRegexParser.FLOAT); - this.state = 64; - this.match(RTRegexParser.X); - } - break; - case 3: - this.enterOuterAlt(localctx, 3); - { - this.state = 65; - this.match(RTRegexParser.X); - } - break; - case 4: - this.enterOuterAlt(localctx, 4); - { - this.state = 66; - this.match(RTRegexParser.DIGIT_SUBID); - } - break; - } - } catch (re) { - if (re instanceof RecognitionException) { - localctx.exception = re; - this._errHandler.reportError(this, re); - this._errHandler.recover(this, re); - } else { - throw re; - } - } finally { - this.exitRule(); - } - return localctx; - } - // @RuleVersion(0) - public word(): WordContext { - let localctx: WordContext = new WordContext(this, this._ctx, this.state); - this.enterRule(localctx, 6, RTRegexParser.RULE_word); - try { - this.enterOuterAlt(localctx, 1); - { - this.state = 69; - this.match(RTRegexParser.WORD); - } - } catch (re) { - if (re instanceof RecognitionException) { - localctx.exception = re; - this._errHandler.reportError(this, re); - this._errHandler.recover(this, re); - } else { - throw re; - } - } finally { - this.exitRule(); - } - return localctx; - } + this.state = 15; + (localctx as GIdContext)._t = this._input.LT(1); + _la = this._input.LA(1); + if(!((((_la) & ~0x1F) === 0 && ((1 << _la) & 98306) !== 0))) { + (localctx as GIdContext)._t = this._errHandler.recoverInline(this); + } + else { + this._errHandler.reportMatch(this); + this.consume(); + } + this.state = 16; + this.id(); + } + break; + case 2: + { + localctx = new GIdContinuedContext(this, localctx); + this._ctx = localctx; + _prevctx = localctx; + this.state = 17; + (localctx as GIdContinuedContext)._t = this._input.LT(1); + _la = this._input.LA(1); + if(!((((_la) & ~0x1F) === 0 && ((1 << _la) & 98306) !== 0))) { + (localctx as GIdContinuedContext)._t = this._errHandler.recoverInline(this); + } + else { + this._errHandler.reportMatch(this); + this.consume(); + } + this.state = 18; + this.id(); + this.state = 19; + this.expr(13); + } + break; + case 3: + { + localctx = new GArgsContext(this, localctx); + this._ctx = localctx; + _prevctx = localctx; + this.state = 21; + (localctx as GArgsContext)._t = this._input.LT(1); + _la = this._input.LA(1); + if(!((((_la) & ~0x1F) === 0 && ((1 << _la) & 98306) !== 0))) { + (localctx as GArgsContext)._t = this._errHandler.recoverInline(this); + } + else { + this._errHandler.reportMatch(this); + this.consume(); + } + this.state = 22; + this.id(); + this.state = 23; + this.match(RTRegexParser.T__1); + this.state = 24; + this.expr(12); + } + break; + case 4: + { + localctx = new NotationStartContext(this, localctx); + this._ctx = localctx; + _prevctx = localctx; + this.state = 26; + this.match(RTRegexParser.T__2); + this.state = 27; + this.expr(0); + this.state = 28; + this.match(RTRegexParser.T__3); + } + break; + case 5: + { + localctx = new NameContinuedContext(this, localctx); + this._ctx = localctx; + _prevctx = localctx; + this.state = 30; + this.match(RTRegexParser.T__4); + this.state = 31; + this.word(); + this.state = 32; + this.expr(10); + } + break; + case 6: + { + localctx = new NameOnlyContext(this, localctx); + this._ctx = localctx; + _prevctx = localctx; + this.state = 34; + this.match(RTRegexParser.T__4); + this.state = 35; + this.word(); + this.state = 36; + this.match(RTRegexParser.EOF); + } + break; + case 7: + { + localctx = new GSkipContext(this, localctx); + this._ctx = localctx; + _prevctx = localctx; + this.state = 38; + this.match(RTRegexParser.SKIPP); + } + break; + } + this._ctx.stop = this._input.LT(-1); + this.state = 64; + this._errHandler.sync(this); + _alt = this._interp.adaptivePredict(this._input, 3, this._ctx); + while (_alt !== 2 && _alt !== ATN.INVALID_ALT_NUMBER) { + if (_alt === 1) { + if (this._parseListeners != null) { + this.triggerExitRuleEvent(); + } + _prevctx = localctx; + { + this.state = 62; + this._errHandler.sync(this); + switch ( this._interp.adaptivePredict(this._input, 2, this._ctx) ) { + case 1: + { + localctx = new GAlternativeContext(this, new ExprContext(this, _parentctx, _parentState)); + this.pushNewRecursionContext(localctx, _startState, RTRegexParser.RULE_expr); + this.state = 41; + if (!(this.precpred(this._ctx, 7))) { + throw this.createFailedPredicateException("this.precpred(this._ctx, 7)"); + } + this.state = 42; + (localctx as GAlternativeContext)._op = this.match(RTRegexParser.T__6); + this.state = 43; + this.expr(8); + } + break; + case 2: + { + localctx = new GChoiceContext(this, new ExprContext(this, _parentctx, _parentState)); + this.pushNewRecursionContext(localctx, _startState, RTRegexParser.RULE_expr); + this.state = 44; + if (!(this.precpred(this._ctx, 6))) { + throw this.createFailedPredicateException("this.precpred(this._ctx, 6)"); + } + this.state = 45; + (localctx as GChoiceContext)._op = this.match(RTRegexParser.T__7); + this.state = 46; + this.expr(7); + } + break; + case 3: + { + localctx = new GAnyOrderContext(this, new ExprContext(this, _parentctx, _parentState)); + this.pushNewRecursionContext(localctx, _startState, RTRegexParser.RULE_expr); + this.state = 47; + if (!(this.precpred(this._ctx, 5))) { + throw this.createFailedPredicateException("this.precpred(this._ctx, 5)"); + } + this.state = 48; + (localctx as GAnyOrderContext)._op = this.match(RTRegexParser.T__8); + this.state = 49; + this.expr(6); + } + break; + case 4: + { + localctx = new GInterleavedContext(this, new ExprContext(this, _parentctx, _parentState)); + this.pushNewRecursionContext(localctx, _startState, RTRegexParser.RULE_expr); + this.state = 50; + if (!(this.precpred(this._ctx, 4))) { + throw this.createFailedPredicateException("this.precpred(this._ctx, 4)"); + } + this.state = 51; + (localctx as GInterleavedContext)._op = this.match(RTRegexParser.INT); + this.state = 52; + this.expr(5); + } + break; + case 5: + { + localctx = new GSequenceContext(this, new ExprContext(this, _parentctx, _parentState)); + this.pushNewRecursionContext(localctx, _startState, RTRegexParser.RULE_expr); + this.state = 53; + if (!(this.precpred(this._ctx, 3))) { + throw this.createFailedPredicateException("this.precpred(this._ctx, 3)"); + } + this.state = 54; + (localctx as GSequenceContext)._op = this.match(RTRegexParser.SEQ); + this.state = 55; + this.expr(4); + } + break; + case 6: + { + localctx = new GDegradationContext(this, new ExprContext(this, _parentctx, _parentState)); + this.pushNewRecursionContext(localctx, _startState, RTRegexParser.RULE_expr); + this.state = 56; + if (!(this.precpred(this._ctx, 2))) { + throw this.createFailedPredicateException("this.precpred(this._ctx, 2)"); + } + this.state = 57; + (localctx as GDegradationContext)._op = this.match(RTRegexParser.T__9); + this.state = 58; + this.expr(3); + } + break; + case 7: + { + localctx = new GRetryContext(this, new ExprContext(this, _parentctx, _parentState)); + this.pushNewRecursionContext(localctx, _startState, RTRegexParser.RULE_expr); + this.state = 59; + if (!(this.precpred(this._ctx, 8))) { + throw this.createFailedPredicateException("this.precpred(this._ctx, 8)"); + } + this.state = 60; + (localctx as GRetryContext)._op = this.match(RTRegexParser.T__5); + this.state = 61; + this.match(RTRegexParser.FLOAT); + } + break; + } + } + } + this.state = 66; + this._errHandler.sync(this); + _alt = this._interp.adaptivePredict(this._input, 3, this._ctx); + } + } + } + catch (re) { + if (re instanceof RecognitionException) { + localctx.exception = re; + this._errHandler.reportError(this, re); + this._errHandler.recover(this, re); + } else { + throw re; + } + } + finally { + this.unrollRecursionContexts(_parentctx); + } + return localctx; + } + // @RuleVersion(0) + public id(): IdContext { + let localctx: IdContext = new IdContext(this, this._ctx, this.state); + this.enterRule(localctx, 4, RTRegexParser.RULE_id); + try { + this.state = 72; + this._errHandler.sync(this); + switch ( this._interp.adaptivePredict(this._input, 4, this._ctx) ) { + case 1: + this.enterOuterAlt(localctx, 1); + { + this.state = 67; + this.match(RTRegexParser.FLOAT); + } + break; + case 2: + this.enterOuterAlt(localctx, 2); + { + this.state = 68; + this.match(RTRegexParser.FLOAT); + this.state = 69; + this.match(RTRegexParser.X); + } + break; + case 3: + this.enterOuterAlt(localctx, 3); + { + this.state = 70; + this.match(RTRegexParser.X); + } + break; + case 4: + this.enterOuterAlt(localctx, 4); + { + this.state = 71; + this.match(RTRegexParser.DIGIT_SUBID); + } + break; + } + } + catch (re) { + if (re instanceof RecognitionException) { + localctx.exception = re; + this._errHandler.reportError(this, re); + this._errHandler.recover(this, re); + } else { + throw re; + } + } + finally { + this.exitRule(); + } + return localctx; + } + // @RuleVersion(0) + public word(): WordContext { + let localctx: WordContext = new WordContext(this, this._ctx, this.state); + this.enterRule(localctx, 6, RTRegexParser.RULE_word); + try { + this.enterOuterAlt(localctx, 1); + { + this.state = 74; + this.match(RTRegexParser.WORD); + } + } + catch (re) { + if (re instanceof RecognitionException) { + localctx.exception = re; + this._errHandler.reportError(this, re); + this._errHandler.recover(this, re); + } else { + throw re; + } + } + finally { + this.exitRule(); + } + return localctx; + } - public sempred( - localctx: RuleContext, - ruleIndex: number, - predIndex: number, - ): boolean { - switch (ruleIndex) { - case 1: - return this.expr_sempred(localctx as ExprContext, predIndex); - } - return true; - } - private expr_sempred(localctx: ExprContext, predIndex: number): boolean { - switch (predIndex) { - case 0: - return this.precpred(this._ctx, 6); - case 1: - return this.precpred(this._ctx, 5); - case 2: - return this.precpred(this._ctx, 4); - case 3: - return this.precpred(this._ctx, 3); - case 4: - return this.precpred(this._ctx, 7); - } - return true; - } + public sempred(localctx: RuleContext, ruleIndex: number, predIndex: number): boolean { + switch (ruleIndex) { + case 1: + return this.expr_sempred(localctx as ExprContext, predIndex); + } + return true; + } + private expr_sempred(localctx: ExprContext, predIndex: number): boolean { + switch (predIndex) { + case 0: + return this.precpred(this._ctx, 7); + case 1: + return this.precpred(this._ctx, 6); + case 2: + return this.precpred(this._ctx, 5); + case 3: + return this.precpred(this._ctx, 4); + case 4: + return this.precpred(this._ctx, 3); + case 5: + return this.precpred(this._ctx, 2); + case 6: + return this.precpred(this._ctx, 8); + } + return true; + } - public static readonly _serializedATN: number[] = [ - 4, 1, 21, 72, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 1, 0, 1, 0, 1, - 0, 1, 0, 3, 0, 13, 8, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 41, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 1, 58, 8, 1, - 10, 1, 12, 1, 61, 9, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 3, 2, 68, 8, 2, 1, 3, - 1, 3, 1, 3, 0, 1, 2, 4, 0, 2, 4, 6, 0, 1, 2, 0, 1, 1, 14, 15, 83, 0, 12, 1, - 0, 0, 0, 2, 40, 1, 0, 0, 0, 4, 67, 1, 0, 0, 0, 6, 69, 1, 0, 0, 0, 8, 9, 3, - 2, 1, 0, 9, 10, 5, 0, 0, 1, 10, 13, 1, 0, 0, 0, 11, 13, 5, 0, 0, 1, 12, 8, - 1, 0, 0, 0, 12, 11, 1, 0, 0, 0, 13, 1, 1, 0, 0, 0, 14, 15, 6, 1, -1, 0, 15, - 16, 7, 0, 0, 0, 16, 41, 3, 4, 2, 0, 17, 18, 7, 0, 0, 0, 18, 19, 3, 4, 2, 0, - 19, 20, 3, 2, 1, 12, 20, 41, 1, 0, 0, 0, 21, 22, 7, 0, 0, 0, 22, 23, 3, 4, - 2, 0, 23, 24, 5, 2, 0, 0, 24, 25, 3, 2, 1, 11, 25, 41, 1, 0, 0, 0, 26, 27, - 5, 3, 0, 0, 27, 28, 3, 2, 1, 0, 28, 29, 5, 4, 0, 0, 29, 41, 1, 0, 0, 0, 30, - 31, 5, 5, 0, 0, 31, 32, 3, 6, 3, 0, 32, 33, 3, 2, 1, 9, 33, 41, 1, 0, 0, 0, - 34, 35, 5, 5, 0, 0, 35, 36, 3, 6, 3, 0, 36, 37, 5, 0, 0, 1, 37, 41, 1, 0, 0, - 0, 38, 41, 5, 9, 0, 0, 39, 41, 5, 16, 0, 0, 40, 14, 1, 0, 0, 0, 40, 17, 1, - 0, 0, 0, 40, 21, 1, 0, 0, 0, 40, 26, 1, 0, 0, 0, 40, 30, 1, 0, 0, 0, 40, 34, - 1, 0, 0, 0, 40, 38, 1, 0, 0, 0, 40, 39, 1, 0, 0, 0, 41, 59, 1, 0, 0, 0, 42, - 43, 10, 6, 0, 0, 43, 44, 5, 7, 0, 0, 44, 58, 3, 2, 1, 7, 45, 46, 10, 5, 0, - 0, 46, 47, 5, 13, 0, 0, 47, 58, 3, 2, 1, 6, 48, 49, 10, 4, 0, 0, 49, 50, 5, - 12, 0, 0, 50, 58, 3, 2, 1, 5, 51, 52, 10, 3, 0, 0, 52, 53, 5, 8, 0, 0, 53, - 58, 3, 2, 1, 4, 54, 55, 10, 7, 0, 0, 55, 56, 5, 6, 0, 0, 56, 58, 5, 11, 0, - 0, 57, 42, 1, 0, 0, 0, 57, 45, 1, 0, 0, 0, 57, 48, 1, 0, 0, 0, 57, 51, 1, 0, - 0, 0, 57, 54, 1, 0, 0, 0, 58, 61, 1, 0, 0, 0, 59, 57, 1, 0, 0, 0, 59, 60, 1, - 0, 0, 0, 60, 3, 1, 0, 0, 0, 61, 59, 1, 0, 0, 0, 62, 68, 5, 11, 0, 0, 63, 64, - 5, 11, 0, 0, 64, 68, 5, 17, 0, 0, 65, 68, 5, 17, 0, 0, 66, 68, 5, 10, 0, 0, - 67, 62, 1, 0, 0, 0, 67, 63, 1, 0, 0, 0, 67, 65, 1, 0, 0, 0, 67, 66, 1, 0, 0, - 0, 68, 5, 1, 0, 0, 0, 69, 70, 5, 19, 0, 0, 70, 7, 1, 0, 0, 0, 5, 12, 40, 57, - 59, 67, - ]; + public static readonly _serializedATN: number[] = [4,1,22,77,2,0,7,0,2, + 1,7,1,2,2,7,2,2,3,7,3,1,0,1,0,1,0,1,0,3,0,13,8,0,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,3,1,40,8,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,1,63,8,1,10,1,12,1,66,9,1,1,2,1,2,1,2,1, + 2,1,2,3,2,73,8,2,1,3,1,3,1,3,0,1,2,4,0,2,4,6,0,1,2,0,1,1,15,16,89,0,12, + 1,0,0,0,2,39,1,0,0,0,4,72,1,0,0,0,6,74,1,0,0,0,8,9,3,2,1,0,9,10,5,0,0,1, + 10,13,1,0,0,0,11,13,5,0,0,1,12,8,1,0,0,0,12,11,1,0,0,0,13,1,1,0,0,0,14, + 15,6,1,-1,0,15,16,7,0,0,0,16,40,3,4,2,0,17,18,7,0,0,0,18,19,3,4,2,0,19, + 20,3,2,1,13,20,40,1,0,0,0,21,22,7,0,0,0,22,23,3,4,2,0,23,24,5,2,0,0,24, + 25,3,2,1,12,25,40,1,0,0,0,26,27,5,3,0,0,27,28,3,2,1,0,28,29,5,4,0,0,29, + 40,1,0,0,0,30,31,5,5,0,0,31,32,3,6,3,0,32,33,3,2,1,10,33,40,1,0,0,0,34, + 35,5,5,0,0,35,36,3,6,3,0,36,37,5,0,0,1,37,40,1,0,0,0,38,40,5,17,0,0,39, + 14,1,0,0,0,39,17,1,0,0,0,39,21,1,0,0,0,39,26,1,0,0,0,39,30,1,0,0,0,39,34, + 1,0,0,0,39,38,1,0,0,0,40,64,1,0,0,0,41,42,10,7,0,0,42,43,5,7,0,0,43,63, + 3,2,1,8,44,45,10,6,0,0,45,46,5,8,0,0,46,63,3,2,1,7,47,48,10,5,0,0,48,49, + 5,9,0,0,49,63,3,2,1,6,50,51,10,4,0,0,51,52,5,14,0,0,52,63,3,2,1,5,53,54, + 10,3,0,0,54,55,5,13,0,0,55,63,3,2,1,4,56,57,10,2,0,0,57,58,5,10,0,0,58, + 63,3,2,1,3,59,60,10,8,0,0,60,61,5,6,0,0,61,63,5,12,0,0,62,41,1,0,0,0,62, + 44,1,0,0,0,62,47,1,0,0,0,62,50,1,0,0,0,62,53,1,0,0,0,62,56,1,0,0,0,62,59, + 1,0,0,0,63,66,1,0,0,0,64,62,1,0,0,0,64,65,1,0,0,0,65,3,1,0,0,0,66,64,1, + 0,0,0,67,73,5,12,0,0,68,69,5,12,0,0,69,73,5,18,0,0,70,73,5,18,0,0,71,73, + 5,11,0,0,72,67,1,0,0,0,72,68,1,0,0,0,72,70,1,0,0,0,72,71,1,0,0,0,73,5,1, + 0,0,0,74,75,5,20,0,0,75,7,1,0,0,0,5,12,39,62,64,72]; - private static __ATN: ATN; - public static get _ATN(): ATN { - if (!RTRegexParser.__ATN) { - RTRegexParser.__ATN = new ATNDeserializer().deserialize( - RTRegexParser._serializedATN, - ); - } + private static __ATN: ATN; + public static get _ATN(): ATN { + if (!RTRegexParser.__ATN) { + RTRegexParser.__ATN = new ATNDeserializer().deserialize(RTRegexParser._serializedATN); + } - return RTRegexParser.__ATN; - } + return RTRegexParser.__ATN; + } + + + static DecisionsToDFA = RTRegexParser._ATN.decisionToState.map( (ds: DecisionState, index: number) => new DFA(ds, index) ); - static DecisionsToDFA = RTRegexParser._ATN.decisionToState.map( - (ds: DecisionState, index: number) => new DFA(ds, index), - ); } export class RtContext extends ParserRuleContext { - constructor( - parser?: RTRegexParser, - parent?: ParserRuleContext, - invokingState?: number, - ) { - super(parent, invokingState); - this.parser = parser; - } - public get ruleIndex(): number { - return RTRegexParser.RULE_rt; - } - public override copyFrom(ctx: RtContext): void { - super.copyFrom(ctx); - } + constructor(parser?: RTRegexParser, parent?: ParserRuleContext, invokingState?: number) { + super(parent, invokingState); + this.parser = parser; + } + public get ruleIndex(): number { + return RTRegexParser.RULE_rt; + } + public override copyFrom(ctx: RtContext): void { + super.copyFrom(ctx); + } } export class BlankContext extends RtContext { - constructor(parser: RTRegexParser, ctx: RtContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public EOF(): TerminalNode { - return this.getToken(RTRegexParser.EOF, 0); - } - public enterRule(listener: RTRegexListener): void { - if (listener.enterBlank) { - listener.enterBlank(this); - } - } - public exitRule(listener: RTRegexListener): void { - if (listener.exitBlank) { - listener.exitBlank(this); - } - } + constructor(parser: RTRegexParser, ctx: RtContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public EOF(): TerminalNode { + return this.getToken(RTRegexParser.EOF, 0); + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterBlank) { + listener.enterBlank(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitBlank) { + listener.exitBlank(this); + } + } } export class PrintExprContext extends RtContext { - constructor(parser: RTRegexParser, ctx: RtContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public expr(): ExprContext { - return this.getTypedRuleContext(ExprContext, 0) as ExprContext; - } - public EOF(): TerminalNode { - return this.getToken(RTRegexParser.EOF, 0); - } - public enterRule(listener: RTRegexListener): void { - if (listener.enterPrintExpr) { - listener.enterPrintExpr(this); - } - } - public exitRule(listener: RTRegexListener): void { - if (listener.exitPrintExpr) { - listener.exitPrintExpr(this); - } - } + constructor(parser: RTRegexParser, ctx: RtContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public expr(): ExprContext { + return this.getTypedRuleContext(ExprContext, 0) as ExprContext; + } + public EOF(): TerminalNode { + return this.getToken(RTRegexParser.EOF, 0); + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterPrintExpr) { + listener.enterPrintExpr(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitPrintExpr) { + listener.exitPrintExpr(this); + } + } } + export class ExprContext extends ParserRuleContext { - constructor( - parser?: RTRegexParser, - parent?: ParserRuleContext, - invokingState?: number, - ) { - super(parent, invokingState); - this.parser = parser; - } - public get ruleIndex(): number { - return RTRegexParser.RULE_expr; - } - public override copyFrom(ctx: ExprContext): void { - super.copyFrom(ctx); - } + constructor(parser?: RTRegexParser, parent?: ParserRuleContext, invokingState?: number) { + super(parent, invokingState); + this.parser = parser; + } + public get ruleIndex(): number { + return RTRegexParser.RULE_expr; + } + public override copyFrom(ctx: ExprContext): void { + super.copyFrom(ctx); + } +} +export class GAnyOrderContext extends ExprContext { + public _op!: Token; + constructor(parser: RTRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public expr_list(): ExprContext[] { + return this.getTypedRuleContexts(ExprContext) as ExprContext[]; + } + public expr(i: number): ExprContext { + return this.getTypedRuleContext(ExprContext, i) as ExprContext; + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterGAnyOrder) { + listener.enterGAnyOrder(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitGAnyOrder) { + listener.exitGAnyOrder(this); + } + } } export class GIdContext extends ExprContext { - public _t!: Token; - constructor(parser: RTRegexParser, ctx: ExprContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public id(): IdContext { - return this.getTypedRuleContext(IdContext, 0) as IdContext; - } - public GOAL(): TerminalNode { - return this.getToken(RTRegexParser.GOAL, 0); - } - public TASK(): TerminalNode { - return this.getToken(RTRegexParser.TASK, 0); - } - public enterRule(listener: RTRegexListener): void { - if (listener.enterGId) { - listener.enterGId(this); - } - } - public exitRule(listener: RTRegexListener): void { - if (listener.exitGId) { - listener.exitGId(this); - } - } + public _t!: Token; + constructor(parser: RTRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public id(): IdContext { + return this.getTypedRuleContext(IdContext, 0) as IdContext; + } + public GOAL(): TerminalNode { + return this.getToken(RTRegexParser.GOAL, 0); + } + public TASK(): TerminalNode { + return this.getToken(RTRegexParser.TASK, 0); + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterGId) { + listener.enterGId(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitGId) { + listener.exitGId(this); + } + } } export class NameOnlyContext extends ExprContext { - constructor(parser: RTRegexParser, ctx: ExprContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public word(): WordContext { - return this.getTypedRuleContext(WordContext, 0) as WordContext; - } - public EOF(): TerminalNode { - return this.getToken(RTRegexParser.EOF, 0); - } - public enterRule(listener: RTRegexListener): void { - if (listener.enterNameOnly) { - listener.enterNameOnly(this); - } - } - public exitRule(listener: RTRegexListener): void { - if (listener.exitNameOnly) { - listener.exitNameOnly(this); - } - } + constructor(parser: RTRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public word(): WordContext { + return this.getTypedRuleContext(WordContext, 0) as WordContext; + } + public EOF(): TerminalNode { + return this.getToken(RTRegexParser.EOF, 0); + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterNameOnly) { + listener.enterNameOnly(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitNameOnly) { + listener.exitNameOnly(this); + } + } } export class GInterleavedContext extends ExprContext { - public _op!: Token; - constructor(parser: RTRegexParser, ctx: ExprContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public expr_list(): ExprContext[] { - return this.getTypedRuleContexts(ExprContext) as ExprContext[]; - } - public expr(i: number): ExprContext { - return this.getTypedRuleContext(ExprContext, i) as ExprContext; - } - public INT(): TerminalNode { - return this.getToken(RTRegexParser.INT, 0); - } - public enterRule(listener: RTRegexListener): void { - if (listener.enterGInterleaved) { - listener.enterGInterleaved(this); - } - } - public exitRule(listener: RTRegexListener): void { - if (listener.exitGInterleaved) { - listener.exitGInterleaved(this); - } - } + public _op!: Token; + constructor(parser: RTRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public expr_list(): ExprContext[] { + return this.getTypedRuleContexts(ExprContext) as ExprContext[]; + } + public expr(i: number): ExprContext { + return this.getTypedRuleContext(ExprContext, i) as ExprContext; + } + public INT(): TerminalNode { + return this.getToken(RTRegexParser.INT, 0); + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterGInterleaved) { + listener.enterGInterleaved(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitGInterleaved) { + listener.exitGInterleaved(this); + } + } } export class GChoiceContext extends ExprContext { - public _op!: Token; - constructor(parser: RTRegexParser, ctx: ExprContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public enterRule(listener: RTRegexListener): void { - if (listener.enterGChoice) { - listener.enterGChoice(this); - } - } - public exitRule(listener: RTRegexListener): void { - if (listener.exitGChoice) { - listener.exitGChoice(this); - } - } + public _op!: Token; + constructor(parser: RTRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public expr_list(): ExprContext[] { + return this.getTypedRuleContexts(ExprContext) as ExprContext[]; + } + public expr(i: number): ExprContext { + return this.getTypedRuleContext(ExprContext, i) as ExprContext; + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterGChoice) { + listener.enterGChoice(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitGChoice) { + listener.exitGChoice(this); + } + } } export class GArgsContext extends ExprContext { - public _t!: Token; - constructor(parser: RTRegexParser, ctx: ExprContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public id(): IdContext { - return this.getTypedRuleContext(IdContext, 0) as IdContext; - } - public expr(): ExprContext { - return this.getTypedRuleContext(ExprContext, 0) as ExprContext; - } - public GOAL(): TerminalNode { - return this.getToken(RTRegexParser.GOAL, 0); - } - public TASK(): TerminalNode { - return this.getToken(RTRegexParser.TASK, 0); - } - public enterRule(listener: RTRegexListener): void { - if (listener.enterGArgs) { - listener.enterGArgs(this); - } - } - public exitRule(listener: RTRegexListener): void { - if (listener.exitGArgs) { - listener.exitGArgs(this); - } - } + public _t!: Token; + constructor(parser: RTRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public id(): IdContext { + return this.getTypedRuleContext(IdContext, 0) as IdContext; + } + public expr(): ExprContext { + return this.getTypedRuleContext(ExprContext, 0) as ExprContext; + } + public GOAL(): TerminalNode { + return this.getToken(RTRegexParser.GOAL, 0); + } + public TASK(): TerminalNode { + return this.getToken(RTRegexParser.TASK, 0); + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterGArgs) { + listener.enterGArgs(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitGArgs) { + listener.exitGArgs(this); + } + } } export class NameContinuedContext extends ExprContext { - constructor(parser: RTRegexParser, ctx: ExprContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public word(): WordContext { - return this.getTypedRuleContext(WordContext, 0) as WordContext; - } - public expr(): ExprContext { - return this.getTypedRuleContext(ExprContext, 0) as ExprContext; - } - public enterRule(listener: RTRegexListener): void { - if (listener.enterNameContinued) { - listener.enterNameContinued(this); - } - } - public exitRule(listener: RTRegexListener): void { - if (listener.exitNameContinued) { - listener.exitNameContinued(this); - } - } + constructor(parser: RTRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public word(): WordContext { + return this.getTypedRuleContext(WordContext, 0) as WordContext; + } + public expr(): ExprContext { + return this.getTypedRuleContext(ExprContext, 0) as ExprContext; + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterNameContinued) { + listener.enterNameContinued(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitNameContinued) { + listener.exitNameContinued(this); + } + } } export class GAlternativeContext extends ExprContext { - public _op!: Token; - constructor(parser: RTRegexParser, ctx: ExprContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public expr_list(): ExprContext[] { - return this.getTypedRuleContexts(ExprContext) as ExprContext[]; - } - public expr(i: number): ExprContext { - return this.getTypedRuleContext(ExprContext, i) as ExprContext; - } - public enterRule(listener: RTRegexListener): void { - if (listener.enterGAlternative) { - listener.enterGAlternative(this); - } - } - public exitRule(listener: RTRegexListener): void { - if (listener.exitGAlternative) { - listener.exitGAlternative(this); - } - } + public _op!: Token; + constructor(parser: RTRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public expr_list(): ExprContext[] { + return this.getTypedRuleContexts(ExprContext) as ExprContext[]; + } + public expr(i: number): ExprContext { + return this.getTypedRuleContext(ExprContext, i) as ExprContext; + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterGAlternative) { + listener.enterGAlternative(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitGAlternative) { + listener.exitGAlternative(this); + } + } } export class GDegradationContext extends ExprContext { - public _op!: Token; - constructor(parser: RTRegexParser, ctx: ExprContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public expr_list(): ExprContext[] { - return this.getTypedRuleContexts(ExprContext) as ExprContext[]; - } - public expr(i: number): ExprContext { - return this.getTypedRuleContext(ExprContext, i) as ExprContext; - } - public enterRule(listener: RTRegexListener): void { - if (listener.enterGDegradation) { - listener.enterGDegradation(this); - } - } - public exitRule(listener: RTRegexListener): void { - if (listener.exitGDegradation) { - listener.exitGDegradation(this); - } - } + public _op!: Token; + constructor(parser: RTRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public expr_list(): ExprContext[] { + return this.getTypedRuleContexts(ExprContext) as ExprContext[]; + } + public expr(i: number): ExprContext { + return this.getTypedRuleContext(ExprContext, i) as ExprContext; + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterGDegradation) { + listener.enterGDegradation(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitGDegradation) { + listener.exitGDegradation(this); + } + } } export class GSkipContext extends ExprContext { - constructor(parser: RTRegexParser, ctx: ExprContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public SKIPP(): TerminalNode { - return this.getToken(RTRegexParser.SKIPP, 0); - } - public enterRule(listener: RTRegexListener): void { - if (listener.enterGSkip) { - listener.enterGSkip(this); - } - } - public exitRule(listener: RTRegexListener): void { - if (listener.exitGSkip) { - listener.exitGSkip(this); - } - } + constructor(parser: RTRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public SKIPP(): TerminalNode { + return this.getToken(RTRegexParser.SKIPP, 0); + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterGSkip) { + listener.enterGSkip(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitGSkip) { + listener.exitGSkip(this); + } + } } export class NotationStartContext extends ExprContext { - constructor(parser: RTRegexParser, ctx: ExprContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public expr(): ExprContext { - return this.getTypedRuleContext(ExprContext, 0) as ExprContext; - } - public enterRule(listener: RTRegexListener): void { - if (listener.enterNotationStart) { - listener.enterNotationStart(this); - } - } - public exitRule(listener: RTRegexListener): void { - if (listener.exitNotationStart) { - listener.exitNotationStart(this); - } - } + constructor(parser: RTRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public expr(): ExprContext { + return this.getTypedRuleContext(ExprContext, 0) as ExprContext; + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterNotationStart) { + listener.enterNotationStart(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitNotationStart) { + listener.exitNotationStart(this); + } + } } export class GRetryContext extends ExprContext { - public _op!: Token; - constructor(parser: RTRegexParser, ctx: ExprContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public expr(): ExprContext { - return this.getTypedRuleContext(ExprContext, 0) as ExprContext; - } - public FLOAT(): TerminalNode { - return this.getToken(RTRegexParser.FLOAT, 0); - } - public enterRule(listener: RTRegexListener): void { - if (listener.enterGRetry) { - listener.enterGRetry(this); - } - } - public exitRule(listener: RTRegexListener): void { - if (listener.exitGRetry) { - listener.exitGRetry(this); - } - } + public _op!: Token; + constructor(parser: RTRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public expr(): ExprContext { + return this.getTypedRuleContext(ExprContext, 0) as ExprContext; + } + public FLOAT(): TerminalNode { + return this.getToken(RTRegexParser.FLOAT, 0); + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterGRetry) { + listener.enterGRetry(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitGRetry) { + listener.exitGRetry(this); + } + } } export class GSequenceContext extends ExprContext { - public _op!: Token; - constructor(parser: RTRegexParser, ctx: ExprContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public expr_list(): ExprContext[] { - return this.getTypedRuleContexts(ExprContext) as ExprContext[]; - } - public expr(i: number): ExprContext { - return this.getTypedRuleContext(ExprContext, i) as ExprContext; - } - public SEQ(): TerminalNode { - return this.getToken(RTRegexParser.SEQ, 0); - } - public enterRule(listener: RTRegexListener): void { - if (listener.enterGSequence) { - listener.enterGSequence(this); - } - } - public exitRule(listener: RTRegexListener): void { - if (listener.exitGSequence) { - listener.exitGSequence(this); - } - } + public _op!: Token; + constructor(parser: RTRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public expr_list(): ExprContext[] { + return this.getTypedRuleContexts(ExprContext) as ExprContext[]; + } + public expr(i: number): ExprContext { + return this.getTypedRuleContext(ExprContext, i) as ExprContext; + } + public SEQ(): TerminalNode { + return this.getToken(RTRegexParser.SEQ, 0); + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterGSequence) { + listener.enterGSequence(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitGSequence) { + listener.exitGSequence(this); + } + } } export class GIdContinuedContext extends ExprContext { - public _t!: Token; - constructor(parser: RTRegexParser, ctx: ExprContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public id(): IdContext { - return this.getTypedRuleContext(IdContext, 0) as IdContext; - } - public expr(): ExprContext { - return this.getTypedRuleContext(ExprContext, 0) as ExprContext; - } - public GOAL(): TerminalNode { - return this.getToken(RTRegexParser.GOAL, 0); - } - public TASK(): TerminalNode { - return this.getToken(RTRegexParser.TASK, 0); - } - public enterRule(listener: RTRegexListener): void { - if (listener.enterGIdContinued) { - listener.enterGIdContinued(this); - } - } - public exitRule(listener: RTRegexListener): void { - if (listener.exitGIdContinued) { - listener.exitGIdContinued(this); - } - } + public _t!: Token; + constructor(parser: RTRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public id(): IdContext { + return this.getTypedRuleContext(IdContext, 0) as IdContext; + } + public expr(): ExprContext { + return this.getTypedRuleContext(ExprContext, 0) as ExprContext; + } + public GOAL(): TerminalNode { + return this.getToken(RTRegexParser.GOAL, 0); + } + public TASK(): TerminalNode { + return this.getToken(RTRegexParser.TASK, 0); + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterGIdContinued) { + listener.enterGIdContinued(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitGIdContinued) { + listener.exitGIdContinued(this); + } + } } + export class IdContext extends ParserRuleContext { - constructor( - parser?: RTRegexParser, - parent?: ParserRuleContext, - invokingState?: number, - ) { - super(parent, invokingState); - this.parser = parser; - } - public FLOAT(): TerminalNode { - return this.getToken(RTRegexParser.FLOAT, 0); - } - public X(): TerminalNode { - return this.getToken(RTRegexParser.X, 0); - } - public DIGIT_SUBID(): TerminalNode { - return this.getToken(RTRegexParser.DIGIT_SUBID, 0); - } - public get ruleIndex(): number { - return RTRegexParser.RULE_id; - } - public enterRule(listener: RTRegexListener): void { - if (listener.enterId) { - listener.enterId(this); - } - } - public exitRule(listener: RTRegexListener): void { - if (listener.exitId) { - listener.exitId(this); - } - } + constructor(parser?: RTRegexParser, parent?: ParserRuleContext, invokingState?: number) { + super(parent, invokingState); + this.parser = parser; + } + public FLOAT(): TerminalNode { + return this.getToken(RTRegexParser.FLOAT, 0); + } + public X(): TerminalNode { + return this.getToken(RTRegexParser.X, 0); + } + public DIGIT_SUBID(): TerminalNode { + return this.getToken(RTRegexParser.DIGIT_SUBID, 0); + } + public get ruleIndex(): number { + return RTRegexParser.RULE_id; + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterId) { + listener.enterId(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitId) { + listener.exitId(this); + } + } } + export class WordContext extends ParserRuleContext { - constructor( - parser?: RTRegexParser, - parent?: ParserRuleContext, - invokingState?: number, - ) { - super(parent, invokingState); - this.parser = parser; - } - public WORD(): TerminalNode { - return this.getToken(RTRegexParser.WORD, 0); - } - public get ruleIndex(): number { - return RTRegexParser.RULE_word; - } - public enterRule(listener: RTRegexListener): void { - if (listener.enterWord) { - listener.enterWord(this); - } - } - public exitRule(listener: RTRegexListener): void { - if (listener.exitWord) { - listener.exitWord(this); - } - } + constructor(parser?: RTRegexParser, parent?: ParserRuleContext, invokingState?: number) { + super(parent, invokingState); + this.parser = parser; + } + public WORD(): TerminalNode { + return this.getToken(RTRegexParser.WORD, 0); + } + public get ruleIndex(): number { + return RTRegexParser.RULE_word; + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterWord) { + listener.enterWord(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitWord) { + listener.exitWord(this); + } + } } diff --git a/packages/goal-tree/src/parsers/goalNameParser.ts b/packages/goal-tree/src/parsers/goalNameParser.ts index 846bf74f..a5283428 100644 --- a/packages/goal-tree/src/parsers/goalNameParser.ts +++ b/packages/goal-tree/src/parsers/goalNameParser.ts @@ -5,6 +5,7 @@ import RTRegexListener from '../antlr/RTRegexListener'; import type { ExprContext, GAlternativeContext, + GAnyOrderContext, GChoiceContext, GDegradationContext, GIdContinuedContext, @@ -37,6 +38,7 @@ export const getGoalDetail = ({ let degradationList: string[] = []; let interleaved: string[] = []; let sequence: string[] = []; + let anyOrder: string[] = []; let retry: Dictionary = {}; let choice: boolean = false; class RTNotationTreeWalker extends RTRegexListener { @@ -48,7 +50,7 @@ export const getGoalDetail = ({ // Goal with ID, like G1 return [expr.getText()]; } else if (expr.getChildCount() === 3) { - // Binary operation (e.g., G1|G2, G1->G2, G1#G2, G1;G2) + // Binary operation (e.g., G1|G2, G1?G2, G1+G2, G1->G2, G1#G2, G1;G2) const left = this.extractGoalIds(expr.getChild(0) as ExprContext); const right = this.extractGoalIds(expr.getChild(2) as ExprContext); return [...left, ...right]; @@ -94,6 +96,13 @@ export const getGoalDetail = ({ .filter(Boolean); }; + exitGAnyOrder = (ctx: GAnyOrderContext) => { + anyOrder = ctx + .expr_list() + .flatMap((e) => this.extractGoalIds(e)) + .filter(Boolean); + }; + exitGRetry = (ctx: GRetryContext) => { const goalToRetry = ctx.expr().getText(); const amountOfRetries = ctx.FLOAT().getText(); @@ -101,7 +110,7 @@ export const getGoalDetail = ({ }; exitGChoice = (ctx: GChoiceContext) => { - choice = ctx._op.text === '+'; + choice = ctx._op.text === '?'; }; } @@ -135,6 +144,14 @@ export const getGoalDetail = ({ }; } + if (anyOrder.length > 0) { + return { + id, + goalName: goalSanitizedName.trim(), + executionDetail: { type: 'anyOrder', anyOrder }, + }; + } + if (alternative.length > 0) { return { id, diff --git a/packages/goal-tree/src/types/goalTree.ts b/packages/goal-tree/src/types/goalTree.ts index b827b097..6f36855b 100644 --- a/packages/goal-tree/src/types/goalTree.ts +++ b/packages/goal-tree/src/types/goalTree.ts @@ -14,6 +14,7 @@ export type GoalExecutionDetail = ( | { type: 'interleaved'; interleaved: string[] } | { type: 'alternative'; alternative: string[] } | { type: 'sequence'; sequence: string[] } + | { type: 'anyOrder'; anyOrder: string[] } | { type: 'degradation'; degradationList: string[] } | { type: 'decisionMaking'; dm: string[] } | { type: 'choice' } diff --git a/packages/goal-tree/test/parsers/goalNameParser.test.ts b/packages/goal-tree/test/parsers/goalNameParser.test.ts index aabcbc0b..df3a45da 100644 --- a/packages/goal-tree/test/parsers/goalNameParser.test.ts +++ b/packages/goal-tree/test/parsers/goalNameParser.test.ts @@ -57,6 +57,34 @@ describe('GoalNameParser', () => { }); }); + it('should handle any-order (unordered AND) goals', () => { + const goalText = 'G0: Any Order Goal [G1+G2]'; + const result = getGoalDetail({ goalText }); + + assert.deepStrictEqual(result, { + id: 'G0', + goalName: 'Any Order Goal', + executionDetail: { + type: 'anyOrder', + anyOrder: ['G1', 'G2'], + }, + }); + }); + + it('should handle any-order with multiple children', () => { + const goalText = 'G1: Unordered Tasks [G2+G3+G4+G5]'; + const result = getGoalDetail({ goalText }); + + assert.deepStrictEqual(result, { + id: 'G1', + goalName: 'Unordered Tasks', + executionDetail: { + type: 'anyOrder', + anyOrder: ['G2', 'G3', 'G4', 'G5'], + }, + }); + }); + it('should handle degradation goals', () => { const goalText = 'G8: Degradation Goal [G9->G10]'; const result = getGoalDetail({ goalText }); @@ -72,7 +100,7 @@ describe('GoalNameParser', () => { }); it('should handle choice goals', () => { - const goalText = 'G11: Choice Goal +'; + const goalText = 'G11: Choice Goal [G12?G13]'; const result = getGoalDetail({ goalText }); assert.deepStrictEqual(result, { @@ -84,6 +112,19 @@ describe('GoalNameParser', () => { }); }); + it('should handle choice with multiple children', () => { + const goalText = 'G1: Multiple Choices [G2?G3?G4?G5]'; + const result = getGoalDetail({ goalText }); + + assert.deepStrictEqual(result, { + id: 'G1', + goalName: 'Multiple Choices', + executionDetail: { + type: 'choice', + }, + }); + }); + it('should handle degradation goals with retry map', () => { const goalText = 'G1: Support in emergency [G3->G4@3]'; const result = getGoalDetail({ goalText }); diff --git a/packages/lib/grammar/RTRegex.g4 b/packages/lib/grammar/RTRegex.g4 index 79e05d71..00fd1de6 100644 --- a/packages/lib/grammar/RTRegex.g4 +++ b/packages/lib/grammar/RTRegex.g4 @@ -17,10 +17,11 @@ expr: | ':' word EOF # nameOnly | expr op = '@' FLOAT # gRetry | expr op = '|' expr # gAlternative + | expr op = '?' expr # gChoice + | expr op = '+' expr # gAnyOrder | expr op = '#' expr # gInterleaved | expr op = ';' expr # gSequence | expr op = '->' expr # gDegradation - | op = '+' # gChoice | SKIPP # gSkip; id: FLOAT | FLOAT X | X | DIGIT_SUBID; diff --git a/packages/lib/src/antlr/AssertionRegexLexer.ts b/packages/lib/src/antlr/AssertionRegexLexer.ts index 23880d51..01c1347c 100644 --- a/packages/lib/src/antlr/AssertionRegexLexer.ts +++ b/packages/lib/src/antlr/AssertionRegexLexer.ts @@ -1,178 +1,113 @@ // Generated from grammar/AssertionRegex.g4 by ANTLR 4.13.2 // noinspection ES6UnusedImports,JSUnusedGlobalSymbols,JSUnusedLocalSymbols import { - ATN, - ATNDeserializer, - CharStream, - DecisionState, - DFA, - Lexer, - LexerATNSimulator, - RuleContext, - PredictionContextCache, - Token, -} from 'antlr4'; + ATN, + ATNDeserializer, + CharStream, + DecisionState, DFA, + Lexer, + LexerATNSimulator, + RuleContext, + PredictionContextCache, + Token +} from "antlr4"; export default class AssertionRegexLexer extends Lexer { - public static readonly T__0 = 1; - public static readonly T__1 = 2; - public static readonly T__2 = 3; - public static readonly T__3 = 4; - public static readonly T__4 = 5; - public static readonly T__5 = 6; - public static readonly T__6 = 7; - public static readonly T__7 = 8; - public static readonly T__8 = 9; - public static readonly T__9 = 10; - public static readonly T__10 = 11; - public static readonly BOOLEAN = 12; - public static readonly ID = 13; - public static readonly INT = 14; - public static readonly WS = 15; - public static readonly EOF = Token.EOF; + public static readonly T__0 = 1; + public static readonly T__1 = 2; + public static readonly T__2 = 3; + public static readonly T__3 = 4; + public static readonly T__4 = 5; + public static readonly T__5 = 6; + public static readonly T__6 = 7; + public static readonly T__7 = 8; + public static readonly T__8 = 9; + public static readonly T__9 = 10; + public static readonly T__10 = 11; + public static readonly BOOLEAN = 12; + public static readonly ID = 13; + public static readonly INT = 14; + public static readonly WS = 15; + public static readonly EOF = Token.EOF; - public static readonly channelNames: string[] = [ - 'DEFAULT_TOKEN_CHANNEL', - 'HIDDEN', - ]; - public static readonly literalNames: (string | null)[] = [ - null, - "'&'", - "'|'", - "'!'", - "'('", - "')'", - "'='", - "'!='", - "'<'", - "'<='", - "'>'", - "'>='", - ]; - public static readonly symbolicNames: (string | null)[] = [ - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - 'BOOLEAN', - 'ID', - 'INT', - 'WS', - ]; - public static readonly modeNames: string[] = ['DEFAULT_MODE']; + public static readonly channelNames: string[] = [ "DEFAULT_TOKEN_CHANNEL", "HIDDEN" ]; + public static readonly literalNames: (string | null)[] = [ null, "'&'", + "'|'", "'!'", + "'('", "')'", + "'='", "'!='", + "'<'", "'<='", + "'>'", "'>='" ]; + public static readonly symbolicNames: (string | null)[] = [ null, null, + null, null, + null, null, + null, null, + null, null, + null, null, + "BOOLEAN", + "ID", "INT", + "WS" ]; + public static readonly modeNames: string[] = [ "DEFAULT_MODE", ]; - public static readonly ruleNames: string[] = [ - 'T__0', - 'T__1', - 'T__2', - 'T__3', - 'T__4', - 'T__5', - 'T__6', - 'T__7', - 'T__8', - 'T__9', - 'T__10', - 'BOOLEAN', - 'ID', - 'INT', - 'WS', - ]; + public static readonly ruleNames: string[] = [ + "T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6", "T__7", "T__8", + "T__9", "T__10", "BOOLEAN", "ID", "INT", "WS", + ]; - constructor(input: CharStream) { - super(input); - this._interp = new LexerATNSimulator( - this, - AssertionRegexLexer._ATN, - AssertionRegexLexer.DecisionsToDFA, - new PredictionContextCache(), - ); - } - public get grammarFileName(): string { - return 'AssertionRegex.g4'; - } + constructor(input: CharStream) { + super(input); + this._interp = new LexerATNSimulator(this, AssertionRegexLexer._ATN, AssertionRegexLexer.DecisionsToDFA, new PredictionContextCache()); + } - public get literalNames(): (string | null)[] { - return AssertionRegexLexer.literalNames; - } - public get symbolicNames(): (string | null)[] { - return AssertionRegexLexer.symbolicNames; - } - public get ruleNames(): string[] { - return AssertionRegexLexer.ruleNames; - } + public get grammarFileName(): string { return "AssertionRegex.g4"; } - public get serializedATN(): number[] { - return AssertionRegexLexer._serializedATN; - } + public get literalNames(): (string | null)[] { return AssertionRegexLexer.literalNames; } + public get symbolicNames(): (string | null)[] { return AssertionRegexLexer.symbolicNames; } + public get ruleNames(): string[] { return AssertionRegexLexer.ruleNames; } - public get channelNames(): string[] { - return AssertionRegexLexer.channelNames; - } + public get serializedATN(): number[] { return AssertionRegexLexer._serializedATN; } - public get modeNames(): string[] { - return AssertionRegexLexer.modeNames; - } + public get channelNames(): string[] { return AssertionRegexLexer.channelNames; } - public static readonly _serializedATN: number[] = [ - 4, 0, 15, 88, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, - 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, - 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 1, 0, 1, 0, 1, - 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, - 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, 10, 1, 10, 1, 10, 1, 11, 1, 11, - 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 3, 11, 66, 8, 11, 1, 12, 1, - 12, 5, 12, 70, 8, 12, 10, 12, 12, 12, 73, 9, 12, 1, 13, 1, 13, 5, 13, 77, 8, - 13, 10, 13, 12, 13, 80, 9, 13, 1, 14, 4, 14, 83, 8, 14, 11, 14, 12, 14, 84, - 1, 14, 1, 14, 0, 0, 15, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, - 17, 9, 19, 10, 21, 11, 23, 12, 25, 13, 27, 14, 29, 15, 1, 0, 5, 3, 0, 65, - 90, 95, 95, 97, 122, 4, 0, 48, 57, 65, 90, 95, 95, 97, 122, 1, 0, 49, 57, 1, - 0, 48, 57, 3, 0, 9, 10, 13, 13, 32, 32, 91, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, - 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, - 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, - 0, 21, 1, 0, 0, 0, 0, 23, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, 27, 1, 0, 0, 0, - 0, 29, 1, 0, 0, 0, 1, 31, 1, 0, 0, 0, 3, 33, 1, 0, 0, 0, 5, 35, 1, 0, 0, 0, - 7, 37, 1, 0, 0, 0, 9, 39, 1, 0, 0, 0, 11, 41, 1, 0, 0, 0, 13, 43, 1, 0, 0, - 0, 15, 46, 1, 0, 0, 0, 17, 48, 1, 0, 0, 0, 19, 51, 1, 0, 0, 0, 21, 53, 1, 0, - 0, 0, 23, 65, 1, 0, 0, 0, 25, 67, 1, 0, 0, 0, 27, 74, 1, 0, 0, 0, 29, 82, 1, - 0, 0, 0, 31, 32, 5, 38, 0, 0, 32, 2, 1, 0, 0, 0, 33, 34, 5, 124, 0, 0, 34, - 4, 1, 0, 0, 0, 35, 36, 5, 33, 0, 0, 36, 6, 1, 0, 0, 0, 37, 38, 5, 40, 0, 0, - 38, 8, 1, 0, 0, 0, 39, 40, 5, 41, 0, 0, 40, 10, 1, 0, 0, 0, 41, 42, 5, 61, - 0, 0, 42, 12, 1, 0, 0, 0, 43, 44, 5, 33, 0, 0, 44, 45, 5, 61, 0, 0, 45, 14, - 1, 0, 0, 0, 46, 47, 5, 60, 0, 0, 47, 16, 1, 0, 0, 0, 48, 49, 5, 60, 0, 0, - 49, 50, 5, 61, 0, 0, 50, 18, 1, 0, 0, 0, 51, 52, 5, 62, 0, 0, 52, 20, 1, 0, - 0, 0, 53, 54, 5, 62, 0, 0, 54, 55, 5, 61, 0, 0, 55, 22, 1, 0, 0, 0, 56, 57, - 5, 116, 0, 0, 57, 58, 5, 114, 0, 0, 58, 59, 5, 117, 0, 0, 59, 66, 5, 101, 0, - 0, 60, 61, 5, 102, 0, 0, 61, 62, 5, 97, 0, 0, 62, 63, 5, 108, 0, 0, 63, 64, - 5, 115, 0, 0, 64, 66, 5, 101, 0, 0, 65, 56, 1, 0, 0, 0, 65, 60, 1, 0, 0, 0, - 66, 24, 1, 0, 0, 0, 67, 71, 7, 0, 0, 0, 68, 70, 7, 1, 0, 0, 69, 68, 1, 0, 0, - 0, 70, 73, 1, 0, 0, 0, 71, 69, 1, 0, 0, 0, 71, 72, 1, 0, 0, 0, 72, 26, 1, 0, - 0, 0, 73, 71, 1, 0, 0, 0, 74, 78, 7, 2, 0, 0, 75, 77, 7, 3, 0, 0, 76, 75, 1, - 0, 0, 0, 77, 80, 1, 0, 0, 0, 78, 76, 1, 0, 0, 0, 78, 79, 1, 0, 0, 0, 79, 28, - 1, 0, 0, 0, 80, 78, 1, 0, 0, 0, 81, 83, 7, 4, 0, 0, 82, 81, 1, 0, 0, 0, 83, - 84, 1, 0, 0, 0, 84, 82, 1, 0, 0, 0, 84, 85, 1, 0, 0, 0, 85, 86, 1, 0, 0, 0, - 86, 87, 6, 14, 0, 0, 87, 30, 1, 0, 0, 0, 5, 0, 65, 71, 78, 84, 1, 6, 0, 0, - ]; + public get modeNames(): string[] { return AssertionRegexLexer.modeNames; } - private static __ATN: ATN; - public static get _ATN(): ATN { - if (!AssertionRegexLexer.__ATN) { - AssertionRegexLexer.__ATN = new ATNDeserializer().deserialize( - AssertionRegexLexer._serializedATN, - ); - } + public static readonly _serializedATN: number[] = [4,0,15,88,6,-1,2,0,7, + 0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7,6,2,7,7,7,2,8,7,8,2,9,7, + 9,2,10,7,10,2,11,7,11,2,12,7,12,2,13,7,13,2,14,7,14,1,0,1,0,1,1,1,1,1,2, + 1,2,1,3,1,3,1,4,1,4,1,5,1,5,1,6,1,6,1,6,1,7,1,7,1,8,1,8,1,8,1,9,1,9,1,10, + 1,10,1,10,1,11,1,11,1,11,1,11,1,11,1,11,1,11,1,11,1,11,3,11,66,8,11,1,12, + 1,12,5,12,70,8,12,10,12,12,12,73,9,12,1,13,1,13,5,13,77,8,13,10,13,12,13, + 80,9,13,1,14,4,14,83,8,14,11,14,12,14,84,1,14,1,14,0,0,15,1,1,3,2,5,3,7, + 4,9,5,11,6,13,7,15,8,17,9,19,10,21,11,23,12,25,13,27,14,29,15,1,0,5,3,0, + 65,90,95,95,97,122,4,0,48,57,65,90,95,95,97,122,1,0,49,57,1,0,48,57,3,0, + 9,10,13,13,32,32,91,0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,1,0,0,0,0,9, + 1,0,0,0,0,11,1,0,0,0,0,13,1,0,0,0,0,15,1,0,0,0,0,17,1,0,0,0,0,19,1,0,0, + 0,0,21,1,0,0,0,0,23,1,0,0,0,0,25,1,0,0,0,0,27,1,0,0,0,0,29,1,0,0,0,1,31, + 1,0,0,0,3,33,1,0,0,0,5,35,1,0,0,0,7,37,1,0,0,0,9,39,1,0,0,0,11,41,1,0,0, + 0,13,43,1,0,0,0,15,46,1,0,0,0,17,48,1,0,0,0,19,51,1,0,0,0,21,53,1,0,0,0, + 23,65,1,0,0,0,25,67,1,0,0,0,27,74,1,0,0,0,29,82,1,0,0,0,31,32,5,38,0,0, + 32,2,1,0,0,0,33,34,5,124,0,0,34,4,1,0,0,0,35,36,5,33,0,0,36,6,1,0,0,0,37, + 38,5,40,0,0,38,8,1,0,0,0,39,40,5,41,0,0,40,10,1,0,0,0,41,42,5,61,0,0,42, + 12,1,0,0,0,43,44,5,33,0,0,44,45,5,61,0,0,45,14,1,0,0,0,46,47,5,60,0,0,47, + 16,1,0,0,0,48,49,5,60,0,0,49,50,5,61,0,0,50,18,1,0,0,0,51,52,5,62,0,0,52, + 20,1,0,0,0,53,54,5,62,0,0,54,55,5,61,0,0,55,22,1,0,0,0,56,57,5,116,0,0, + 57,58,5,114,0,0,58,59,5,117,0,0,59,66,5,101,0,0,60,61,5,102,0,0,61,62,5, + 97,0,0,62,63,5,108,0,0,63,64,5,115,0,0,64,66,5,101,0,0,65,56,1,0,0,0,65, + 60,1,0,0,0,66,24,1,0,0,0,67,71,7,0,0,0,68,70,7,1,0,0,69,68,1,0,0,0,70,73, + 1,0,0,0,71,69,1,0,0,0,71,72,1,0,0,0,72,26,1,0,0,0,73,71,1,0,0,0,74,78,7, + 2,0,0,75,77,7,3,0,0,76,75,1,0,0,0,77,80,1,0,0,0,78,76,1,0,0,0,78,79,1,0, + 0,0,79,28,1,0,0,0,80,78,1,0,0,0,81,83,7,4,0,0,82,81,1,0,0,0,83,84,1,0,0, + 0,84,82,1,0,0,0,84,85,1,0,0,0,85,86,1,0,0,0,86,87,6,14,0,0,87,30,1,0,0, + 0,5,0,65,71,78,84,1,6,0,0]; - return AssertionRegexLexer.__ATN; - } + private static __ATN: ATN; + public static get _ATN(): ATN { + if (!AssertionRegexLexer.__ATN) { + AssertionRegexLexer.__ATN = new ATNDeserializer().deserialize(AssertionRegexLexer._serializedATN); + } - static DecisionsToDFA = AssertionRegexLexer._ATN.decisionToState.map( - (ds: DecisionState, index: number) => new DFA(ds, index), - ); -} + return AssertionRegexLexer.__ATN; + } + + + static DecisionsToDFA = AssertionRegexLexer._ATN.decisionToState.map( (ds: DecisionState, index: number) => new DFA(ds, index) ); +} \ No newline at end of file diff --git a/packages/lib/src/antlr/AssertionRegexListener.ts b/packages/lib/src/antlr/AssertionRegexListener.ts index be1f2927..b9902d63 100644 --- a/packages/lib/src/antlr/AssertionRegexListener.ts +++ b/packages/lib/src/antlr/AssertionRegexListener.ts @@ -1,152 +1,155 @@ // Generated from grammar/AssertionRegex.g4 by ANTLR 4.13.2 -import { ParseTreeListener } from 'antlr4'; +import {ParseTreeListener} from "antlr4"; + + +import { PrintExprContext } from "./AssertionRegexParser.js"; +import { BlankContext } from "./AssertionRegexParser.js"; +import { IdentifierContext } from "./AssertionRegexParser.js"; +import { NotExprContext } from "./AssertionRegexParser.js"; +import { BooleanContext } from "./AssertionRegexParser.js"; +import { AssignmentContext } from "./AssertionRegexParser.js"; +import { IntComparisonContext } from "./AssertionRegexParser.js"; +import { OrExprContext } from "./AssertionRegexParser.js"; +import { ParenExprContext } from "./AssertionRegexParser.js"; +import { AndExprContext } from "./AssertionRegexParser.js"; +import { ComparatorContext } from "./AssertionRegexParser.js"; -import { PrintExprContext } from './AssertionRegexParser.js'; -import { BlankContext } from './AssertionRegexParser.js'; -import { IdentifierContext } from './AssertionRegexParser.js'; -import { NotExprContext } from './AssertionRegexParser.js'; -import { BooleanContext } from './AssertionRegexParser.js'; -import { AssignmentContext } from './AssertionRegexParser.js'; -import { IntComparisonContext } from './AssertionRegexParser.js'; -import { OrExprContext } from './AssertionRegexParser.js'; -import { ParenExprContext } from './AssertionRegexParser.js'; -import { AndExprContext } from './AssertionRegexParser.js'; -import { ComparatorContext } from './AssertionRegexParser.js'; /** * This interface defines a complete listener for a parse tree produced by * `AssertionRegexParser`. */ export default class AssertionRegexListener extends ParseTreeListener { - /** - * Enter a parse tree produced by the `printExpr` - * labeled alternative in `AssertionRegexParser.assertion`. - * @param ctx the parse tree - */ - enterPrintExpr?: (ctx: PrintExprContext) => void; - /** - * Exit a parse tree produced by the `printExpr` - * labeled alternative in `AssertionRegexParser.assertion`. - * @param ctx the parse tree - */ - exitPrintExpr?: (ctx: PrintExprContext) => void; - /** - * Enter a parse tree produced by the `blank` - * labeled alternative in `AssertionRegexParser.assertion`. - * @param ctx the parse tree - */ - enterBlank?: (ctx: BlankContext) => void; - /** - * Exit a parse tree produced by the `blank` - * labeled alternative in `AssertionRegexParser.assertion`. - * @param ctx the parse tree - */ - exitBlank?: (ctx: BlankContext) => void; - /** - * Enter a parse tree produced by the `identifier` - * labeled alternative in `AssertionRegexParser.expr`. - * @param ctx the parse tree - */ - enterIdentifier?: (ctx: IdentifierContext) => void; - /** - * Exit a parse tree produced by the `identifier` - * labeled alternative in `AssertionRegexParser.expr`. - * @param ctx the parse tree - */ - exitIdentifier?: (ctx: IdentifierContext) => void; - /** - * Enter a parse tree produced by the `notExpr` - * labeled alternative in `AssertionRegexParser.expr`. - * @param ctx the parse tree - */ - enterNotExpr?: (ctx: NotExprContext) => void; - /** - * Exit a parse tree produced by the `notExpr` - * labeled alternative in `AssertionRegexParser.expr`. - * @param ctx the parse tree - */ - exitNotExpr?: (ctx: NotExprContext) => void; - /** - * Enter a parse tree produced by the `boolean` - * labeled alternative in `AssertionRegexParser.expr`. - * @param ctx the parse tree - */ - enterBoolean?: (ctx: BooleanContext) => void; - /** - * Exit a parse tree produced by the `boolean` - * labeled alternative in `AssertionRegexParser.expr`. - * @param ctx the parse tree - */ - exitBoolean?: (ctx: BooleanContext) => void; - /** - * Enter a parse tree produced by the `assignment` - * labeled alternative in `AssertionRegexParser.expr`. - * @param ctx the parse tree - */ - enterAssignment?: (ctx: AssignmentContext) => void; - /** - * Exit a parse tree produced by the `assignment` - * labeled alternative in `AssertionRegexParser.expr`. - * @param ctx the parse tree - */ - exitAssignment?: (ctx: AssignmentContext) => void; - /** - * Enter a parse tree produced by the `intComparison` - * labeled alternative in `AssertionRegexParser.expr`. - * @param ctx the parse tree - */ - enterIntComparison?: (ctx: IntComparisonContext) => void; - /** - * Exit a parse tree produced by the `intComparison` - * labeled alternative in `AssertionRegexParser.expr`. - * @param ctx the parse tree - */ - exitIntComparison?: (ctx: IntComparisonContext) => void; - /** - * Enter a parse tree produced by the `orExpr` - * labeled alternative in `AssertionRegexParser.expr`. - * @param ctx the parse tree - */ - enterOrExpr?: (ctx: OrExprContext) => void; - /** - * Exit a parse tree produced by the `orExpr` - * labeled alternative in `AssertionRegexParser.expr`. - * @param ctx the parse tree - */ - exitOrExpr?: (ctx: OrExprContext) => void; - /** - * Enter a parse tree produced by the `parenExpr` - * labeled alternative in `AssertionRegexParser.expr`. - * @param ctx the parse tree - */ - enterParenExpr?: (ctx: ParenExprContext) => void; - /** - * Exit a parse tree produced by the `parenExpr` - * labeled alternative in `AssertionRegexParser.expr`. - * @param ctx the parse tree - */ - exitParenExpr?: (ctx: ParenExprContext) => void; - /** - * Enter a parse tree produced by the `andExpr` - * labeled alternative in `AssertionRegexParser.expr`. - * @param ctx the parse tree - */ - enterAndExpr?: (ctx: AndExprContext) => void; - /** - * Exit a parse tree produced by the `andExpr` - * labeled alternative in `AssertionRegexParser.expr`. - * @param ctx the parse tree - */ - exitAndExpr?: (ctx: AndExprContext) => void; - /** - * Enter a parse tree produced by `AssertionRegexParser.comparator`. - * @param ctx the parse tree - */ - enterComparator?: (ctx: ComparatorContext) => void; - /** - * Exit a parse tree produced by `AssertionRegexParser.comparator`. - * @param ctx the parse tree - */ - exitComparator?: (ctx: ComparatorContext) => void; + /** + * Enter a parse tree produced by the `printExpr` + * labeled alternative in `AssertionRegexParser.assertion`. + * @param ctx the parse tree + */ + enterPrintExpr?: (ctx: PrintExprContext) => void; + /** + * Exit a parse tree produced by the `printExpr` + * labeled alternative in `AssertionRegexParser.assertion`. + * @param ctx the parse tree + */ + exitPrintExpr?: (ctx: PrintExprContext) => void; + /** + * Enter a parse tree produced by the `blank` + * labeled alternative in `AssertionRegexParser.assertion`. + * @param ctx the parse tree + */ + enterBlank?: (ctx: BlankContext) => void; + /** + * Exit a parse tree produced by the `blank` + * labeled alternative in `AssertionRegexParser.assertion`. + * @param ctx the parse tree + */ + exitBlank?: (ctx: BlankContext) => void; + /** + * Enter a parse tree produced by the `identifier` + * labeled alternative in `AssertionRegexParser.expr`. + * @param ctx the parse tree + */ + enterIdentifier?: (ctx: IdentifierContext) => void; + /** + * Exit a parse tree produced by the `identifier` + * labeled alternative in `AssertionRegexParser.expr`. + * @param ctx the parse tree + */ + exitIdentifier?: (ctx: IdentifierContext) => void; + /** + * Enter a parse tree produced by the `notExpr` + * labeled alternative in `AssertionRegexParser.expr`. + * @param ctx the parse tree + */ + enterNotExpr?: (ctx: NotExprContext) => void; + /** + * Exit a parse tree produced by the `notExpr` + * labeled alternative in `AssertionRegexParser.expr`. + * @param ctx the parse tree + */ + exitNotExpr?: (ctx: NotExprContext) => void; + /** + * Enter a parse tree produced by the `boolean` + * labeled alternative in `AssertionRegexParser.expr`. + * @param ctx the parse tree + */ + enterBoolean?: (ctx: BooleanContext) => void; + /** + * Exit a parse tree produced by the `boolean` + * labeled alternative in `AssertionRegexParser.expr`. + * @param ctx the parse tree + */ + exitBoolean?: (ctx: BooleanContext) => void; + /** + * Enter a parse tree produced by the `assignment` + * labeled alternative in `AssertionRegexParser.expr`. + * @param ctx the parse tree + */ + enterAssignment?: (ctx: AssignmentContext) => void; + /** + * Exit a parse tree produced by the `assignment` + * labeled alternative in `AssertionRegexParser.expr`. + * @param ctx the parse tree + */ + exitAssignment?: (ctx: AssignmentContext) => void; + /** + * Enter a parse tree produced by the `intComparison` + * labeled alternative in `AssertionRegexParser.expr`. + * @param ctx the parse tree + */ + enterIntComparison?: (ctx: IntComparisonContext) => void; + /** + * Exit a parse tree produced by the `intComparison` + * labeled alternative in `AssertionRegexParser.expr`. + * @param ctx the parse tree + */ + exitIntComparison?: (ctx: IntComparisonContext) => void; + /** + * Enter a parse tree produced by the `orExpr` + * labeled alternative in `AssertionRegexParser.expr`. + * @param ctx the parse tree + */ + enterOrExpr?: (ctx: OrExprContext) => void; + /** + * Exit a parse tree produced by the `orExpr` + * labeled alternative in `AssertionRegexParser.expr`. + * @param ctx the parse tree + */ + exitOrExpr?: (ctx: OrExprContext) => void; + /** + * Enter a parse tree produced by the `parenExpr` + * labeled alternative in `AssertionRegexParser.expr`. + * @param ctx the parse tree + */ + enterParenExpr?: (ctx: ParenExprContext) => void; + /** + * Exit a parse tree produced by the `parenExpr` + * labeled alternative in `AssertionRegexParser.expr`. + * @param ctx the parse tree + */ + exitParenExpr?: (ctx: ParenExprContext) => void; + /** + * Enter a parse tree produced by the `andExpr` + * labeled alternative in `AssertionRegexParser.expr`. + * @param ctx the parse tree + */ + enterAndExpr?: (ctx: AndExprContext) => void; + /** + * Exit a parse tree produced by the `andExpr` + * labeled alternative in `AssertionRegexParser.expr`. + * @param ctx the parse tree + */ + exitAndExpr?: (ctx: AndExprContext) => void; + /** + * Enter a parse tree produced by `AssertionRegexParser.comparator`. + * @param ctx the parse tree + */ + enterComparator?: (ctx: ComparatorContext) => void; + /** + * Exit a parse tree produced by `AssertionRegexParser.comparator`. + * @param ctx the parse tree + */ + exitComparator?: (ctx: ComparatorContext) => void; } + diff --git a/packages/lib/src/antlr/AssertionRegexParser.ts b/packages/lib/src/antlr/AssertionRegexParser.ts index 3a184a42..b175f8b4 100644 --- a/packages/lib/src/antlr/AssertionRegexParser.ts +++ b/packages/lib/src/antlr/AssertionRegexParser.ts @@ -2,699 +2,609 @@ // noinspection ES6UnusedImports,JSUnusedGlobalSymbols,JSUnusedLocalSymbols import { - ATN, - ATNDeserializer, - DecisionState, - DFA, - FailedPredicateException, - RecognitionException, - NoViableAltException, - BailErrorStrategy, - Parser, - ParserATNSimulator, - RuleContext, - ParserRuleContext, - PredictionMode, - PredictionContextCache, - TerminalNode, - RuleNode, - Token, - TokenStream, - Interval, - IntervalSet, + ATN, + ATNDeserializer, DecisionState, DFA, FailedPredicateException, + RecognitionException, NoViableAltException, BailErrorStrategy, + Parser, ParserATNSimulator, + RuleContext, ParserRuleContext, PredictionMode, PredictionContextCache, + TerminalNode, RuleNode, + Token, TokenStream, + Interval, IntervalSet } from 'antlr4'; -import AssertionRegexListener from './AssertionRegexListener.js'; +import AssertionRegexListener from "./AssertionRegexListener.js"; // for running tests with parameters, TODO: discuss strategy for typed parameters in CI // eslint-disable-next-line no-unused-vars type int = number; export default class AssertionRegexParser extends Parser { - public static readonly T__0 = 1; - public static readonly T__1 = 2; - public static readonly T__2 = 3; - public static readonly T__3 = 4; - public static readonly T__4 = 5; - public static readonly T__5 = 6; - public static readonly T__6 = 7; - public static readonly T__7 = 8; - public static readonly T__8 = 9; - public static readonly T__9 = 10; - public static readonly T__10 = 11; - public static readonly BOOLEAN = 12; - public static readonly ID = 13; - public static readonly INT = 14; - public static readonly WS = 15; - public static override readonly EOF = Token.EOF; - public static readonly RULE_assertion = 0; - public static readonly RULE_expr = 1; - public static readonly RULE_comparator = 2; - public static readonly literalNames: (string | null)[] = [ - null, - "'&'", - "'|'", - "'!'", - "'('", - "')'", - "'='", - "'!='", - "'<'", - "'<='", - "'>'", - "'>='", - ]; - public static readonly symbolicNames: (string | null)[] = [ - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - 'BOOLEAN', - 'ID', - 'INT', - 'WS', - ]; - // tslint:disable:no-trailing-whitespace - public static readonly ruleNames: string[] = [ - 'assertion', - 'expr', - 'comparator', - ]; - public get grammarFileName(): string { - return 'AssertionRegex.g4'; - } - public get literalNames(): (string | null)[] { - return AssertionRegexParser.literalNames; - } - public get symbolicNames(): (string | null)[] { - return AssertionRegexParser.symbolicNames; - } - public get ruleNames(): string[] { - return AssertionRegexParser.ruleNames; - } - public get serializedATN(): number[] { - return AssertionRegexParser._serializedATN; - } + public static readonly T__0 = 1; + public static readonly T__1 = 2; + public static readonly T__2 = 3; + public static readonly T__3 = 4; + public static readonly T__4 = 5; + public static readonly T__5 = 6; + public static readonly T__6 = 7; + public static readonly T__7 = 8; + public static readonly T__8 = 9; + public static readonly T__9 = 10; + public static readonly T__10 = 11; + public static readonly BOOLEAN = 12; + public static readonly ID = 13; + public static readonly INT = 14; + public static readonly WS = 15; + public static override readonly EOF = Token.EOF; + public static readonly RULE_assertion = 0; + public static readonly RULE_expr = 1; + public static readonly RULE_comparator = 2; + public static readonly literalNames: (string | null)[] = [ null, "'&'", + "'|'", "'!'", + "'('", "')'", + "'='", "'!='", + "'<'", "'<='", + "'>'", "'>='" ]; + public static readonly symbolicNames: (string | null)[] = [ null, null, + null, null, + null, null, + null, null, + null, null, + null, null, + "BOOLEAN", + "ID", "INT", + "WS" ]; + // tslint:disable:no-trailing-whitespace + public static readonly ruleNames: string[] = [ + "assertion", "expr", "comparator", + ]; + public get grammarFileName(): string { return "AssertionRegex.g4"; } + public get literalNames(): (string | null)[] { return AssertionRegexParser.literalNames; } + public get symbolicNames(): (string | null)[] { return AssertionRegexParser.symbolicNames; } + public get ruleNames(): string[] { return AssertionRegexParser.ruleNames; } + public get serializedATN(): number[] { return AssertionRegexParser._serializedATN; } - protected createFailedPredicateException( - predicate?: string, - message?: string, - ): FailedPredicateException { - return new FailedPredicateException(this, predicate, message); - } + protected createFailedPredicateException(predicate?: string, message?: string): FailedPredicateException { + return new FailedPredicateException(this, predicate, message); + } - constructor(input: TokenStream) { - super(input); - this._interp = new ParserATNSimulator( - this, - AssertionRegexParser._ATN, - AssertionRegexParser.DecisionsToDFA, - new PredictionContextCache(), - ); - } - // @RuleVersion(0) - public assertion(): AssertionContext { - let localctx: AssertionContext = new AssertionContext( - this, - this._ctx, - this.state, - ); - this.enterRule(localctx, 0, AssertionRegexParser.RULE_assertion); - try { - this.state = 10; - this._errHandler.sync(this); - switch (this._input.LA(1)) { - case 3: - case 4: - case 12: - case 13: - localctx = new PrintExprContext(this, localctx); - this.enterOuterAlt(localctx, 1); - { - this.state = 6; - this.expr(0); - this.state = 7; - this.match(AssertionRegexParser.EOF); - } - break; - case -1: - localctx = new BlankContext(this, localctx); - this.enterOuterAlt(localctx, 2); - { - this.state = 9; - this.match(AssertionRegexParser.EOF); - } - break; - default: - throw new NoViableAltException(this); - } - } catch (re) { - if (re instanceof RecognitionException) { - localctx.exception = re; - this._errHandler.reportError(this, re); - this._errHandler.recover(this, re); - } else { - throw re; - } - } finally { - this.exitRule(); - } - return localctx; - } + constructor(input: TokenStream) { + super(input); + this._interp = new ParserATNSimulator(this, AssertionRegexParser._ATN, AssertionRegexParser.DecisionsToDFA, new PredictionContextCache()); + } + // @RuleVersion(0) + public assertion(): AssertionContext { + let localctx: AssertionContext = new AssertionContext(this, this._ctx, this.state); + this.enterRule(localctx, 0, AssertionRegexParser.RULE_assertion); + try { + this.state = 10; + this._errHandler.sync(this); + switch (this._input.LA(1)) { + case 3: + case 4: + case 12: + case 13: + localctx = new PrintExprContext(this, localctx); + this.enterOuterAlt(localctx, 1); + { + this.state = 6; + this.expr(0); + this.state = 7; + this.match(AssertionRegexParser.EOF); + } + break; + case -1: + localctx = new BlankContext(this, localctx); + this.enterOuterAlt(localctx, 2); + { + this.state = 9; + this.match(AssertionRegexParser.EOF); + } + break; + default: + throw new NoViableAltException(this); + } + } + catch (re) { + if (re instanceof RecognitionException) { + localctx.exception = re; + this._errHandler.reportError(this, re); + this._errHandler.recover(this, re); + } else { + throw re; + } + } + finally { + this.exitRule(); + } + return localctx; + } - public expr(): ExprContext; - public expr(_p: number): ExprContext; - // @RuleVersion(0) - public expr(_p?: number): ExprContext { - if (_p === undefined) { - _p = 0; - } + public expr(): ExprContext; + public expr(_p: number): ExprContext; + // @RuleVersion(0) + public expr(_p?: number): ExprContext { + if (_p === undefined) { + _p = 0; + } - let _parentctx: ParserRuleContext = this._ctx; - let _parentState: number = this.state; - let localctx: ExprContext = new ExprContext(this, this._ctx, _parentState); - let _prevctx: ExprContext = localctx; - let _startState: number = 2; - this.enterRecursionRule(localctx, 2, AssertionRegexParser.RULE_expr, _p); - try { - let _alt: number; - this.enterOuterAlt(localctx, 1); - { - this.state = 28; - this._errHandler.sync(this); - switch (this._interp.adaptivePredict(this._input, 1, this._ctx)) { - case 1: - { - localctx = new NotExprContext(this, localctx); - this._ctx = localctx; - _prevctx = localctx; + let _parentctx: ParserRuleContext = this._ctx; + let _parentState: number = this.state; + let localctx: ExprContext = new ExprContext(this, this._ctx, _parentState); + let _prevctx: ExprContext = localctx; + let _startState: number = 2; + this.enterRecursionRule(localctx, 2, AssertionRegexParser.RULE_expr, _p); + try { + let _alt: number; + this.enterOuterAlt(localctx, 1); + { + this.state = 28; + this._errHandler.sync(this); + switch ( this._interp.adaptivePredict(this._input, 1, this._ctx) ) { + case 1: + { + localctx = new NotExprContext(this, localctx); + this._ctx = localctx; + _prevctx = localctx; - this.state = 13; - this.match(AssertionRegexParser.T__2); - this.state = 14; - this.expr(6); - } - break; - case 2: - { - localctx = new ParenExprContext(this, localctx); - this._ctx = localctx; - _prevctx = localctx; - this.state = 15; - this.match(AssertionRegexParser.T__3); - this.state = 16; - this.expr(0); - this.state = 17; - this.match(AssertionRegexParser.T__4); - } - break; - case 3: - { - localctx = new AssignmentContext(this, localctx); - this._ctx = localctx; - _prevctx = localctx; - this.state = 19; - this.match(AssertionRegexParser.ID); - this.state = 20; - this.match(AssertionRegexParser.T__5); - this.state = 21; - this.match(AssertionRegexParser.BOOLEAN); - } - break; - case 4: - { - localctx = new IntComparisonContext(this, localctx); - this._ctx = localctx; - _prevctx = localctx; - this.state = 22; - this.match(AssertionRegexParser.ID); - this.state = 23; - this.comparator(); - this.state = 24; - this.match(AssertionRegexParser.INT); - } - break; - case 5: - { - localctx = new IdentifierContext(this, localctx); - this._ctx = localctx; - _prevctx = localctx; - this.state = 26; - this.match(AssertionRegexParser.ID); - } - break; - case 6: - { - localctx = new BooleanContext(this, localctx); - this._ctx = localctx; - _prevctx = localctx; - this.state = 27; - this.match(AssertionRegexParser.BOOLEAN); - } - break; - } - this._ctx.stop = this._input.LT(-1); - this.state = 38; - this._errHandler.sync(this); - _alt = this._interp.adaptivePredict(this._input, 3, this._ctx); - while (_alt !== 2 && _alt !== ATN.INVALID_ALT_NUMBER) { - if (_alt === 1) { - if (this._parseListeners != null) { - this.triggerExitRuleEvent(); - } - _prevctx = localctx; - { - this.state = 36; - this._errHandler.sync(this); - switch (this._interp.adaptivePredict(this._input, 2, this._ctx)) { - case 1: - { - localctx = new AndExprContext( - this, - new ExprContext(this, _parentctx, _parentState), - ); - this.pushNewRecursionContext( - localctx, - _startState, - AssertionRegexParser.RULE_expr, - ); - this.state = 30; - if (!this.precpred(this._ctx, 8)) { - throw this.createFailedPredicateException( - 'this.precpred(this._ctx, 8)', - ); - } - this.state = 31; - this.match(AssertionRegexParser.T__0); - this.state = 32; - this.expr(9); - } - break; - case 2: - { - localctx = new OrExprContext( - this, - new ExprContext(this, _parentctx, _parentState), - ); - this.pushNewRecursionContext( - localctx, - _startState, - AssertionRegexParser.RULE_expr, - ); - this.state = 33; - if (!this.precpred(this._ctx, 7)) { - throw this.createFailedPredicateException( - 'this.precpred(this._ctx, 7)', - ); - } - this.state = 34; - this.match(AssertionRegexParser.T__1); - this.state = 35; - this.expr(8); - } - break; - } - } - } - this.state = 40; - this._errHandler.sync(this); - _alt = this._interp.adaptivePredict(this._input, 3, this._ctx); - } - } - } catch (re) { - if (re instanceof RecognitionException) { - localctx.exception = re; - this._errHandler.reportError(this, re); - this._errHandler.recover(this, re); - } else { - throw re; - } - } finally { - this.unrollRecursionContexts(_parentctx); - } - return localctx; - } - // @RuleVersion(0) - public comparator(): ComparatorContext { - let localctx: ComparatorContext = new ComparatorContext( - this, - this._ctx, - this.state, - ); - this.enterRule(localctx, 4, AssertionRegexParser.RULE_comparator); - let _la: number; - try { - this.enterOuterAlt(localctx, 1); - { - this.state = 41; - _la = this._input.LA(1); - if (!((_la & ~0x1f) === 0 && ((1 << _la) & 4032) !== 0)) { - this._errHandler.recoverInline(this); - } else { - this._errHandler.reportMatch(this); - this.consume(); - } - } - } catch (re) { - if (re instanceof RecognitionException) { - localctx.exception = re; - this._errHandler.reportError(this, re); - this._errHandler.recover(this, re); - } else { - throw re; - } - } finally { - this.exitRule(); - } - return localctx; - } + this.state = 13; + this.match(AssertionRegexParser.T__2); + this.state = 14; + this.expr(6); + } + break; + case 2: + { + localctx = new ParenExprContext(this, localctx); + this._ctx = localctx; + _prevctx = localctx; + this.state = 15; + this.match(AssertionRegexParser.T__3); + this.state = 16; + this.expr(0); + this.state = 17; + this.match(AssertionRegexParser.T__4); + } + break; + case 3: + { + localctx = new AssignmentContext(this, localctx); + this._ctx = localctx; + _prevctx = localctx; + this.state = 19; + this.match(AssertionRegexParser.ID); + this.state = 20; + this.match(AssertionRegexParser.T__5); + this.state = 21; + this.match(AssertionRegexParser.BOOLEAN); + } + break; + case 4: + { + localctx = new IntComparisonContext(this, localctx); + this._ctx = localctx; + _prevctx = localctx; + this.state = 22; + this.match(AssertionRegexParser.ID); + this.state = 23; + this.comparator(); + this.state = 24; + this.match(AssertionRegexParser.INT); + } + break; + case 5: + { + localctx = new IdentifierContext(this, localctx); + this._ctx = localctx; + _prevctx = localctx; + this.state = 26; + this.match(AssertionRegexParser.ID); + } + break; + case 6: + { + localctx = new BooleanContext(this, localctx); + this._ctx = localctx; + _prevctx = localctx; + this.state = 27; + this.match(AssertionRegexParser.BOOLEAN); + } + break; + } + this._ctx.stop = this._input.LT(-1); + this.state = 38; + this._errHandler.sync(this); + _alt = this._interp.adaptivePredict(this._input, 3, this._ctx); + while (_alt !== 2 && _alt !== ATN.INVALID_ALT_NUMBER) { + if (_alt === 1) { + if (this._parseListeners != null) { + this.triggerExitRuleEvent(); + } + _prevctx = localctx; + { + this.state = 36; + this._errHandler.sync(this); + switch ( this._interp.adaptivePredict(this._input, 2, this._ctx) ) { + case 1: + { + localctx = new AndExprContext(this, new ExprContext(this, _parentctx, _parentState)); + this.pushNewRecursionContext(localctx, _startState, AssertionRegexParser.RULE_expr); + this.state = 30; + if (!(this.precpred(this._ctx, 8))) { + throw this.createFailedPredicateException("this.precpred(this._ctx, 8)"); + } + this.state = 31; + this.match(AssertionRegexParser.T__0); + this.state = 32; + this.expr(9); + } + break; + case 2: + { + localctx = new OrExprContext(this, new ExprContext(this, _parentctx, _parentState)); + this.pushNewRecursionContext(localctx, _startState, AssertionRegexParser.RULE_expr); + this.state = 33; + if (!(this.precpred(this._ctx, 7))) { + throw this.createFailedPredicateException("this.precpred(this._ctx, 7)"); + } + this.state = 34; + this.match(AssertionRegexParser.T__1); + this.state = 35; + this.expr(8); + } + break; + } + } + } + this.state = 40; + this._errHandler.sync(this); + _alt = this._interp.adaptivePredict(this._input, 3, this._ctx); + } + } + } + catch (re) { + if (re instanceof RecognitionException) { + localctx.exception = re; + this._errHandler.reportError(this, re); + this._errHandler.recover(this, re); + } else { + throw re; + } + } + finally { + this.unrollRecursionContexts(_parentctx); + } + return localctx; + } + // @RuleVersion(0) + public comparator(): ComparatorContext { + let localctx: ComparatorContext = new ComparatorContext(this, this._ctx, this.state); + this.enterRule(localctx, 4, AssertionRegexParser.RULE_comparator); + let _la: number; + try { + this.enterOuterAlt(localctx, 1); + { + this.state = 41; + _la = this._input.LA(1); + if(!((((_la) & ~0x1F) === 0 && ((1 << _la) & 4032) !== 0))) { + this._errHandler.recoverInline(this); + } + else { + this._errHandler.reportMatch(this); + this.consume(); + } + } + } + catch (re) { + if (re instanceof RecognitionException) { + localctx.exception = re; + this._errHandler.reportError(this, re); + this._errHandler.recover(this, re); + } else { + throw re; + } + } + finally { + this.exitRule(); + } + return localctx; + } - public sempred( - localctx: RuleContext, - ruleIndex: number, - predIndex: number, - ): boolean { - switch (ruleIndex) { - case 1: - return this.expr_sempred(localctx as ExprContext, predIndex); - } - return true; - } - private expr_sempred(localctx: ExprContext, predIndex: number): boolean { - switch (predIndex) { - case 0: - return this.precpred(this._ctx, 8); - case 1: - return this.precpred(this._ctx, 7); - } - return true; - } + public sempred(localctx: RuleContext, ruleIndex: number, predIndex: number): boolean { + switch (ruleIndex) { + case 1: + return this.expr_sempred(localctx as ExprContext, predIndex); + } + return true; + } + private expr_sempred(localctx: ExprContext, predIndex: number): boolean { + switch (predIndex) { + case 0: + return this.precpred(this._ctx, 8); + case 1: + return this.precpred(this._ctx, 7); + } + return true; + } - public static readonly _serializedATN: number[] = [ - 4, 1, 15, 44, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 1, 0, 1, 0, 1, 0, 1, 0, 3, - 0, 11, 8, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 29, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 5, 1, 37, 8, 1, 10, 1, 12, 1, 40, 9, 1, 1, 2, 1, 2, 1, 2, 0, 1, 2, - 3, 0, 2, 4, 0, 1, 1, 0, 6, 11, 48, 0, 10, 1, 0, 0, 0, 2, 28, 1, 0, 0, 0, 4, - 41, 1, 0, 0, 0, 6, 7, 3, 2, 1, 0, 7, 8, 5, 0, 0, 1, 8, 11, 1, 0, 0, 0, 9, - 11, 5, 0, 0, 1, 10, 6, 1, 0, 0, 0, 10, 9, 1, 0, 0, 0, 11, 1, 1, 0, 0, 0, 12, - 13, 6, 1, -1, 0, 13, 14, 5, 3, 0, 0, 14, 29, 3, 2, 1, 6, 15, 16, 5, 4, 0, 0, - 16, 17, 3, 2, 1, 0, 17, 18, 5, 5, 0, 0, 18, 29, 1, 0, 0, 0, 19, 20, 5, 13, - 0, 0, 20, 21, 5, 6, 0, 0, 21, 29, 5, 12, 0, 0, 22, 23, 5, 13, 0, 0, 23, 24, - 3, 4, 2, 0, 24, 25, 5, 14, 0, 0, 25, 29, 1, 0, 0, 0, 26, 29, 5, 13, 0, 0, - 27, 29, 5, 12, 0, 0, 28, 12, 1, 0, 0, 0, 28, 15, 1, 0, 0, 0, 28, 19, 1, 0, - 0, 0, 28, 22, 1, 0, 0, 0, 28, 26, 1, 0, 0, 0, 28, 27, 1, 0, 0, 0, 29, 38, 1, - 0, 0, 0, 30, 31, 10, 8, 0, 0, 31, 32, 5, 1, 0, 0, 32, 37, 3, 2, 1, 9, 33, - 34, 10, 7, 0, 0, 34, 35, 5, 2, 0, 0, 35, 37, 3, 2, 1, 8, 36, 30, 1, 0, 0, 0, - 36, 33, 1, 0, 0, 0, 37, 40, 1, 0, 0, 0, 38, 36, 1, 0, 0, 0, 38, 39, 1, 0, 0, - 0, 39, 3, 1, 0, 0, 0, 40, 38, 1, 0, 0, 0, 41, 42, 7, 0, 0, 0, 42, 5, 1, 0, - 0, 0, 4, 10, 28, 36, 38, - ]; + public static readonly _serializedATN: number[] = [4,1,15,44,2,0,7,0,2, + 1,7,1,2,2,7,2,1,0,1,0,1,0,1,0,3,0,11,8,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,1,29,8,1,1,1,1,1,1,1,1,1,1,1,1,1,5, + 1,37,8,1,10,1,12,1,40,9,1,1,2,1,2,1,2,0,1,2,3,0,2,4,0,1,1,0,6,11,48,0,10, + 1,0,0,0,2,28,1,0,0,0,4,41,1,0,0,0,6,7,3,2,1,0,7,8,5,0,0,1,8,11,1,0,0,0, + 9,11,5,0,0,1,10,6,1,0,0,0,10,9,1,0,0,0,11,1,1,0,0,0,12,13,6,1,-1,0,13,14, + 5,3,0,0,14,29,3,2,1,6,15,16,5,4,0,0,16,17,3,2,1,0,17,18,5,5,0,0,18,29,1, + 0,0,0,19,20,5,13,0,0,20,21,5,6,0,0,21,29,5,12,0,0,22,23,5,13,0,0,23,24, + 3,4,2,0,24,25,5,14,0,0,25,29,1,0,0,0,26,29,5,13,0,0,27,29,5,12,0,0,28,12, + 1,0,0,0,28,15,1,0,0,0,28,19,1,0,0,0,28,22,1,0,0,0,28,26,1,0,0,0,28,27,1, + 0,0,0,29,38,1,0,0,0,30,31,10,8,0,0,31,32,5,1,0,0,32,37,3,2,1,9,33,34,10, + 7,0,0,34,35,5,2,0,0,35,37,3,2,1,8,36,30,1,0,0,0,36,33,1,0,0,0,37,40,1,0, + 0,0,38,36,1,0,0,0,38,39,1,0,0,0,39,3,1,0,0,0,40,38,1,0,0,0,41,42,7,0,0, + 0,42,5,1,0,0,0,4,10,28,36,38]; - private static __ATN: ATN; - public static get _ATN(): ATN { - if (!AssertionRegexParser.__ATN) { - AssertionRegexParser.__ATN = new ATNDeserializer().deserialize( - AssertionRegexParser._serializedATN, - ); - } + private static __ATN: ATN; + public static get _ATN(): ATN { + if (!AssertionRegexParser.__ATN) { + AssertionRegexParser.__ATN = new ATNDeserializer().deserialize(AssertionRegexParser._serializedATN); + } - return AssertionRegexParser.__ATN; - } + return AssertionRegexParser.__ATN; + } + + + static DecisionsToDFA = AssertionRegexParser._ATN.decisionToState.map( (ds: DecisionState, index: number) => new DFA(ds, index) ); - static DecisionsToDFA = AssertionRegexParser._ATN.decisionToState.map( - (ds: DecisionState, index: number) => new DFA(ds, index), - ); } export class AssertionContext extends ParserRuleContext { - constructor( - parser?: AssertionRegexParser, - parent?: ParserRuleContext, - invokingState?: number, - ) { - super(parent, invokingState); - this.parser = parser; - } - public get ruleIndex(): number { - return AssertionRegexParser.RULE_assertion; - } - public override copyFrom(ctx: AssertionContext): void { - super.copyFrom(ctx); - } + constructor(parser?: AssertionRegexParser, parent?: ParserRuleContext, invokingState?: number) { + super(parent, invokingState); + this.parser = parser; + } + public get ruleIndex(): number { + return AssertionRegexParser.RULE_assertion; + } + public override copyFrom(ctx: AssertionContext): void { + super.copyFrom(ctx); + } } export class BlankContext extends AssertionContext { - constructor(parser: AssertionRegexParser, ctx: AssertionContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public EOF(): TerminalNode { - return this.getToken(AssertionRegexParser.EOF, 0); - } - public enterRule(listener: AssertionRegexListener): void { - if (listener.enterBlank) { - listener.enterBlank(this); - } - } - public exitRule(listener: AssertionRegexListener): void { - if (listener.exitBlank) { - listener.exitBlank(this); - } - } + constructor(parser: AssertionRegexParser, ctx: AssertionContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public EOF(): TerminalNode { + return this.getToken(AssertionRegexParser.EOF, 0); + } + public enterRule(listener: AssertionRegexListener): void { + if(listener.enterBlank) { + listener.enterBlank(this); + } + } + public exitRule(listener: AssertionRegexListener): void { + if(listener.exitBlank) { + listener.exitBlank(this); + } + } } export class PrintExprContext extends AssertionContext { - constructor(parser: AssertionRegexParser, ctx: AssertionContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public expr(): ExprContext { - return this.getTypedRuleContext(ExprContext, 0) as ExprContext; - } - public EOF(): TerminalNode { - return this.getToken(AssertionRegexParser.EOF, 0); - } - public enterRule(listener: AssertionRegexListener): void { - if (listener.enterPrintExpr) { - listener.enterPrintExpr(this); - } - } - public exitRule(listener: AssertionRegexListener): void { - if (listener.exitPrintExpr) { - listener.exitPrintExpr(this); - } - } + constructor(parser: AssertionRegexParser, ctx: AssertionContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public expr(): ExprContext { + return this.getTypedRuleContext(ExprContext, 0) as ExprContext; + } + public EOF(): TerminalNode { + return this.getToken(AssertionRegexParser.EOF, 0); + } + public enterRule(listener: AssertionRegexListener): void { + if(listener.enterPrintExpr) { + listener.enterPrintExpr(this); + } + } + public exitRule(listener: AssertionRegexListener): void { + if(listener.exitPrintExpr) { + listener.exitPrintExpr(this); + } + } } + export class ExprContext extends ParserRuleContext { - constructor( - parser?: AssertionRegexParser, - parent?: ParserRuleContext, - invokingState?: number, - ) { - super(parent, invokingState); - this.parser = parser; - } - public get ruleIndex(): number { - return AssertionRegexParser.RULE_expr; - } - public override copyFrom(ctx: ExprContext): void { - super.copyFrom(ctx); - } + constructor(parser?: AssertionRegexParser, parent?: ParserRuleContext, invokingState?: number) { + super(parent, invokingState); + this.parser = parser; + } + public get ruleIndex(): number { + return AssertionRegexParser.RULE_expr; + } + public override copyFrom(ctx: ExprContext): void { + super.copyFrom(ctx); + } } export class IdentifierContext extends ExprContext { - constructor(parser: AssertionRegexParser, ctx: ExprContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public ID(): TerminalNode { - return this.getToken(AssertionRegexParser.ID, 0); - } - public enterRule(listener: AssertionRegexListener): void { - if (listener.enterIdentifier) { - listener.enterIdentifier(this); - } - } - public exitRule(listener: AssertionRegexListener): void { - if (listener.exitIdentifier) { - listener.exitIdentifier(this); - } - } + constructor(parser: AssertionRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public ID(): TerminalNode { + return this.getToken(AssertionRegexParser.ID, 0); + } + public enterRule(listener: AssertionRegexListener): void { + if(listener.enterIdentifier) { + listener.enterIdentifier(this); + } + } + public exitRule(listener: AssertionRegexListener): void { + if(listener.exitIdentifier) { + listener.exitIdentifier(this); + } + } } export class NotExprContext extends ExprContext { - constructor(parser: AssertionRegexParser, ctx: ExprContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public expr(): ExprContext { - return this.getTypedRuleContext(ExprContext, 0) as ExprContext; - } - public enterRule(listener: AssertionRegexListener): void { - if (listener.enterNotExpr) { - listener.enterNotExpr(this); - } - } - public exitRule(listener: AssertionRegexListener): void { - if (listener.exitNotExpr) { - listener.exitNotExpr(this); - } - } + constructor(parser: AssertionRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public expr(): ExprContext { + return this.getTypedRuleContext(ExprContext, 0) as ExprContext; + } + public enterRule(listener: AssertionRegexListener): void { + if(listener.enterNotExpr) { + listener.enterNotExpr(this); + } + } + public exitRule(listener: AssertionRegexListener): void { + if(listener.exitNotExpr) { + listener.exitNotExpr(this); + } + } } export class BooleanContext extends ExprContext { - constructor(parser: AssertionRegexParser, ctx: ExprContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public BOOLEAN(): TerminalNode { - return this.getToken(AssertionRegexParser.BOOLEAN, 0); - } - public enterRule(listener: AssertionRegexListener): void { - if (listener.enterBoolean) { - listener.enterBoolean(this); - } - } - public exitRule(listener: AssertionRegexListener): void { - if (listener.exitBoolean) { - listener.exitBoolean(this); - } - } + constructor(parser: AssertionRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public BOOLEAN(): TerminalNode { + return this.getToken(AssertionRegexParser.BOOLEAN, 0); + } + public enterRule(listener: AssertionRegexListener): void { + if(listener.enterBoolean) { + listener.enterBoolean(this); + } + } + public exitRule(listener: AssertionRegexListener): void { + if(listener.exitBoolean) { + listener.exitBoolean(this); + } + } } export class AssignmentContext extends ExprContext { - constructor(parser: AssertionRegexParser, ctx: ExprContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public ID(): TerminalNode { - return this.getToken(AssertionRegexParser.ID, 0); - } - public BOOLEAN(): TerminalNode { - return this.getToken(AssertionRegexParser.BOOLEAN, 0); - } - public enterRule(listener: AssertionRegexListener): void { - if (listener.enterAssignment) { - listener.enterAssignment(this); - } - } - public exitRule(listener: AssertionRegexListener): void { - if (listener.exitAssignment) { - listener.exitAssignment(this); - } - } + constructor(parser: AssertionRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public ID(): TerminalNode { + return this.getToken(AssertionRegexParser.ID, 0); + } + public BOOLEAN(): TerminalNode { + return this.getToken(AssertionRegexParser.BOOLEAN, 0); + } + public enterRule(listener: AssertionRegexListener): void { + if(listener.enterAssignment) { + listener.enterAssignment(this); + } + } + public exitRule(listener: AssertionRegexListener): void { + if(listener.exitAssignment) { + listener.exitAssignment(this); + } + } } export class IntComparisonContext extends ExprContext { - constructor(parser: AssertionRegexParser, ctx: ExprContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public ID(): TerminalNode { - return this.getToken(AssertionRegexParser.ID, 0); - } - public comparator(): ComparatorContext { - return this.getTypedRuleContext(ComparatorContext, 0) as ComparatorContext; - } - public INT(): TerminalNode { - return this.getToken(AssertionRegexParser.INT, 0); - } - public enterRule(listener: AssertionRegexListener): void { - if (listener.enterIntComparison) { - listener.enterIntComparison(this); - } - } - public exitRule(listener: AssertionRegexListener): void { - if (listener.exitIntComparison) { - listener.exitIntComparison(this); - } - } + constructor(parser: AssertionRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public ID(): TerminalNode { + return this.getToken(AssertionRegexParser.ID, 0); + } + public comparator(): ComparatorContext { + return this.getTypedRuleContext(ComparatorContext, 0) as ComparatorContext; + } + public INT(): TerminalNode { + return this.getToken(AssertionRegexParser.INT, 0); + } + public enterRule(listener: AssertionRegexListener): void { + if(listener.enterIntComparison) { + listener.enterIntComparison(this); + } + } + public exitRule(listener: AssertionRegexListener): void { + if(listener.exitIntComparison) { + listener.exitIntComparison(this); + } + } } export class OrExprContext extends ExprContext { - constructor(parser: AssertionRegexParser, ctx: ExprContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public expr_list(): ExprContext[] { - return this.getTypedRuleContexts(ExprContext) as ExprContext[]; - } - public expr(i: number): ExprContext { - return this.getTypedRuleContext(ExprContext, i) as ExprContext; - } - public enterRule(listener: AssertionRegexListener): void { - if (listener.enterOrExpr) { - listener.enterOrExpr(this); - } - } - public exitRule(listener: AssertionRegexListener): void { - if (listener.exitOrExpr) { - listener.exitOrExpr(this); - } - } + constructor(parser: AssertionRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public expr_list(): ExprContext[] { + return this.getTypedRuleContexts(ExprContext) as ExprContext[]; + } + public expr(i: number): ExprContext { + return this.getTypedRuleContext(ExprContext, i) as ExprContext; + } + public enterRule(listener: AssertionRegexListener): void { + if(listener.enterOrExpr) { + listener.enterOrExpr(this); + } + } + public exitRule(listener: AssertionRegexListener): void { + if(listener.exitOrExpr) { + listener.exitOrExpr(this); + } + } } export class ParenExprContext extends ExprContext { - constructor(parser: AssertionRegexParser, ctx: ExprContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public expr(): ExprContext { - return this.getTypedRuleContext(ExprContext, 0) as ExprContext; - } - public enterRule(listener: AssertionRegexListener): void { - if (listener.enterParenExpr) { - listener.enterParenExpr(this); - } - } - public exitRule(listener: AssertionRegexListener): void { - if (listener.exitParenExpr) { - listener.exitParenExpr(this); - } - } + constructor(parser: AssertionRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public expr(): ExprContext { + return this.getTypedRuleContext(ExprContext, 0) as ExprContext; + } + public enterRule(listener: AssertionRegexListener): void { + if(listener.enterParenExpr) { + listener.enterParenExpr(this); + } + } + public exitRule(listener: AssertionRegexListener): void { + if(listener.exitParenExpr) { + listener.exitParenExpr(this); + } + } } export class AndExprContext extends ExprContext { - constructor(parser: AssertionRegexParser, ctx: ExprContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public expr_list(): ExprContext[] { - return this.getTypedRuleContexts(ExprContext) as ExprContext[]; - } - public expr(i: number): ExprContext { - return this.getTypedRuleContext(ExprContext, i) as ExprContext; - } - public enterRule(listener: AssertionRegexListener): void { - if (listener.enterAndExpr) { - listener.enterAndExpr(this); - } - } - public exitRule(listener: AssertionRegexListener): void { - if (listener.exitAndExpr) { - listener.exitAndExpr(this); - } - } + constructor(parser: AssertionRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public expr_list(): ExprContext[] { + return this.getTypedRuleContexts(ExprContext) as ExprContext[]; + } + public expr(i: number): ExprContext { + return this.getTypedRuleContext(ExprContext, i) as ExprContext; + } + public enterRule(listener: AssertionRegexListener): void { + if(listener.enterAndExpr) { + listener.enterAndExpr(this); + } + } + public exitRule(listener: AssertionRegexListener): void { + if(listener.exitAndExpr) { + listener.exitAndExpr(this); + } + } } + export class ComparatorContext extends ParserRuleContext { - constructor( - parser?: AssertionRegexParser, - parent?: ParserRuleContext, - invokingState?: number, - ) { - super(parent, invokingState); - this.parser = parser; - } - public get ruleIndex(): number { - return AssertionRegexParser.RULE_comparator; - } - public enterRule(listener: AssertionRegexListener): void { - if (listener.enterComparator) { - listener.enterComparator(this); - } - } - public exitRule(listener: AssertionRegexListener): void { - if (listener.exitComparator) { - listener.exitComparator(this); - } - } + constructor(parser?: AssertionRegexParser, parent?: ParserRuleContext, invokingState?: number) { + super(parent, invokingState); + this.parser = parser; + } + public get ruleIndex(): number { + return AssertionRegexParser.RULE_comparator; + } + public enterRule(listener: AssertionRegexListener): void { + if(listener.enterComparator) { + listener.enterComparator(this); + } + } + public exitRule(listener: AssertionRegexListener): void { + if(listener.exitComparator) { + listener.exitComparator(this); + } + } } diff --git a/packages/lib/src/antlr/RTRegexLexer.ts b/packages/lib/src/antlr/RTRegexLexer.ts index df27ffe5..d015b90c 100644 --- a/packages/lib/src/antlr/RTRegexLexer.ts +++ b/packages/lib/src/antlr/RTRegexLexer.ts @@ -1,216 +1,138 @@ -// Generated from grammar/RTRegex.g4 by ANTLR 4.13.2 +// Generated from RTRegex.g4 by ANTLR 4.13.2 // noinspection ES6UnusedImports,JSUnusedGlobalSymbols,JSUnusedLocalSymbols import { - ATN, - ATNDeserializer, - CharStream, - DecisionState, - DFA, - Lexer, - LexerATNSimulator, - RuleContext, - PredictionContextCache, - Token, -} from 'antlr4'; + ATN, + ATNDeserializer, + CharStream, + DecisionState, DFA, + Lexer, + LexerATNSimulator, + RuleContext, + PredictionContextCache, + Token +} from "antlr4"; export default class RTRegexLexer extends Lexer { - public static readonly T__0 = 1; - public static readonly T__1 = 2; - public static readonly T__2 = 3; - public static readonly T__3 = 4; - public static readonly T__4 = 5; - public static readonly T__5 = 6; - public static readonly T__6 = 7; - public static readonly T__7 = 8; - public static readonly T__8 = 9; - public static readonly DIGIT_SUBID = 10; - public static readonly FLOAT = 11; - public static readonly SEQ = 12; - public static readonly INT = 13; - public static readonly TASK = 14; - public static readonly GOAL = 15; - public static readonly SKIPP = 16; - public static readonly X = 17; - public static readonly NEWLINE = 18; - public static readonly WORD = 19; - public static readonly SUBID = 20; - public static readonly WS = 21; - public static readonly EOF = Token.EOF; + public static readonly T__0 = 1; + public static readonly T__1 = 2; + public static readonly T__2 = 3; + public static readonly T__3 = 4; + public static readonly T__4 = 5; + public static readonly T__5 = 6; + public static readonly T__6 = 7; + public static readonly T__7 = 8; + public static readonly T__8 = 9; + public static readonly T__9 = 10; + public static readonly DIGIT_SUBID = 11; + public static readonly FLOAT = 12; + public static readonly SEQ = 13; + public static readonly INT = 14; + public static readonly TASK = 15; + public static readonly GOAL = 16; + public static readonly SKIPP = 17; + public static readonly X = 18; + public static readonly NEWLINE = 19; + public static readonly WORD = 20; + public static readonly SUBID = 21; + public static readonly WS = 22; + public static readonly EOF = Token.EOF; - public static readonly channelNames: string[] = [ - 'DEFAULT_TOKEN_CHANNEL', - 'HIDDEN', - ]; - public static readonly literalNames: (string | null)[] = [ - null, - "'R'", - "','", - "'['", - "']'", - "':'", - "'@'", - "'|'", - "'->'", - "'+'", - null, - null, - "';'", - "'#'", - "'T'", - "'G'", - "'skip'", - "'X'", - ]; - public static readonly symbolicNames: (string | null)[] = [ - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - 'DIGIT_SUBID', - 'FLOAT', - 'SEQ', - 'INT', - 'TASK', - 'GOAL', - 'SKIPP', - 'X', - 'NEWLINE', - 'WORD', - 'SUBID', - 'WS', - ]; - public static readonly modeNames: string[] = ['DEFAULT_MODE']; + public static readonly channelNames: string[] = [ "DEFAULT_TOKEN_CHANNEL", "HIDDEN" ]; + public static readonly literalNames: (string | null)[] = [ null, "'R'", + "','", "'['", + "']'", "':'", + "'@'", "'|'", + "'?'", "'+'", + "'->'", null, + null, "';'", + "'#'", "'T'", + "'G'", "'skip'", + "'X'" ]; + public static readonly symbolicNames: (string | null)[] = [ null, null, + null, null, + null, null, + null, null, + null, null, + null, "DIGIT_SUBID", + "FLOAT", "SEQ", + "INT", "TASK", + "GOAL", "SKIPP", + "X", "NEWLINE", + "WORD", "SUBID", + "WS" ]; + public static readonly modeNames: string[] = [ "DEFAULT_MODE", ]; - public static readonly ruleNames: string[] = [ - 'T__0', - 'T__1', - 'T__2', - 'T__3', - 'T__4', - 'T__5', - 'T__6', - 'T__7', - 'T__8', - 'DIGIT_SUBID', - 'FLOAT', - 'SEQ', - 'INT', - 'TASK', - 'GOAL', - 'SKIPP', - 'X', - 'NEWLINE', - 'WORD', - 'SUBID', - 'WS', - 'DIGIT', - ]; + public static readonly ruleNames: string[] = [ + "T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6", "T__7", "T__8", + "T__9", "DIGIT_SUBID", "FLOAT", "SEQ", "INT", "TASK", "GOAL", "SKIPP", + "X", "NEWLINE", "WORD", "SUBID", "WS", "DIGIT", + ]; - constructor(input: CharStream) { - super(input); - this._interp = new LexerATNSimulator( - this, - RTRegexLexer._ATN, - RTRegexLexer.DecisionsToDFA, - new PredictionContextCache(), - ); - } - public get grammarFileName(): string { - return 'RTRegex.g4'; - } + constructor(input: CharStream) { + super(input); + this._interp = new LexerATNSimulator(this, RTRegexLexer._ATN, RTRegexLexer.DecisionsToDFA, new PredictionContextCache()); + } - public get literalNames(): (string | null)[] { - return RTRegexLexer.literalNames; - } - public get symbolicNames(): (string | null)[] { - return RTRegexLexer.symbolicNames; - } - public get ruleNames(): string[] { - return RTRegexLexer.ruleNames; - } + public get grammarFileName(): string { return "RTRegex.g4"; } - public get serializedATN(): number[] { - return RTRegexLexer._serializedATN; - } + public get literalNames(): (string | null)[] { return RTRegexLexer.literalNames; } + public get symbolicNames(): (string | null)[] { return RTRegexLexer.symbolicNames; } + public get ruleNames(): string[] { return RTRegexLexer.ruleNames; } - public get channelNames(): string[] { - return RTRegexLexer.channelNames; - } + public get serializedATN(): number[] { return RTRegexLexer._serializedATN; } - public get modeNames(): string[] { - return RTRegexLexer.modeNames; - } + public get channelNames(): string[] { return RTRegexLexer.channelNames; } - public static readonly _serializedATN: number[] = [ - 4, 0, 21, 117, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, - 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, - 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, - 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 2, 20, 7, 20, 2, 21, 7, - 21, 1, 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, - 1, 6, 1, 6, 1, 7, 1, 7, 1, 7, 1, 8, 1, 8, 1, 9, 1, 9, 1, 9, 1, 10, 4, 10, - 69, 8, 10, 11, 10, 12, 10, 70, 1, 10, 3, 10, 74, 8, 10, 1, 10, 5, 10, 77, 8, - 10, 10, 10, 12, 10, 80, 9, 10, 1, 11, 1, 11, 1, 12, 1, 12, 1, 13, 1, 13, 1, - 14, 1, 14, 1, 15, 1, 15, 1, 15, 1, 15, 1, 15, 1, 16, 1, 16, 1, 17, 4, 17, - 98, 8, 17, 11, 17, 12, 17, 99, 1, 18, 4, 18, 103, 8, 18, 11, 18, 12, 18, - 104, 1, 19, 1, 19, 1, 20, 4, 20, 110, 8, 20, 11, 20, 12, 20, 111, 1, 20, 1, - 20, 1, 21, 1, 21, 0, 0, 22, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, - 8, 17, 9, 19, 10, 21, 11, 23, 12, 25, 13, 27, 14, 29, 15, 31, 16, 33, 17, - 35, 18, 37, 19, 39, 20, 41, 21, 43, 0, 1, 0, 5, 2, 0, 10, 10, 13, 13, 5, 0, - 32, 32, 39, 39, 45, 45, 65, 90, 97, 122, 1, 0, 97, 122, 1, 0, 9, 9, 1, 0, - 48, 57, 121, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, - 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, - 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 0, 23, 1, - 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, 27, 1, 0, 0, 0, 0, 29, 1, 0, 0, 0, 0, 31, 1, - 0, 0, 0, 0, 33, 1, 0, 0, 0, 0, 35, 1, 0, 0, 0, 0, 37, 1, 0, 0, 0, 0, 39, 1, - 0, 0, 0, 0, 41, 1, 0, 0, 0, 1, 45, 1, 0, 0, 0, 3, 47, 1, 0, 0, 0, 5, 49, 1, - 0, 0, 0, 7, 51, 1, 0, 0, 0, 9, 53, 1, 0, 0, 0, 11, 55, 1, 0, 0, 0, 13, 57, - 1, 0, 0, 0, 15, 59, 1, 0, 0, 0, 17, 62, 1, 0, 0, 0, 19, 64, 1, 0, 0, 0, 21, - 68, 1, 0, 0, 0, 23, 81, 1, 0, 0, 0, 25, 83, 1, 0, 0, 0, 27, 85, 1, 0, 0, 0, - 29, 87, 1, 0, 0, 0, 31, 89, 1, 0, 0, 0, 33, 94, 1, 0, 0, 0, 35, 97, 1, 0, 0, - 0, 37, 102, 1, 0, 0, 0, 39, 106, 1, 0, 0, 0, 41, 109, 1, 0, 0, 0, 43, 115, - 1, 0, 0, 0, 45, 46, 5, 82, 0, 0, 46, 2, 1, 0, 0, 0, 47, 48, 5, 44, 0, 0, 48, - 4, 1, 0, 0, 0, 49, 50, 5, 91, 0, 0, 50, 6, 1, 0, 0, 0, 51, 52, 5, 93, 0, 0, - 52, 8, 1, 0, 0, 0, 53, 54, 5, 58, 0, 0, 54, 10, 1, 0, 0, 0, 55, 56, 5, 64, - 0, 0, 56, 12, 1, 0, 0, 0, 57, 58, 5, 124, 0, 0, 58, 14, 1, 0, 0, 0, 59, 60, - 5, 45, 0, 0, 60, 61, 5, 62, 0, 0, 61, 16, 1, 0, 0, 0, 62, 63, 5, 43, 0, 0, - 63, 18, 1, 0, 0, 0, 64, 65, 3, 43, 21, 0, 65, 66, 3, 39, 19, 0, 66, 20, 1, - 0, 0, 0, 67, 69, 3, 43, 21, 0, 68, 67, 1, 0, 0, 0, 69, 70, 1, 0, 0, 0, 70, - 68, 1, 0, 0, 0, 70, 71, 1, 0, 0, 0, 71, 73, 1, 0, 0, 0, 72, 74, 5, 46, 0, 0, - 73, 72, 1, 0, 0, 0, 73, 74, 1, 0, 0, 0, 74, 78, 1, 0, 0, 0, 75, 77, 3, 43, - 21, 0, 76, 75, 1, 0, 0, 0, 77, 80, 1, 0, 0, 0, 78, 76, 1, 0, 0, 0, 78, 79, - 1, 0, 0, 0, 79, 22, 1, 0, 0, 0, 80, 78, 1, 0, 0, 0, 81, 82, 5, 59, 0, 0, 82, - 24, 1, 0, 0, 0, 83, 84, 5, 35, 0, 0, 84, 26, 1, 0, 0, 0, 85, 86, 5, 84, 0, - 0, 86, 28, 1, 0, 0, 0, 87, 88, 5, 71, 0, 0, 88, 30, 1, 0, 0, 0, 89, 90, 5, - 115, 0, 0, 90, 91, 5, 107, 0, 0, 91, 92, 5, 105, 0, 0, 92, 93, 5, 112, 0, 0, - 93, 32, 1, 0, 0, 0, 94, 95, 5, 88, 0, 0, 95, 34, 1, 0, 0, 0, 96, 98, 7, 0, - 0, 0, 97, 96, 1, 0, 0, 0, 98, 99, 1, 0, 0, 0, 99, 97, 1, 0, 0, 0, 99, 100, - 1, 0, 0, 0, 100, 36, 1, 0, 0, 0, 101, 103, 7, 1, 0, 0, 102, 101, 1, 0, 0, 0, - 103, 104, 1, 0, 0, 0, 104, 102, 1, 0, 0, 0, 104, 105, 1, 0, 0, 0, 105, 38, - 1, 0, 0, 0, 106, 107, 7, 2, 0, 0, 107, 40, 1, 0, 0, 0, 108, 110, 7, 3, 0, 0, - 109, 108, 1, 0, 0, 0, 110, 111, 1, 0, 0, 0, 111, 109, 1, 0, 0, 0, 111, 112, - 1, 0, 0, 0, 112, 113, 1, 0, 0, 0, 113, 114, 6, 20, 0, 0, 114, 42, 1, 0, 0, - 0, 115, 116, 7, 4, 0, 0, 116, 44, 1, 0, 0, 0, 7, 0, 70, 73, 78, 99, 104, - 111, 1, 6, 0, 0, - ]; + public get modeNames(): string[] { return RTRegexLexer.modeNames; } - private static __ATN: ATN; - public static get _ATN(): ATN { - if (!RTRegexLexer.__ATN) { - RTRegexLexer.__ATN = new ATNDeserializer().deserialize( - RTRegexLexer._serializedATN, - ); - } + public static readonly _serializedATN: number[] = [4,0,22,121,6,-1,2,0, + 7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7,6,2,7,7,7,2,8,7,8,2,9, + 7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,13,7,13,2,14,7,14,2,15,7,15,2,16,7, + 16,2,17,7,17,2,18,7,18,2,19,7,19,2,20,7,20,2,21,7,21,2,22,7,22,1,0,1,0, + 1,1,1,1,1,2,1,2,1,3,1,3,1,4,1,4,1,5,1,5,1,6,1,6,1,7,1,7,1,8,1,8,1,9,1,9, + 1,9,1,10,1,10,1,10,1,11,4,11,73,8,11,11,11,12,11,74,1,11,3,11,78,8,11,1, + 11,5,11,81,8,11,10,11,12,11,84,9,11,1,12,1,12,1,13,1,13,1,14,1,14,1,15, + 1,15,1,16,1,16,1,16,1,16,1,16,1,17,1,17,1,18,4,18,102,8,18,11,18,12,18, + 103,1,19,4,19,107,8,19,11,19,12,19,108,1,20,1,20,1,21,4,21,114,8,21,11, + 21,12,21,115,1,21,1,21,1,22,1,22,0,0,23,1,1,3,2,5,3,7,4,9,5,11,6,13,7,15, + 8,17,9,19,10,21,11,23,12,25,13,27,14,29,15,31,16,33,17,35,18,37,19,39,20, + 41,21,43,22,45,0,1,0,5,2,0,10,10,13,13,5,0,32,32,39,39,45,45,65,90,97,122, + 1,0,97,122,1,0,9,9,1,0,48,57,125,0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0, + 7,1,0,0,0,0,9,1,0,0,0,0,11,1,0,0,0,0,13,1,0,0,0,0,15,1,0,0,0,0,17,1,0,0, + 0,0,19,1,0,0,0,0,21,1,0,0,0,0,23,1,0,0,0,0,25,1,0,0,0,0,27,1,0,0,0,0,29, + 1,0,0,0,0,31,1,0,0,0,0,33,1,0,0,0,0,35,1,0,0,0,0,37,1,0,0,0,0,39,1,0,0, + 0,0,41,1,0,0,0,0,43,1,0,0,0,1,47,1,0,0,0,3,49,1,0,0,0,5,51,1,0,0,0,7,53, + 1,0,0,0,9,55,1,0,0,0,11,57,1,0,0,0,13,59,1,0,0,0,15,61,1,0,0,0,17,63,1, + 0,0,0,19,65,1,0,0,0,21,68,1,0,0,0,23,72,1,0,0,0,25,85,1,0,0,0,27,87,1,0, + 0,0,29,89,1,0,0,0,31,91,1,0,0,0,33,93,1,0,0,0,35,98,1,0,0,0,37,101,1,0, + 0,0,39,106,1,0,0,0,41,110,1,0,0,0,43,113,1,0,0,0,45,119,1,0,0,0,47,48,5, + 82,0,0,48,2,1,0,0,0,49,50,5,44,0,0,50,4,1,0,0,0,51,52,5,91,0,0,52,6,1,0, + 0,0,53,54,5,93,0,0,54,8,1,0,0,0,55,56,5,58,0,0,56,10,1,0,0,0,57,58,5,64, + 0,0,58,12,1,0,0,0,59,60,5,124,0,0,60,14,1,0,0,0,61,62,5,63,0,0,62,16,1, + 0,0,0,63,64,5,43,0,0,64,18,1,0,0,0,65,66,5,45,0,0,66,67,5,62,0,0,67,20, + 1,0,0,0,68,69,3,45,22,0,69,70,3,41,20,0,70,22,1,0,0,0,71,73,3,45,22,0,72, + 71,1,0,0,0,73,74,1,0,0,0,74,72,1,0,0,0,74,75,1,0,0,0,75,77,1,0,0,0,76,78, + 5,46,0,0,77,76,1,0,0,0,77,78,1,0,0,0,78,82,1,0,0,0,79,81,3,45,22,0,80,79, + 1,0,0,0,81,84,1,0,0,0,82,80,1,0,0,0,82,83,1,0,0,0,83,24,1,0,0,0,84,82,1, + 0,0,0,85,86,5,59,0,0,86,26,1,0,0,0,87,88,5,35,0,0,88,28,1,0,0,0,89,90,5, + 84,0,0,90,30,1,0,0,0,91,92,5,71,0,0,92,32,1,0,0,0,93,94,5,115,0,0,94,95, + 5,107,0,0,95,96,5,105,0,0,96,97,5,112,0,0,97,34,1,0,0,0,98,99,5,88,0,0, + 99,36,1,0,0,0,100,102,7,0,0,0,101,100,1,0,0,0,102,103,1,0,0,0,103,101,1, + 0,0,0,103,104,1,0,0,0,104,38,1,0,0,0,105,107,7,1,0,0,106,105,1,0,0,0,107, + 108,1,0,0,0,108,106,1,0,0,0,108,109,1,0,0,0,109,40,1,0,0,0,110,111,7,2, + 0,0,111,42,1,0,0,0,112,114,7,3,0,0,113,112,1,0,0,0,114,115,1,0,0,0,115, + 113,1,0,0,0,115,116,1,0,0,0,116,117,1,0,0,0,117,118,6,21,0,0,118,44,1,0, + 0,0,119,120,7,4,0,0,120,46,1,0,0,0,7,0,74,77,82,103,108,115,1,6,0,0]; - return RTRegexLexer.__ATN; - } + private static __ATN: ATN; + public static get _ATN(): ATN { + if (!RTRegexLexer.__ATN) { + RTRegexLexer.__ATN = new ATNDeserializer().deserialize(RTRegexLexer._serializedATN); + } - static DecisionsToDFA = RTRegexLexer._ATN.decisionToState.map( - (ds: DecisionState, index: number) => new DFA(ds, index), - ); -} + return RTRegexLexer.__ATN; + } + + + static DecisionsToDFA = RTRegexLexer._ATN.decisionToState.map( (ds: DecisionState, index: number) => new DFA(ds, index) ); +} \ No newline at end of file diff --git a/packages/lib/src/antlr/RTRegexListener.ts b/packages/lib/src/antlr/RTRegexListener.ts index 5277ca36..1db0fa09 100644 --- a/packages/lib/src/antlr/RTRegexListener.ts +++ b/packages/lib/src/antlr/RTRegexListener.ts @@ -1,228 +1,244 @@ -// Generated from grammar/RTRegex.g4 by ANTLR 4.13.2 +// Generated from RTRegex.g4 by ANTLR 4.13.2 -import { ParseTreeListener } from 'antlr4'; +import {ParseTreeListener} from "antlr4"; + + +import { PrintExprContext } from "./RTRegexParser.js"; +import { BlankContext } from "./RTRegexParser.js"; +import { GAnyOrderContext } from "./RTRegexParser.js"; +import { GIdContext } from "./RTRegexParser.js"; +import { NameOnlyContext } from "./RTRegexParser.js"; +import { GInterleavedContext } from "./RTRegexParser.js"; +import { GChoiceContext } from "./RTRegexParser.js"; +import { GArgsContext } from "./RTRegexParser.js"; +import { NameContinuedContext } from "./RTRegexParser.js"; +import { GAlternativeContext } from "./RTRegexParser.js"; +import { GDegradationContext } from "./RTRegexParser.js"; +import { GSkipContext } from "./RTRegexParser.js"; +import { NotationStartContext } from "./RTRegexParser.js"; +import { GRetryContext } from "./RTRegexParser.js"; +import { GSequenceContext } from "./RTRegexParser.js"; +import { GIdContinuedContext } from "./RTRegexParser.js"; +import { IdContext } from "./RTRegexParser.js"; +import { WordContext } from "./RTRegexParser.js"; -import { PrintExprContext } from './RTRegexParser.js'; -import { BlankContext } from './RTRegexParser.js'; -import { GIdContext } from './RTRegexParser.js'; -import { NameOnlyContext } from './RTRegexParser.js'; -import { GInterleavedContext } from './RTRegexParser.js'; -import { GChoiceContext } from './RTRegexParser.js'; -import { GArgsContext } from './RTRegexParser.js'; -import { NameContinuedContext } from './RTRegexParser.js'; -import { GAlternativeContext } from './RTRegexParser.js'; -import { GDegradationContext } from './RTRegexParser.js'; -import { GSkipContext } from './RTRegexParser.js'; -import { NotationStartContext } from './RTRegexParser.js'; -import { GRetryContext } from './RTRegexParser.js'; -import { GSequenceContext } from './RTRegexParser.js'; -import { GIdContinuedContext } from './RTRegexParser.js'; -import { IdContext } from './RTRegexParser.js'; -import { WordContext } from './RTRegexParser.js'; /** * This interface defines a complete listener for a parse tree produced by * `RTRegexParser`. */ export default class RTRegexListener extends ParseTreeListener { - /** - * Enter a parse tree produced by the `printExpr` - * labeled alternative in `RTRegexParser.rt`. - * @param ctx the parse tree - */ - enterPrintExpr?: (ctx: PrintExprContext) => void; - /** - * Exit a parse tree produced by the `printExpr` - * labeled alternative in `RTRegexParser.rt`. - * @param ctx the parse tree - */ - exitPrintExpr?: (ctx: PrintExprContext) => void; - /** - * Enter a parse tree produced by the `blank` - * labeled alternative in `RTRegexParser.rt`. - * @param ctx the parse tree - */ - enterBlank?: (ctx: BlankContext) => void; - /** - * Exit a parse tree produced by the `blank` - * labeled alternative in `RTRegexParser.rt`. - * @param ctx the parse tree - */ - exitBlank?: (ctx: BlankContext) => void; - /** - * Enter a parse tree produced by the `gId` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - enterGId?: (ctx: GIdContext) => void; - /** - * Exit a parse tree produced by the `gId` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - exitGId?: (ctx: GIdContext) => void; - /** - * Enter a parse tree produced by the `nameOnly` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - enterNameOnly?: (ctx: NameOnlyContext) => void; - /** - * Exit a parse tree produced by the `nameOnly` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - exitNameOnly?: (ctx: NameOnlyContext) => void; - /** - * Enter a parse tree produced by the `gInterleaved` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - enterGInterleaved?: (ctx: GInterleavedContext) => void; - /** - * Exit a parse tree produced by the `gInterleaved` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - exitGInterleaved?: (ctx: GInterleavedContext) => void; - /** - * Enter a parse tree produced by the `gChoice` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - enterGChoice?: (ctx: GChoiceContext) => void; - /** - * Exit a parse tree produced by the `gChoice` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - exitGChoice?: (ctx: GChoiceContext) => void; - /** - * Enter a parse tree produced by the `gArgs` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - enterGArgs?: (ctx: GArgsContext) => void; - /** - * Exit a parse tree produced by the `gArgs` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - exitGArgs?: (ctx: GArgsContext) => void; - /** - * Enter a parse tree produced by the `nameContinued` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - enterNameContinued?: (ctx: NameContinuedContext) => void; - /** - * Exit a parse tree produced by the `nameContinued` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - exitNameContinued?: (ctx: NameContinuedContext) => void; - /** - * Enter a parse tree produced by the `gAlternative` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - enterGAlternative?: (ctx: GAlternativeContext) => void; - /** - * Exit a parse tree produced by the `gAlternative` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - exitGAlternative?: (ctx: GAlternativeContext) => void; - /** - * Enter a parse tree produced by the `gDegradation` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - enterGDegradation?: (ctx: GDegradationContext) => void; - /** - * Exit a parse tree produced by the `gDegradation` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - exitGDegradation?: (ctx: GDegradationContext) => void; - /** - * Enter a parse tree produced by the `gSkip` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - enterGSkip?: (ctx: GSkipContext) => void; - /** - * Exit a parse tree produced by the `gSkip` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - exitGSkip?: (ctx: GSkipContext) => void; - /** - * Enter a parse tree produced by the `notationStart` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - enterNotationStart?: (ctx: NotationStartContext) => void; - /** - * Exit a parse tree produced by the `notationStart` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - exitNotationStart?: (ctx: NotationStartContext) => void; - /** - * Enter a parse tree produced by the `gRetry` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - enterGRetry?: (ctx: GRetryContext) => void; - /** - * Exit a parse tree produced by the `gRetry` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - exitGRetry?: (ctx: GRetryContext) => void; - /** - * Enter a parse tree produced by the `gSequence` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - enterGSequence?: (ctx: GSequenceContext) => void; - /** - * Exit a parse tree produced by the `gSequence` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - exitGSequence?: (ctx: GSequenceContext) => void; - /** - * Enter a parse tree produced by the `gIdContinued` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - enterGIdContinued?: (ctx: GIdContinuedContext) => void; - /** - * Exit a parse tree produced by the `gIdContinued` - * labeled alternative in `RTRegexParser.expr`. - * @param ctx the parse tree - */ - exitGIdContinued?: (ctx: GIdContinuedContext) => void; - /** - * Enter a parse tree produced by `RTRegexParser.id`. - * @param ctx the parse tree - */ - enterId?: (ctx: IdContext) => void; - /** - * Exit a parse tree produced by `RTRegexParser.id`. - * @param ctx the parse tree - */ - exitId?: (ctx: IdContext) => void; - /** - * Enter a parse tree produced by `RTRegexParser.word`. - * @param ctx the parse tree - */ - enterWord?: (ctx: WordContext) => void; - /** - * Exit a parse tree produced by `RTRegexParser.word`. - * @param ctx the parse tree - */ - exitWord?: (ctx: WordContext) => void; + /** + * Enter a parse tree produced by the `printExpr` + * labeled alternative in `RTRegexParser.rt`. + * @param ctx the parse tree + */ + enterPrintExpr?: (ctx: PrintExprContext) => void; + /** + * Exit a parse tree produced by the `printExpr` + * labeled alternative in `RTRegexParser.rt`. + * @param ctx the parse tree + */ + exitPrintExpr?: (ctx: PrintExprContext) => void; + /** + * Enter a parse tree produced by the `blank` + * labeled alternative in `RTRegexParser.rt`. + * @param ctx the parse tree + */ + enterBlank?: (ctx: BlankContext) => void; + /** + * Exit a parse tree produced by the `blank` + * labeled alternative in `RTRegexParser.rt`. + * @param ctx the parse tree + */ + exitBlank?: (ctx: BlankContext) => void; + /** + * Enter a parse tree produced by the `gAnyOrder` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + enterGAnyOrder?: (ctx: GAnyOrderContext) => void; + /** + * Exit a parse tree produced by the `gAnyOrder` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + exitGAnyOrder?: (ctx: GAnyOrderContext) => void; + /** + * Enter a parse tree produced by the `gId` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + enterGId?: (ctx: GIdContext) => void; + /** + * Exit a parse tree produced by the `gId` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + exitGId?: (ctx: GIdContext) => void; + /** + * Enter a parse tree produced by the `nameOnly` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + enterNameOnly?: (ctx: NameOnlyContext) => void; + /** + * Exit a parse tree produced by the `nameOnly` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + exitNameOnly?: (ctx: NameOnlyContext) => void; + /** + * Enter a parse tree produced by the `gInterleaved` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + enterGInterleaved?: (ctx: GInterleavedContext) => void; + /** + * Exit a parse tree produced by the `gInterleaved` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + exitGInterleaved?: (ctx: GInterleavedContext) => void; + /** + * Enter a parse tree produced by the `gChoice` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + enterGChoice?: (ctx: GChoiceContext) => void; + /** + * Exit a parse tree produced by the `gChoice` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + exitGChoice?: (ctx: GChoiceContext) => void; + /** + * Enter a parse tree produced by the `gArgs` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + enterGArgs?: (ctx: GArgsContext) => void; + /** + * Exit a parse tree produced by the `gArgs` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + exitGArgs?: (ctx: GArgsContext) => void; + /** + * Enter a parse tree produced by the `nameContinued` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + enterNameContinued?: (ctx: NameContinuedContext) => void; + /** + * Exit a parse tree produced by the `nameContinued` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + exitNameContinued?: (ctx: NameContinuedContext) => void; + /** + * Enter a parse tree produced by the `gAlternative` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + enterGAlternative?: (ctx: GAlternativeContext) => void; + /** + * Exit a parse tree produced by the `gAlternative` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + exitGAlternative?: (ctx: GAlternativeContext) => void; + /** + * Enter a parse tree produced by the `gDegradation` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + enterGDegradation?: (ctx: GDegradationContext) => void; + /** + * Exit a parse tree produced by the `gDegradation` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + exitGDegradation?: (ctx: GDegradationContext) => void; + /** + * Enter a parse tree produced by the `gSkip` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + enterGSkip?: (ctx: GSkipContext) => void; + /** + * Exit a parse tree produced by the `gSkip` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + exitGSkip?: (ctx: GSkipContext) => void; + /** + * Enter a parse tree produced by the `notationStart` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + enterNotationStart?: (ctx: NotationStartContext) => void; + /** + * Exit a parse tree produced by the `notationStart` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + exitNotationStart?: (ctx: NotationStartContext) => void; + /** + * Enter a parse tree produced by the `gRetry` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + enterGRetry?: (ctx: GRetryContext) => void; + /** + * Exit a parse tree produced by the `gRetry` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + exitGRetry?: (ctx: GRetryContext) => void; + /** + * Enter a parse tree produced by the `gSequence` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + enterGSequence?: (ctx: GSequenceContext) => void; + /** + * Exit a parse tree produced by the `gSequence` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + exitGSequence?: (ctx: GSequenceContext) => void; + /** + * Enter a parse tree produced by the `gIdContinued` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + enterGIdContinued?: (ctx: GIdContinuedContext) => void; + /** + * Exit a parse tree produced by the `gIdContinued` + * labeled alternative in `RTRegexParser.expr`. + * @param ctx the parse tree + */ + exitGIdContinued?: (ctx: GIdContinuedContext) => void; + /** + * Enter a parse tree produced by `RTRegexParser.id`. + * @param ctx the parse tree + */ + enterId?: (ctx: IdContext) => void; + /** + * Exit a parse tree produced by `RTRegexParser.id`. + * @param ctx the parse tree + */ + exitId?: (ctx: IdContext) => void; + /** + * Enter a parse tree produced by `RTRegexParser.word`. + * @param ctx the parse tree + */ + enterWord?: (ctx: WordContext) => void; + /** + * Exit a parse tree produced by `RTRegexParser.word`. + * @param ctx the parse tree + */ + exitWord?: (ctx: WordContext) => void; } + diff --git a/packages/lib/src/antlr/RTRegexParser.ts b/packages/lib/src/antlr/RTRegexParser.ts index bf65d1c7..a43e7326 100644 --- a/packages/lib/src/antlr/RTRegexParser.ts +++ b/packages/lib/src/antlr/RTRegexParser.ts @@ -1,1078 +1,1006 @@ -// Generated from grammar/RTRegex.g4 by ANTLR 4.13.2 +// Generated from RTRegex.g4 by ANTLR 4.13.2 // noinspection ES6UnusedImports,JSUnusedGlobalSymbols,JSUnusedLocalSymbols import { - ATN, - ATNDeserializer, - DecisionState, - DFA, - FailedPredicateException, - RecognitionException, - NoViableAltException, - BailErrorStrategy, - Parser, - ParserATNSimulator, - RuleContext, - ParserRuleContext, - PredictionMode, - PredictionContextCache, - TerminalNode, - RuleNode, - Token, - TokenStream, - Interval, - IntervalSet, + ATN, + ATNDeserializer, DecisionState, DFA, FailedPredicateException, + RecognitionException, NoViableAltException, BailErrorStrategy, + Parser, ParserATNSimulator, + RuleContext, ParserRuleContext, PredictionMode, PredictionContextCache, + TerminalNode, RuleNode, + Token, TokenStream, + Interval, IntervalSet } from 'antlr4'; -import RTRegexListener from './RTRegexListener.js'; +import RTRegexListener from "./RTRegexListener.js"; // for running tests with parameters, TODO: discuss strategy for typed parameters in CI // eslint-disable-next-line no-unused-vars type int = number; export default class RTRegexParser extends Parser { - public static readonly T__0 = 1; - public static readonly T__1 = 2; - public static readonly T__2 = 3; - public static readonly T__3 = 4; - public static readonly T__4 = 5; - public static readonly T__5 = 6; - public static readonly T__6 = 7; - public static readonly T__7 = 8; - public static readonly T__8 = 9; - public static readonly DIGIT_SUBID = 10; - public static readonly FLOAT = 11; - public static readonly SEQ = 12; - public static readonly INT = 13; - public static readonly TASK = 14; - public static readonly GOAL = 15; - public static readonly SKIPP = 16; - public static readonly X = 17; - public static readonly NEWLINE = 18; - public static readonly WORD = 19; - public static readonly SUBID = 20; - public static readonly WS = 21; - public static override readonly EOF = Token.EOF; - public static readonly RULE_rt = 0; - public static readonly RULE_expr = 1; - public static readonly RULE_id = 2; - public static readonly RULE_word = 3; - public static readonly literalNames: (string | null)[] = [ - null, - "'R'", - "','", - "'['", - "']'", - "':'", - "'@'", - "'|'", - "'->'", - "'+'", - null, - null, - "';'", - "'#'", - "'T'", - "'G'", - "'skip'", - "'X'", - ]; - public static readonly symbolicNames: (string | null)[] = [ - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - 'DIGIT_SUBID', - 'FLOAT', - 'SEQ', - 'INT', - 'TASK', - 'GOAL', - 'SKIPP', - 'X', - 'NEWLINE', - 'WORD', - 'SUBID', - 'WS', - ]; - // tslint:disable:no-trailing-whitespace - public static readonly ruleNames: string[] = ['rt', 'expr', 'id', 'word']; - public get grammarFileName(): string { - return 'RTRegex.g4'; - } - public get literalNames(): (string | null)[] { - return RTRegexParser.literalNames; - } - public get symbolicNames(): (string | null)[] { - return RTRegexParser.symbolicNames; - } - public get ruleNames(): string[] { - return RTRegexParser.ruleNames; - } - public get serializedATN(): number[] { - return RTRegexParser._serializedATN; - } + public static readonly T__0 = 1; + public static readonly T__1 = 2; + public static readonly T__2 = 3; + public static readonly T__3 = 4; + public static readonly T__4 = 5; + public static readonly T__5 = 6; + public static readonly T__6 = 7; + public static readonly T__7 = 8; + public static readonly T__8 = 9; + public static readonly T__9 = 10; + public static readonly DIGIT_SUBID = 11; + public static readonly FLOAT = 12; + public static readonly SEQ = 13; + public static readonly INT = 14; + public static readonly TASK = 15; + public static readonly GOAL = 16; + public static readonly SKIPP = 17; + public static readonly X = 18; + public static readonly NEWLINE = 19; + public static readonly WORD = 20; + public static readonly SUBID = 21; + public static readonly WS = 22; + public static override readonly EOF = Token.EOF; + public static readonly RULE_rt = 0; + public static readonly RULE_expr = 1; + public static readonly RULE_id = 2; + public static readonly RULE_word = 3; + public static readonly literalNames: (string | null)[] = [ null, "'R'", + "','", "'['", + "']'", "':'", + "'@'", "'|'", + "'?'", "'+'", + "'->'", null, + null, "';'", + "'#'", "'T'", + "'G'", "'skip'", + "'X'" ]; + public static readonly symbolicNames: (string | null)[] = [ null, null, + null, null, + null, null, + null, null, + null, null, + null, "DIGIT_SUBID", + "FLOAT", "SEQ", + "INT", "TASK", + "GOAL", "SKIPP", + "X", "NEWLINE", + "WORD", "SUBID", + "WS" ]; + // tslint:disable:no-trailing-whitespace + public static readonly ruleNames: string[] = [ + "rt", "expr", "id", "word", + ]; + public get grammarFileName(): string { return "RTRegex.g4"; } + public get literalNames(): (string | null)[] { return RTRegexParser.literalNames; } + public get symbolicNames(): (string | null)[] { return RTRegexParser.symbolicNames; } + public get ruleNames(): string[] { return RTRegexParser.ruleNames; } + public get serializedATN(): number[] { return RTRegexParser._serializedATN; } - protected createFailedPredicateException( - predicate?: string, - message?: string, - ): FailedPredicateException { - return new FailedPredicateException(this, predicate, message); - } + protected createFailedPredicateException(predicate?: string, message?: string): FailedPredicateException { + return new FailedPredicateException(this, predicate, message); + } - constructor(input: TokenStream) { - super(input); - this._interp = new ParserATNSimulator( - this, - RTRegexParser._ATN, - RTRegexParser.DecisionsToDFA, - new PredictionContextCache(), - ); - } - // @RuleVersion(0) - public rt(): RtContext { - let localctx: RtContext = new RtContext(this, this._ctx, this.state); - this.enterRule(localctx, 0, RTRegexParser.RULE_rt); - try { - this.state = 12; - this._errHandler.sync(this); - switch (this._input.LA(1)) { - case 1: - case 3: - case 5: - case 9: - case 14: - case 15: - case 16: - localctx = new PrintExprContext(this, localctx); - this.enterOuterAlt(localctx, 1); - { - this.state = 8; - this.expr(0); - this.state = 9; - this.match(RTRegexParser.EOF); - } - break; - case -1: - localctx = new BlankContext(this, localctx); - this.enterOuterAlt(localctx, 2); - { - this.state = 11; - this.match(RTRegexParser.EOF); - } - break; - default: - throw new NoViableAltException(this); - } - } catch (re) { - if (re instanceof RecognitionException) { - localctx.exception = re; - this._errHandler.reportError(this, re); - this._errHandler.recover(this, re); - } else { - throw re; - } - } finally { - this.exitRule(); - } - return localctx; - } + constructor(input: TokenStream) { + super(input); + this._interp = new ParserATNSimulator(this, RTRegexParser._ATN, RTRegexParser.DecisionsToDFA, new PredictionContextCache()); + } + // @RuleVersion(0) + public rt(): RtContext { + let localctx: RtContext = new RtContext(this, this._ctx, this.state); + this.enterRule(localctx, 0, RTRegexParser.RULE_rt); + try { + this.state = 12; + this._errHandler.sync(this); + switch (this._input.LA(1)) { + case 1: + case 3: + case 5: + case 15: + case 16: + case 17: + localctx = new PrintExprContext(this, localctx); + this.enterOuterAlt(localctx, 1); + { + this.state = 8; + this.expr(0); + this.state = 9; + this.match(RTRegexParser.EOF); + } + break; + case -1: + localctx = new BlankContext(this, localctx); + this.enterOuterAlt(localctx, 2); + { + this.state = 11; + this.match(RTRegexParser.EOF); + } + break; + default: + throw new NoViableAltException(this); + } + } + catch (re) { + if (re instanceof RecognitionException) { + localctx.exception = re; + this._errHandler.reportError(this, re); + this._errHandler.recover(this, re); + } else { + throw re; + } + } + finally { + this.exitRule(); + } + return localctx; + } - public expr(): ExprContext; - public expr(_p: number): ExprContext; - // @RuleVersion(0) - public expr(_p?: number): ExprContext { - if (_p === undefined) { - _p = 0; - } + public expr(): ExprContext; + public expr(_p: number): ExprContext; + // @RuleVersion(0) + public expr(_p?: number): ExprContext { + if (_p === undefined) { + _p = 0; + } - let _parentctx: ParserRuleContext = this._ctx; - let _parentState: number = this.state; - let localctx: ExprContext = new ExprContext(this, this._ctx, _parentState); - let _prevctx: ExprContext = localctx; - let _startState: number = 2; - this.enterRecursionRule(localctx, 2, RTRegexParser.RULE_expr, _p); - let _la: number; - try { - let _alt: number; - this.enterOuterAlt(localctx, 1); - { - this.state = 40; - this._errHandler.sync(this); - switch (this._interp.adaptivePredict(this._input, 1, this._ctx)) { - case 1: - { - localctx = new GIdContext(this, localctx); - this._ctx = localctx; - _prevctx = localctx; + let _parentctx: ParserRuleContext = this._ctx; + let _parentState: number = this.state; + let localctx: ExprContext = new ExprContext(this, this._ctx, _parentState); + let _prevctx: ExprContext = localctx; + let _startState: number = 2; + this.enterRecursionRule(localctx, 2, RTRegexParser.RULE_expr, _p); + let _la: number; + try { + let _alt: number; + this.enterOuterAlt(localctx, 1); + { + this.state = 39; + this._errHandler.sync(this); + switch ( this._interp.adaptivePredict(this._input, 1, this._ctx) ) { + case 1: + { + localctx = new GIdContext(this, localctx); + this._ctx = localctx; + _prevctx = localctx; - this.state = 15; - (localctx as GIdContext)._t = this._input.LT(1); - _la = this._input.LA(1); - if (!((_la & ~0x1f) === 0 && ((1 << _la) & 49154) !== 0)) { - (localctx as GIdContext)._t = - this._errHandler.recoverInline(this); - } else { - this._errHandler.reportMatch(this); - this.consume(); - } - this.state = 16; - this.id(); - } - break; - case 2: - { - localctx = new GIdContinuedContext(this, localctx); - this._ctx = localctx; - _prevctx = localctx; - this.state = 17; - (localctx as GIdContinuedContext)._t = this._input.LT(1); - _la = this._input.LA(1); - if (!((_la & ~0x1f) === 0 && ((1 << _la) & 49154) !== 0)) { - (localctx as GIdContinuedContext)._t = - this._errHandler.recoverInline(this); - } else { - this._errHandler.reportMatch(this); - this.consume(); - } - this.state = 18; - this.id(); - this.state = 19; - this.expr(12); - } - break; - case 3: - { - localctx = new GArgsContext(this, localctx); - this._ctx = localctx; - _prevctx = localctx; - this.state = 21; - (localctx as GArgsContext)._t = this._input.LT(1); - _la = this._input.LA(1); - if (!((_la & ~0x1f) === 0 && ((1 << _la) & 49154) !== 0)) { - (localctx as GArgsContext)._t = - this._errHandler.recoverInline(this); - } else { - this._errHandler.reportMatch(this); - this.consume(); - } - this.state = 22; - this.id(); - this.state = 23; - this.match(RTRegexParser.T__1); - this.state = 24; - this.expr(11); - } - break; - case 4: - { - localctx = new NotationStartContext(this, localctx); - this._ctx = localctx; - _prevctx = localctx; - this.state = 26; - this.match(RTRegexParser.T__2); - this.state = 27; - this.expr(0); - this.state = 28; - this.match(RTRegexParser.T__3); - } - break; - case 5: - { - localctx = new NameContinuedContext(this, localctx); - this._ctx = localctx; - _prevctx = localctx; - this.state = 30; - this.match(RTRegexParser.T__4); - this.state = 31; - this.word(); - this.state = 32; - this.expr(9); - } - break; - case 6: - { - localctx = new NameOnlyContext(this, localctx); - this._ctx = localctx; - _prevctx = localctx; - this.state = 34; - this.match(RTRegexParser.T__4); - this.state = 35; - this.word(); - this.state = 36; - this.match(RTRegexParser.EOF); - } - break; - case 7: - { - localctx = new GChoiceContext(this, localctx); - this._ctx = localctx; - _prevctx = localctx; - this.state = 38; - (localctx as GChoiceContext)._op = this.match(RTRegexParser.T__8); - } - break; - case 8: - { - localctx = new GSkipContext(this, localctx); - this._ctx = localctx; - _prevctx = localctx; - this.state = 39; - this.match(RTRegexParser.SKIPP); - } - break; - } - this._ctx.stop = this._input.LT(-1); - this.state = 59; - this._errHandler.sync(this); - _alt = this._interp.adaptivePredict(this._input, 3, this._ctx); - while (_alt !== 2 && _alt !== ATN.INVALID_ALT_NUMBER) { - if (_alt === 1) { - if (this._parseListeners != null) { - this.triggerExitRuleEvent(); - } - _prevctx = localctx; - { - this.state = 57; - this._errHandler.sync(this); - switch (this._interp.adaptivePredict(this._input, 2, this._ctx)) { - case 1: - { - localctx = new GAlternativeContext( - this, - new ExprContext(this, _parentctx, _parentState), - ); - this.pushNewRecursionContext( - localctx, - _startState, - RTRegexParser.RULE_expr, - ); - this.state = 42; - if (!this.precpred(this._ctx, 6)) { - throw this.createFailedPredicateException( - 'this.precpred(this._ctx, 6)', - ); - } - this.state = 43; - (localctx as GAlternativeContext)._op = this.match( - RTRegexParser.T__6, - ); - this.state = 44; - this.expr(7); - } - break; - case 2: - { - localctx = new GInterleavedContext( - this, - new ExprContext(this, _parentctx, _parentState), - ); - this.pushNewRecursionContext( - localctx, - _startState, - RTRegexParser.RULE_expr, - ); - this.state = 45; - if (!this.precpred(this._ctx, 5)) { - throw this.createFailedPredicateException( - 'this.precpred(this._ctx, 5)', - ); - } - this.state = 46; - (localctx as GInterleavedContext)._op = this.match( - RTRegexParser.INT, - ); - this.state = 47; - this.expr(6); - } - break; - case 3: - { - localctx = new GSequenceContext( - this, - new ExprContext(this, _parentctx, _parentState), - ); - this.pushNewRecursionContext( - localctx, - _startState, - RTRegexParser.RULE_expr, - ); - this.state = 48; - if (!this.precpred(this._ctx, 4)) { - throw this.createFailedPredicateException( - 'this.precpred(this._ctx, 4)', - ); - } - this.state = 49; - (localctx as GSequenceContext)._op = this.match( - RTRegexParser.SEQ, - ); - this.state = 50; - this.expr(5); - } - break; - case 4: - { - localctx = new GDegradationContext( - this, - new ExprContext(this, _parentctx, _parentState), - ); - this.pushNewRecursionContext( - localctx, - _startState, - RTRegexParser.RULE_expr, - ); - this.state = 51; - if (!this.precpred(this._ctx, 3)) { - throw this.createFailedPredicateException( - 'this.precpred(this._ctx, 3)', - ); - } - this.state = 52; - (localctx as GDegradationContext)._op = this.match( - RTRegexParser.T__7, - ); - this.state = 53; - this.expr(4); - } - break; - case 5: - { - localctx = new GRetryContext( - this, - new ExprContext(this, _parentctx, _parentState), - ); - this.pushNewRecursionContext( - localctx, - _startState, - RTRegexParser.RULE_expr, - ); - this.state = 54; - if (!this.precpred(this._ctx, 7)) { - throw this.createFailedPredicateException( - 'this.precpred(this._ctx, 7)', - ); - } - this.state = 55; - (localctx as GRetryContext)._op = this.match( - RTRegexParser.T__5, - ); - this.state = 56; - this.match(RTRegexParser.FLOAT); - } - break; - } - } - } - this.state = 61; - this._errHandler.sync(this); - _alt = this._interp.adaptivePredict(this._input, 3, this._ctx); - } - } - } catch (re) { - if (re instanceof RecognitionException) { - localctx.exception = re; - this._errHandler.reportError(this, re); - this._errHandler.recover(this, re); - } else { - throw re; - } - } finally { - this.unrollRecursionContexts(_parentctx); - } - return localctx; - } - // @RuleVersion(0) - public id(): IdContext { - let localctx: IdContext = new IdContext(this, this._ctx, this.state); - this.enterRule(localctx, 4, RTRegexParser.RULE_id); - try { - this.state = 67; - this._errHandler.sync(this); - switch (this._interp.adaptivePredict(this._input, 4, this._ctx)) { - case 1: - this.enterOuterAlt(localctx, 1); - { - this.state = 62; - this.match(RTRegexParser.FLOAT); - } - break; - case 2: - this.enterOuterAlt(localctx, 2); - { - this.state = 63; - this.match(RTRegexParser.FLOAT); - this.state = 64; - this.match(RTRegexParser.X); - } - break; - case 3: - this.enterOuterAlt(localctx, 3); - { - this.state = 65; - this.match(RTRegexParser.X); - } - break; - case 4: - this.enterOuterAlt(localctx, 4); - { - this.state = 66; - this.match(RTRegexParser.DIGIT_SUBID); - } - break; - } - } catch (re) { - if (re instanceof RecognitionException) { - localctx.exception = re; - this._errHandler.reportError(this, re); - this._errHandler.recover(this, re); - } else { - throw re; - } - } finally { - this.exitRule(); - } - return localctx; - } - // @RuleVersion(0) - public word(): WordContext { - let localctx: WordContext = new WordContext(this, this._ctx, this.state); - this.enterRule(localctx, 6, RTRegexParser.RULE_word); - try { - this.enterOuterAlt(localctx, 1); - { - this.state = 69; - this.match(RTRegexParser.WORD); - } - } catch (re) { - if (re instanceof RecognitionException) { - localctx.exception = re; - this._errHandler.reportError(this, re); - this._errHandler.recover(this, re); - } else { - throw re; - } - } finally { - this.exitRule(); - } - return localctx; - } + this.state = 15; + (localctx as GIdContext)._t = this._input.LT(1); + _la = this._input.LA(1); + if(!((((_la) & ~0x1F) === 0 && ((1 << _la) & 98306) !== 0))) { + (localctx as GIdContext)._t = this._errHandler.recoverInline(this); + } + else { + this._errHandler.reportMatch(this); + this.consume(); + } + this.state = 16; + this.id(); + } + break; + case 2: + { + localctx = new GIdContinuedContext(this, localctx); + this._ctx = localctx; + _prevctx = localctx; + this.state = 17; + (localctx as GIdContinuedContext)._t = this._input.LT(1); + _la = this._input.LA(1); + if(!((((_la) & ~0x1F) === 0 && ((1 << _la) & 98306) !== 0))) { + (localctx as GIdContinuedContext)._t = this._errHandler.recoverInline(this); + } + else { + this._errHandler.reportMatch(this); + this.consume(); + } + this.state = 18; + this.id(); + this.state = 19; + this.expr(13); + } + break; + case 3: + { + localctx = new GArgsContext(this, localctx); + this._ctx = localctx; + _prevctx = localctx; + this.state = 21; + (localctx as GArgsContext)._t = this._input.LT(1); + _la = this._input.LA(1); + if(!((((_la) & ~0x1F) === 0 && ((1 << _la) & 98306) !== 0))) { + (localctx as GArgsContext)._t = this._errHandler.recoverInline(this); + } + else { + this._errHandler.reportMatch(this); + this.consume(); + } + this.state = 22; + this.id(); + this.state = 23; + this.match(RTRegexParser.T__1); + this.state = 24; + this.expr(12); + } + break; + case 4: + { + localctx = new NotationStartContext(this, localctx); + this._ctx = localctx; + _prevctx = localctx; + this.state = 26; + this.match(RTRegexParser.T__2); + this.state = 27; + this.expr(0); + this.state = 28; + this.match(RTRegexParser.T__3); + } + break; + case 5: + { + localctx = new NameContinuedContext(this, localctx); + this._ctx = localctx; + _prevctx = localctx; + this.state = 30; + this.match(RTRegexParser.T__4); + this.state = 31; + this.word(); + this.state = 32; + this.expr(10); + } + break; + case 6: + { + localctx = new NameOnlyContext(this, localctx); + this._ctx = localctx; + _prevctx = localctx; + this.state = 34; + this.match(RTRegexParser.T__4); + this.state = 35; + this.word(); + this.state = 36; + this.match(RTRegexParser.EOF); + } + break; + case 7: + { + localctx = new GSkipContext(this, localctx); + this._ctx = localctx; + _prevctx = localctx; + this.state = 38; + this.match(RTRegexParser.SKIPP); + } + break; + } + this._ctx.stop = this._input.LT(-1); + this.state = 64; + this._errHandler.sync(this); + _alt = this._interp.adaptivePredict(this._input, 3, this._ctx); + while (_alt !== 2 && _alt !== ATN.INVALID_ALT_NUMBER) { + if (_alt === 1) { + if (this._parseListeners != null) { + this.triggerExitRuleEvent(); + } + _prevctx = localctx; + { + this.state = 62; + this._errHandler.sync(this); + switch ( this._interp.adaptivePredict(this._input, 2, this._ctx) ) { + case 1: + { + localctx = new GAlternativeContext(this, new ExprContext(this, _parentctx, _parentState)); + this.pushNewRecursionContext(localctx, _startState, RTRegexParser.RULE_expr); + this.state = 41; + if (!(this.precpred(this._ctx, 7))) { + throw this.createFailedPredicateException("this.precpred(this._ctx, 7)"); + } + this.state = 42; + (localctx as GAlternativeContext)._op = this.match(RTRegexParser.T__6); + this.state = 43; + this.expr(8); + } + break; + case 2: + { + localctx = new GChoiceContext(this, new ExprContext(this, _parentctx, _parentState)); + this.pushNewRecursionContext(localctx, _startState, RTRegexParser.RULE_expr); + this.state = 44; + if (!(this.precpred(this._ctx, 6))) { + throw this.createFailedPredicateException("this.precpred(this._ctx, 6)"); + } + this.state = 45; + (localctx as GChoiceContext)._op = this.match(RTRegexParser.T__7); + this.state = 46; + this.expr(7); + } + break; + case 3: + { + localctx = new GAnyOrderContext(this, new ExprContext(this, _parentctx, _parentState)); + this.pushNewRecursionContext(localctx, _startState, RTRegexParser.RULE_expr); + this.state = 47; + if (!(this.precpred(this._ctx, 5))) { + throw this.createFailedPredicateException("this.precpred(this._ctx, 5)"); + } + this.state = 48; + (localctx as GAnyOrderContext)._op = this.match(RTRegexParser.T__8); + this.state = 49; + this.expr(6); + } + break; + case 4: + { + localctx = new GInterleavedContext(this, new ExprContext(this, _parentctx, _parentState)); + this.pushNewRecursionContext(localctx, _startState, RTRegexParser.RULE_expr); + this.state = 50; + if (!(this.precpred(this._ctx, 4))) { + throw this.createFailedPredicateException("this.precpred(this._ctx, 4)"); + } + this.state = 51; + (localctx as GInterleavedContext)._op = this.match(RTRegexParser.INT); + this.state = 52; + this.expr(5); + } + break; + case 5: + { + localctx = new GSequenceContext(this, new ExprContext(this, _parentctx, _parentState)); + this.pushNewRecursionContext(localctx, _startState, RTRegexParser.RULE_expr); + this.state = 53; + if (!(this.precpred(this._ctx, 3))) { + throw this.createFailedPredicateException("this.precpred(this._ctx, 3)"); + } + this.state = 54; + (localctx as GSequenceContext)._op = this.match(RTRegexParser.SEQ); + this.state = 55; + this.expr(4); + } + break; + case 6: + { + localctx = new GDegradationContext(this, new ExprContext(this, _parentctx, _parentState)); + this.pushNewRecursionContext(localctx, _startState, RTRegexParser.RULE_expr); + this.state = 56; + if (!(this.precpred(this._ctx, 2))) { + throw this.createFailedPredicateException("this.precpred(this._ctx, 2)"); + } + this.state = 57; + (localctx as GDegradationContext)._op = this.match(RTRegexParser.T__9); + this.state = 58; + this.expr(3); + } + break; + case 7: + { + localctx = new GRetryContext(this, new ExprContext(this, _parentctx, _parentState)); + this.pushNewRecursionContext(localctx, _startState, RTRegexParser.RULE_expr); + this.state = 59; + if (!(this.precpred(this._ctx, 8))) { + throw this.createFailedPredicateException("this.precpred(this._ctx, 8)"); + } + this.state = 60; + (localctx as GRetryContext)._op = this.match(RTRegexParser.T__5); + this.state = 61; + this.match(RTRegexParser.FLOAT); + } + break; + } + } + } + this.state = 66; + this._errHandler.sync(this); + _alt = this._interp.adaptivePredict(this._input, 3, this._ctx); + } + } + } + catch (re) { + if (re instanceof RecognitionException) { + localctx.exception = re; + this._errHandler.reportError(this, re); + this._errHandler.recover(this, re); + } else { + throw re; + } + } + finally { + this.unrollRecursionContexts(_parentctx); + } + return localctx; + } + // @RuleVersion(0) + public id(): IdContext { + let localctx: IdContext = new IdContext(this, this._ctx, this.state); + this.enterRule(localctx, 4, RTRegexParser.RULE_id); + try { + this.state = 72; + this._errHandler.sync(this); + switch ( this._interp.adaptivePredict(this._input, 4, this._ctx) ) { + case 1: + this.enterOuterAlt(localctx, 1); + { + this.state = 67; + this.match(RTRegexParser.FLOAT); + } + break; + case 2: + this.enterOuterAlt(localctx, 2); + { + this.state = 68; + this.match(RTRegexParser.FLOAT); + this.state = 69; + this.match(RTRegexParser.X); + } + break; + case 3: + this.enterOuterAlt(localctx, 3); + { + this.state = 70; + this.match(RTRegexParser.X); + } + break; + case 4: + this.enterOuterAlt(localctx, 4); + { + this.state = 71; + this.match(RTRegexParser.DIGIT_SUBID); + } + break; + } + } + catch (re) { + if (re instanceof RecognitionException) { + localctx.exception = re; + this._errHandler.reportError(this, re); + this._errHandler.recover(this, re); + } else { + throw re; + } + } + finally { + this.exitRule(); + } + return localctx; + } + // @RuleVersion(0) + public word(): WordContext { + let localctx: WordContext = new WordContext(this, this._ctx, this.state); + this.enterRule(localctx, 6, RTRegexParser.RULE_word); + try { + this.enterOuterAlt(localctx, 1); + { + this.state = 74; + this.match(RTRegexParser.WORD); + } + } + catch (re) { + if (re instanceof RecognitionException) { + localctx.exception = re; + this._errHandler.reportError(this, re); + this._errHandler.recover(this, re); + } else { + throw re; + } + } + finally { + this.exitRule(); + } + return localctx; + } - public sempred( - localctx: RuleContext, - ruleIndex: number, - predIndex: number, - ): boolean { - switch (ruleIndex) { - case 1: - return this.expr_sempred(localctx as ExprContext, predIndex); - } - return true; - } - private expr_sempred(localctx: ExprContext, predIndex: number): boolean { - switch (predIndex) { - case 0: - return this.precpred(this._ctx, 6); - case 1: - return this.precpred(this._ctx, 5); - case 2: - return this.precpred(this._ctx, 4); - case 3: - return this.precpred(this._ctx, 3); - case 4: - return this.precpred(this._ctx, 7); - } - return true; - } + public sempred(localctx: RuleContext, ruleIndex: number, predIndex: number): boolean { + switch (ruleIndex) { + case 1: + return this.expr_sempred(localctx as ExprContext, predIndex); + } + return true; + } + private expr_sempred(localctx: ExprContext, predIndex: number): boolean { + switch (predIndex) { + case 0: + return this.precpred(this._ctx, 7); + case 1: + return this.precpred(this._ctx, 6); + case 2: + return this.precpred(this._ctx, 5); + case 3: + return this.precpred(this._ctx, 4); + case 4: + return this.precpred(this._ctx, 3); + case 5: + return this.precpred(this._ctx, 2); + case 6: + return this.precpred(this._ctx, 8); + } + return true; + } - public static readonly _serializedATN: number[] = [ - 4, 1, 21, 72, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 1, 0, 1, 0, 1, - 0, 1, 0, 3, 0, 13, 8, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 41, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 1, 58, 8, 1, - 10, 1, 12, 1, 61, 9, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 3, 2, 68, 8, 2, 1, 3, - 1, 3, 1, 3, 0, 1, 2, 4, 0, 2, 4, 6, 0, 1, 2, 0, 1, 1, 14, 15, 83, 0, 12, 1, - 0, 0, 0, 2, 40, 1, 0, 0, 0, 4, 67, 1, 0, 0, 0, 6, 69, 1, 0, 0, 0, 8, 9, 3, - 2, 1, 0, 9, 10, 5, 0, 0, 1, 10, 13, 1, 0, 0, 0, 11, 13, 5, 0, 0, 1, 12, 8, - 1, 0, 0, 0, 12, 11, 1, 0, 0, 0, 13, 1, 1, 0, 0, 0, 14, 15, 6, 1, -1, 0, 15, - 16, 7, 0, 0, 0, 16, 41, 3, 4, 2, 0, 17, 18, 7, 0, 0, 0, 18, 19, 3, 4, 2, 0, - 19, 20, 3, 2, 1, 12, 20, 41, 1, 0, 0, 0, 21, 22, 7, 0, 0, 0, 22, 23, 3, 4, - 2, 0, 23, 24, 5, 2, 0, 0, 24, 25, 3, 2, 1, 11, 25, 41, 1, 0, 0, 0, 26, 27, - 5, 3, 0, 0, 27, 28, 3, 2, 1, 0, 28, 29, 5, 4, 0, 0, 29, 41, 1, 0, 0, 0, 30, - 31, 5, 5, 0, 0, 31, 32, 3, 6, 3, 0, 32, 33, 3, 2, 1, 9, 33, 41, 1, 0, 0, 0, - 34, 35, 5, 5, 0, 0, 35, 36, 3, 6, 3, 0, 36, 37, 5, 0, 0, 1, 37, 41, 1, 0, 0, - 0, 38, 41, 5, 9, 0, 0, 39, 41, 5, 16, 0, 0, 40, 14, 1, 0, 0, 0, 40, 17, 1, - 0, 0, 0, 40, 21, 1, 0, 0, 0, 40, 26, 1, 0, 0, 0, 40, 30, 1, 0, 0, 0, 40, 34, - 1, 0, 0, 0, 40, 38, 1, 0, 0, 0, 40, 39, 1, 0, 0, 0, 41, 59, 1, 0, 0, 0, 42, - 43, 10, 6, 0, 0, 43, 44, 5, 7, 0, 0, 44, 58, 3, 2, 1, 7, 45, 46, 10, 5, 0, - 0, 46, 47, 5, 13, 0, 0, 47, 58, 3, 2, 1, 6, 48, 49, 10, 4, 0, 0, 49, 50, 5, - 12, 0, 0, 50, 58, 3, 2, 1, 5, 51, 52, 10, 3, 0, 0, 52, 53, 5, 8, 0, 0, 53, - 58, 3, 2, 1, 4, 54, 55, 10, 7, 0, 0, 55, 56, 5, 6, 0, 0, 56, 58, 5, 11, 0, - 0, 57, 42, 1, 0, 0, 0, 57, 45, 1, 0, 0, 0, 57, 48, 1, 0, 0, 0, 57, 51, 1, 0, - 0, 0, 57, 54, 1, 0, 0, 0, 58, 61, 1, 0, 0, 0, 59, 57, 1, 0, 0, 0, 59, 60, 1, - 0, 0, 0, 60, 3, 1, 0, 0, 0, 61, 59, 1, 0, 0, 0, 62, 68, 5, 11, 0, 0, 63, 64, - 5, 11, 0, 0, 64, 68, 5, 17, 0, 0, 65, 68, 5, 17, 0, 0, 66, 68, 5, 10, 0, 0, - 67, 62, 1, 0, 0, 0, 67, 63, 1, 0, 0, 0, 67, 65, 1, 0, 0, 0, 67, 66, 1, 0, 0, - 0, 68, 5, 1, 0, 0, 0, 69, 70, 5, 19, 0, 0, 70, 7, 1, 0, 0, 0, 5, 12, 40, 57, - 59, 67, - ]; + public static readonly _serializedATN: number[] = [4,1,22,77,2,0,7,0,2, + 1,7,1,2,2,7,2,2,3,7,3,1,0,1,0,1,0,1,0,3,0,13,8,0,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,3,1,40,8,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,1,63,8,1,10,1,12,1,66,9,1,1,2,1,2,1,2,1, + 2,1,2,3,2,73,8,2,1,3,1,3,1,3,0,1,2,4,0,2,4,6,0,1,2,0,1,1,15,16,89,0,12, + 1,0,0,0,2,39,1,0,0,0,4,72,1,0,0,0,6,74,1,0,0,0,8,9,3,2,1,0,9,10,5,0,0,1, + 10,13,1,0,0,0,11,13,5,0,0,1,12,8,1,0,0,0,12,11,1,0,0,0,13,1,1,0,0,0,14, + 15,6,1,-1,0,15,16,7,0,0,0,16,40,3,4,2,0,17,18,7,0,0,0,18,19,3,4,2,0,19, + 20,3,2,1,13,20,40,1,0,0,0,21,22,7,0,0,0,22,23,3,4,2,0,23,24,5,2,0,0,24, + 25,3,2,1,12,25,40,1,0,0,0,26,27,5,3,0,0,27,28,3,2,1,0,28,29,5,4,0,0,29, + 40,1,0,0,0,30,31,5,5,0,0,31,32,3,6,3,0,32,33,3,2,1,10,33,40,1,0,0,0,34, + 35,5,5,0,0,35,36,3,6,3,0,36,37,5,0,0,1,37,40,1,0,0,0,38,40,5,17,0,0,39, + 14,1,0,0,0,39,17,1,0,0,0,39,21,1,0,0,0,39,26,1,0,0,0,39,30,1,0,0,0,39,34, + 1,0,0,0,39,38,1,0,0,0,40,64,1,0,0,0,41,42,10,7,0,0,42,43,5,7,0,0,43,63, + 3,2,1,8,44,45,10,6,0,0,45,46,5,8,0,0,46,63,3,2,1,7,47,48,10,5,0,0,48,49, + 5,9,0,0,49,63,3,2,1,6,50,51,10,4,0,0,51,52,5,14,0,0,52,63,3,2,1,5,53,54, + 10,3,0,0,54,55,5,13,0,0,55,63,3,2,1,4,56,57,10,2,0,0,57,58,5,10,0,0,58, + 63,3,2,1,3,59,60,10,8,0,0,60,61,5,6,0,0,61,63,5,12,0,0,62,41,1,0,0,0,62, + 44,1,0,0,0,62,47,1,0,0,0,62,50,1,0,0,0,62,53,1,0,0,0,62,56,1,0,0,0,62,59, + 1,0,0,0,63,66,1,0,0,0,64,62,1,0,0,0,64,65,1,0,0,0,65,3,1,0,0,0,66,64,1, + 0,0,0,67,73,5,12,0,0,68,69,5,12,0,0,69,73,5,18,0,0,70,73,5,18,0,0,71,73, + 5,11,0,0,72,67,1,0,0,0,72,68,1,0,0,0,72,70,1,0,0,0,72,71,1,0,0,0,73,5,1, + 0,0,0,74,75,5,20,0,0,75,7,1,0,0,0,5,12,39,62,64,72]; - private static __ATN: ATN; - public static get _ATN(): ATN { - if (!RTRegexParser.__ATN) { - RTRegexParser.__ATN = new ATNDeserializer().deserialize( - RTRegexParser._serializedATN, - ); - } + private static __ATN: ATN; + public static get _ATN(): ATN { + if (!RTRegexParser.__ATN) { + RTRegexParser.__ATN = new ATNDeserializer().deserialize(RTRegexParser._serializedATN); + } - return RTRegexParser.__ATN; - } + return RTRegexParser.__ATN; + } + + + static DecisionsToDFA = RTRegexParser._ATN.decisionToState.map( (ds: DecisionState, index: number) => new DFA(ds, index) ); - static DecisionsToDFA = RTRegexParser._ATN.decisionToState.map( - (ds: DecisionState, index: number) => new DFA(ds, index), - ); } export class RtContext extends ParserRuleContext { - constructor( - parser?: RTRegexParser, - parent?: ParserRuleContext, - invokingState?: number, - ) { - super(parent, invokingState); - this.parser = parser; - } - public get ruleIndex(): number { - return RTRegexParser.RULE_rt; - } - public override copyFrom(ctx: RtContext): void { - super.copyFrom(ctx); - } + constructor(parser?: RTRegexParser, parent?: ParserRuleContext, invokingState?: number) { + super(parent, invokingState); + this.parser = parser; + } + public get ruleIndex(): number { + return RTRegexParser.RULE_rt; + } + public override copyFrom(ctx: RtContext): void { + super.copyFrom(ctx); + } } export class BlankContext extends RtContext { - constructor(parser: RTRegexParser, ctx: RtContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public EOF(): TerminalNode { - return this.getToken(RTRegexParser.EOF, 0); - } - public enterRule(listener: RTRegexListener): void { - if (listener.enterBlank) { - listener.enterBlank(this); - } - } - public exitRule(listener: RTRegexListener): void { - if (listener.exitBlank) { - listener.exitBlank(this); - } - } + constructor(parser: RTRegexParser, ctx: RtContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public EOF(): TerminalNode { + return this.getToken(RTRegexParser.EOF, 0); + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterBlank) { + listener.enterBlank(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitBlank) { + listener.exitBlank(this); + } + } } export class PrintExprContext extends RtContext { - constructor(parser: RTRegexParser, ctx: RtContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public expr(): ExprContext { - return this.getTypedRuleContext(ExprContext, 0) as ExprContext; - } - public EOF(): TerminalNode { - return this.getToken(RTRegexParser.EOF, 0); - } - public enterRule(listener: RTRegexListener): void { - if (listener.enterPrintExpr) { - listener.enterPrintExpr(this); - } - } - public exitRule(listener: RTRegexListener): void { - if (listener.exitPrintExpr) { - listener.exitPrintExpr(this); - } - } + constructor(parser: RTRegexParser, ctx: RtContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public expr(): ExprContext { + return this.getTypedRuleContext(ExprContext, 0) as ExprContext; + } + public EOF(): TerminalNode { + return this.getToken(RTRegexParser.EOF, 0); + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterPrintExpr) { + listener.enterPrintExpr(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitPrintExpr) { + listener.exitPrintExpr(this); + } + } } + export class ExprContext extends ParserRuleContext { - constructor( - parser?: RTRegexParser, - parent?: ParserRuleContext, - invokingState?: number, - ) { - super(parent, invokingState); - this.parser = parser; - } - public get ruleIndex(): number { - return RTRegexParser.RULE_expr; - } - public override copyFrom(ctx: ExprContext): void { - super.copyFrom(ctx); - } + constructor(parser?: RTRegexParser, parent?: ParserRuleContext, invokingState?: number) { + super(parent, invokingState); + this.parser = parser; + } + public get ruleIndex(): number { + return RTRegexParser.RULE_expr; + } + public override copyFrom(ctx: ExprContext): void { + super.copyFrom(ctx); + } +} +export class GAnyOrderContext extends ExprContext { + public _op!: Token; + constructor(parser: RTRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public expr_list(): ExprContext[] { + return this.getTypedRuleContexts(ExprContext) as ExprContext[]; + } + public expr(i: number): ExprContext { + return this.getTypedRuleContext(ExprContext, i) as ExprContext; + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterGAnyOrder) { + listener.enterGAnyOrder(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitGAnyOrder) { + listener.exitGAnyOrder(this); + } + } } export class GIdContext extends ExprContext { - public _t!: Token; - constructor(parser: RTRegexParser, ctx: ExprContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public id(): IdContext { - return this.getTypedRuleContext(IdContext, 0) as IdContext; - } - public GOAL(): TerminalNode { - return this.getToken(RTRegexParser.GOAL, 0); - } - public TASK(): TerminalNode { - return this.getToken(RTRegexParser.TASK, 0); - } - public enterRule(listener: RTRegexListener): void { - if (listener.enterGId) { - listener.enterGId(this); - } - } - public exitRule(listener: RTRegexListener): void { - if (listener.exitGId) { - listener.exitGId(this); - } - } + public _t!: Token; + constructor(parser: RTRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public id(): IdContext { + return this.getTypedRuleContext(IdContext, 0) as IdContext; + } + public GOAL(): TerminalNode { + return this.getToken(RTRegexParser.GOAL, 0); + } + public TASK(): TerminalNode { + return this.getToken(RTRegexParser.TASK, 0); + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterGId) { + listener.enterGId(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitGId) { + listener.exitGId(this); + } + } } export class NameOnlyContext extends ExprContext { - constructor(parser: RTRegexParser, ctx: ExprContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public word(): WordContext { - return this.getTypedRuleContext(WordContext, 0) as WordContext; - } - public EOF(): TerminalNode { - return this.getToken(RTRegexParser.EOF, 0); - } - public enterRule(listener: RTRegexListener): void { - if (listener.enterNameOnly) { - listener.enterNameOnly(this); - } - } - public exitRule(listener: RTRegexListener): void { - if (listener.exitNameOnly) { - listener.exitNameOnly(this); - } - } + constructor(parser: RTRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public word(): WordContext { + return this.getTypedRuleContext(WordContext, 0) as WordContext; + } + public EOF(): TerminalNode { + return this.getToken(RTRegexParser.EOF, 0); + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterNameOnly) { + listener.enterNameOnly(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitNameOnly) { + listener.exitNameOnly(this); + } + } } export class GInterleavedContext extends ExprContext { - public _op!: Token; - constructor(parser: RTRegexParser, ctx: ExprContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public expr_list(): ExprContext[] { - return this.getTypedRuleContexts(ExprContext) as ExprContext[]; - } - public expr(i: number): ExprContext { - return this.getTypedRuleContext(ExprContext, i) as ExprContext; - } - public INT(): TerminalNode { - return this.getToken(RTRegexParser.INT, 0); - } - public enterRule(listener: RTRegexListener): void { - if (listener.enterGInterleaved) { - listener.enterGInterleaved(this); - } - } - public exitRule(listener: RTRegexListener): void { - if (listener.exitGInterleaved) { - listener.exitGInterleaved(this); - } - } + public _op!: Token; + constructor(parser: RTRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public expr_list(): ExprContext[] { + return this.getTypedRuleContexts(ExprContext) as ExprContext[]; + } + public expr(i: number): ExprContext { + return this.getTypedRuleContext(ExprContext, i) as ExprContext; + } + public INT(): TerminalNode { + return this.getToken(RTRegexParser.INT, 0); + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterGInterleaved) { + listener.enterGInterleaved(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitGInterleaved) { + listener.exitGInterleaved(this); + } + } } export class GChoiceContext extends ExprContext { - public _op!: Token; - constructor(parser: RTRegexParser, ctx: ExprContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public enterRule(listener: RTRegexListener): void { - if (listener.enterGChoice) { - listener.enterGChoice(this); - } - } - public exitRule(listener: RTRegexListener): void { - if (listener.exitGChoice) { - listener.exitGChoice(this); - } - } + public _op!: Token; + constructor(parser: RTRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public expr_list(): ExprContext[] { + return this.getTypedRuleContexts(ExprContext) as ExprContext[]; + } + public expr(i: number): ExprContext { + return this.getTypedRuleContext(ExprContext, i) as ExprContext; + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterGChoice) { + listener.enterGChoice(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitGChoice) { + listener.exitGChoice(this); + } + } } export class GArgsContext extends ExprContext { - public _t!: Token; - constructor(parser: RTRegexParser, ctx: ExprContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public id(): IdContext { - return this.getTypedRuleContext(IdContext, 0) as IdContext; - } - public expr(): ExprContext { - return this.getTypedRuleContext(ExprContext, 0) as ExprContext; - } - public GOAL(): TerminalNode { - return this.getToken(RTRegexParser.GOAL, 0); - } - public TASK(): TerminalNode { - return this.getToken(RTRegexParser.TASK, 0); - } - public enterRule(listener: RTRegexListener): void { - if (listener.enterGArgs) { - listener.enterGArgs(this); - } - } - public exitRule(listener: RTRegexListener): void { - if (listener.exitGArgs) { - listener.exitGArgs(this); - } - } + public _t!: Token; + constructor(parser: RTRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public id(): IdContext { + return this.getTypedRuleContext(IdContext, 0) as IdContext; + } + public expr(): ExprContext { + return this.getTypedRuleContext(ExprContext, 0) as ExprContext; + } + public GOAL(): TerminalNode { + return this.getToken(RTRegexParser.GOAL, 0); + } + public TASK(): TerminalNode { + return this.getToken(RTRegexParser.TASK, 0); + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterGArgs) { + listener.enterGArgs(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitGArgs) { + listener.exitGArgs(this); + } + } } export class NameContinuedContext extends ExprContext { - constructor(parser: RTRegexParser, ctx: ExprContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public word(): WordContext { - return this.getTypedRuleContext(WordContext, 0) as WordContext; - } - public expr(): ExprContext { - return this.getTypedRuleContext(ExprContext, 0) as ExprContext; - } - public enterRule(listener: RTRegexListener): void { - if (listener.enterNameContinued) { - listener.enterNameContinued(this); - } - } - public exitRule(listener: RTRegexListener): void { - if (listener.exitNameContinued) { - listener.exitNameContinued(this); - } - } + constructor(parser: RTRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public word(): WordContext { + return this.getTypedRuleContext(WordContext, 0) as WordContext; + } + public expr(): ExprContext { + return this.getTypedRuleContext(ExprContext, 0) as ExprContext; + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterNameContinued) { + listener.enterNameContinued(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitNameContinued) { + listener.exitNameContinued(this); + } + } } export class GAlternativeContext extends ExprContext { - public _op!: Token; - constructor(parser: RTRegexParser, ctx: ExprContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public expr_list(): ExprContext[] { - return this.getTypedRuleContexts(ExprContext) as ExprContext[]; - } - public expr(i: number): ExprContext { - return this.getTypedRuleContext(ExprContext, i) as ExprContext; - } - public enterRule(listener: RTRegexListener): void { - if (listener.enterGAlternative) { - listener.enterGAlternative(this); - } - } - public exitRule(listener: RTRegexListener): void { - if (listener.exitGAlternative) { - listener.exitGAlternative(this); - } - } + public _op!: Token; + constructor(parser: RTRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public expr_list(): ExprContext[] { + return this.getTypedRuleContexts(ExprContext) as ExprContext[]; + } + public expr(i: number): ExprContext { + return this.getTypedRuleContext(ExprContext, i) as ExprContext; + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterGAlternative) { + listener.enterGAlternative(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitGAlternative) { + listener.exitGAlternative(this); + } + } } export class GDegradationContext extends ExprContext { - public _op!: Token; - constructor(parser: RTRegexParser, ctx: ExprContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public expr_list(): ExprContext[] { - return this.getTypedRuleContexts(ExprContext) as ExprContext[]; - } - public expr(i: number): ExprContext { - return this.getTypedRuleContext(ExprContext, i) as ExprContext; - } - public enterRule(listener: RTRegexListener): void { - if (listener.enterGDegradation) { - listener.enterGDegradation(this); - } - } - public exitRule(listener: RTRegexListener): void { - if (listener.exitGDegradation) { - listener.exitGDegradation(this); - } - } + public _op!: Token; + constructor(parser: RTRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public expr_list(): ExprContext[] { + return this.getTypedRuleContexts(ExprContext) as ExprContext[]; + } + public expr(i: number): ExprContext { + return this.getTypedRuleContext(ExprContext, i) as ExprContext; + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterGDegradation) { + listener.enterGDegradation(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitGDegradation) { + listener.exitGDegradation(this); + } + } } export class GSkipContext extends ExprContext { - constructor(parser: RTRegexParser, ctx: ExprContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public SKIPP(): TerminalNode { - return this.getToken(RTRegexParser.SKIPP, 0); - } - public enterRule(listener: RTRegexListener): void { - if (listener.enterGSkip) { - listener.enterGSkip(this); - } - } - public exitRule(listener: RTRegexListener): void { - if (listener.exitGSkip) { - listener.exitGSkip(this); - } - } + constructor(parser: RTRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public SKIPP(): TerminalNode { + return this.getToken(RTRegexParser.SKIPP, 0); + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterGSkip) { + listener.enterGSkip(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitGSkip) { + listener.exitGSkip(this); + } + } } export class NotationStartContext extends ExprContext { - constructor(parser: RTRegexParser, ctx: ExprContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public expr(): ExprContext { - return this.getTypedRuleContext(ExprContext, 0) as ExprContext; - } - public enterRule(listener: RTRegexListener): void { - if (listener.enterNotationStart) { - listener.enterNotationStart(this); - } - } - public exitRule(listener: RTRegexListener): void { - if (listener.exitNotationStart) { - listener.exitNotationStart(this); - } - } + constructor(parser: RTRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public expr(): ExprContext { + return this.getTypedRuleContext(ExprContext, 0) as ExprContext; + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterNotationStart) { + listener.enterNotationStart(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitNotationStart) { + listener.exitNotationStart(this); + } + } } export class GRetryContext extends ExprContext { - public _op!: Token; - constructor(parser: RTRegexParser, ctx: ExprContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public expr(): ExprContext { - return this.getTypedRuleContext(ExprContext, 0) as ExprContext; - } - public FLOAT(): TerminalNode { - return this.getToken(RTRegexParser.FLOAT, 0); - } - public enterRule(listener: RTRegexListener): void { - if (listener.enterGRetry) { - listener.enterGRetry(this); - } - } - public exitRule(listener: RTRegexListener): void { - if (listener.exitGRetry) { - listener.exitGRetry(this); - } - } + public _op!: Token; + constructor(parser: RTRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public expr(): ExprContext { + return this.getTypedRuleContext(ExprContext, 0) as ExprContext; + } + public FLOAT(): TerminalNode { + return this.getToken(RTRegexParser.FLOAT, 0); + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterGRetry) { + listener.enterGRetry(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitGRetry) { + listener.exitGRetry(this); + } + } } export class GSequenceContext extends ExprContext { - public _op!: Token; - constructor(parser: RTRegexParser, ctx: ExprContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public expr_list(): ExprContext[] { - return this.getTypedRuleContexts(ExprContext) as ExprContext[]; - } - public expr(i: number): ExprContext { - return this.getTypedRuleContext(ExprContext, i) as ExprContext; - } - public SEQ(): TerminalNode { - return this.getToken(RTRegexParser.SEQ, 0); - } - public enterRule(listener: RTRegexListener): void { - if (listener.enterGSequence) { - listener.enterGSequence(this); - } - } - public exitRule(listener: RTRegexListener): void { - if (listener.exitGSequence) { - listener.exitGSequence(this); - } - } + public _op!: Token; + constructor(parser: RTRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public expr_list(): ExprContext[] { + return this.getTypedRuleContexts(ExprContext) as ExprContext[]; + } + public expr(i: number): ExprContext { + return this.getTypedRuleContext(ExprContext, i) as ExprContext; + } + public SEQ(): TerminalNode { + return this.getToken(RTRegexParser.SEQ, 0); + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterGSequence) { + listener.enterGSequence(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitGSequence) { + listener.exitGSequence(this); + } + } } export class GIdContinuedContext extends ExprContext { - public _t!: Token; - constructor(parser: RTRegexParser, ctx: ExprContext) { - super(parser, ctx.parentCtx, ctx.invokingState); - super.copyFrom(ctx); - } - public id(): IdContext { - return this.getTypedRuleContext(IdContext, 0) as IdContext; - } - public expr(): ExprContext { - return this.getTypedRuleContext(ExprContext, 0) as ExprContext; - } - public GOAL(): TerminalNode { - return this.getToken(RTRegexParser.GOAL, 0); - } - public TASK(): TerminalNode { - return this.getToken(RTRegexParser.TASK, 0); - } - public enterRule(listener: RTRegexListener): void { - if (listener.enterGIdContinued) { - listener.enterGIdContinued(this); - } - } - public exitRule(listener: RTRegexListener): void { - if (listener.exitGIdContinued) { - listener.exitGIdContinued(this); - } - } + public _t!: Token; + constructor(parser: RTRegexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public id(): IdContext { + return this.getTypedRuleContext(IdContext, 0) as IdContext; + } + public expr(): ExprContext { + return this.getTypedRuleContext(ExprContext, 0) as ExprContext; + } + public GOAL(): TerminalNode { + return this.getToken(RTRegexParser.GOAL, 0); + } + public TASK(): TerminalNode { + return this.getToken(RTRegexParser.TASK, 0); + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterGIdContinued) { + listener.enterGIdContinued(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitGIdContinued) { + listener.exitGIdContinued(this); + } + } } + export class IdContext extends ParserRuleContext { - constructor( - parser?: RTRegexParser, - parent?: ParserRuleContext, - invokingState?: number, - ) { - super(parent, invokingState); - this.parser = parser; - } - public FLOAT(): TerminalNode { - return this.getToken(RTRegexParser.FLOAT, 0); - } - public X(): TerminalNode { - return this.getToken(RTRegexParser.X, 0); - } - public DIGIT_SUBID(): TerminalNode { - return this.getToken(RTRegexParser.DIGIT_SUBID, 0); - } - public get ruleIndex(): number { - return RTRegexParser.RULE_id; - } - public enterRule(listener: RTRegexListener): void { - if (listener.enterId) { - listener.enterId(this); - } - } - public exitRule(listener: RTRegexListener): void { - if (listener.exitId) { - listener.exitId(this); - } - } + constructor(parser?: RTRegexParser, parent?: ParserRuleContext, invokingState?: number) { + super(parent, invokingState); + this.parser = parser; + } + public FLOAT(): TerminalNode { + return this.getToken(RTRegexParser.FLOAT, 0); + } + public X(): TerminalNode { + return this.getToken(RTRegexParser.X, 0); + } + public DIGIT_SUBID(): TerminalNode { + return this.getToken(RTRegexParser.DIGIT_SUBID, 0); + } + public get ruleIndex(): number { + return RTRegexParser.RULE_id; + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterId) { + listener.enterId(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitId) { + listener.exitId(this); + } + } } + export class WordContext extends ParserRuleContext { - constructor( - parser?: RTRegexParser, - parent?: ParserRuleContext, - invokingState?: number, - ) { - super(parent, invokingState); - this.parser = parser; - } - public WORD(): TerminalNode { - return this.getToken(RTRegexParser.WORD, 0); - } - public get ruleIndex(): number { - return RTRegexParser.RULE_word; - } - public enterRule(listener: RTRegexListener): void { - if (listener.enterWord) { - listener.enterWord(this); - } - } - public exitRule(listener: RTRegexListener): void { - if (listener.exitWord) { - listener.exitWord(this); - } - } + constructor(parser?: RTRegexParser, parent?: ParserRuleContext, invokingState?: number) { + super(parent, invokingState); + this.parser = parser; + } + public WORD(): TerminalNode { + return this.getToken(RTRegexParser.WORD, 0); + } + public get ruleIndex(): number { + return RTRegexParser.RULE_word; + } + public enterRule(listener: RTRegexListener): void { + if(listener.enterWord) { + listener.enterWord(this); + } + } + public exitRule(listener: RTRegexListener): void { + if(listener.exitWord) { + listener.exitWord(this); + } + } } diff --git a/packages/lib/src/engines/edge/types.ts b/packages/lib/src/engines/edge/types.ts index ed0357bd..97154c2f 100644 --- a/packages/lib/src/engines/edge/types.ts +++ b/packages/lib/src/engines/edge/types.ts @@ -25,6 +25,7 @@ export type GoalExecutionDetail = ( | { type: 'interleaved'; interleaved: string[] } | { type: 'alternative'; alternative: string[] } | { type: 'sequence'; sequence: string[] } + | { type: 'anyOrder'; anyOrder: string[] } | { type: 'degradation'; degradationList: string[] } | { type: 'decisionMaking'; dm: string[] } | { type: 'choice' } diff --git a/packages/lib/src/engines/edgeV2/index.ts b/packages/lib/src/engines/edgeV2/index.ts index a91ba081..f1449b74 100644 --- a/packages/lib/src/engines/edgeV2/index.ts +++ b/packages/lib/src/engines/edgeV2/index.ts @@ -25,6 +25,7 @@ export { // Types export type { + Decision, EdgeGoalProps, EdgeResourceProps, EdgeResourceVariable, diff --git a/packages/lib/src/engines/edgeV2/logger/logger.ts b/packages/lib/src/engines/edgeV2/logger/logger.ts index 6f0b769d..22b0206c 100644 --- a/packages/lib/src/engines/edgeV2/logger/logger.ts +++ b/packages/lib/src/engines/edgeV2/logger/logger.ts @@ -32,6 +32,7 @@ type LoggerStore = { goalTypeAlternative: number; goalTypeSequence: number; goalTypeInterleaved: number; + goalTypeAnyOrder: number; totalTasks: number; totalResources: number; totalNodes: number; @@ -53,6 +54,7 @@ type LoggerReport = { goalTypeAlternative: number; goalTypeSequence: number; goalTypeInterleaved: number; + goalTypeAnyOrder: number; goalModules: number; goalVariables: number; goalPursueLines: number; @@ -117,6 +119,7 @@ export const createStore = (): LoggerStore => { goalTypeAlternative: 0, goalTypeSequence: 0, goalTypeInterleaved: 0, + goalTypeAnyOrder: 0, totalTasks: 0, totalResources: 0, totalNodes: 0, @@ -175,6 +178,11 @@ const createLogger = ( }; const loggerInstance = { + decisionVariable: (decisionVariable: [string, number]) => { + write( + `[DECISION VARIABLES]: ${decisionVariable[0]}: space ${decisionVariable[1]}\n`, + ); + }, initGoal: (goal: GoalNode) => { store.goalModules++; store.totalGoals++; @@ -197,6 +205,9 @@ const createLogger = ( case 'interleaved': store.goalTypeInterleaved++; break; + case 'anyOrder': + store.goalTypeAnyOrder++; + break; } } @@ -260,7 +271,7 @@ const createLogger = ( achievabilityFormulaDefinition: ( goalId: string, formula: string, - type: 'AND' | 'OR' | 'SINGLE_GOAL' | 'LEAF', + type: 'AND' | 'OR' | 'SINGLE_GOAL', sentence: string, prismLine: string, ) => { @@ -405,6 +416,13 @@ const createLogger = ( '\t\t[EXECUTION DETAIL: INTERLEAVED] interleaved goals have no guard condition\n', ); }, + anyOrder: (currentGoal: string, siblings: string[]) => { + write( + `\t\t[EXECUTION DETAIL: ANY ORDER] ${currentGoal} siblings: ${ + siblings.length > 0 ? siblings.join(', ') : 'none' + }\n`, + ); + }, activationContext: (sentence: string) => { write( `\t\t[EXECUTION DETAIL: CONTEXT] Guard statement: ${sentence}\n`, @@ -542,6 +560,7 @@ const createLogger = ( summaryLines.push( `[GOAL TYPE: INTERLEAVED] ${store.goalTypeInterleaved}\n`, ); + summaryLines.push(`[GOAL TYPE: ANY ORDER] ${store.goalTypeAnyOrder}\n`); summaryLines.push('----------GOAL SUMMARY----------\n'); summaryLines.push(`[GOAL MODULES] ${store.goalModules}\n`); summaryLines.push(`[GOAL VARIABLES] ${store.goalVariables}\n`); @@ -589,6 +608,7 @@ const createLogger = ( goalTypeAlternative: store.goalTypeAlternative, goalTypeSequence: store.goalTypeSequence, goalTypeInterleaved: store.goalTypeInterleaved, + goalTypeAnyOrder: store.goalTypeAnyOrder, goalModules: store.goalModules, goalVariables: store.goalVariables, goalPursueLines: store.goalPursueLines, @@ -639,6 +659,7 @@ const createLogger = ( write(`[GOAL TYPE: ALTERNATIVE] ${store.goalTypeAlternative}\n`); write(`[GOAL TYPE: SEQUENCE] ${store.goalTypeSequence}\n`); write(`[GOAL TYPE: INTERLEAVED] ${store.goalTypeInterleaved}\n`); + write(`[GOAL TYPE: ANY ORDER] ${store.goalTypeAnyOrder}\n`); write('----------GOAL SUMMARY----------\n'); write(`[GOAL MODULES] ${store.goalModules}\n`); write(`[GOAL VARIABLES] ${store.goalVariables}\n`); diff --git a/packages/lib/src/engines/edgeV2/mapper.ts b/packages/lib/src/engines/edgeV2/mapper.ts index 62d40e3a..ed730d16 100644 --- a/packages/lib/src/engines/edgeV2/mapper.ts +++ b/packages/lib/src/engines/edgeV2/mapper.ts @@ -12,12 +12,12 @@ import { type Task, } from '@goal-controller/goal-tree'; import type { + Decision, EdgeResourceProps, EdgeTaskProps, ExecCondition, GoalExecutionDetail, } from './types'; -import { parseStrictInt } from './retryCoercion'; /** * Allowed keys for Edge goal custom properties @@ -28,6 +28,7 @@ export const EDGE_GOAL_KEYS = [ 'utility', 'cost', 'dependsOn', + 'variables', 'type', 'maintain', 'assertion', @@ -53,6 +54,32 @@ export type EdgeGoalKey = (typeof EDGE_GOAL_KEYS)[number]; export type EdgeTaskKey = (typeof EDGE_TASK_KEYS)[number]; export type EdgeResourceKey = (typeof EDGE_RESOURCE_KEYS)[number]; +const parseDecision = ( + decision: string | undefined, +): Array<{ variable: string; space: number }> => { + if (!decision) { + return []; + } + const parsedDecision = decision.split(',').map((d) => d.split(':')); + parsedDecision.forEach((d) => { + if (d.length !== 2) { + throw new Error( + `[INVALID DECISION]: decision must be a variable and space: got ${decision}, expected format variable:space`, + ); + } + if (isNaN(parseInt(d[1] ?? ''))) { + throw new Error( + `[INVALID DECISION]: space must be a number: got ${d[1]}`, + ); + } + }); + + return parsedDecision.map((d) => ({ + variable: d[0]?.trim() ?? '', + space: parseInt(d[1] ?? '', 10), + })); +}; + /** * Parse and validate maxRetries value * Returns 0 if not provided, throws if invalid @@ -132,6 +159,7 @@ export interface EdgeGoalPropsResolved { dependsOn: EdgeGoalNode[]; executionDetail: GoalExecutionDetail | null; execCondition?: ExecCondition; + decision: Decision; maxRetries: number; } @@ -161,6 +189,7 @@ export const edgeEngineMapper = createEngineMapper< allowedTaskKeys: EDGE_TASK_KEYS, allowedResourceKeys: EDGE_RESOURCE_KEYS, mapGoalProps: ({ raw, executionDetail }) => { + const decisionVars = parseDecision(raw.variables); const execCondition = getMaintainCondition(raw, 'goal'); return { @@ -169,6 +198,10 @@ export const edgeEngineMapper = createEngineMapper< dependsOn: [], executionDetail, execCondition, + decision: { + decisionVars, + hasDecision: decisionVars.length > 0, + } satisfies Decision, maxRetries: parseMaxRetries(raw.maxRetries, 'goal'), }; }, @@ -215,12 +248,12 @@ export const edgeEngineMapper = createEngineMapper< ); } - const lowerBoundInt = parseStrictInt(lowerBound); - const upperBoundInt = parseStrictInt(upperBound); + const lowerBoundInt = parseInt(lowerBound, 10); + const upperBoundInt = parseInt(upperBound, 10); if (isNaN(lowerBoundInt) || isNaN(upperBoundInt)) { throw new Error( - `[INVALID RESOURCE]: Resource bounds must be plain integers, got: lowerBound="${lowerBound}" upperBound="${upperBound}"`, + '[INVALID RESOURCE]: Resource must have valid numeric lower and upper bounds', ); } @@ -230,11 +263,11 @@ export const edgeEngineMapper = createEngineMapper< ); } - const initialValueInt = parseStrictInt(initialValue); + const initialValueInt = parseInt(initialValue, 10); if (isNaN(initialValueInt)) { throw new Error( - `[INVALID RESOURCE]: Resource initial value must be a plain integer, got: "${initialValue}"`, + `[INVALID RESOURCE]: Resource must have a valid numeric initial value, got: "${initialValue}"`, ); } diff --git a/packages/lib/src/engines/edgeV2/mdp/common.ts b/packages/lib/src/engines/edgeV2/mdp/common.ts index db3813f4..29bd7dca 100644 --- a/packages/lib/src/engines/edgeV2/mdp/common.ts +++ b/packages/lib/src/engines/edgeV2/mdp/common.ts @@ -20,8 +20,6 @@ export const parenthesis = (s: string): string => (s ? `(${s})` : s); export const achieved = (goalId: string): string => `${goalId}_achieved`; export const achievable = (goalId: string): string => `${goalId}_achievable`; -/** Goal pursuit flag in Edge V2 PRISM modules (snippets: g0, g1, … as 0/1). */ -export const goalState = (goalId: string): string => `${goalId}_state`; export const pursued = (goalId: string): string => `${goalId}_pursued`; export const achievedOrPursued = (goalId: string): string => pursued(`${achieved(goalId)}_or`); diff --git a/packages/lib/src/engines/edgeV2/retryCoercion.ts b/packages/lib/src/engines/edgeV2/retryCoercion.ts deleted file mode 100644 index d0446a38..00000000 --- a/packages/lib/src/engines/edgeV2/retryCoercion.ts +++ /dev/null @@ -1,28 +0,0 @@ -/** Matches strings that are a plain integer with no decimal point or trailing characters. */ -const STRICT_INT_RE = /^-?\d+$/; - -/** - * Parse a string as a strict integer: rejects decimals ("1.5"), partial-numeric - * strings ("10abc"), and empty/whitespace-only strings. - * Returns NaN for any rejected input so callers can treat it like a failed parse. - */ -export const parseStrictInt = (s: string): number => { - if (!STRICT_INT_RE.test(s.trim())) return NaN; - return Number(s.trim()); -}; - -/** - * Normalize degradation retry counts from the model (numbers or numeric strings from JSON). - * Rejects non-integer numbers (e.g. 1.5) and partial-numeric strings (e.g. "10abc", "1.5"). - */ -export const coercePositiveIntRetry = (value: unknown): number | null => { - if (typeof value === 'number') { - if (!Number.isFinite(value) || !Number.isInteger(value)) return null; - return value > 0 ? value : null; - } - if (typeof value === 'string') { - const n = parseStrictInt(value); - if (!Number.isNaN(n) && n > 0) return n; - } - return null; -}; diff --git a/packages/lib/src/engines/edgeV2/template/common.ts b/packages/lib/src/engines/edgeV2/template/common.ts index a3a4df60..770f3538 100644 --- a/packages/lib/src/engines/edgeV2/template/common.ts +++ b/packages/lib/src/engines/edgeV2/template/common.ts @@ -1,14 +1,18 @@ -// Variable names +// Variable names (goal module vars use lowercase id: G0 → g0_state) +const varId = (goalId: string): string => goalId.toLowerCase(); + +export const stateVariable = (goalId: string): string => `${varId(goalId)}_state`; export const pursuedVariable = (goalId: string): string => `${goalId}_pursued`; +/** Achieved formula name for goals (EDGEV2): g_achieved */ +export const achievedFormula = (goalId: string): string => + `${varId(goalId)}_achieved`; +/** Module/task achieved var — preserves id case (tasks still use T1_achieved) */ export const achievedVariable = (goalId: string): string => `${goalId}_achieved`; -export const chosenVariable = (goalId: string): string => `${goalId}_chosen`; -/** One PRISM int per goal module for nondeterministic resolution (snippets: decision_G0). */ -export const decisionVariable = (goalId: string): string => - `decision_${goalId}`; -/** OR-goal secondary nondet constant (snippets: _decision_G0 for child choice/shares). */ -export const underscoredOrDecisionVariable = (goalId: string): string => - `_decision_${goalId}`; +export const chosenVariable = (goalId: string): string => + `${varId(goalId)}_chosen`; +export const goalFailedVariable = (goalId: string): string => + `${varId(goalId)}_failed`; // Transition labels export const pursueTransition = (goalId: string): string => `pursue_${goalId}`; @@ -17,7 +21,7 @@ export const achievedTransition = (goalId: string): string => export const failedTransition = (goalId: string): string => `failed_${goalId}`; export const tryTransition = (goalId: string): string => `try_${goalId}`; -// formulas +// formulas / task failed counters (preserve original id case) export const achievableFormulaVariable = (goalId: string): string => `${goalId}_achievable`; export const failed = (goalId: string): string => `${goalId}_failed`; diff --git a/packages/lib/src/engines/edgeV2/template/decisionVariables.ts b/packages/lib/src/engines/edgeV2/template/decisionVariables.ts index 71785c2b..4ead4c7e 100644 --- a/packages/lib/src/engines/edgeV2/template/decisionVariables.ts +++ b/packages/lib/src/engines/edgeV2/template/decisionVariables.ts @@ -1,34 +1,57 @@ import { GoalTree } from '@goal-controller/goal-tree'; -import type { EdgeGoalTree } from '../types'; -import { decisionVariable, underscoredOrDecisionVariable } from './common'; -import { goalNumberId } from './modules/goalModule/goalModules'; - -/** - * Uninterpreted decision constants after `dtmc`: every goal gets - * `decision_`; OR goals also get `_decision_` (snippet tie-break); - * every task gets `decision_` for child pursue thresholds under basic AND. - */ +import type { EdgeGoalNode, EdgeGoalTree } from '../types'; +import { getLogger } from '../logger/logger'; + +// Kept for template API compatibility; v2 decision vars are no longer discretized by achievability space +export const DEFAULT_ACHIEVABILITY_SPACE = 4; + +export const decisionVariableName = (goalId: string): string => + `decision_${goalId}`; + +/** Child-selection const `_decision_G` — used by OR joints and AND anyOrder. */ +export const selectionDecisionVariableName = (goalId: string): string => + `_decision_${goalId}`; + +const isOrGoal = (goal: EdgeGoalNode): boolean => + goal.relationToChildren === 'or'; + +const isAnyOrderAndGoal = (goal: EdgeGoalNode): boolean => + goal.relationToChildren === 'and' && + goal.properties.engine.executionDetail?.type === 'anyOrder'; + +/** Decision vars for a goal: always decision_G; OR and AND+anyOrder also get _decision_G. */ +export const decisionVariableNamesForGoal = (goal: EdgeGoalNode): string[] => { + const names = [decisionVariableName(goal.id)]; + if (isOrGoal(goal) || isAnyOrderAndGoal(goal)) { + names.push(selectionDecisionVariableName(goal.id)); + } + return names; +}; + export const decisionVariablesTemplate = ({ gm, + enabled = true, }: { gm: EdgeGoalTree; + enabled?: boolean; + /** @deprecated Unused in edgeV2; kept for call-site compatibility */ + achievabilitySpace?: number; }): string => { - const goals = GoalTree.allByType(gm, 'goal'); - const tasks = GoalTree.allByType(gm, 'task'); - - const goalLines = goals - .sort((a, b) => Number(goalNumberId(a.id)) - Number(goalNumberId(b.id))) - .flatMap((g) => { - const lines = [`const int ${decisionVariable(g.id)};`]; - if (g.relationToChildren === 'or') { - lines.push(`const int ${underscoredOrDecisionVariable(g.id)};`); - } - return lines; - }); + if (!enabled) { + return ''; + } - const taskLines = tasks - .sort((a, b) => Number(goalNumberId(a.id)) - Number(goalNumberId(b.id))) - .map((t) => `const int ${decisionVariable(t.id)};`); + const logger = getLogger(); + const decisionVariables: string[] = []; + const allGoals = GoalTree.allByType(gm, 'goal'); + + allGoals.forEach((goal) => { + const names = decisionVariableNamesForGoal(goal); + names.forEach((name) => { + logger.decisionVariable([name, 1]); + decisionVariables.push(`const int ${name};`); + }); + }); - return [...goalLines, ...taskLines].join('\n'); + return decisionVariables.join('\n'); }; diff --git a/packages/lib/src/engines/edgeV2/template/index.ts b/packages/lib/src/engines/edgeV2/template/index.ts index 5a503779..7dbb12b4 100644 --- a/packages/lib/src/engines/edgeV2/template/index.ts +++ b/packages/lib/src/engines/edgeV2/template/index.ts @@ -1,6 +1,6 @@ +import { validate, formatValidationReport } from '../validator'; +import { decisionVariablesTemplate, DEFAULT_ACHIEVABILITY_SPACE } from './decisionVariables'; import type { EdgeGoalTree } from '../types'; -import { summarizeValidationFailures, validate } from '../validator'; -import { decisionVariablesTemplate } from './decisionVariables'; import { changeManagerModule } from './modules/changeManager/changeManager'; import { goalModules } from './modules/goalModule/goalModules'; import { systemModule } from './modules/system/system'; @@ -10,15 +10,19 @@ const edgeDTMCTemplate = ({ fileName, clean = false, variables = {}, + generateDecisionVars = true, + achievabilitySpace = DEFAULT_ACHIEVABILITY_SPACE, }: { gm: EdgeGoalTree; fileName: string; clean?: boolean; variables?: Record; + generateDecisionVars?: boolean; + achievabilitySpace?: number; }): string => { const dtmcModel = `dtmc -${decisionVariablesTemplate({ gm })} +${decisionVariablesTemplate({ gm, enabled: generateDecisionVars, achievabilitySpace })} ${goalModules({ gm })} @@ -34,18 +38,22 @@ export const generateValidatedPrismModel = ({ fileName, clean = false, variables = {}, + generateDecisionVars = true, + achievabilitySpace = DEFAULT_ACHIEVABILITY_SPACE, }: { gm: EdgeGoalTree; fileName: string; clean?: boolean; variables?: Record; + generateDecisionVars?: boolean; + achievabilitySpace?: number; }): string => { - const prismModel = edgeDTMCTemplate({ gm, fileName, clean, variables }); + const prismModel = edgeDTMCTemplate({ gm, fileName, clean, variables, generateDecisionVars, achievabilitySpace }); const report = validate(gm, prismModel, fileName); if (report.summary.totalMissing > 0) { throw new Error( - `PRISM model is not valid.\n${summarizeValidationFailures(report)}`, + `PRISM model is not valid\n${formatValidationReport(report)}`, ); } return prismModel; diff --git a/packages/lib/src/engines/edgeV2/template/modules/changeManager/template/achievabilityVariables/taskAchievabilityVariables.ts b/packages/lib/src/engines/edgeV2/template/modules/changeManager/template/achievabilityVariables/taskAchievabilityVariables.ts index cf25f2a1..4b16f468 100644 --- a/packages/lib/src/engines/edgeV2/template/modules/changeManager/template/achievabilityVariables/taskAchievabilityVariables.ts +++ b/packages/lib/src/engines/edgeV2/template/modules/changeManager/template/achievabilityVariables/taskAchievabilityVariables.ts @@ -1,6 +1,6 @@ import type { Task } from '@goal-controller/goal-tree'; import { getLogger } from '../../../../../logger/logger'; -import { achievableFormulaVariable } from '../../../../common'; +import { achievableFormulaVariable } from '../../../../../template/common'; const DEFAULT_ACHIEVABILITY = 0.5; diff --git a/packages/lib/src/engines/edgeV2/template/modules/changeManager/template/tasks/transitions.ts b/packages/lib/src/engines/edgeV2/template/modules/changeManager/template/tasks/transitions.ts index b658767f..a77ea1c4 100644 --- a/packages/lib/src/engines/edgeV2/template/modules/changeManager/template/tasks/transitions.ts +++ b/packages/lib/src/engines/edgeV2/template/modules/changeManager/template/tasks/transitions.ts @@ -1,12 +1,12 @@ +import type { EdgeTask } from '../../../../../types'; import { getLogger } from '../../../../../logger/logger'; import { parenthesis } from '../../../../../mdp/common'; -import type { EdgeTask } from '../../../../../types'; import { achievableFormulaVariable, achievedTransition, pursueTransition, tryTransition, -} from '../../../../common'; +} from '../../../../../template/common'; import { hasBeenAchieved, hasBeenAchievedAndPursued, diff --git a/packages/lib/src/engines/edgeV2/template/modules/changeManager/template/tasks/variables.ts b/packages/lib/src/engines/edgeV2/template/modules/changeManager/template/tasks/variables.ts index 55c49fe6..0a98842f 100644 --- a/packages/lib/src/engines/edgeV2/template/modules/changeManager/template/tasks/variables.ts +++ b/packages/lib/src/engines/edgeV2/template/modules/changeManager/template/tasks/variables.ts @@ -1,6 +1,10 @@ -import { getLogger } from '../../../../../logger/logger'; import type { EdgeTask } from '../../../../../types'; -import { achievedVariable, failed, pursuedVariable } from '../../../../common'; +import { getLogger } from '../../../../../logger/logger'; +import { + achievedVariable, + failed, + pursuedVariable, +} from '../../../../../template/common'; const defineVariable = (variable: string): string => { const upperBound = 1; diff --git a/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/achieve.ts b/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/achieve.ts index 3ee3dec0..49b0f09d 100644 --- a/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/achieve.ts +++ b/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/achieve.ts @@ -1,57 +1,45 @@ -import type { Relation } from '@goal-controller/goal-tree'; import { Node } from '@goal-controller/goal-tree'; +import type { EdgeGoalNode, EdgeTask } from '../../../../types'; import { getLogger } from '../../../../logger/logger'; +import { separator } from '../../../../mdp/common'; import { - achieved, - goalState, - pursued, - separator, -} from '../../../../mdp/common'; -import type { EdgeGoalNode, EdgeTask } from '../../../../types'; -import { achievedMaintain } from './formulas'; -import { hasBeenPursued } from './pursue/common'; - -const isValidSeparator = ( - relation: Relation | null, -): relation is 'and' | 'or' => { - return ['and', 'or'].includes(relation ?? ''); -}; + achievedFormula, + pursuedVariable, + stateVariable, +} from '../../../../template/common'; +/** Child idle: goals use g*_state=0; tasks still use T*_pursued=0 */ const childIdle = (child: EdgeGoalNode | EdgeTask): string => - child.type === 'task' ? `${pursued(child.id)}=0` : `${goalState(child.id)}=0`; + Node.isTask(child) + ? `${pursuedVariable(child.id)}=0` + : `${stateVariable(child.id)}=0`; -export const achieveCondition = (goal: EdgeGoalNode): string => { - if (!isValidSeparator(goal.relationToChildren)) { - return ''; - } - const pursueableChildren = Node.children(goal).filter( - (child) => !Node.isResource(child), +const childrenIdle = (goal: EdgeGoalNode): string => { + const children = Node.children(goal).filter( + (child): child is EdgeGoalNode | EdgeTask => !Node.isResource(child), ); - if (!pursueableChildren.length) { + if (children.length === 0) { return ''; } - return pursueableChildren - .map((child) => childIdle(child as EdgeGoalNode | EdgeTask)) - .join(' & '); + return children.map(childIdle).join(separator('and')); }; +/** + * EDGEV2: + * [achieved_G0] g0_state=1 & g0_achieved & g1_state=0 & g2_state=0 -> (g0_state'=0); + */ export const achieveStatement = (goal: EdgeGoalNode): string => { const logger = getLogger(); - const achievedGuard = goal.properties.engine.execCondition?.maintain - ? `${achievedMaintain(goal.id)}=true` - : `${achieved(goal.id)}`; - - const cond = achieveCondition(goal); const leftStatement = [ - hasBeenPursued(goal, { condition: true }), - achievedGuard, - cond, + `${stateVariable(goal.id)}=1`, + achievedFormula(goal.id), + childrenIdle(goal), ] .filter(Boolean) .join(separator('and')); - const updateStatement = `(${goalState(goal.id)}'=0);`; + const updateStatement = `(${stateVariable(goal.id)}'=0);`; const prismLabelStatement = `[achieved_${goal.id}] ${leftStatement} -> ${updateStatement}`; diff --git a/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/formulas.ts b/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/formulas.ts index f3bf7590..dd09cf58 100644 --- a/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/formulas.ts +++ b/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/formulas.ts @@ -1,27 +1,31 @@ import { Node } from '@goal-controller/goal-tree'; +import type { EdgeGoalNode, EdgeTask } from '../../../../types'; import { getLogger } from '../../../../logger/logger'; import { parenthesis, separator } from '../../../../mdp/common'; -import type { EdgeGoalNode } from '../../../../types'; -import { achievableFormulaVariable, achievedVariable } from '../../../common'; +import { + achievableFormulaVariable, + achievedFormula, + achievedVariable, +} from '../../../../template/common'; -export const achievedMaintain = (goalId: string): string => { - return `${goalId}_achieved_maintain`; -}; +/** @deprecated Use achievedFormula — maintain goals share g*_achieved */ +export const achievedMaintain = achievedFormula; export const maintainConditionFormula = (goal: EdgeGoalNode): string => { if (!goal.properties.engine.execCondition?.maintain) { return ''; } const logger = getLogger(); + const name = achievedFormula(goal.id); - const prismLine = `formula ${achievedMaintain(goal.id)} = ${ + const prismLine = `formula ${name} = ${ goal.properties.engine.execCondition.maintain.sentence || 'ASSERTION_UNDEFINED' };`; logger.maintainFormulaDefinition( goal.id, - achievedMaintain(goal.id), + name, goal.properties.engine.execCondition.maintain.sentence || 'ASSERTION_UNDEFINED', prismLine, @@ -29,26 +33,56 @@ export const maintainConditionFormula = (goal: EdgeGoalNode): string => { return prismLine; }; -/** Same combinators as Edge v1: `*` for AND children, inclusion–exclusion for OR. */ -export const achievableGoalFormula = (goal: EdgeGoalNode): string => { +/** Child achieved ref: goal → g*_achieved formula; task → T*_achieved var */ +const childAchievedRef = (child: EdgeGoalNode | EdgeTask): string => + Node.isTask(child) ? achievedVariable(child.id) : achievedFormula(child.id); + +/** + * EDGEV2 achieved formula: + * formula g0_achieved = (g1_achieved & g2_achieved); // AND + * formula g0_achieved = (g1_achieved | g2_achieved); // OR + * Skipped for maintain goals (maintainConditionFormula emits g*_achieved from the maintain sentence). + */ +export const achievedGoalFormula = (goal: EdgeGoalNode): string => { + if (goal.properties.engine.execCondition?.maintain) { + return ''; + } + const children = Node.children(goal).filter( - (child) => !Node.isResource(child), + (child): child is EdgeGoalNode | EdgeTask => !Node.isResource(child), ); - const formulaName = achievableFormulaVariable(goal.id); - const logger = getLogger(); - if (children.length === 0) { - const formula = `formula ${formulaName} = 1;`; - logger.achievabilityFormulaDefinition( - goal.id, - formulaName, - 'LEAF', - '1', - formula, - ); - return formula; + return ''; } + const formulaName = achievedFormula(goal.id); + const childRefs = children.map(childAchievedRef); + + let sentence: string; + if (children.length === 1) { + sentence = childRefs[0]!; + } else { + switch (goal.relationToChildren) { + case 'and': + sentence = parenthesis(childRefs.join(separator('and'))); + break; + case 'or': + sentence = parenthesis(childRefs.join(separator('or'))); + break; + default: + throw new Error( + `Invalid relation to children for achieved formula: ${goal.relationToChildren ?? 'none'}`, + ); + } + } + + return `formula ${formulaName} = ${sentence};`; +}; + +export const achievableGoalFormula = (goal: EdgeGoalNode): string => { + const children = Node.children(goal); + const formulaName = `${achievableFormulaVariable(goal.id)}`; + const logger = getLogger(); if (children.length === 1) { const firstChild = children[0]; if (!firstChild) { @@ -104,54 +138,3 @@ export const achievableGoalFormula = (goal: EdgeGoalNode): string => { ); } }; - -export const achievedGoalFormula = (goal: EdgeGoalNode): string => { - const children = Node.children(goal).filter( - (child) => !Node.isResource(child), - ); - const formulaName = `${achievedVariable(goal.id)}`; - const logger = getLogger(); - const childrenAchievedExpressions = children.map((child) => - achievedVariable(child.id), - ); - - if (childrenAchievedExpressions.length === 0) { - const formula = `formula ${formulaName} = false;`; - logger.achievabilityFormulaDefinition( - goal.id, - formulaName, - 'SINGLE_GOAL', - 'false', - formula, - ); - return formula; - } - - if (childrenAchievedExpressions.length === 1) { - const [onlyChildExpression] = childrenAchievedExpressions; - if (!onlyChildExpression) { - throw new Error(`Expected achieved expression for goal ${goal.id}`); - } - const formula = `formula ${formulaName} = ${onlyChildExpression};`; - logger.achievabilityFormulaDefinition( - goal.id, - formulaName, - 'SINGLE_GOAL', - onlyChildExpression, - formula, - ); - return formula; - } - - const relation = goal.relationToChildren === 'and' ? 'and' : 'or'; - const sentence = `(${childrenAchievedExpressions.join(separator(relation))})`; - const formula = `formula ${formulaName} = ${sentence};`; - logger.achievabilityFormulaDefinition( - goal.id, - formulaName, - relation === 'and' ? 'AND' : 'OR', - sentence, - formula, - ); - return formula; -}; diff --git a/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/index.ts b/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/index.ts index 163ffd97..85e60785 100644 --- a/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/index.ts +++ b/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/index.ts @@ -1,15 +1,11 @@ import { getLogger } from '../../../../logger/logger'; import { achieveStatement } from './achieve'; -import { - achievableGoalFormula, - achievedGoalFormula, - maintainConditionFormula, -} from './formulas'; +import { achievableGoalFormula, achievedGoalFormula, maintainConditionFormula } from './formulas'; import { Node } from '@goal-controller/goal-tree'; import type { EdgeGoalNode } from '../../../../types'; import { pursueStatements } from './pursue'; -import { skipStatements } from './skip'; +import { skipStatement } from './skip'; import { variablesDefinition } from './variables'; export const goalModule = (goal: EdgeGoalNode): string => { @@ -18,8 +14,8 @@ export const goalModule = (goal: EdgeGoalNode): string => { const formulaStatements = [ maintainConditionFormula(goal), - achievableGoalFormula(goal), achievedGoalFormula(goal), + achievableGoalFormula(goal), ] .filter(Boolean) .join('\n'); @@ -38,7 +34,7 @@ module ${goal.id} ${achieveStatement(goal)} - ${skipStatements(goal).join('\n ')} + ${skipStatement(goal)} endmodule ${formulaStatements} diff --git a/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/pursue/andGoal.ts b/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/pursue/andGoal.ts index 9ec8803b..4cd116f1 100644 --- a/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/pursue/andGoal.ts +++ b/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/pursue/andGoal.ts @@ -1,23 +1,13 @@ -import type { TreeNode } from '@goal-controller/goal-tree'; -import { Node } from '@goal-controller/goal-tree'; -import type { EdgeGoalNode, EdgeTask } from '../../../../../types'; import { getLogger } from '../../../../../logger/logger'; -import { achieved, separator } from '../../../../../mdp/common'; -import { achievableGtDecision } from '../../../../prismGuards'; -import { hasBeenAchieved } from './common'; - -// Type for nodes that can be achieved (goals and tasks, but not resources) -type AchievableNode = EdgeGoalNode | EdgeTask; - -/** Snippets use `G1_achieved` on sequential pursues; maintain goals still expose `G*_achieved`. */ -const priorSequentialSiblingGuard = (node: AchievableNode): string => - node.type === 'task' - ? hasBeenAchieved(node, { condition: true }) - : achieved(node.id); - -/** Interleaved AND: per-child guard from snippets (`G1_achievable*10.0 > decision_G1`). */ -export const pursueAndInterleavedGoal = (childId: string): string => - achievableGtDecision(childId); +import { parenthesis, separator } from '../../../../../mdp/common'; +import { achievedFormula, stateVariable } from '../../../../../template/common'; +import type { EdgeGoalNode } from '../../../../../types'; +import { + joinGuards, + otherChildrenNotPursued, + parentShouldPursue, + selectChildByDecision, +} from './decisionGuards'; export const splitSequence = ( sequence: string[], @@ -32,11 +22,14 @@ export const splitSequence = ( return [sequence.slice(0, sequenceIndex), sequence.slice(sequenceIndex + 1)]; }; +/** + * AND + sequence (EDGEV2): + * G0_achievable*10.0 > decision_G0 [& g{prev}_achieved ...] + */ export const pursueAndSequentialGoal = ( goal: EdgeGoalNode, sequence: string[], childId: string, - children: TreeNode[], ): string => { if (goal.relationToChildren === 'or') { throw new Error( @@ -44,37 +37,68 @@ export const pursueAndSequentialGoal = ( ); } - const [leftGoals, rightGoals] = splitSequence(sequence, childId); + const [leftGoals] = splitSequence(sequence, childId); if (!goal.relationToChildren) { return ''; } - // Filter out resources - they cannot be achieved - const achievableChildren = children.filter( - (child): child is AchievableNode => !Node.isResource(child), - ); + const { sequence: sequenceLogger } = getLogger().pursue.executionDetail; + sequenceLogger(goal.id, childId, leftGoals, []); + + const priors = + leftGoals.length > 0 + ? leftGoals.map((id) => achievedFormula(id)).join(separator('and')) + : ''; - const childrenMap = new Map( - achievableChildren.map((child) => [child.id, child]), + return joinGuards(parentShouldPursue(goal.id), priors); +}; + +/** + * AND + anyOrder (EDGEV2): + * G0_achievable*10.0 > decision_G0 + * & g{sibling}_state!=1 + * & (g{sibling}_state=1 | ratio vs _decision_G0) + * + * Children may run in any order, but not concurrently; `_decision` picks who goes first. + */ +export const pursueAndAnyOrderGoal = ( + goal: EdgeGoalNode, + anyOrder: string[], + childId: string, +): string => { + if (goal.relationToChildren === 'or') { + throw new Error( + `Any-order goals are not supported for OR joints. Found in goal ${goal.id}`, + ); + } + + if (!anyOrder.includes(childId)) { + throw new Error( + `Child ID ${childId} not found in anyOrder ${anyOrder.join(', ')}`, + ); + } + + const { anyOrder: anyOrderLogger } = getLogger().pursue.executionDetail; + anyOrderLogger( + childId, + anyOrder.filter((id) => id !== childId), ); - const { sequence: sequenceLogger } = getLogger().pursue.executionDetail; - sequenceLogger(goal.id, childId, leftGoals, rightGoals); + const siblings = anyOrder.filter((id) => id !== childId); + const select = selectChildByDecision(goal.id, anyOrder, childId); - if (goal.relationToChildren === 'and') { - const decisionGuard = achievableGtDecision(goal.id); - const previousAchieved = leftGoals.map((id) => { - const node = childrenMap.get(id); - if (!node) { - throw new Error( - `Child with ID ${id} not found in children map for goal ${goal.id}`, - ); - } - return priorSequentialSiblingGuard(node); - }); - return [decisionGuard, ...previousAchieved].join(separator('and')); + if (siblings.length === 0) { + return joinGuards(parentShouldPursue(goal.id), select); } - return ''; + const siblingPursued = siblings + .map((id) => `${stateVariable(id)}=1`) + .join(' | '); + + return joinGuards( + parentShouldPursue(goal.id), + otherChildrenNotPursued(anyOrder, childId), + parenthesis(`${siblingPursued} | ${select}`), + ); }; diff --git a/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/pursue/common.ts b/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/pursue/common.ts index 32309781..3b02c40d 100644 --- a/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/pursue/common.ts +++ b/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/pursue/common.ts @@ -1,12 +1,10 @@ -import { Node } from '@goal-controller/goal-tree'; import type { EdgeGoalNode, EdgeTask } from '../../../../../types'; +import { separator } from '../../../../../mdp/common'; import { - achieved, - goalState, - pursued, - separator, -} from '../../../../../mdp/common'; -import { achievedMaintain } from '../formulas'; + achievedFormula, + goalFailedVariable, + stateVariable, +} from '../../../../../template/common'; // Node type that has both id and properties.engine.execCondition type NodeWithExecCondition = EdgeGoalNode | EdgeTask; @@ -15,33 +13,18 @@ export const hasBeenAchieved = ( node: NodeWithExecCondition, { condition, update }: { condition: boolean; update?: boolean }, ): string => { - if (node.type === 'task') { - return `${achieved(node.id)}${update ? "'" : ''}=${condition ? 1 : 0}`; - } - - if (node.properties.engine.execCondition?.maintain) { - if (update) { - throw new Error( - 'Invalid update option for goal of type maintain, please verify', - ); - } - return `${achievedMaintain(node.id)}=${condition ? 'true' : 'false'}`; - } - if (update) { - throw new Error( - 'Invalid update option for goal achieved formula, please verify', - ); + return `${achievedFormula(node.id)}'=${condition ? 1 : 0}`; } - return condition ? `${achieved(node.id)}` : `!${achieved(node.id)}`; + + return condition ? achievedFormula(node.id) : `!${achievedFormula(node.id)}`; }; export const hasBeenPursued = ( node: NodeWithExecCondition, { condition, update }: { condition: boolean; update?: boolean }, ): string => { - const name = Node.isTask(node) ? pursued(node.id) : goalState(node.id); - return `${name}${update ? "'" : ''}=${condition ? 1 : 0}`; + return `${stateVariable(node.id)}${update ? "'" : ''}=${condition ? 1 : 0}`; }; export const hasBeenAchievedAndPursued = ( @@ -55,9 +38,17 @@ export const hasBeenAchievedAndPursued = ( }; export const hasFailedAtLeastNTimes = (goalId: string, n: number): string => { - return `${goalId}_failed >= ${n}`; + return `${goalFailedVariable(goalId)}>=${n}`; }; export const hasFailedAtMostNTimes = (goalId: string, n: number): string => { - return `${goalId}_failed <= ${n}`; + return `${goalFailedVariable(goalId)}<=${n}`; +}; + +export const hasFailedLessThanNTimes = (goalId: string, n: number): string => { + return `${goalFailedVariable(goalId)}<${n}`; +}; + +export const hasFailedExactlyNTimes = (goalId: string, n: number): string => { + return `${goalFailedVariable(goalId)}=${n}`; }; diff --git a/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/pursue/decisionGuards.ts b/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/pursue/decisionGuards.ts new file mode 100644 index 00000000..a17c3c32 --- /dev/null +++ b/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/pursue/decisionGuards.ts @@ -0,0 +1,101 @@ +import { parenthesis } from '../../../../../mdp/common'; +import { + achievableFormulaVariable, + stateVariable, +} from '../../../../../template/common'; +import { + decisionVariableName, + selectionDecisionVariableName, +} from '../../../../../template/decisionVariables'; + +export type PursueStatement = { left: string; right: string }; + +/** G{id}_achievable*10.0 > decision_G{id} */ +export const shouldPursue = (goalId: string): string => + `${achievableFormulaVariable(goalId)}*10.0 > ${decisionVariableName(goalId)}`; + +export const parentShouldPursue = shouldPursue; +export const childShouldPursue = shouldPursue; + +/** Other children not currently pursued: g*_state!=1 */ +export const otherChildrenNotPursued = ( + childIds: string[], + currentChildId: string, +): string => + childIds + .filter((id) => id !== currentChildId) + .map((id) => `${stateVariable(id)}!=1`) + .join(' & '); + +/** Other children idle: g*_state=0 */ +export const otherChildrenIdle = ( + childIds: string[], + currentChildId: string, +): string => + childIds + .filter((id) => id !== currentChildId) + .map((id) => `${stateVariable(id)}=0`) + .join(' & '); + +/** G{id}_achievable*10.0 <= decision_G{id} */ +export const shouldSkip = (goalId: string): string => + `${achievableFormulaVariable(goalId)}*10.0 <= ${decisionVariableName(goalId)}`; + +export const parentShouldSkip = shouldSkip; + +/** + * Child selection vs `_decision_G{parent}` on a 0..10 scale. + * Used by OR joints and AND anyOrder. + * N=2 matches EDGEV2: (G1/(G1+G2))*10.0 ?> _decision + * N>2: ordered cumulative achievability bands. + */ +export const selectChildByDecision = ( + parentGoalId: string, + orderedChildIds: string[], + currentChildId: string, +): string => { + const index = orderedChildIds.indexOf(currentChildId); + if (index < 0) { + throw new Error( + `Child ${currentChildId} not in children [${orderedChildIds.join(', ')}]`, + ); + } + + const decision = selectionDecisionVariableName(parentGoalId); + const terms = orderedChildIds.map((id) => achievableFormulaVariable(id)); + const sum = terms.join('+'); + const cum = (endExclusive: number): string => { + const slice = terms.slice(0, endExclusive); + const [first, ...rest] = slice; + if (!first) { + return '0'; + } + return rest.length === 0 ? first : parenthesis(slice.join('+')); + }; + + const n = orderedChildIds.length; + if (n === 1) { + return 'true'; + } + + // band upper for first k children: sum(s0..s_{k-1})/S * 10 + const bandUpper = (k: number): string => + `${parenthesis(`${cum(k)}/(${sum})`)}*10.0`; + + if (index === 0) { + // first: (s0/S)*10 > _decision + return `${bandUpper(1)} > ${decision}`; + } + if (index === n - 1) { + // last: sum(s0..s_{n-2})/S*10 <= _decision + return `${bandUpper(n - 1)} <= ${decision}`; + } + // middle: lower <= _decision < upper + return `${bandUpper(index)} <= ${decision} & ${bandUpper(index + 1)} > ${decision}`; +}; + +/** Append non-empty guard fragments with & */ +export const joinGuards = ( + ...parts: Array +): string => + parts.filter((p): p is string => Boolean(p && p.length > 0)).join(' & '); diff --git a/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/pursue/index.ts b/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/pursue/index.ts index d9b9aeb1..f9025a9a 100644 --- a/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/pursue/index.ts +++ b/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/pursue/index.ts @@ -1,20 +1,23 @@ import { Node, type GoalNode } from '@goal-controller/goal-tree'; import { getLogger } from '../../../../../logger/logger'; +import { separator } from '../../../../../mdp/common'; import { - achieved, - failed, - goalState, - parenthesis, - separator, -} from '../../../../../mdp/common'; + achievedFormula, + stateVariable, +} from '../../../../../template/common'; import type { EdgeGoalNode, EdgeTask } from '../../../../../types'; -import { chosenVariable } from '../../../../common'; -import { pursueableChildren } from '../../../../prismGuards'; -import { achievedMaintain } from '../formulas'; -import { degradationRetryCapFromMap } from '../variables'; -import { pursueAndInterleavedGoal, pursueAndSequentialGoal } from './andGoal'; +import { pursueAndAnyOrderGoal, pursueAndSequentialGoal } from './andGoal'; import { hasBeenAchieved } from './common'; -import { pursueAlternativeGoal } from './orGoal'; +import { + childShouldPursue, + joinGuards, + type PursueStatement, +} from './decisionGuards'; +import { + pursueAlternativeGoal, + pursueChoiceGoal, + pursueDegradationGoal, +} from './orGoal'; // Type for nodes that can be pursued (goals and tasks, but not resources) type PursueableNode = EdgeGoalNode | EdgeTask; @@ -44,8 +47,8 @@ export const goalDependencyStatement = (goal: EdgeGoalNode): string => { return validDependencies.length > 0 ? ` & (${validDependencies - .map((dep) => hasBeenAchieved(dep, { condition: true })) - .join(separator('and'))})` + .map((dep) => hasBeenAchieved(dep, { condition: true })) + .join(separator('and'))})` : ''; }; @@ -56,19 +59,26 @@ const removeRepeatedConditions = (condition: string): string => { .join(' & '); }; +const appendGuards = (baseLeft: string, extra: string): string => + extra ? `${baseLeft} & ${extra}` : baseLeft; + export const pursueStatements = (goal: EdgeGoalNode): string[] => { const logger = getLogger(); const pursueLogger = logger.pursue; - const goalsToPursue: PursueableNode[] = [goal, ...pursueableChildren(goal)]; + // Filter out resources - they cannot be pursued + const allChildren = Node.children(goal); + const pursueableChildren = allChildren.filter( + (child): child is PursueableNode => !Node.isResource(child), + ); + const goalsToPursue: PursueableNode[] = [goal, ...pursueableChildren]; const isItself = (child: PursueableNode): boolean => child.id === goal.id; const pursueLines = goalsToPursue - - .map((child, _): [PursueableNode, { left: string; right: string }] => { - // first map, responsible for writing the first column of the pursue lines - // itself: [pursue_G1] G1_pursued=0 & G1_achieved=0 -> (G1_pursued'=1) - // non-itself: [pursue_G2] G1_pursued=1 & G1_achieved=0 -> true + .map((child, _): [PursueableNode, PursueStatement] => { + // first map — base column (EDGEV2.txt): + // itself: [pursue_G0] !g0_achieved & g0_state=0 & GUARD -> (g0_state'=1) + // non-itself: [pursue_G1] !g0_achieved & g0_state=1 -> true const itself = isItself(child); pursueLogger.pursue(child, 1); @@ -78,11 +88,9 @@ export const pursueStatements = (goal: EdgeGoalNode): string[] => { goal.id, (goal.properties.engine.dependsOn ?? []).map((dep) => dep.id), ); + const notAchieved = `!${achievedFormula(goal.id)}`; const statement = - `[pursue_${child.id}] ${goalState(goal.id)}=${itself ? 0 : 1} & ${ - goal.properties.engine.execCondition?.maintain - ? `${achievedMaintain(goal.id)}=false` - : `!${achieved(goal.id)}` + `[pursue_${child.id}] ${notAchieved} & ${stateVariable(goal.id)}=${itself ? 0 : 1 }` + (itself ? dependencyStatement : ''); pursueLogger.defaultPursueCondition(statement); @@ -91,7 +99,7 @@ export const pursueStatements = (goal: EdgeGoalNode): string[] => { const calcRightStatement = (): string => { if (itself) { - const update = `(${goalState(goal.id)}'=1)`; + const update = `(${stateVariable(goal.id)}'=1)`; pursueLogger.update(update); return update; } @@ -105,46 +113,26 @@ export const pursueStatements = (goal: EdgeGoalNode): string[] => { }; if (isItself(child)) { - return [ - child, - { - left, - right, - }, - ] as const; + return [child, { left, right }] as const; } pursueLogger.stepStatement(1, left, right); return [child, { left, right }] as const; }) - .map( - ( - [child, { left, right }], - index, - ): [PursueableNode, { left: string; right: string }] => { - // second map, responsible for writing the second column of the pursue lines - // defines how a goal should be pursued based on the execution detail - // skips itself and handles or and and goals - // or goal: - // - alternatives: pursueAlternativeGoal(goal, child.id) - // - choice: two [pursue_child] per child — commit (chosen=0 + alternative guards) then execute (chosen=k + child achievable vs decision) - // - degradation: per-sibling failed from retryMap — retry/failover flatMap, or alternative-only if no map entry - // and goal: - // - sequence: pursueAndSequentialGoal(goal, goal.executionDetail.sequence, child.id, [...(goal.children ?? []), ...(goal.tasks ?? [])]) - // - interleaved: return [child, { left, right }] - const calcExecutionDetail = (): [ - PursueableNode, - { left: string; right: string }, - ] => { + .flatMap( + ([child, { left, right }]): Array< + [PursueableNode, PursueStatement] + > => { + // second map — execution detail (EDGEV2.txt); may emit multiple lines + const calcExecutionDetail = (): PursueStatement[] => { pursueLogger.pursue(child, 2); if (isItself(child)) { - // skip itself logger.info( '[EXECUTION DETAIL: SKIP] Skipping condition generation for itself on runtime guard generation step', 2, ); - return [child, { left, right }]; + return [{ left, right }]; } if (goal.relationToChildren === 'or') { @@ -160,7 +148,8 @@ export const pursueStatements = (goal: EdgeGoalNode): string[] => { ); } case 'choice': { - if (pursueableChildren(goal).length === 0) { + const children = pursueableChildren.map((c) => c.id); + if (children.length === 0) { logger.error( goal.id, 'choice execution detail detected without pursueable children', @@ -173,8 +162,12 @@ export const pursueStatements = (goal: EdgeGoalNode): string[] => { child.id, 'choice execution detail detected with children', ); - // Commit vs execute split in flatMap after this step - return [child, { left, right }]; + return pursueChoiceGoal(goal, children, child.id).map( + (fragment) => ({ + left: appendGuards(left, fragment.left), + right: fragment.right, + }), + ); } case 'degradation': { logger.trace( @@ -182,7 +175,14 @@ export const pursueStatements = (goal: EdgeGoalNode): string[] => { 'degradation execution detail detected', 2, ); - return [child, { left, right }]; + return pursueDegradationGoal( + goal, + goal.properties.engine.executionDetail.degradationList, + child.id, + ).map((fragment) => ({ + left: appendGuards(left, fragment.left), + right: fragment.right, + })); } case 'alternative': { logger.trace( @@ -191,28 +191,24 @@ export const pursueStatements = (goal: EdgeGoalNode): string[] => { 2, ); const pursueCondition = pursueAlternativeGoal(goal, child.id); - return [child, { left: left + ` & ${pursueCondition}`, right }]; + return [ + { + left: appendGuards(left, pursueCondition), + right, + }, + ]; } default: logger.info( `[EXECUTION DETAIL: SKIP] Skipping condition generation for ${child.id} on runtime guard generation step, no execution detail`, 2, ); - // Basic OR (no execution detail): same alternative-style guards as annotated OR goals. - if (!isItself(child)) { - const pursueCondition = pursueAlternativeGoal(goal, child.id); - return [ - child, - { left: left + ` & ${pursueCondition}`, right }, - ]; - } - return [child, { left, right }]; + return [{ left, right }]; } } if (goal.relationToChildren === 'and') { logger.trace(child.id, 'and goal detected', 2); - // organize pursue conditions by execution detail type switch (goal.properties.engine.executionDetail?.type) { case 'sequence': { logger.trace(child.id, 'sequence execution detail detected', 2); @@ -220,12 +216,10 @@ export const pursueStatements = (goal: EdgeGoalNode): string[] => { goal, goal.properties.engine.executionDetail.sequence, child.id, - Node.children(goal), ); return [ - child, { - left: left + ` & ${pursueCondition}`, + left: appendGuards(left, pursueCondition), right, }, ]; @@ -253,14 +247,23 @@ export const pursueStatements = (goal: EdgeGoalNode): string[] => { 2, ); pursueLogger.executionDetail.interleaved(); - if (isItself(child)) { - return [child, { left, right }]; - } - const pursueCondition = pursueAndInterleavedGoal(child.id); return [ - child, { - left: `${left} & ${pursueCondition}`, + left: appendGuards(left, childShouldPursue(child.id)), + right, + }, + ]; + } + case 'anyOrder': { + logger.trace(child.id, 'anyOrder execution detail detected', 2); + const pursueCondition = pursueAndAnyOrderGoal( + goal, + goal.properties.engine.executionDetail.anyOrder, + child.id, + ); + return [ + { + left: appendGuards(left, pursueCondition), right, }, ]; @@ -270,18 +273,7 @@ export const pursueStatements = (goal: EdgeGoalNode): string[] => { `[EXECUTION DETAIL: SKIP] Skipping condition generation for ${child.id} on runtime guard generation step, no execution detail`, 2, ); - // Basic AND (no execution detail): same per-child decision threshold as interleaved. - if (!isItself(child)) { - const pursueCondition = pursueAndInterleavedGoal(child.id); - return [ - child, - { - left: `${left} & ${pursueCondition}`, - right, - }, - ]; - } - return [child, { left, right }]; + return [{ left, right }]; } } @@ -289,98 +281,38 @@ export const pursueStatements = (goal: EdgeGoalNode): string[] => { `[EXECUTION DETAIL: ERROR] ${child.id} is not an OR or AND goal`, 2, ); - return [child, { left, right }]; + return [{ left, right }]; }; - const executionDetail = calcExecutionDetail(); + const statements = calcExecutionDetail(); + statements.forEach((statement) => { + pursueLogger.stepStatement(2, statement.left, statement.right); + }); - pursueLogger.stepStatement( - 2, - executionDetail[1].left, - executionDetail[1].right, + return statements.map( + (statement) => [child, statement] as [PursueableNode, PursueStatement], ); - - return executionDetail; - }, - ) - .flatMap( - ( - entry: [PursueableNode, { left: string; right: string }], - ): Array<[PursueableNode, { left: string; right: string }]> => { - const [child, { left }] = entry; - if ( - goal.relationToChildren === 'or' && - goal.properties.engine.executionDetail?.type === 'degradation' && - !isItself(child) - ) { - const cap = degradationRetryCapFromMap(goal, child.id); - if (cap !== null) { - const retryLeft = `${left} & ${failed(child.id)}<${cap} & ${pursueAndInterleavedGoal(child.id)}`; - const retryRight = parenthesis( - `${failed(child.id)}'=min(${cap}, ${failed(child.id)}+1)`, - ); - const failoverLeft = `${left} & ${failed(child.id)}=${cap} & ${pursueAlternativeGoal(goal, child.id)}`; - const failoverRight = 'true'; - return [ - [child, { left: retryLeft, right: retryRight }], - [child, { left: failoverLeft, right: failoverRight }], - ]; - } - const altOnlyLeft = `${left} & ${pursueAlternativeGoal(goal, child.id)}`; - return [[child, { left: altOnlyLeft, right: 'true' }]]; - } - if ( - goal.relationToChildren === 'or' && - goal.properties.engine.executionDetail?.type === 'choice' && - !isItself(child) - ) { - const branchIndex = goalsToPursue.indexOf(child); - const commitLeft = `${left} & ${chosenVariable(goal.id)}=0 & ${pursueAlternativeGoal(goal, child.id)}`; - const commitRight = parenthesis( - `${chosenVariable(goal.id)}'=${branchIndex}`, - ); - const execLeft = `${left} & ${chosenVariable(goal.id)}=${branchIndex} & ${pursueAndInterleavedGoal(child.id)}`; - const execRight = 'true'; - return [ - [child, { left: commitLeft, right: commitRight }], - [child, { left: execLeft, right: execRight }], - ]; - } - return [entry]; }, ) .map( - ([child, statement]): [ - PursueableNode, - { left: string; right: string }, - ] => { - // third map, responsible for writing the third column of the pursue lines - // defines the activation context and maintain context guards - // if itself add context guard only if it has an activation context - // if child add context guard only if it has a maintain condition - - // parent goals have activation context independently of the maintain condition + ([child, statement]): [PursueableNode, PursueStatement] => { + // third map — activation / maintain context guards const activationContextCondition = ((isItself(child) || Node.isTask(child)) && child.properties.engine.execCondition?.assertion?.sentence) || ''; - // child goals have maintain condition only if they are not itself const maintainContextGuard = child.properties.engine.execCondition?.maintain?.sentence && - !isItself(child) - ? `${achievedMaintain(child.id)}=false` + !isItself(child) + ? `!${achievedFormula(child.id)}` : ''; - const left = - activationContextCondition || maintainContextGuard - ? `${statement.left} & ${[ - activationContextCondition, - maintainContextGuard, - ] - .filter(Boolean) - .join(' & ')}` - : statement.left; + const left = joinGuards( + statement.left, + activationContextCondition || null, + maintainContextGuard || null, + ); if (child.properties.engine.execCondition) { logger.trace(child.id, 'activation context guard detected', 2); @@ -395,50 +327,13 @@ export const pursueStatements = (goal: EdgeGoalNode): string[] => { child, { left, - right: `${statement.right}`, + right: statement.right, }, ]; }, ) - .map(([child, statement]) => { - // fourth map, responsible for writing the update of the failed counter variable - // defines the update failed counter statement - // if child has a max retries, update the failed counter variable - // if itself, skip the update failed counter statement - - // TODO: only update if child is part of a degradation goal - const maxRetries = child.properties.engine.maxRetries; - const updateFailedCounterStatement = - maxRetries > 0 - ? `(${failed(child.id)}'=min(${maxRetries}, ${failed(child.id)}+1))` - : ''; - - if ( - !updateFailedCounterStatement || - isItself(child) || - (goal.relationToChildren === 'or' && - goal.properties.engine.executionDetail?.type === 'degradation') - ) { - return [child, statement] as const; - } - - const rightStatement = - // overwrite default true with update failed counter statement - statement.right === 'true' - ? updateFailedCounterStatement - : `${statement.right} & ${updateFailedCounterStatement}`; - return [ - child, - { - left: statement.left, - right: rightStatement, - }, - ] as const; - }) .map(([_, statement]) => { - // fifth map - // cleans up the left and right statements by removing repeated conditions - // TODO: dependencies + // fourth map — dedupe (decision thresholds already in calcExecutionDetail) return { left: `${removeRepeatedConditions(statement.left)}`, right: `${removeRepeatedConditions(statement.right)}`, diff --git a/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/pursue/orGoal.ts b/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/pursue/orGoal.ts index e3f6b3cd..5773d2d5 100644 --- a/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/pursue/orGoal.ts +++ b/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/pursue/orGoal.ts @@ -1,109 +1,176 @@ -import { getLogger } from '../../../../../logger/logger'; -import { achievable, separator } from '../../../../../mdp/common'; +import { Node } from '@goal-controller/goal-tree'; import type { EdgeGoalNode, EdgeTask } from '../../../../../types'; +import { getLogger } from '../../../../../logger/logger'; import { chosenVariable, - decisionVariable, - underscoredOrDecisionVariable, -} from '../../../../common'; + goalFailedVariable, +} from '../../../../../template/common'; +import { + hasFailedExactlyNTimes, + hasFailedLessThanNTimes, +} from './common'; import { - ACHIEVABILITY_DECISION_SCALE, - achievableGtDecision, - childIdle, - pursueableChildren as sharedPursueableChildren, -} from '../../../../prismGuards'; - -/* -G1: Goal[T1|T2] -module G1 //non-idempotent, a.k.a choose once! - G1_pursued : [0..1] init 0; - G1_achieved : [0..1] init 0; - G1_chosen : [0..2] init 0; //which one is chosen? - -// [pursue_T1] G1_pursued=1 & G1_achieved=0 & G1_chosen!=2 -> (G1_chosen'=1); -// [pursue_T2] G1_pursued=1 & G1_achieved=0 & G1_chosen!=1 -> (G1_chosen'=2); - - [achieved_G1] (T1_achieved>0 | T2_achieved>0) & G1_pursued=1 -> (G1_pursued'=0) & (G1_achieved'=1); -endmodule -*/ + childShouldPursue, + joinGuards, + otherChildrenIdle, + selectChildByDecision, + parentShouldPursue, + type PursueStatement, +} from './decisionGuards'; -export const pursueChoiceGoal = ( +type PursueableNode = EdgeGoalNode | EdgeTask; + +const pursueableChildIds = (goal: EdgeGoalNode): string[] => + Node.children(goal) + .filter((child): child is PursueableNode => !Node.isResource(child)) + .map((child) => child.id); + +/** + * OR + alternative (EDGEV2): + * parent decide & other state=0 & ratio vs _decision + */ +export const pursueAlternativeGoal = ( goal: EdgeGoalNode, - alternative: string[], currentChildId: string, ): string => { + const children = pursueableChildIds(goal); + const { alternative: alternativeLogger } = getLogger().pursue.executionDetail; + + alternativeLogger( + currentChildId, + children.filter((id) => id !== currentChildId), + ); + + return joinGuards( + parentShouldPursue(goal.id), + otherChildrenIdle(children, currentChildId), + selectChildByDecision(goal.id, children, currentChildId), + ); +}; + +/** + * OR + choice (EDGEV2) — two lines: + * 1) choose: chosen=0 & parent decide & others idle & ratio -> (chosen'=i) + * 2) continue: chosen=i & child decide -> true + */ +export const pursueChoiceGoal = ( + goal: EdgeGoalNode, + orderedChildren: string[], + currentChildId: string, +): PursueStatement[] => { if (goal.relationToChildren === 'and') { throw new Error( - `Alternative goals are not supported for AND joints. Found in goal ${goal.id}`, + `Choice goals are not supported for AND joints. Found in goal ${goal.id}`, ); } + const index = orderedChildren.indexOf(currentChildId); + if (index < 0) { + throw new Error( + `Child ${currentChildId} not in choice children [${orderedChildren.join(', ')}]`, + ); + } + const chosenIndex = index + 1; // 1-based + const chosen = chosenVariable(goal.id); const { choice: choiceLogger } = getLogger().pursue.executionDetail; + choiceLogger( + currentChildId, + orderedChildren.filter((id) => id !== currentChildId), + `${chosen}=0`, + ); - if (goal.relationToChildren === 'or') { - const otherGoals = alternative.filter( - (goalId) => goalId !== currentChildId, - ); - const notChosen = otherGoals - .map((goalId) => { - const originalIndex = alternative.indexOf(goalId); - return `${chosenVariable(goal.id)}!=${originalIndex + 1}`; - }) - .join(separator('and')); - - choiceLogger(currentChildId, otherGoals, notChosen); - return notChosen; + const chooseOnce: PursueStatement = { + left: joinGuards( + `${chosen}=0`, + parentShouldPursue(goal.id), + otherChildrenIdle(orderedChildren, currentChildId), + selectChildByDecision(goal.id, orderedChildren, currentChildId), + ), + right: `(${chosen}'=${chosenIndex})`, + }; + + const continueChosen: PursueStatement = { + left: joinGuards(`${chosen}=${chosenIndex}`, childShouldPursue(currentChildId)), + right: 'true', + }; + + return [chooseOnce, continueChosen]; +}; + +const retryLimitForChild = ( + goal: EdgeGoalNode, + childId: string, +): number | null => { + const fromMap = goal.properties.engine.executionDetail?.retryMap?.[childId]; + if (typeof fromMap === 'number' && fromMap > 0) { + return fromMap; } - return ''; + const child = Node.children(goal).find((c) => c.id === childId); + if (!child || Node.isResource(child)) { + return null; + } + const maxRetries = child.properties.engine.maxRetries; + return typeof maxRetries === 'number' && maxRetries > 0 ? maxRetries : null; }; -// chooses either one of the children always (snippets: parent achievability vs decision, -// siblings idle, then (G1_ach/(G1_ach+G2_ach))*10 >/<= _decision_parent) -export const pursueAlternativeGoal = ( +/** + * OR + degradation (EDGEV2) — per child: + * - If this child has retries: retry line failed (failed'=failed+1) + * - Fallback (after retries exhausted on retrying children): failed=N & alternative-style select + * + * For children without their own retries, only emit the fallback line (gated on + * exhausted retries of earlier degradation children that have maxRetries). + */ +export const pursueDegradationGoal = ( goal: EdgeGoalNode, + degradationList: string[], currentChildId: string, -): string => { - type PursueableNode = EdgeGoalNode | EdgeTask; - const pursueableNodes = sharedPursueableChildren(goal) as PursueableNode[]; - const otherGoals = pursueableNodes.filter( - (child: PursueableNode) => child.id !== currentChildId, - ); - const { alternative: alternativeLogger } = getLogger().pursue.executionDetail; +): PursueStatement[] => { + if (goal.relationToChildren === 'and') { + throw new Error( + `Degradation goals are not supported for AND joints. Found in goal ${goal.id}`, + ); + } - alternativeLogger( - currentChildId, - otherGoals.map((child: PursueableNode) => child.id), - ); + const { degradation: degradationLogger } = getLogger().pursue.executionDetail; + degradationLogger.init(currentChildId, degradationList); - const parentVsDecision = achievableGtDecision(goal.id); + const statements: PursueStatement[] = []; + const ownRetries = retryLimitForChild(goal, currentChildId); - const siblingIdle = otherGoals - .map((child: PursueableNode) => childIdle(child)) - .join(separator('and')); + const retryChildren = degradationList + .map((id) => ({ id, n: retryLimitForChild(goal, id) })) + .filter((x): x is { id: string; n: number } => x.n !== null); - const parts: string[] = [parentVsDecision]; - if (siblingIdle) { - parts.push(siblingIdle); + if (ownRetries !== null) { + degradationLogger.retry(currentChildId, currentChildId, ownRetries); + const failed = goalFailedVariable(currentChildId); + statements.push({ + left: joinGuards( + hasFailedLessThanNTimes(currentChildId, ownRetries), + childShouldPursue(currentChildId), + ), + right: `(${failed}'=${failed}+1)`, + }); } - if (pursueableNodes.length >= 2) { - const first = pursueableNodes[0]; - if (!first) { - throw new Error( - `Pursueable children unexpectedly empty for alternative goal ${goal.id}`, - ); - } - const sumAchievable = pursueableNodes - .map((c) => achievable(c.id)) - .join('+'); - const ratioExpr = `(${achievable(first.id)}/(${sumAchievable}))*${ACHIEVABILITY_DECISION_SCALE}`; - const underscored = underscoredOrDecisionVariable(goal.id); - parts.push( - currentChildId === first.id - ? `${ratioExpr} > ${underscored}` - : `${ratioExpr} <= ${underscored}`, - ); - } + // Fallback / OR-select phase once all retry counters are exhausted + const exhaustedGate = retryChildren + .map(({ id, n }) => hasFailedExactlyNTimes(id, n)) + .join(' & '); + + // If there are no retry children, still allow alternative-style fallback + const fallbackLeft = joinGuards( + exhaustedGate || null, + parentShouldPursue(goal.id), + otherChildrenIdle(degradationList, currentChildId), + selectChildByDecision(goal.id, degradationList, currentChildId), + ); + + statements.push({ + left: fallbackLeft, + right: 'true', + }); - return parts.join(separator('and')); + return statements; }; diff --git a/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/skip.ts b/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/skip.ts index 84d3241e..1100ab61 100644 --- a/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/skip.ts +++ b/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/skip.ts @@ -1,163 +1,54 @@ -import type { TreeNode } from '@goal-controller/goal-tree'; import { Node } from '@goal-controller/goal-tree'; -import type { EdgeGoalNode } from '../../../../types'; +import type { EdgeGoalNode, EdgeTask } from '../../../../types'; import { getLogger } from '../../../../logger/logger'; +import { separator } from '../../../../mdp/common'; import { - achieved, - failed, - goalState, - pursued, - separator, -} from '../../../../mdp/common'; -import { chosenVariable, decisionVariable } from '../../../common'; -import { - achievableGtDecision, - achievableLeDecision, - childIdle, - pursueableChildren, -} from '../../../prismGuards'; -import { cappedDegradationChildren } from './variables'; - -const pursueMemberNodes = (goal: EdgeGoalNode): TreeNode[] => - goal.children?.length ? goal.children : goal.tasks?.length ? goal.tasks : []; - -/** Snippet: `!(G2_achievable*10.0 > decision_G2 | G1_achievable*10.0 > decision_G1)`. */ -const interleavedSkipNoChildPursueGuard = (goal: EdgeGoalNode): string => { - const disjuncts = pursueMemberNodes(goal) - .filter((c) => !Node.isResource(c)) - .map((child) => achievableGtDecision(child.id)); - if (disjuncts.length === 0) return ''; - return `!(${disjuncts.join(separator('or'))})`; -}; - -const childrenHasNotBeenPursued = (goal: EdgeGoalNode) => { - const pursueMembers = pursueMemberNodes(goal); - return pursueMembers - .map((child: TreeNode) => childIdle(child)) - .join(separator('and')); + achievedFormula, + pursuedVariable, + stateVariable, +} from '../../../../template/common'; +import { parentShouldSkip } from './pursue/decisionGuards'; + +/** Child idle: goals use g*_state=0; tasks still use T*_pursued=0 */ +const childIdle = (child: EdgeGoalNode | EdgeTask): string => + Node.isTask(child) + ? `${pursuedVariable(child.id)}=0` + : `${stateVariable(child.id)}=0`; + +const childrenIdle = (goal: EdgeGoalNode): string => { + const children = Node.children(goal).filter( + (child): child is EdgeGoalNode | EdgeTask => !Node.isResource(child), + ); + if (children.length === 0) { + return ''; + } + return children.map(childIdle).join(separator('and')); }; /** - * All `[skip_G]` PRISM lines for this goal (`OR` choice may emit several with the same label). + * EDGEV2: + * [skip_G0] !g0_achieved & g0_state=1 & g1_state=0 & g2_state=0 [& G0_achievable*10.0 <= decision_G0] -> (g0_state'=0); + * + * Parent decision threshold is included for sequence and anyOrder (EDGEV2 sketch). */ -export const skipStatements = (goal: EdgeGoalNode): string[] => { +export const skipStatement = (goal: EdgeGoalNode): string => { const logger = getLogger(); - const idleChildren = childrenHasNotBeenPursued(goal); - const edType = goal.properties.engine.executionDetail?.type; - const pursueableOrdered = pursueableChildren(goal); - - const updateStatement = `(${goalState(goal.id)}'=0);`; - - const emit = (leftStatement: string): string => { - const prismLabelStatement = `[skip_${goal.id}] ${leftStatement} -> ${updateStatement}`; - logger.skip(goal.id, leftStatement, updateStatement, prismLabelStatement); - return prismLabelStatement; - }; - - if ( - goal.relationToChildren === 'or' && - edType === 'choice' && - pursueableOrdered.length > 0 - ) { - const lines: string[] = []; - const idleAll = pursueableOrdered - .map((c) => childIdle(c)) - .join(separator('and')); - const uncommitted: string[] = [ - `!${achieved(goal.id)}`, - `${goalState(goal.id)}=1`, - ]; - if (idleAll) uncommitted.push(idleAll); - uncommitted.push(`${chosenVariable(goal.id)}=0`); - uncommitted.push(achievableLeDecision(goal.id)); - lines.push(emit(uncommitted.join(separator('and')))); - - pursueableOrdered.forEach((child, i) => { - const branchIndex = i + 1; - const parts: string[] = [ - `!${achieved(goal.id)}`, - `${goalState(goal.id)}=1`, - childIdle(child), - `${chosenVariable(goal.id)}=${branchIndex}`, - achievableLeDecision(child.id), - ]; - lines.push(emit(parts.join(separator('and')))); - }); - return lines; - } - - if ( - goal.relationToChildren === 'or' && - edType === 'degradation' && - pursueableOrdered.length > 0 - ) { - const lines: string[] = []; - const idleAll = pursueableOrdered - .map((c) => childIdle(c)) - .join(separator('and')); - const cappedChildren = cappedDegradationChildren(goal); - - // Retry regime (`child_failed < N`): skip this child branch when it cannot be pursued. - cappedChildren.forEach(({ child, cap }) => { - const parts: string[] = [ - `!${achieved(goal.id)}`, - `${goalState(goal.id)}=1`, - childIdle(child), - `${failed(child.id)}<${cap}`, - achievableLeDecision(child.id), - ]; - lines.push(emit(parts.join(separator('and')))); - }); - - // Failover regime (`child_failed = N`): skip when parent-level pursue cannot proceed. - if (cappedChildren.length > 0) { - cappedChildren.forEach(({ child, cap }) => { - const parts: string[] = [ - `!${achieved(goal.id)}`, - `${goalState(goal.id)}=1`, - `${failed(child.id)}=${cap}`, - achievableLeDecision(goal.id), - ]; - if (idleAll) parts.splice(2, 0, idleAll); - lines.push(emit(parts.join(separator('and')))); - }); - } else { - const parts: string[] = [ - `!${achieved(goal.id)}`, - `${goalState(goal.id)}=1`, - achievableLeDecision(goal.id), - ]; - if (idleAll) parts.splice(2, 0, idleAll); - lines.push(emit(parts.join(separator('and')))); - } - - return lines; - } - - const isAndSequential = - goal.relationToChildren === 'and' && edType === 'sequence'; - const isOrAlternative = - goal.relationToChildren === 'or' && edType === 'alternative'; - const useParentAchievableLeDecisionSkip = isAndSequential || isOrAlternative; - const isAndInterleaved = - goal.relationToChildren === 'and' && edType !== 'sequence'; - - const parts: string[] = []; - if (useParentAchievableLeDecisionSkip) { - parts.push(`!${achieved(goal.id)}`); - parts.push(`${goalState(goal.id)}=1`); - if (idleChildren) parts.push(idleChildren); - parts.push(achievableLeDecision(goal.id)); - } else if (isAndInterleaved) { - parts.push(`${goalState(goal.id)}=1`); - if (idleChildren) parts.push(idleChildren); - parts.push(`!${achieved(goal.id)}`); - const interleavedGuard = interleavedSkipNoChildPursueGuard(goal); - if (interleavedGuard) parts.push(interleavedGuard); - } else { - parts.push(`${goalState(goal.id)}=1`); - if (idleChildren) parts.push(idleChildren); - } + const executionType = goal.properties.engine.executionDetail?.type; + const includeParentSkipThreshold = + goal.relationToChildren === 'and' && + (executionType === 'sequence' || executionType === 'anyOrder'); + + const leftStatement = [ + `!${achievedFormula(goal.id)}`, + `${stateVariable(goal.id)}=1`, + childrenIdle(goal), + includeParentSkipThreshold ? parentShouldSkip(goal.id) : '', + ] + .filter(Boolean) + .join(separator('and')); + const updateStatement = `(${stateVariable(goal.id)}'=0);`; + const prismLabelStatement = `[skip_${goal.id}] ${leftStatement} -> ${updateStatement}`; - return [emit(parts.join(separator('and')))]; + logger.skip(goal.id, leftStatement, updateStatement, prismLabelStatement); + return prismLabelStatement; }; diff --git a/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/variables.ts b/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/variables.ts index 8d676f74..bf187a29 100644 --- a/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/variables.ts +++ b/packages/lib/src/engines/edgeV2/template/modules/goalModule/template/variables.ts @@ -1,48 +1,11 @@ -import { getLogger } from '../../../../logger/logger'; -import { failed } from '../../../../mdp/common'; +import { Node } from '@goal-controller/goal-tree'; import type { EdgeGoalNode, EdgeTask } from '../../../../types'; -import { coercePositiveIntRetry } from '../../../../retryCoercion'; -import { chosenVariable } from '../../../common'; -import { pursueableChildren } from '../../../prismGuards'; - -const goalStateVariable = (goalId: string): string => `${goalId}_state`; - -/** Retry cap N for degradation pursue lines (`sibling_failed < N` / `= N`), or null if absent from retryMap. */ -export const degradationRetryCapFromMap = ( - goal: EdgeGoalNode, - childId: string, -): number | null => { - if (goal.relationToChildren !== 'or') return null; - const ed = goal.properties.engine.executionDetail; - if (ed?.type !== 'degradation') return null; - return coercePositiveIntRetry(ed.retryMap?.[childId]); -}; - -/** - * Ordered list of `{ child, cap }` for every pursueable child in an OR - * degradation goal whose retryMap entry has a positive integer cap. - * Single source of truth for pursue, skip, and validator expected counts. - */ -export const cappedDegradationChildren = ( - goal: EdgeGoalNode, -): Array<{ child: EdgeGoalNode | EdgeTask; cap: number }> => { - if (goal.relationToChildren !== 'or') return []; - const ed = goal.properties.engine.executionDetail; - if (ed?.type !== 'degradation') return []; - return pursueableChildren(goal).flatMap((child) => { - const cap = coercePositiveIntRetry(ed.retryMap?.[child.id]); - return cap !== null ? [{ child, cap }] : []; - }); -}; - -const degradationSiblingFailedVariableLines = ( - goal: EdgeGoalNode, - defineVariable: (variable: string, upperBound: number) => string, -): string[] => { - return cappedDegradationChildren(goal).map(({ child, cap }) => - defineVariable(failed(child.id), cap), - ); -}; +import { getLogger } from '../../../../logger/logger'; +import { + chosenVariable, + goalFailedVariable, + stateVariable, +} from '../../../../template/common'; export const variablesDefinition = (goal: EdgeGoalNode): string => { const logger = getLogger(); @@ -56,25 +19,36 @@ export const variablesDefinition = (goal: EdgeGoalNode): string => { }); return `${variable} : [0..${upperBound}] init 0;`; }; - const stateVariableStatement = defineVariable(goalStateVariable(goal.id), 1); - const pursueableChildrenCount = pursueableChildren(goal).length; + const stateVariableStatement = defineVariable(stateVariable(goal.id), 1); + + const pursueableChildren = Node.children(goal).filter( + (child) => !Node.isResource(child), + ); + const isOrChoice = + goal.relationToChildren === 'or' && + goal.properties.engine.executionDetail?.type === 'choice'; const chosenVariableStatement = - goal.properties.engine.executionDetail?.type === 'choice' && - pursueableChildrenCount > 0 - ? defineVariable(chosenVariable(goal.id), pursueableChildrenCount) + isOrChoice && pursueableChildren.length > 0 + ? defineVariable(chosenVariable(goal.id), pursueableChildren.length) : null; - const degradationFailedLines = degradationSiblingFailedVariableLines( - goal, - defineVariable, - ); + const isDegradation = + goal.properties.engine.executionDetail?.type === 'degradation'; + const childrenWithMaxRetries = isDegradation + ? Node.childrenWithRetries(goal) + : []; + const maxRetriesVariableStatement = + childrenWithMaxRetries.length > 0 + ? childrenWithMaxRetries + .map((child: EdgeGoalNode | EdgeTask) => { + const maxRetries = child.properties.engine.maxRetries; + return defineVariable(goalFailedVariable(child.id), maxRetries); + }) + .join('\n ') + : null; - return [ - stateVariableStatement, - chosenVariableStatement, - ...degradationFailedLines, - ] + return [stateVariableStatement, chosenVariableStatement, maxRetriesVariableStatement] .filter(Boolean) .join('\n '); }; diff --git a/packages/lib/src/engines/edgeV2/template/prismGuards.ts b/packages/lib/src/engines/edgeV2/template/prismGuards.ts deleted file mode 100644 index 68e18d54..00000000 --- a/packages/lib/src/engines/edgeV2/template/prismGuards.ts +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Shared Edge V2 PRISM guard string builders. - * - * A single source of truth for the snippet `achievable * 10.0 > decision` / - * `<= decision` pattern and for "child is idle" guards so they cannot drift - * across skip, pursue, and validator files. - */ -import { Node } from '@goal-controller/goal-tree'; -import type { TreeNode } from '@goal-controller/goal-tree'; -import type { EdgeGoalNode, EdgeTask } from '../types'; -import { achievable, goalState, pursued } from '../mdp/common'; -import { decisionVariable } from './common'; - -/** Scale factor shared across all EDGE snippet pursue/skip guards. */ -export const ACHIEVABILITY_DECISION_SCALE = 10.0; - -/** `child_achievable*10.0 > decision_child` (used in pursue guards). */ -export const achievableGtDecision = (id: string): string => - `${achievable(id)}*${ACHIEVABILITY_DECISION_SCALE} > ${decisionVariable(id)}`; - -/** `child_achievable*10.0 <= decision_child` (used in skip guards). */ -export const achievableLeDecision = (id: string): string => - `${achievable(id)}*${ACHIEVABILITY_DECISION_SCALE} <= ${decisionVariable(id)}`; - -/** - * "This node is not currently being pursued": - * - task → `task_pursued=0` - * - goal → `goal_state=0` - */ -export const childIdle = (child: TreeNode | EdgeGoalNode | EdgeTask): string => - child.type === 'task' ? `${pursued(child.id)}=0` : `${goalState(child.id)}=0`; - -/** - * Ordered list of pursueable (non-resource) children for a goal. - * Stable because `Node.children` preserves declaration order. - */ -export const pursueableChildren = ( - goal: EdgeGoalNode, -): Array => - Node.children(goal).filter( - (c): c is EdgeGoalNode | EdgeTask => !Node.isResource(c), - ); diff --git a/packages/lib/src/engines/edgeV2/types.ts b/packages/lib/src/engines/edgeV2/types.ts index 66a1a008..97154c2f 100644 --- a/packages/lib/src/engines/edgeV2/types.ts +++ b/packages/lib/src/engines/edgeV2/types.ts @@ -16,10 +16,16 @@ export type ExecCondition = { }; }; +export type Decision = { + decisionVars: Array<{ variable: string; space: number }>; + hasDecision: boolean; +}; + export type GoalExecutionDetail = ( | { type: 'interleaved'; interleaved: string[] } | { type: 'alternative'; alternative: string[] } | { type: 'sequence'; sequence: string[] } + | { type: 'anyOrder'; anyOrder: string[] } | { type: 'degradation'; degradationList: string[] } | { type: 'decisionMaking'; dm: string[] } | { type: 'choice' } @@ -39,6 +45,7 @@ export type EdgeGoalProps = { dependsOn: TGoalNode[]; executionDetail: GoalExecutionDetail | null; execCondition?: ExecCondition; + decision: Decision; maxRetries: number; }; diff --git a/packages/lib/src/engines/edgeV2/validator/expectedElements.ts b/packages/lib/src/engines/edgeV2/validator/expectedElements.ts index 746255d6..250a78f6 100644 --- a/packages/lib/src/engines/edgeV2/validator/expectedElements.ts +++ b/packages/lib/src/engines/edgeV2/validator/expectedElements.ts @@ -1,53 +1,47 @@ import type { Resource } from '@goal-controller/goal-tree'; -import { GoalTree } from '@goal-controller/goal-tree'; +import { GoalTree, Node } from '@goal-controller/goal-tree'; import type { EdgeGoalNode, EdgeGoalTree, EdgeTask } from '../types'; // Type aliases for this file type GoalNode = EdgeGoalNode; type Task = EdgeTask; type GoalTreeType = EdgeGoalTree; -import { failed } from '../mdp/common'; import { achievableFormulaVariable, + achievedFormula, achievedTransition, achievedVariable, chosenVariable, - decisionVariable, + goalFailedVariable, pursueTransition, - underscoredOrDecisionVariable, + stateVariable, } from '../template/common'; -import { cappedDegradationChildren } from '../template/modules/goalModule/template/variables'; -import { pursueableChildren } from '../template/prismGuards'; import type { ExpectedElements } from './types'; -const achievedMaintain = (goalId: string): string => { - return `${goalId}_achieved_maintain`; -}; -const goalStateVariable = (goalId: string): string => `${goalId}_state`; - const calculateGoalVariables = (goal: GoalNode): string[] => { const variables: string[] = []; - // Always has state variable - variables.push(goalStateVariable(goal.id)); + // Always has state (pursued / not pursued) + variables.push(stateVariable(goal.id)); - // One nondeterministic-resolution int per goal module - variables.push(decisionVariable(goal.id)); - - if (goal.relationToChildren === 'or') { - variables.push(underscoredOrDecisionVariable(goal.id)); - } - - // Has chosen if choice execution detail - if (goal.properties.engine.executionDetail?.type === 'choice') { - if (pursueableChildren(goal).length > 0) { + // OR + choice: chosen child index + if ( + goal.relationToChildren === 'or' && + goal.properties.engine.executionDetail?.type === 'choice' + ) { + const pursueableChildren = Node.children(goal).filter( + (child) => !Node.isResource(child), + ); + if (pursueableChildren.length > 0) { variables.push(chosenVariable(goal.id)); } } - // Degradation OR: one failed counter per sibling id in retryMap (parent module) - for (const { child } of cappedDegradationChildren(goal)) { - variables.push(failed(child.id)); + // Degradation: failed counters for children with maxRetries + if (goal.properties.engine.executionDetail?.type === 'degradation') { + Node.childrenWithRetries(goal).forEach((child) => { + variables.push(goalFailedVariable(child.id)); + }); } return variables; @@ -58,54 +52,19 @@ const calculateGoalTransitions = (goal: GoalNode): string[] => { // Always has pursue transitions: one for itself + one for each pursueable child transitions.push(pursueTransition(goal.id)); - const children = pursueableChildren(goal); - const executionDetail = goal.properties.engine.executionDetail; - const cappedChildren = cappedDegradationChildren(goal); - - children.forEach((child) => { + // Filter out resources - only goals and tasks can be pursued + const pursueableChildren = Node.children(goal).filter( + (child) => !Node.isResource(child), + ); + pursueableChildren.forEach((child) => { transitions.push(pursueTransition(child.id)); - if ( - goal.relationToChildren === 'or' && - executionDetail?.type === 'choice' - ) { - transitions.push(pursueTransition(child.id)); - } - if ( - goal.relationToChildren === 'or' && - executionDetail?.type === 'degradation' && - cappedChildren.some(({ child: c }) => c.id === child.id) - ) { - transitions.push(pursueTransition(child.id)); - } }); // Always has achieve transition transitions.push(achievedTransition(goal.id)); - // Skip: OR choice emits one line per chosen branch (0 = uncommitted) plus default; else single skip - if ( - goal.relationToChildren === 'or' && - executionDetail?.type === 'choice' && - children.length > 0 - ) { - for (let i = 0; i <= children.length; i++) { - transitions.push(`skip_${goal.id}`); - } - } else if ( - goal.relationToChildren === 'or' && - executionDetail?.type === 'degradation' - ) { - if (cappedChildren.length > 0) { - // Per capped sibling: one retry-skip (`failed { const calculateGoalFormulas = (goal: GoalNode): string[] => { const formulas: string[] = []; - // Achievability formula (Edge v1 combinators over child `_achievable`) + // Always has achievability formula formulas.push(achievableFormulaVariable(goal.id)); - // Achieved formula (derived from child goals/tasks) - formulas.push(achievedVariable(goal.id)); - - // Has maintain formula if maintain goal + // Achieved formula (EDGEV2): children composition, or maintain sentence if (goal.properties.engine.execCondition?.maintain) { - formulas.push(achievedMaintain(goal.id)); + formulas.push(achievedFormula(goal.id)); + } else { + const hasPursueableChildren = Node.children(goal).some( + (child) => !Node.isResource(child), + ); + if (hasPursueableChildren) { + formulas.push(achievedFormula(goal.id)); + } } return formulas; diff --git a/packages/lib/src/engines/edgeV2/validator/index.ts b/packages/lib/src/engines/edgeV2/validator/index.ts index e78b2eff..76b1dc76 100644 --- a/packages/lib/src/engines/edgeV2/validator/index.ts +++ b/packages/lib/src/engines/edgeV2/validator/index.ts @@ -4,7 +4,6 @@ import { formatValidationReport, getValidationSummary, serializeValidationReportToJSON, - summarizeValidationFailures, } from './report'; import type { ValidationReport } from './types'; import { validatePrismModel } from './validator'; @@ -15,7 +14,6 @@ export { formatValidationReport, getValidationSummary, serializeValidationReportToJSON, - summarizeValidationFailures, validatePrismModel, }; diff --git a/packages/lib/src/engines/edgeV2/validator/parser.ts b/packages/lib/src/engines/edgeV2/validator/parser.ts index 39cf1d1a..72d7fd3b 100644 --- a/packages/lib/src/engines/edgeV2/validator/parser.ts +++ b/packages/lib/src/engines/edgeV2/validator/parser.ts @@ -55,7 +55,7 @@ const extractVariablesFromGuard = (guard: string): string[] => { // Match variable patterns in the guard // Patterns: var=value, var'=value, var>=value, var<=value, var!=value, var>value, var=|<=|!=|>|<|=)/g; let match; @@ -168,6 +168,7 @@ const parseModule = ( | 'degradation' | 'sequence' | 'interleaved' + | 'anyOrder' | 'alternative' | 'basic' | undefined; @@ -189,6 +190,9 @@ const parseModule = ( } else if (typeStr === 'interleaved') { goalType = 'interleaved'; break; + } else if (typeStr === 'anyorder') { + goalType = 'anyOrder'; + break; } else if (typeStr === 'alternative') { goalType = 'alternative'; break; @@ -259,7 +263,6 @@ export const parsePrismModel = (prismModel: string): ParsedPrismModel => { let systemModule: ModuleInfo | undefined; const formulas: FormulaInfo[] = []; const constants = new Map(); - const nondetConstants: string[] = []; let i = 0; @@ -277,13 +280,6 @@ export const parsePrismModel = (prismModel: string): ParsedPrismModel => { while (i < lines.length) { const line = lines[i]?.trim() || ''; - const constIntNondet = line.match(/^\s*const\s+int\s+(\w+)\s*;\s*$/); - if (constIntNondet?.[1]) { - nondetConstants.push(constIntNondet[1]); - i++; - continue; - } - // Check if it's a module if (line.startsWith('module ')) { const result = parseModule(lines, i); @@ -328,6 +324,5 @@ export const parsePrismModel = (prismModel: string): ParsedPrismModel => { systemModule, formulas, constants, - nondetConstants, }; }; diff --git a/packages/lib/src/engines/edgeV2/validator/report.ts b/packages/lib/src/engines/edgeV2/validator/report.ts index fb280044..ca41b08e 100644 --- a/packages/lib/src/engines/edgeV2/validator/report.ts +++ b/packages/lib/src/engines/edgeV2/validator/report.ts @@ -1,57 +1,5 @@ import type { ValidationReport } from './types'; -/** Short, log-friendly list of what failed structural validation. */ -export const summarizeValidationFailures = ( - report: ValidationReport, -): string => { - const lines: string[] = []; - lines.push(`Missing count: ${report.summary.totalMissing}`); - report.goals.forEach((v, goalId) => { - const parts: string[] = []; - if (v.module.missing > 0) { - parts.push('goal module not found in PRISM output'); - } - if (v.variables.missing > 0) { - parts.push(`variables [${v.variables.details.missing.join(', ')}]`); - } - if (v.transitions.missing > 0) { - parts.push(`transitions [${v.transitions.details.missing.join(', ')}]`); - } - if (v.formulas.missing > 0) { - parts.push(`formulas [${v.formulas.details.missing.join(', ')}]`); - } - if (v.contextVariables.missing > 0) { - parts.push( - `contextVariables [${v.contextVariables.details.missing.join(', ')}]`, - ); - } - if (parts.length > 0) { - lines.push(` ${goalId}: ${parts.join('; ')}`); - } - }); - if (report.changeManager.taskVariables.missing > 0) { - lines.push( - ` ChangeManager task variables: [${report.changeManager.taskVariables.details.missing.join(', ')}]`, - ); - } - if (report.changeManager.taskTransitions.missing > 0) { - lines.push( - ` ChangeManager task transitions: [${report.changeManager.taskTransitions.details.missing.join(', ')}]`, - ); - } - if (report.system.contextVariables.missing > 0) { - lines.push( - ` System contextVariables: [${report.system.contextVariables.details.missing.join(', ')}]`, - ); - } - if (report.system.resourceVariables.missing > 0) { - lines.push( - ` System resourceVariables: [${report.system.resourceVariables.details.missing.join(', ')}]`, - ); - } - return lines.join('\n'); -}; - export const serializeValidationReportToJSON = ( report: ValidationReport, ): Record => { @@ -160,6 +108,11 @@ export const serializeValidationReportToJSON = ( emitted: report.goalTypes.interleaved.emitted, missing: report.goalTypes.interleaved.missing, }, + anyOrder: { + expected: report.goalTypes.anyOrder.expected, + emitted: report.goalTypes.anyOrder.emitted, + missing: report.goalTypes.anyOrder.missing, + }, alternative: { expected: report.goalTypes.alternative.expected, emitted: report.goalTypes.alternative.emitted, @@ -250,6 +203,9 @@ export const formatValidationReport = (report: ValidationReport): string => { lines.push( `Interleaved: expected=${report.goalTypes.interleaved.expected}, emitted=${report.goalTypes.interleaved.emitted}, missing=${report.goalTypes.interleaved.missing}`, ); + lines.push( + `AnyOrder: expected=${report.goalTypes.anyOrder.expected}, emitted=${report.goalTypes.anyOrder.emitted}, missing=${report.goalTypes.anyOrder.missing}`, + ); lines.push( `Alternative: expected=${report.goalTypes.alternative.expected}, emitted=${report.goalTypes.alternative.emitted}, missing=${report.goalTypes.alternative.missing}`, ); diff --git a/packages/lib/src/engines/edgeV2/validator/types.ts b/packages/lib/src/engines/edgeV2/validator/types.ts index 017d1b42..a5c0b58c 100644 --- a/packages/lib/src/engines/edgeV2/validator/types.ts +++ b/packages/lib/src/engines/edgeV2/validator/types.ts @@ -26,6 +26,7 @@ export type ModuleInfo = { | 'degradation' | 'sequence' | 'interleaved' + | 'anyOrder' | 'alternative' | 'basic'; lineCount?: number; @@ -37,8 +38,6 @@ export type ParsedPrismModel = { systemModule?: ModuleInfo; formulas: FormulaInfo[]; constants: Map; - /** Top-level `const int x;` nondeterministic constants (e.g. decision_G0). */ - nondetConstants: string[]; }; export type ElementCount = { @@ -76,6 +75,7 @@ export type GoalTypeCounts = { degradation: ElementCount; sequence: ElementCount; interleaved: ElementCount; + anyOrder: ElementCount; alternative: ElementCount; basic: ElementCount; }; diff --git a/packages/lib/src/engines/edgeV2/validator/validator.ts b/packages/lib/src/engines/edgeV2/validator/validator.ts index daba6fb2..e0f33f61 100644 --- a/packages/lib/src/engines/edgeV2/validator/validator.ts +++ b/packages/lib/src/engines/edgeV2/validator/validator.ts @@ -17,24 +17,12 @@ import type { type GoalTreeType = EdgeGoalTree; -/** - * Multiset-style matching so duplicate transition labels (e.g. two `pursue_G1` commands) - * require the same multiplicity in the emitted model. - */ const createElementCount = ( expected: string[], emitted: string[], ): ElementCount & { details: ElementDetails } => { - const emittedRemaining = [...emitted]; - const missing: string[] = []; - for (const item of expected) { - const idx = emittedRemaining.indexOf(item); - if (idx === -1) { - missing.push(item); - } else { - emittedRemaining.splice(idx, 1); - } - } + const emittedSet = new Set(emitted); + const missing = expected.filter((item) => !emittedSet.has(item)); return { expected: expected.length, @@ -42,7 +30,7 @@ const createElementCount = ( missing: missing.length, details: { expected, - emitted: Array.from(new Set(emitted)), + emitted: Array.from(emittedSet), missing, }, }; @@ -59,20 +47,18 @@ const validateGoal = ( parsedModel: ParsedPrismModel, ): GoalValidation => { const goalModule = parsedModel.goalModules.get(goalId); - const moduleVarNames = goalModule?.variables.map((v) => v.name) || []; - const fromNondet = expected.variables.filter((name) => - parsedModel.nondetConstants.includes(name), - ); - const emittedVariables = Array.from( - new Set([...moduleVarNames, ...fromNondet]), - ); + const emittedVariables = goalModule?.variables.map((v) => v.name) || []; const emittedTransitions = goalModule?.transitions.map((t) => t.label) || []; - // Filter formulas that belong to this goal - // Formulas are named like: G1_achievable, G1_achieved, G1_achieved_maintain - // We need to match formulas that start with goalId + '_' to avoid matching - // G10, G11, etc. when looking for G1 + // Formulas may use original id (G1_achievable) or lowercase EDGEV2 names (g1_achieved) + const lowerGoalId = goalId.toLowerCase(); const emittedFormulas = parsedModel.formulas - .filter((f) => f.name === goalId || f.name.startsWith(`${goalId}_`)) + .filter( + (f) => + f.name === goalId || + f.name === lowerGoalId || + f.name.startsWith(`${goalId}_`) || + f.name.startsWith(`${lowerGoalId}_`), + ) .map((f) => f.name); // Check if module exists @@ -97,11 +83,11 @@ const validateGoal = ( ); // Extract context variables from the first pursue transition's guard - // Filter out goal-specific variables (like G5_state, G5_chosen, etc.) + // Filter out goal-specific variables (EDGEV2: g1_state / g1_achieved / g1_chosen / g1_failed) const systemContextVars = parsedModel.systemModule?.variables.map((v) => v.name) || []; const goalVariablePattern = new RegExp( - `^(${goalId}_(state|pursued|achieved|chosen|failed|achievable)|_decision_${goalId})$`, + `^(${goalId}|${lowerGoalId})_(pursued|achieved|chosen|failed|state)$`, ); const emittedContextVars = @@ -227,6 +213,7 @@ export const validatePrismModel = ( degradation: { expected: 0, emitted: 0, missing: 0 }, sequence: { expected: 0, emitted: 0, missing: 0 }, interleaved: { expected: 0, emitted: 0, missing: 0 }, + anyOrder: { expected: 0, emitted: 0, missing: 0 }, alternative: { expected: 0, emitted: 0, missing: 0 }, basic: { expected: 0, emitted: 0, missing: 0 }, }; @@ -243,9 +230,11 @@ export const validatePrismModel = ( ? 'sequence' : goal.properties.engine.executionDetail?.type === 'interleaved' ? 'interleaved' - : goal.properties.engine.executionDetail?.type === 'alternative' - ? 'alternative' - : 'basic'; + : goal.properties.engine.executionDetail?.type === 'anyOrder' + ? 'anyOrder' + : goal.properties.engine.executionDetail?.type === 'alternative' + ? 'alternative' + : 'basic'; goalTypes[goalType].expected++; }); diff --git a/packages/lib/src/engines/index.ts b/packages/lib/src/engines/index.ts index 501a49d6..ea5afd5b 100644 --- a/packages/lib/src/engines/index.ts +++ b/packages/lib/src/engines/index.ts @@ -12,6 +12,7 @@ * * Available Engines: * - **Edge**: Generates PRISM models for probabilistic verification + * - **EdgeV2**: Next-generation Edge PRISM model generator * - **SLEEC**: Generates SLEEC specifications for runtime monitoring */ diff --git a/packages/lib/src/index.ts b/packages/lib/src/index.ts index 25d16f92..bc621c3d 100644 --- a/packages/lib/src/index.ts +++ b/packages/lib/src/index.ts @@ -10,6 +10,11 @@ import { } from './engines/edge'; import { initLogger } from './engines/edge/logger/logger'; import { validate } from './engines/edge/validator'; +import { + edgeEngineMapper as edgeV2EngineMapper, + generateValidatedPrismModel as generateEdgeV2PrismModel, +} from './engines/edgeV2'; +import { initLogger as initEdgeV2Logger } from './engines/edgeV2/logger/logger'; import { sleecTemplateEngine } from './engines/sleec'; export type { @@ -35,6 +40,18 @@ export { type EdgeGoalTree, type EdgeTask, } from './engines/edge'; + +// EdgeV2 engine mapper and template +export { + edgeV2EngineMapper, + generateEdgeV2PrismModel, + initEdgeV2Logger, +}; +export type { + EdgeGoalNode as EdgeV2GoalNode, + EdgeGoalTree as EdgeV2GoalTree, + EdgeTask as EdgeV2Task, +} from './engines/edgeV2'; export type { Decision, EdgeGoalProps, @@ -52,15 +69,6 @@ export { } from './engines/sleec'; export type { SleecGoalProps, SleecTaskProps } from './engines/sleec'; -// Edge V2 (PRISM / EDGE snippets encoding) -export { - edgeEngineMapper as edgeV2EngineMapper, - type EdgeGoalNode as EdgeV2GoalNode, - type EdgeGoalTree as EdgeV2GoalTree, - type EdgeTask as EdgeV2Task, -} from './engines/edgeV2'; -export { generateValidatedPrismModel as generateValidatedEdgeV2PrismModel } from './engines/edgeV2/template'; - // Core transformation engines (remain in lib) export { generateValidatedPrismModel, sleecTemplateEngine }; @@ -70,7 +78,6 @@ export { validate }; // Logger export type { LoggerReport } from './engines/edge/logger/logger'; export { initLogger }; -export { initLogger as initEdgeV2Logger } from './engines/edgeV2/logger/logger'; // CLI entry point - if this file is executed directly, run the CLI script diff --git a/packages/lib/test/engines/edgeV2/template/modules/goalModule/template/pursue/andGoal.test.ts b/packages/lib/test/engines/edgeV2/template/modules/goalModule/template/pursue/andGoal.test.ts new file mode 100644 index 00000000..e7c497ef --- /dev/null +++ b/packages/lib/test/engines/edgeV2/template/modules/goalModule/template/pursue/andGoal.test.ts @@ -0,0 +1,190 @@ +import * as assert from 'assert'; +import { before, describe, it } from 'mocha'; +import { + pursueAndAnyOrderGoal, + pursueAndSequentialGoal, + splitSequence, +} from '../../../../../../../../src/engines/edgeV2/template/modules/goalModule/template/pursue/andGoal'; +import { skipStatement } from '../../../../../../../../src/engines/edgeV2/template/modules/goalModule/template/skip'; +import { decisionVariableNamesForGoal } from '../../../../../../../../src/engines/edgeV2/template/decisionVariables'; +import { achievableGoalFormula } from '../../../../../../../../src/engines/edgeV2/template/modules/goalModule/template/formulas'; +import { initLogger } from '../../../../../../../../src/engines/edgeV2/logger/logger'; +import type { EdgeGoalNode } from '../../../../../../../../src/engines/edgeV2/types'; + +const emptyDecision = { + decisionVars: [] as Array<{ variable: string; space: number }>, + hasDecision: false, +}; + +const childGoal = (id: string): EdgeGoalNode => + ({ + iStarId: id, + id, + type: 'goal', + name: id, + relationToChildren: null, + children: [], + tasks: [], + properties: { + isQuality: false, + engine: { + utility: '', + cost: '', + dependsOn: [], + executionDetail: null, + decision: emptyDecision, + maxRetries: 0, + }, + }, + }) as EdgeGoalNode; + +const andParent = ( + executionDetail: EdgeGoalNode['properties']['engine']['executionDetail'], + childIds: string[], +): EdgeGoalNode => + ({ + iStarId: 'G0', + id: 'G0', + type: 'goal', + name: 'Parent', + relationToChildren: 'and', + children: childIds.map(childGoal), + tasks: [], + properties: { + isQuality: false, + engine: { + utility: '', + cost: '', + dependsOn: [], + executionDetail, + decision: emptyDecision, + maxRetries: 0, + }, + }, + }) as EdgeGoalNode; + +describe('edgeV2 AND anyOrder', () => { + before(() => { + initLogger('anyOrder-test', false, true); + }); + + describe('pursueAndAnyOrderGoal', () => { + it('matches EDGEV2 N=2 pursue guards', () => { + const goal = andParent( + { type: 'anyOrder', anyOrder: ['G1', 'G2'] }, + ['G1', 'G2'], + ); + + assert.strictEqual( + pursueAndAnyOrderGoal(goal, ['G1', 'G2'], 'G1'), + 'G0_achievable*10.0 > decision_G0 & g2_state!=1 & (g2_state=1 | (G1_achievable/(G1_achievable+G2_achievable))*10.0 > _decision_G0)', + ); + assert.strictEqual( + pursueAndAnyOrderGoal(goal, ['G1', 'G2'], 'G2'), + 'G0_achievable*10.0 > decision_G0 & g1_state!=1 & (g1_state=1 | (G1_achievable/(G1_achievable+G2_achievable))*10.0 <= _decision_G0)', + ); + }); + + it('rejects OR parents', () => { + const goal = { + ...andParent({ type: 'anyOrder', anyOrder: ['G1', 'G2'] }, ['G1', 'G2']), + relationToChildren: 'or' as const, + }; + assert.throws( + () => pursueAndAnyOrderGoal(goal, ['G1', 'G2'], 'G1'), + /Any-order goals are not supported for OR/, + ); + }); + + it('rejects unknown child ids', () => { + const goal = andParent( + { type: 'anyOrder', anyOrder: ['G1', 'G2'] }, + ['G1', 'G2'], + ); + assert.throws( + () => pursueAndAnyOrderGoal(goal, ['G1', 'G2'], 'G99'), + /Child ID G99 not found in anyOrder/, + ); + }); + }); + + describe('decisionVariableNamesForGoal', () => { + it('emits _decision for AND anyOrder parents', () => { + const goal = andParent( + { type: 'anyOrder', anyOrder: ['G1', 'G2'] }, + ['G1', 'G2'], + ); + assert.deepStrictEqual(decisionVariableNamesForGoal(goal), [ + 'decision_G0', + '_decision_G0', + ]); + }); + + it('does not emit _decision for AND sequence parents', () => { + const goal = andParent( + { type: 'sequence', sequence: ['G1', 'G2'] }, + ['G1', 'G2'], + ); + assert.deepStrictEqual(decisionVariableNamesForGoal(goal), [ + 'decision_G0', + ]); + }); + }); + + describe('skipStatement', () => { + it('includes parent skip threshold for anyOrder', () => { + const goal = andParent( + { type: 'anyOrder', anyOrder: ['G1', 'G2'] }, + ['G1', 'G2'], + ); + assert.strictEqual( + skipStatement(goal), + '[skip_G0] !g0_achieved & g0_state=1 & g1_state=0 & g2_state=0 & G0_achievable*10.0 <= decision_G0 -> (g0_state\'=0);', + ); + }); + + it('includes parent skip threshold for sequence', () => { + const goal = andParent( + { type: 'sequence', sequence: ['G1', 'G2'] }, + ['G1', 'G2'], + ); + assert.strictEqual( + skipStatement(goal), + '[skip_G0] !g0_achieved & g0_state=1 & g1_state=0 & g2_state=0 & G0_achievable*10.0 <= decision_G0 -> (g0_state\'=0);', + ); + }); + }); + + describe('achievableGoalFormula', () => { + it('emits AND product for anyOrder parents', () => { + const goal = andParent( + { type: 'anyOrder', anyOrder: ['G1', 'G2'] }, + ['G1', 'G2'], + ); + assert.strictEqual( + achievableGoalFormula(goal), + 'formula G0_achievable = G1_achievable * G2_achievable;', + ); + }); + }); + + describe('splitSequence / pursueAndSequentialGoal (regression)', () => { + it('still splits sequences', () => { + assert.deepStrictEqual(splitSequence(['G1', 'G2', 'G3'], 'G2'), [ + ['G1'], + ['G3'], + ]); + }); + + it('still builds sequence pursue guards', () => { + const goal = andParent( + { type: 'sequence', sequence: ['G1', 'G2'] }, + ['G1', 'G2'], + ); + assert.strictEqual( + pursueAndSequentialGoal(goal, ['G1', 'G2'], 'G2'), + 'G0_achievable*10.0 > decision_G0 & g1_achieved', + ); + }); + }); +}); diff --git a/packages/ui/app/api/transform/route.ts b/packages/ui/app/api/transform/route.ts index 6c38d23c..48fee211 100644 --- a/packages/ui/app/api/transform/route.ts +++ b/packages/ui/app/api/transform/route.ts @@ -1,14 +1,18 @@ import { - generateValidatedEdgeV2PrismModel, generateValidatedPrismModel, - initEdgeV2Logger, + generateEdgeV2PrismModel, initLogger, + initEdgeV2Logger, sleecTemplateEngine, type LoggerReport, } from '@goal-controller/lib'; import { NextRequest } from 'next/server'; import { ApiResponse } from '../../../lib/api'; import { GoalModel } from '../../../lib/models'; +import { + isTransformEngine, + type TransformEngine, +} from '../../../lib/types'; export async function POST(request: NextRequest) { try { @@ -27,15 +31,16 @@ export async function POST(request: NextRequest) { return ApiResponse.badRequest('Model JSON is required'); } - if (!engine || !['prism', 'sleec', 'edgeV2'].includes(engine)) { + if (!engine || !isTransformEngine(engine)) { return ApiResponse.badRequest( - 'Valid engine (prism/sleec/edgeV2) is required', + 'Valid engine (edge/edgev2/sleec) is required', ); } - // Logger is engine-specific: Edge V2 template calls getLogger() from the edgeV2 module. + const selectedEngine = engine as TransformEngine; + const logger = - engine === 'edgeV2' + selectedEngine === 'edgev2' ? initEdgeV2Logger(fileName || 'model', false, true) : initLogger(fileName || 'model', false, true); @@ -43,8 +48,7 @@ export async function POST(request: NextRequest) { let output: string; let report: LoggerReport | null = null; try { - if (engine === 'prism') { - // Parse and validate model with Edge mapper for PRISM + if (selectedEngine === 'edge') { const parseResult = GoalModel.parseForEdge(modelJson); if (!parseResult.success) { @@ -59,7 +63,7 @@ export async function POST(request: NextRequest) { if (process.env.NODE_ENV === 'development') { console.log('[API] Model parsed and tree converted successfully'); - console.log('[API] Generating PRISM model...'); + console.log('[API] Generating Edge model...'); } output = generateValidatedPrismModel({ gm: parseResult.tree, @@ -69,7 +73,7 @@ export async function POST(request: NextRequest) { generateDecisionVars, achievabilitySpace, }); - } else if (engine === 'edgeV2') { + } else if (selectedEngine === 'edgev2') { const parseResult = GoalModel.parseForEdgeV2(modelJson); if (!parseResult.success) { @@ -84,13 +88,15 @@ export async function POST(request: NextRequest) { if (process.env.NODE_ENV === 'development') { console.log('[API] Model parsed and tree converted successfully'); - console.log('[API] Generating Edge V2 PRISM model...'); + console.log('[API] Generating EdgeV2 model...'); } - output = generateValidatedEdgeV2PrismModel({ + output = generateEdgeV2PrismModel({ gm: parseResult.tree, fileName: fileName || 'model', clean, variables, + generateDecisionVars, + achievabilitySpace, }); } else { // Parse and validate model with SLEEC mapper diff --git a/packages/ui/app/layout.tsx b/packages/ui/app/layout.tsx index 61e87ce5..21d59f2c 100644 --- a/packages/ui/app/layout.tsx +++ b/packages/ui/app/layout.tsx @@ -4,7 +4,7 @@ import QueryProvider from './QueryProvider'; export const metadata: Metadata = { title: 'Goal Transformer - Model Transformation', - description: 'Transform goal models to PRISM or SLEEC specifications', + description: 'Transform goal models to Edge, EdgeV2, or SLEEC specifications', }; export default function RootLayout({ diff --git a/packages/ui/components/EngineSelector.tsx b/packages/ui/components/EngineSelector.tsx index c19f5d02..598ad6d2 100644 --- a/packages/ui/components/EngineSelector.tsx +++ b/packages/ui/components/EngineSelector.tsx @@ -1,6 +1,7 @@ 'use client'; -import type { TransformEngine } from '../lib/transformEngine'; +import type { TransformEngine } from '@/lib/types'; +import { isPrismEngine } from '@/lib/types'; interface EngineSelectorProps { engine: TransformEngine; @@ -37,26 +38,26 @@ export default function EngineSelector({