From 7ff8339a8e5ade445844c9e9a914b115a351d6e5 Mon Sep 17 00:00:00 2001 From: Ronald Tse Date: Sat, 14 Nov 2026 09:48:38 +0800 Subject: [PATCH 1/3] fix(isc): use inside sequence/parallel blocks per spec 3.2 The generated grammar's rule_line now accepts the use directive inside sequence/parallel blocks (PG grammar regenerated from the canonical .parg; sha pin bumped), and the converter/expansion layer implements the rs-canonical semantics: a used ruleset's rules flatten into the enclosing collection in position, an override block merges per-rule (child-wins on exact from-equality), and a non-rule target (funcalls, stage runs inside the used ruleset) is a named MapLogicError - non-rule items cannot join a pass. rs is the reference implementation and is unchanged. No corpus map uses the constructs (428 maps parse unchanged); the probe shapes from the parity audit (tst-use-inseq / use-in-parallel) pin the behavior. Suite 378 -> 385 passed (+7 wf1 tests), parser-parity and conformance gates green in CI. --- src/isc/converter.ts | 8 +- src/isc/expand.ts | 137 +++++++++++++++++++++++++++--- src/isc/grammar/actions.ts | 52 ++++++++---- src/isc/grammar/grammar-source.ts | 10 +-- src/isc/types.ts | 33 ++++--- test/isc/wf1.test.ts | 65 ++++++++++++++ 6 files changed, 256 insertions(+), 49 deletions(-) diff --git a/src/isc/converter.ts b/src/isc/converter.ts index 7de63af..db2c339 100644 --- a/src/isc/converter.ts +++ b/src/isc/converter.ts @@ -123,11 +123,15 @@ function convertStageItem(item: IscStageItem, resolveDep: DepResolver): Rule { `unexpanded use "${item.dependency ? `${item.dependency}.` : ""}${item.name}" reached the converter`, ) case "parallel": { - const r: ParallelRule = { kind: "parallel", rules: item.rules.map(convertRule) } + // Post-expansion, block rule lists are rules only (WO18 G5: `use` + // rows flattened during expandDocument()). + const rules = item.rules as readonly IscRule[] + const r: ParallelRule = { kind: "parallel", rules: rules.map(convertRule) } return r } case "sequence": { - const r: SequentialRule = { kind: "sequential", rules: item.rules.map(convertRule) } + const rules = item.rules as readonly IscRule[] + const r: SequentialRule = { kind: "sequential", rules: rules.map(convertRule) } return r } case "bare_rule": diff --git a/src/isc/expand.ts b/src/isc/expand.ts index 18c3181..e494272 100644 --- a/src/isc/expand.ts +++ b/src/isc/expand.ts @@ -6,6 +6,14 @@ * ruleset's items at its position (a macro expansion, not a sub-run). * The compiled IR stays flat — expanded rules only, no ruleset nodes. * + * WO18 G5 (§3.2): `use` may also sit INSIDE a parallel/sequence block. + * Items inside a block participate in that block's single pass, so the + * expansion inherits the enclosing pass structure — the referenced + * ruleset's rule content flattens into the enclosing collection. A + * referenced ruleset carrying non-rule items (funcalls, stage runs) + * cannot join a pass — named load error. Overrides merge per-rule on + * the flat list (child-wins; the rows land at the expansion tail). + * * Merge semantics (§4.2), at each expansion site: * 1. A rule of the expansion is REPLACED if an override row exists with * the same from under byte-exact equality (no normalization). If @@ -18,7 +26,14 @@ * error (IscLoadError, §3.2 / §6.4). */ -import type { IscDocument, IscItem, IscRule, IscStage, IscStageItem } from "./types.js" +import type { + IscDocument, + IscItem, + IscRule, + IscStage, + IscStageItem, + IscUseItem, +} from "./types.js" import { IscLoadError } from "./types.js" /** Resolves a dependency target (system code) to its parsed document. */ @@ -55,24 +70,42 @@ interface ExpandScope { readonly chain: readonly string[] } -function expandItems(items: readonly IscStageItem[], scope: ExpandScope): IscStageItem[] { +function expandItems( + items: readonly IscStageItem[], + scope: ExpandScope, + inBlock = false, +): IscStageItem[] { const out: IscStageItem[] = [] for (const item of items) { if (item.kind === "use") { out.push(...expandUse(item, scope)) + } else if (item.kind === "parallel" || item.kind === "sequence") { + // WO18 G5 (§3.2): block bodies are rule_line lists — `use` items + // inside them expand flat into the block's rule list. + out.push({ ...item, rules: item.rules.flatMap((r) => expandBlockRow(r, scope)) }) } else { - // parallel/sequence blocks contain plain rules only (`use` is a - // stage-level item), so no recursion into blocks is needed. out.push(item) } } return out } -function expandUse( +const isUseItem = (row: IscRule | IscUseItem): row is IscUseItem => !("from" in row) + +/** One rule_line row of a parallel/sequence block (§3.2): `use` rows + * flatten the referenced ruleset's rules into the block; rule rows pass + * through. Both return arrays so the caller can splice uniformly. */ +function expandBlockRow(row: IscRule | IscUseItem, scope: ExpandScope): IscRule[] { + return isUseItem(row) ? expandUseFlat(row, scope) : [row] +} + +/** Shared target resolution for a `use` site: owner document, cycle + * guard, memo ruleset lookup; returns the target's structural expansion + * and the inner scope its nested uses resolve against. */ +function resolveRulesetExpansion( item: Extract, scope: ExpandScope, -): IscStageItem[] { +): { expanded: IscStageItem[]; inner: ExpandScope } { // Resolve the owning document: same map, or a declared dependency. let owner = scope.doc let ownerKey = scope.docKey @@ -112,16 +145,86 @@ function expandUse( resolveDep: scope.resolveDep, chain: [...scope.chain, key], } - const expanded = expandItems(ruleset.body, inner) + return { expanded: expandItems(ruleset.body, inner), inner } +} - // W2 — use with override (§4.2): partition the full expansion - // (including nested expansions) by exact from-equality. - if (item.override && item.override.length > 0) { - return applyOverride(expanded, item.override) +/** Stage/ruleset-body-position `use` (§3.1): the expansion splices the + * target's items in position, document order, override rows merged + * structurally (§4.2, incl. the §4.2.6 trailing-parallel join). */ +function expandUse( + item: Extract, + scope: ExpandScope, +): IscStageItem[] { + const { expanded, inner } = resolveRulesetExpansion(item, scope) + if (item.override !== undefined && item.override.length > 0) { + return applyOverride(expanded, expandOverrideRows(item.override, inner)) } return expanded } +/** WO18 G5 — block-position `use` (§3.2): inside a block the expansion + * inherits the enclosing pass structure — the target's rule content + * flattens into the pass; overrides merge per-rule on the flat list + * (child-wins, tail rows). */ +function expandUseFlat( + item: Extract, + scope: ExpandScope, +): IscRule[] { + const { expanded, inner } = resolveRulesetExpansion(item, scope) + let rules = flattenPassItems(expanded) + if (item.override !== undefined && item.override.length > 0) { + rules = mergeOverrideRules(rules, expandOverrideRows(item.override, inner)) + } + return rules +} + +/** + * WO18 G5 (§3.2): flatten a structural expansion into the ordered rule + * list of an enclosing pass. Pass blocks contribute their (already + * expanded) rules in position; non-rule items (funcalls, stage runs) + * cannot join a pass — named load error (interscript-rs flatten_rules). + */ +function flattenPassItems(items: readonly IscStageItem[]): IscRule[] { + const out: IscRule[] = [] + for (const item of items) { + if (item.kind === "parallel" || item.kind === "sequence") { + // expandItems() already flattened `use` rows inside blocks, so the + // list is rules-only at this point. + out.push(...(item.rules as readonly IscRule[])) + } else if (item.kind === "bare_rule") { + out.push(item.rule) + } else { + throw new IscLoadError( + "use inside a parallel/sequence block: the referenced ruleset carries " + + "non-rule items (funcalls/stage runs) that cannot join the pass", + ) + } + } + return out +} + +/** Override rows are rule_line items, so they may themselves be `use` + * directives (rs extract_rule_list recursion); their content flattens + * into the override rule list. */ +function expandOverrideRows( + rows: readonly (IscRule | IscUseItem)[], + scope: ExpandScope, +): IscRule[] { + return rows.flatMap((row) => (isUseItem(row) ? expandUseFlat(row, scope) : [row])) +} + +/** + * §4.2 merge over a FLAT rule list (the block-position use): matching + * rules drop wherever they sit (child-wins on exact from-equality); + * the override rows land at the expansion tail. No trailing-parallel + * join here — the caller re-wraps the list into the enclosing block. + */ +function mergeOverrideRules(rules: readonly IscRule[], overrides: readonly IscRule[]): IscRule[] { + const overrideKeys = new Set(overrides.map(ruleFromKey)) + const kept = rules.filter((r) => !overrideKeys.has(ruleFromKey(r))) + return [...kept, ...overrides] +} + /** * Remove every rule whose from matches an override row (from anywhere in * the expansion — bare rules and rules inside parallel/sequence blocks), @@ -142,7 +245,8 @@ function applyOverride( if (item.kind === "bare_rule") { if (keepRule(item.rule)) kept.push(item) } else if (item.kind === "parallel" || item.kind === "sequence") { - kept.push({ ...item, rules: item.rules.filter(keepRule) }) + // post-expansion block rule lists are rules-only + kept.push({ ...item, rules: (item.rules as readonly IscRule[]).filter(keepRule) }) } else { kept.push(item) } @@ -211,6 +315,15 @@ export function requiredDependencyDocs(doc: IscDocument): string[] { if (item.kind === "use" && item.dependency) { const target = aliases.get(item.dependency) if (target) targets.add(target) + } else if (item.kind === "parallel" || item.kind === "sequence") { + // `use` rows inside blocks may carry dependency qualifiers too + for (const row of item.rules) { + // IscRule is structural (no kind tag): shape-discriminate + if (!("from" in row) && row.dependency) { + const target = aliases.get(row.dependency) + if (target) targets.add(target) + } + } } } } diff --git a/src/isc/grammar/actions.ts b/src/isc/grammar/actions.ts index c3effd4..6474225 100644 --- a/src/isc/grammar/actions.ts +++ b/src/isc/grammar/actions.ts @@ -12,7 +12,15 @@ * decide to align the runtimes. */ -import type { IscDocument, IscItem, IscRule, IscStage, IscStageItem, IscTest } from "../types.js" +import type { + IscDocument, + IscItem, + IscRule, + IscStage, + IscStageItem, + IscTest, + IscUseItem, +} from "../types.js" import { IscParseError } from "../types.js" import { Slice } from "./peg.js" @@ -269,14 +277,37 @@ export class TreeToDocument { return Array.isArray(v) ? v : [v] } - /** rule_items for parallel/sequence/override blocks: skip comment/noop rows. */ - private ruleList(trees: Tree[]): IscRule[] { + /** + * rule_items for parallel/sequence/override blocks: skip comment/noop + * rows; `use` directives splice into the pass (canonical grammar + * rule_line — expand() resolves them in place, spec §3.2). + */ + private ruleList(trees: Tree[]): (IscRule | IscUseItem)[] { return trees .filter((t) => { const h = hash(t) return h.comment === undefined && h.noop === undefined }) - .map((t) => this.rule(t)) + .map((t) => { + const h = hash(t) + return h.use !== undefined ? this.useItem(h) : this.rule(t) + }) + } + + /** A captured use_directive tree lowered to the parse-level item. */ + private useItem(h: Hash): IscUseItem { + const u = hash(h.use) + const name = identifier(hash(u.use_alias)) + const qualified = u.qualified_name !== undefined ? identifier(u.qualified_name) : undefined + const overrides = + u.use_overrides !== undefined ? this.ruleList(array(u.use_overrides)) : undefined + // Hand parser: `use a.b` names the ruleset b, reached through dependency a. + return { + kind: "use", + name: qualified ?? name, + ...(qualified !== undefined ? { dependency: name } : {}), + ...(overrides !== undefined ? { override: overrides } : {}), + } } // -- stage bodies --------------------------------------------------------- @@ -340,18 +371,7 @@ export class TreeToDocument { continue } if (h.use !== undefined) { - const u = hash(h.use) - const name = identifier(hash(u.use_alias)) - const qualified = u.qualified_name !== undefined ? identifier(u.qualified_name) : undefined - const overrides = - u.use_overrides !== undefined ? this.ruleList(array(u.use_overrides)) : undefined - // Hand parser: `use a.b` names the ruleset b, reached through dependency a. - out.push({ - kind: "use", - name: qualified ?? name, - ...(qualified !== undefined ? { dependency: name } : {}), - ...(overrides !== undefined ? { override: overrides } : {}), - }) + out.push(this.useItem(h)) continue } throw new Error(`unknown stage item ${JSON.stringify(Object.keys(h))}`) diff --git a/src/isc/grammar/grammar-source.ts b/src/isc/grammar/grammar-source.ts index 7865ad7..b4a1bcb 100644 --- a/src/isc/grammar/grammar-source.ts +++ b/src/isc/grammar/grammar-source.ts @@ -3,9 +3,8 @@ * interscript-ruby lib/interscript/isc/grammar/isc.parg * * The .parg file is the single semantic source of the ISC syntax; this - * module embeds it verbatim (as of ruby commit cc25797, sha256 b0f7a7caf462a1671a80ef974a59425c636f1d32cb3e405280991b21a6edd712) - * so the TypeScript parser compiles the same grammar text the Ruby - * runtime ships. Update procedure: + * module embeds it verbatim (sha256 52949cb3170554071c8085bc5388553fde3d9a7feb590109d4543478d3561bb7) so the TypeScript parser + * compiles the same grammar text the Ruby runtime ships. Update procedure: * * node scripts/sync-isc-grammar.mjs * @@ -15,8 +14,7 @@ */ /** sha256 of the grammar text embedded below (pin for drift detection). */ -export const ISC_PARG_SHA256 = "b0f7a7caf462a1671a80ef974a59425c636f1d32cb3e405280991b21a6edd712" +export const ISC_PARG_SHA256 = "52949cb3170554071c8085bc5388553fde3d9a7feb590109d4543478d3561bb7" /** The grammar text itself, byte-identical to the ruby checkout copy. */ -export const ISC_PARG_SOURCE = - '# Interscript ISC grammar — parsanol grammar language (PG).\n#\n# Line-oriented port of lib/interscript/isc/grammar/concerns/*.rb.\n# The capture tree must reproduce the Ruby-DSL parser\'s tree exactly:\n# - repetitions are ABNF prefixes (1*x, *x)\n# - negation is !x, positive lookahead is &x\n# - captures at use sites (rule_ref as name) nest inner captures\n# the same way parslet .as does\n#\n# Consumed by the interscript gem (artifact parse) and parsanol npm.\n\ngrammar InterscriptIsc version "0.1.0" {\n\n # -- lexical primitives -------------------------------------------------\n\n chr = %x00-10FFFF\n space_char = %x20 / %x09 / %x0A / %x0B / %x0C / %x0D\n newline = %x0D.0A / %x0A / %x0D\n line_comment = "#" *(!(newline) chr)\n whitespace = 1*(space_char / line_comment)\n ws = *(space_char / line_comment)\n inline_space = 1*(%x20 / %x09)\n inline_ws = *(inline_space / line_comment)\n hexd = %x30-39 / %x41-46 / %x61-66\n digit = %x30-39\n\n ident_first = %x41-5A / %x61-7A / %x5F\n ident_rest = %x41-5A / %x61-7A / %x30-39 / %x5F\n identifier = (ident_first 0*ident_rest) as identifier\n\n keyword = "parallel" / "sequence" / "stage" / "compose" / "separate" / "system" / "metadata" / "aliases" / "tests" / "notes" / "description" / "any_character" / "authority" / "dependency" / "run" / "sub" / "before" / "after" / "not_before" / "not_after" / "any" / "none" / "boundary" / "line_start" / "line_end" / "word_boundary" / "downcase" / "upcase" / "title_case" / "capture" / "maybe" / "some" / "ref" / "name" / "ruleset" / "use" / "override" / "languages" / "when"\n\n # -- string literals ----------------------------------------------------\n\n esc_nl = ("n") as newline\n esc_cr = ("r") as carriage_return\n esc_tab = ("t") as tab\n esc_dq = "\\"" as dquote\n esc_bs = "\\\\" as backslash\n esc_uni4 = "u" (4hexd) as unicode\n esc_uni8 = "U" (4*8hexd) as unicode\n esc_u_lone = "U" as u_lone\n escape_sequence = "\\\\" (esc_nl / esc_cr / esc_tab / esc_dq / esc_bs / esc_uni4 / esc_uni8 / esc_u_lone)\n\n raw_run = 1*(!("\\\\" / "\\"") chr)\n dq_parts = *(escape_sequence / (raw_run as run))\n double_quoted = "\\"" (dq_parts as string) "\\""\n sq_body = *(!"\'" chr)\n single_quoted = "\'" (sq_body as string) "\'"\n quoted_string = double_quoted / single_quoted\n\n arrow = [whitespace] "->" [whitespace]\n comma_ws = "," [whitespace]\n\n # -- metadata -----------------------------------------------------------\n\n md_authority = "authority" whitespace ((quoted_string) as authority)\n md_source_spelling = "source_spelling" whitespace ((quoted_string) as source_spelling)\n md_target_spelling = "target_spelling" whitespace ((quoted_string) as target_spelling)\n md_identifying = "identifying" whitespace ((quoted_string) as identifying)\n md_name = "name" whitespace ((quoted_string) as name)\n md_spec_value = quoted_string as specification\n md_specification = "specification" whitespace ((md_spec_value *(comma_ws md_spec_value)) as specification)\n md_description = "description" [whitespace] "{" [ws] (raw_text as description) [ws] "}"\n md_system_status = "system_status" whitespace (("current" / "former" / "inactive") as system_status)\n md_code_status = "code_status" whitespace (("preferred" / "proposed" / "deprecated") as code_status)\n\n relation_type = "supersedes" / "superseded_by" / "based_on" / "basis_for" / "alias_of" / "adopted_from" / "related_to"\n relation_note = whitespace "note" whitespace (quoted_string as note)\n relation_item = [whitespace] (relation_type as type) whitespace (quoted_string as system) [(relation_note)] [whitespace]\n md_relations = "relations" [whitespace] "{" [ws] ((*(relation_item)) as relations) [ws] "}"\n\n note_item = [whitespace] "note" [whitespace] (quoted_string as note) [whitespace]\n md_notes = "notes" [whitespace] "{" [ws] ((*(note_item)) as notes) [ws] "}"\n\n md_provenance_value = quoted_string as provenance\n md_provenance = "provenance" [whitespace] ((md_provenance_value *(comma_ws md_provenance_value)) as provenance)\n\n md_empty_field = &(newline)\n md_raw_field_value = 1*(!%x0A !"}" !"{" chr)\n md_field_value = quoted_string / (md_raw_field_value as raw)\n md_field_block = "{" [ws] (raw_text as field_block) [ws] "}"\n md_generic_field = (identifier as field_name) inline_ws ((md_field_value as field_value) / md_field_block / md_empty_field)\n\n metadata_field = [whitespace] (md_description / md_relations / md_system_status / md_code_status / md_specification / md_notes / md_provenance / md_generic_field) [whitespace]\n md_items = *(metadata_field)\n metadata_block = "metadata" [whitespace] "{" [ws] (md_items as metadata) [ws] "}"\n\n raw_text = *("\\\\" chr / (!"}" chr))\n\n # -- aliases ------------------------------------------------------------\n\n alias_decl = [whitespace] (identifier as name) [whitespace] "=" [whitespace] (item as value) [whitespace]\n alias_items = *(alias_decl)\n aliases_block = "aliases" [whitespace] "{" [ws] (alias_items as aliases) [ws] "}"\n\n # -- dependencies -------------------------------------------------------\n\n dep_alias = whitespace "as" whitespace (identifier as alias)\n dependency_decl = "dependency" whitespace (quoted_string as target) [(dep_alias)]\n\n # -- item expressions ---------------------------------------------------\n\n zw_primitive = (("boundary") / ("line_start") / ("line_end") / ("word_boundary") / ("space") / ("non_boundary")) as primitive\n fn_lit = (("upcase") / ("downcase") / ("title_case") / ("reverse") / ("strip") / ("swapcase")) as function\n any_char_lit = ("any_character") as any_char\n none_lit = ("none") as none\n\n digit_cap = digit as digit\n capture_reference_body = "ref" "(" [ws] digit_cap [ws] ")"\n capture_reference = capture_reference_body as ref\n\n item_ref = identifier "." (identifier as qualified_name)\n alias_reference = (!(keyword) identifier [("." (identifier as qualified_name))] !"{" ) as alias\n\n item_seq = item_atom\n item_sep = ([ws] "+" [ws]) / whitespace\n item_cont = &item_atom\n\n range_arg = (quoted_string as lo) [ws] ".." [ws] (quoted_string as hi)\n list_item = item\n list_items = (list_item *((comma_ws / whitespace) list_item))\n set_arg = ((quoted_string as single)) / ("[" [ws] ((list_item *((comma_ws / whitespace) list_item)) as list) [ws] "]")\n alias_arg = (!zw_primitive !(keyword) identifier) as alias_ref\n any_arg = range_arg / set_arg / alias_arg\n any_ctor = "any" "(" [ws] (any_arg as any) [ws] ")"\n capture_ctor = "capture" "(" [ws] (item as capture_inner) [ws] ")"\n maybe_ctor = "maybe" "(" [ws] (item as maybe_inner) [ws] ")"\n some_ctor = "some" "(" [ws] (item as some_inner) [ws] ")"\n\n item_atom_start = "\\"" / "\'" / ident_first\n cont_stop = "to" / "before" / "after" / "not_before" / "not_after" / "}"\n alias_decl_stop = identifier [ws] "="\n item_atom = quoted_string / none_lit / zw_primitive / any_char_lit / any_ctor / capture_ctor / maybe_ctor / some_ctor / fn_lit / capture_reference / alias_reference\n item = (item_atom 0*(item_sep !cont_stop !(alias_decl_stop) &item_atom_start item_atom)) as concatenation\n\n # -- rules and stages ---------------------------------------------------\n\n constraint_after = "after" whitespace (item as after)\n constraint_before = "before" whitespace (item as before)\n constraint_not_before = "not_before" whitespace (item as not_before)\n constraint_not_after = "not_after" whitespace (item as not_after)\n constraint = constraint_after / constraint_before / constraint_not_before / constraint_not_after\n constraints = *(whitespace constraint)\n\n compact_rule = "sub" whitespace (item_atom as from) whitespace (item_atom as to) ((*(whitespace constraint)) as constraints) [(when_guard)]\n\n block_rule = "sub" [ws] "{" [ws] "from" whitespace (item as from) [ws] "to" whitespace (item as to) ((*(whitespace constraint)) as constraints) [(when_guard)] [ws] "}"\n\n when_lang = (!(keyword) identifier) as when_lang\n when_guard = (whitespace "when" whitespace (when_lang) *(((comma_ws / whitespace) (when_lang)))) as when\n\n rule = block_rule / compact_rule\n\n comment_item = (("#" *(!%x0A chr)) as comment) / ((!(keyword) identifier) as noop)\n rule_line = [ws] (rule / comment_item) [ws]\n rule_items = *(rule_line)\n sequence_block = "sequence" [ws] "{" [ws] (rule_items as sequence) [ws] "}"\n parallel_block = "parallel" [ws] "{" [ws] (rule_items as parallel) [ws] "}"\n\n separator_part = whitespace "separator" whitespace (item_atom as separator)\n separate_directive = ("separate") as separate [(separator_part)]\n case_directive = (("downcase") / ("upcase")) as case\n case_kwargs_part = whitespace (kwarg_list as case_kwargs)\n title_case_directive = ("title_case") as case [(case_kwargs_part)]\n string_case_directive = case_directive / title_case_directive\n compose_directive = (("compose") / ("decompose")) as compose\n kwarg = (identifier as kwarg_name) [ws] ":" [ws] ((quoted_string) as kwarg_value)\n kwarg_item = (kwarg) as kwarg\n kwarg_list = (kwarg_item *(comma_ws kwarg_item))\n funcall_kwargs_part = whitespace (kwarg_list as funcall_kwargs)\n rababa_directive = ("rababa") as funcall_name [(funcall_kwargs_part)]\n run_dep = "map." (identifier as dep) ".stage." (identifier as stage)\n run_stage_only = ("stage." (identifier as stage)) as run_stage_only\n run_rule = "run" whitespace ((run_dep) / run_stage_only)\n\n bare_rule = (rule) as bare_rule\n\n use_alias = (identifier) as use_alias\n use_qualified = "." (identifier as qualified_name)\n use_overrides_part = whitespace "override" [ws] "{" [ws] ((*(rule_line)) as use_overrides) [ws] "}"\n use_directive = (("use" whitespace (use_alias) [(use_qualified)] [(use_overrides_part)]) as use)\n\n stage_item = [ws] (sequence_block / parallel_block / run_rule / separate_directive / string_case_directive / compose_directive / rababa_directive / use_directive / bare_rule / comment_item) [ws]\n stage_items = *(stage_item)\n stage_name_paren = "(" (identifier as stage_name) ")"\n stage_name_ws = whitespace (identifier as stage_name)\n stage_block = "stage" (stage_name_paren / stage_name_ws) [ws] "{" [ws] (stage_items as stage) [ws] "}"\n\n ruleset_name_ws = whitespace (identifier as ruleset_name)\n ruleset_block = "ruleset" (ruleset_name_ws) [ws] "{" [ws] (stage_items as ruleset) [ws] "}"\n\n # -- tests ---------------------------------------------------------------\n\n test_note = whitespace "note" whitespace (quoted_string as note)\n test_line = [whitespace] (quoted_string as input) arrow (quoted_string as expected) [(test_note)] [whitespace]\n test_items = *(test_line)\n tests_block = "tests" [whitespace] "{" [ws] (test_items as tests) [ws] "}"\n\n # -- system --------------------------------------------------------------\n\n language_ident = (!(keyword) identifier) as language\n languages_decl = ("languages" whitespace ((language_ident *(((comma_ws / whitespace) (language_ident))))) as languages)\n\n block_item = [whitespace] (metadata_block / aliases_block / tests_block / languages_decl / ruleset_block / stage_block / dependency_decl) [whitespace]\n body_items = *(block_item)\n system_block = "system" whitespace ((quoted_string) as system_code) [whitespace] "{" [ws] ((*(block_item)) as body) [ws] "}" [whitespace]\n isc_source = [whitespace] ((system_block) as system) [whitespace]\n\n entry isc: isc_source\n}\n' as string +export const ISC_PARG_SOURCE = "# Interscript ISC grammar — parsanol grammar language (PG).\n#\n# Line-oriented port of lib/interscript/isc/grammar/concerns/*.rb.\n# The capture tree must reproduce the Ruby-DSL parser's tree exactly:\n# - repetitions are ABNF prefixes (1*x, *x)\n# - negation is !x, positive lookahead is &x\n# - captures at use sites (rule_ref as name) nest inner captures\n# the same way parslet .as does\n#\n# Consumed by the interscript gem (artifact parse) and parsanol npm.\n\ngrammar InterscriptIsc version \"0.1.0\" {\n\n # -- lexical primitives -------------------------------------------------\n\n chr = %x00-10FFFF\n space_char = %x20 / %x09 / %x0A / %x0B / %x0C / %x0D\n newline = %x0D.0A / %x0A / %x0D\n line_comment = \"#\" *(!(newline) chr)\n whitespace = 1*(space_char / line_comment)\n ws = *(space_char / line_comment)\n inline_space = 1*(%x20 / %x09)\n inline_ws = *(inline_space / line_comment)\n hexd = %x30-39 / %x41-46 / %x61-66\n digit = %x30-39\n\n ident_first = %x41-5A / %x61-7A / %x5F\n ident_rest = %x41-5A / %x61-7A / %x30-39 / %x5F\n identifier = (ident_first 0*ident_rest) as identifier\n\n keyword = \"parallel\" / \"sequence\" / \"stage\" / \"compose\" / \"separate\" / \"system\" / \"metadata\" / \"aliases\" / \"tests\" / \"notes\" / \"description\" / \"any_character\" / \"authority\" / \"dependency\" / \"run\" / \"sub\" / \"before\" / \"after\" / \"not_before\" / \"not_after\" / \"any\" / \"none\" / \"boundary\" / \"line_start\" / \"line_end\" / \"word_boundary\" / \"downcase\" / \"upcase\" / \"title_case\" / \"capture\" / \"maybe\" / \"some\" / \"ref\" / \"name\" / \"ruleset\" / \"use\" / \"override\" / \"languages\" / \"when\"\n\n # -- string literals ----------------------------------------------------\n\n esc_nl = (\"n\") as newline\n esc_cr = (\"r\") as carriage_return\n esc_tab = (\"t\") as tab\n esc_dq = \"\\\"\" as dquote\n esc_bs = \"\\\\\" as backslash\n esc_uni4 = \"u\" (4hexd) as unicode\n esc_uni8 = \"U\" (4*8hexd) as unicode\n esc_u_lone = \"U\" as u_lone\n escape_sequence = \"\\\\\" (esc_nl / esc_cr / esc_tab / esc_dq / esc_bs / esc_uni4 / esc_uni8 / esc_u_lone)\n\n raw_run = 1*(!(\"\\\\\" / \"\\\"\") chr)\n dq_parts = *(escape_sequence / (raw_run as run))\n double_quoted = \"\\\"\" (dq_parts as string) \"\\\"\"\n sq_body = *(!\"'\" chr)\n single_quoted = \"'\" (sq_body as string) \"'\"\n quoted_string = double_quoted / single_quoted\n\n arrow = [whitespace] \"->\" [whitespace]\n comma_ws = \",\" [whitespace]\n\n # -- metadata -----------------------------------------------------------\n\n md_authority = \"authority\" whitespace ((quoted_string) as authority)\n md_source_spelling = \"source_spelling\" whitespace ((quoted_string) as source_spelling)\n md_target_spelling = \"target_spelling\" whitespace ((quoted_string) as target_spelling)\n md_identifying = \"identifying\" whitespace ((quoted_string) as identifying)\n md_name = \"name\" whitespace ((quoted_string) as name)\n md_spec_value = quoted_string as specification\n md_specification = \"specification\" whitespace ((md_spec_value *(comma_ws md_spec_value)) as specification)\n md_description = \"description\" [whitespace] \"{\" [ws] (raw_text as description) [ws] \"}\"\n md_system_status = \"system_status\" whitespace ((\"current\" / \"former\" / \"inactive\") as system_status)\n md_code_status = \"code_status\" whitespace ((\"preferred\" / \"proposed\" / \"deprecated\") as code_status)\n\n relation_type = \"supersedes\" / \"superseded_by\" / \"based_on\" / \"basis_for\" / \"alias_of\" / \"adopted_from\" / \"related_to\"\n relation_note = whitespace \"note\" whitespace (quoted_string as note)\n relation_item = [whitespace] (relation_type as type) whitespace (quoted_string as system) [(relation_note)] [whitespace]\n md_relations = \"relations\" [whitespace] \"{\" [ws] ((*(relation_item)) as relations) [ws] \"}\"\n\n note_item = [whitespace] \"note\" [whitespace] (quoted_string as note) [whitespace]\n md_notes = \"notes\" [whitespace] \"{\" [ws] ((*(note_item)) as notes) [ws] \"}\"\n\n md_provenance_value = quoted_string as provenance\n md_provenance = \"provenance\" [whitespace] ((md_provenance_value *(comma_ws md_provenance_value)) as provenance)\n\n md_empty_field = &(newline)\n md_raw_field_value = 1*(!%x0A !\"}\" !\"{\" chr)\n md_field_value = quoted_string / (md_raw_field_value as raw)\n md_field_block = \"{\" [ws] (raw_text as field_block) [ws] \"}\"\n md_generic_field = (identifier as field_name) inline_ws ((md_field_value as field_value) / md_field_block / md_empty_field)\n\n metadata_field = [whitespace] (md_description / md_relations / md_system_status / md_code_status / md_specification / md_notes / md_provenance / md_generic_field) [whitespace]\n md_items = *(metadata_field)\n metadata_block = \"metadata\" [whitespace] \"{\" [ws] (md_items as metadata) [ws] \"}\"\n\n raw_text = *(\"\\\\\" chr / (!\"}\" chr))\n\n # -- aliases ------------------------------------------------------------\n\n alias_decl = [whitespace] (identifier as name) [whitespace] \"=\" [whitespace] (item as value) [whitespace]\n alias_items = *(alias_decl)\n aliases_block = \"aliases\" [whitespace] \"{\" [ws] (alias_items as aliases) [ws] \"}\"\n\n # -- dependencies -------------------------------------------------------\n\n dep_alias = whitespace \"as\" whitespace (identifier as alias)\n dependency_decl = \"dependency\" whitespace (quoted_string as target) [(dep_alias)]\n\n # -- item expressions ---------------------------------------------------\n\n zw_primitive = ((\"boundary\") / (\"line_start\") / (\"line_end\") / (\"word_boundary\") / (\"space\") / (\"non_boundary\")) as primitive\n fn_lit = ((\"upcase\") / (\"downcase\") / (\"title_case\") / (\"reverse\") / (\"strip\") / (\"swapcase\")) as function\n any_char_lit = (\"any_character\") as any_char\n none_lit = (\"none\") as none\n\n digit_cap = digit as digit\n capture_reference_body = \"ref\" \"(\" [ws] digit_cap [ws] \")\"\n capture_reference = capture_reference_body as ref\n\n item_ref = identifier \".\" (identifier as qualified_name)\n alias_reference = (!(keyword) identifier [(\".\" (identifier as qualified_name))] !\"{\" ) as alias\n\n item_seq = item_atom\n item_sep = ([ws] \"+\" [ws]) / whitespace\n item_cont = &item_atom\n\n range_arg = (quoted_string as lo) [ws] \"..\" [ws] (quoted_string as hi)\n list_item = item\n list_items = (list_item *((comma_ws / whitespace) list_item))\n set_arg = ((quoted_string as single)) / (\"[\" [ws] ((list_item *((comma_ws / whitespace) list_item)) as list) [ws] \"]\")\n alias_arg = (!zw_primitive !(keyword) identifier) as alias_ref\n any_arg = range_arg / set_arg / alias_arg\n any_ctor = \"any\" \"(\" [ws] (any_arg as any) [ws] \")\"\n capture_ctor = \"capture\" \"(\" [ws] (item as capture_inner) [ws] \")\"\n maybe_ctor = \"maybe\" \"(\" [ws] (item as maybe_inner) [ws] \")\"\n some_ctor = \"some\" \"(\" [ws] (item as some_inner) [ws] \")\"\n\n item_atom_start = \"\\\"\" / \"'\" / ident_first\n cont_stop = \"to\" / \"before\" / \"after\" / \"not_before\" / \"not_after\" / \"}\"\n alias_decl_stop = identifier [ws] \"=\"\n item_atom = quoted_string / none_lit / zw_primitive / any_char_lit / any_ctor / capture_ctor / maybe_ctor / some_ctor / fn_lit / capture_reference / alias_reference\n item = (item_atom 0*(item_sep !cont_stop !(alias_decl_stop) &item_atom_start item_atom)) as concatenation\n\n # -- rules and stages ---------------------------------------------------\n\n constraint_after = \"after\" whitespace (item as after)\n constraint_before = \"before\" whitespace (item as before)\n constraint_not_before = \"not_before\" whitespace (item as not_before)\n constraint_not_after = \"not_after\" whitespace (item as not_after)\n constraint = constraint_after / constraint_before / constraint_not_before / constraint_not_after\n constraints = *(whitespace constraint)\n\n compact_rule = \"sub\" whitespace (item_atom as from) whitespace (item_atom as to) ((*(whitespace constraint)) as constraints) [(when_guard)]\n\n block_rule = \"sub\" [ws] \"{\" [ws] \"from\" whitespace (item as from) [ws] \"to\" whitespace (item as to) ((*(whitespace constraint)) as constraints) [(when_guard)] [ws] \"}\"\n\n when_lang = (!(keyword) identifier) as when_lang\n when_guard = (whitespace \"when\" whitespace (when_lang) *(((comma_ws / whitespace) (when_lang)))) as when\n\n rule = block_rule / compact_rule\n\n comment_item = ((\"#\" *(!%x0A chr)) as comment) / ((!(keyword) identifier) as noop)\n # ISC-WF-1 §3.2: a `use` directive is a rule-line item — items inside a\n # parallel/sequence block participate in that block's single pass, and\n # the expansion flattens the referenced ruleset's rules at this\n # position (mirrors interscript-rs grammar/isc.parg rule_line).\n rule_line = [ws] (rule / use_directive / comment_item) [ws]\n rule_items = *(rule_line)\n sequence_block = \"sequence\" [ws] \"{\" [ws] (rule_items as sequence) [ws] \"}\"\n parallel_block = \"parallel\" [ws] \"{\" [ws] (rule_items as parallel) [ws] \"}\"\n\n separator_part = whitespace \"separator\" whitespace (item_atom as separator)\n separate_directive = (\"separate\") as separate [(separator_part)]\n case_directive = ((\"downcase\") / (\"upcase\")) as case\n case_kwargs_part = whitespace (kwarg_list as case_kwargs)\n title_case_directive = (\"title_case\") as case [(case_kwargs_part)]\n string_case_directive = case_directive / title_case_directive\n compose_directive = ((\"compose\") / (\"decompose\")) as compose\n kwarg = (identifier as kwarg_name) [ws] \":\" [ws] ((quoted_string) as kwarg_value)\n kwarg_item = (kwarg) as kwarg\n kwarg_list = (kwarg_item *(comma_ws kwarg_item))\n funcall_kwargs_part = whitespace (kwarg_list as funcall_kwargs)\n rababa_directive = (\"rababa\") as funcall_name [(funcall_kwargs_part)]\n run_dep = \"map.\" (identifier as dep) \".stage.\" (identifier as stage)\n run_stage_only = (\"stage.\" (identifier as stage)) as run_stage_only\n run_rule = \"run\" whitespace ((run_dep) / run_stage_only)\n\n bare_rule = (rule) as bare_rule\n\n use_alias = (identifier) as use_alias\n use_qualified = \".\" (identifier as qualified_name)\n use_overrides_part = whitespace \"override\" [ws] \"{\" [ws] ((*(rule_line)) as use_overrides) [ws] \"}\"\n use_directive = ((\"use\" whitespace (use_alias) [(use_qualified)] [(use_overrides_part)]) as use)\n\n stage_item = [ws] (sequence_block / parallel_block / run_rule / separate_directive / string_case_directive / compose_directive / rababa_directive / use_directive / bare_rule / comment_item) [ws]\n stage_items = *(stage_item)\n stage_name_paren = \"(\" (identifier as stage_name) \")\"\n stage_name_ws = whitespace (identifier as stage_name)\n stage_block = \"stage\" (stage_name_paren / stage_name_ws) [ws] \"{\" [ws] (stage_items as stage) [ws] \"}\"\n\n ruleset_name_ws = whitespace (identifier as ruleset_name)\n ruleset_block = \"ruleset\" (ruleset_name_ws) [ws] \"{\" [ws] (stage_items as ruleset) [ws] \"}\"\n\n # -- tests ---------------------------------------------------------------\n\n test_note = whitespace \"note\" whitespace (quoted_string as note)\n test_line = [whitespace] (quoted_string as input) arrow (quoted_string as expected) [(test_note)] [whitespace]\n test_items = *(test_line)\n tests_block = \"tests\" [whitespace] \"{\" [ws] (test_items as tests) [ws] \"}\"\n\n # -- system --------------------------------------------------------------\n\n language_ident = (!(keyword) identifier) as language\n languages_decl = (\"languages\" whitespace ((language_ident *(((comma_ws / whitespace) (language_ident))))) as languages)\n\n block_item = [whitespace] (metadata_block / aliases_block / tests_block / languages_decl / ruleset_block / stage_block / dependency_decl) [whitespace]\n body_items = *(block_item)\n system_block = \"system\" whitespace ((quoted_string) as system_code) [whitespace] \"{\" [ws] ((*(block_item)) as body) [ws] \"}\" [whitespace]\n isc_source = [whitespace] ((system_block) as system) [whitespace]\n\n entry isc: isc_source\n}\n" as string diff --git a/src/isc/types.ts b/src/isc/types.ts index 7bfe27a..6a9d5a8 100644 --- a/src/isc/types.ts +++ b/src/isc/types.ts @@ -35,9 +35,26 @@ export interface IscStage { readonly body: readonly IscStageItem[] } +/** + * ISC-WF-1 W1/W2 — `use ` (or `use .`), optionally + * with an `override { ... }` block. Resolved by expandDocument() at + * compile time; never reaches the IR. + */ +export interface IscUseItem { + readonly kind: "use" + readonly name: string + readonly dependency?: string + readonly override?: readonly (IscRule | IscUseItem)[] +} + export type IscStageItem = - | { kind: "parallel"; rules: readonly IscRule[] } - | { kind: "sequence"; rules: readonly IscRule[] } + /** + * WO18 G5 (§3.2): items inside a parallel/sequence block participate in + * that block's single pass — the block's rule list may carry `use` + * items, which expandDocument() flattens in position. + */ + | { kind: "parallel"; rules: readonly (IscRule | IscUseItem)[] } + | { kind: "sequence"; rules: readonly (IscRule | IscUseItem)[] } | { kind: "bare_rule"; rule: IscRule } | { kind: "run"; dependency?: string; stage: string } | { kind: "separate"; separator?: IscItem } @@ -45,17 +62,7 @@ export type IscStageItem = | { kind: "decompose" } | { kind: "string_case"; op: string } | { kind: "funcall"; name: string; kwargs: Readonly> } - /** - * ISC-WF-1 W1/W2 — `use ` (or `use .`), optionally - * with an `override { ... }` block. Resolved by expandDocument() at - * compile time; never reaches the IR. - */ - | { - kind: "use" - name: string - dependency?: string - override?: readonly IscRule[] - } + | IscUseItem export interface IscRule { readonly from: IscItem diff --git a/test/isc/wf1.test.ts b/test/isc/wf1.test.ts index acb3bb3..124bafa 100644 --- a/test/isc/wf1.test.ts +++ b/test/isc/wf1.test.ts @@ -319,6 +319,71 @@ describe("expandDocument — cycle and resolution errors (§3.2, §6.4)", () => }) }) +// --------------------------------------------------------------------------- +// WO18 G5 — use inside parallel/sequence blocks (§3.2): the expansion +// inherits the enclosing pass structure — the target's rule content +// flattens into the enclosing collection; non-rule items (funcalls, +// stage runs) cannot join a pass — named load error. +// --------------------------------------------------------------------------- + +describe("use inside parallel/sequence blocks (§3.2)", () => { + const inSeq = minimalWrap( + `ruleset r1 { parallel { sub "a" "1" } }\n` + + `stage main { sequence { use r1\n sub "b" "2" } }`, + ) + const inPar = minimalWrap( + `ruleset r1 { parallel { sub "a" "1" } }\n` + + `stage main { parallel { use r1\n sub "b" "2" } }`, + ) + const inParOvr = minimalWrap( + `ruleset tbl { parallel { sub "a" "A1"\n sub "b" "B" } }\n` + + `stage main { parallel { use tbl override { sub "a" "A2" } } }`, + ) + const flatSeq = minimalWrap( + `ruleset tbl { parallel { sub "a" "b"\n sub "c" "d" } }\n` + + `stage main { sequence { use tbl\n sub "e" "E" } }`, + ) + + it("splices the used ruleset's rules into a sequence block, in position", () => { + // mirrors maps probe tst-use-inseq (rs expects "12") + expect(run(inSeq, "ab")).toBe("12") + }) + + it("joins the pass: rules from a used ruleset flatten into the enclosing parallel", () => { + // one simultaneous pass: a→1 and b→2 together + expect(run(inPar, "ab")).toBe("12") + }) + + it("flattens a used ruleset's parallel block into the sequence's rule list", () => { + const expanded = expandDocument(parseIsc(flatSeq)) + const seq = expanded.stages[0]!.body[0] as Extract + expect(trace([seq])).toEqual(["sequence[a->b, c->d, e->E]"]) + }) + + it("merges an override block per-rule on the flat list (child-wins)", () => { + // replaced row joins the same single pass, after the kept rows + expect(run(inParOvr, "xa xb")).toBe("xA2 xB") + }) + + it("rejects a non-rule target (funcall in the used ruleset) with a named error", () => { + const doc = parseIsc( + minimalWrap(`ruleset tbl { sub "a" "A"\n upcase }\nstage main { parallel { use tbl } }`), + ) + expect(() => expandDocument(doc)).toThrow(IscLoadError) + expect(() => expandDocument(doc)).toThrow(/cannot join the pass/) + }) + + it("rejects a non-rule target reached through nested use", () => { + const doc = parseIsc( + minimalWrap( + `ruleset tbl { sub "a" "A"\n upcase }\n` + + `ruleset wrap { use tbl }\nstage main { sequence { use wrap } }`, + ), + ) + expect(() => expandDocument(doc)).toThrow(/cannot join the pass/) + }) +}) + // --------------------------------------------------------------------------- // W2 — override merge semantics (§4.2) // --------------------------------------------------------------------------- From 8e9b7791d0f4ee791b189a5cd431772f9cda9fe0 Mon Sep 17 00:00:00 2001 From: Ronald Tse Date: Sat, 14 Nov 2026 10:28:09 +0800 Subject: [PATCH 2/3] style: drop the unused inBlock param (eslint no-unused-vars) G5 restructured block expansion into expandBlockRow, leaving the expandItems inBlock flag with no caller passing it. --- src/isc/expand.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/isc/expand.ts b/src/isc/expand.ts index e494272..08df4c5 100644 --- a/src/isc/expand.ts +++ b/src/isc/expand.ts @@ -73,7 +73,6 @@ interface ExpandScope { function expandItems( items: readonly IscStageItem[], scope: ExpandScope, - inBlock = false, ): IscStageItem[] { const out: IscStageItem[] = [] for (const item of items) { From 74dd31e0e531bc8a07e2c3a8d04fb171c35c43fc Mon Sep 17 00:00:00 2001 From: Ronald Tse Date: Sat, 14 Nov 2026 10:38:05 +0800 Subject: [PATCH 3/3] style: prettier on expand.ts and the regenerated grammar-source --- src/isc/expand.ts | 14 ++------------ src/isc/grammar/grammar-source.ts | 3 ++- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/isc/expand.ts b/src/isc/expand.ts index 08df4c5..c3c71c8 100644 --- a/src/isc/expand.ts +++ b/src/isc/expand.ts @@ -26,14 +26,7 @@ * error (IscLoadError, §3.2 / §6.4). */ -import type { - IscDocument, - IscItem, - IscRule, - IscStage, - IscStageItem, - IscUseItem, -} from "./types.js" +import type { IscDocument, IscItem, IscRule, IscStage, IscStageItem, IscUseItem } from "./types.js" import { IscLoadError } from "./types.js" /** Resolves a dependency target (system code) to its parsed document. */ @@ -70,10 +63,7 @@ interface ExpandScope { readonly chain: readonly string[] } -function expandItems( - items: readonly IscStageItem[], - scope: ExpandScope, -): IscStageItem[] { +function expandItems(items: readonly IscStageItem[], scope: ExpandScope): IscStageItem[] { const out: IscStageItem[] = [] for (const item of items) { if (item.kind === "use") { diff --git a/src/isc/grammar/grammar-source.ts b/src/isc/grammar/grammar-source.ts index b4a1bcb..194cee0 100644 --- a/src/isc/grammar/grammar-source.ts +++ b/src/isc/grammar/grammar-source.ts @@ -17,4 +17,5 @@ export const ISC_PARG_SHA256 = "52949cb3170554071c8085bc5388553fde3d9a7feb590109d4543478d3561bb7" /** The grammar text itself, byte-identical to the ruby checkout copy. */ -export const ISC_PARG_SOURCE = "# Interscript ISC grammar — parsanol grammar language (PG).\n#\n# Line-oriented port of lib/interscript/isc/grammar/concerns/*.rb.\n# The capture tree must reproduce the Ruby-DSL parser's tree exactly:\n# - repetitions are ABNF prefixes (1*x, *x)\n# - negation is !x, positive lookahead is &x\n# - captures at use sites (rule_ref as name) nest inner captures\n# the same way parslet .as does\n#\n# Consumed by the interscript gem (artifact parse) and parsanol npm.\n\ngrammar InterscriptIsc version \"0.1.0\" {\n\n # -- lexical primitives -------------------------------------------------\n\n chr = %x00-10FFFF\n space_char = %x20 / %x09 / %x0A / %x0B / %x0C / %x0D\n newline = %x0D.0A / %x0A / %x0D\n line_comment = \"#\" *(!(newline) chr)\n whitespace = 1*(space_char / line_comment)\n ws = *(space_char / line_comment)\n inline_space = 1*(%x20 / %x09)\n inline_ws = *(inline_space / line_comment)\n hexd = %x30-39 / %x41-46 / %x61-66\n digit = %x30-39\n\n ident_first = %x41-5A / %x61-7A / %x5F\n ident_rest = %x41-5A / %x61-7A / %x30-39 / %x5F\n identifier = (ident_first 0*ident_rest) as identifier\n\n keyword = \"parallel\" / \"sequence\" / \"stage\" / \"compose\" / \"separate\" / \"system\" / \"metadata\" / \"aliases\" / \"tests\" / \"notes\" / \"description\" / \"any_character\" / \"authority\" / \"dependency\" / \"run\" / \"sub\" / \"before\" / \"after\" / \"not_before\" / \"not_after\" / \"any\" / \"none\" / \"boundary\" / \"line_start\" / \"line_end\" / \"word_boundary\" / \"downcase\" / \"upcase\" / \"title_case\" / \"capture\" / \"maybe\" / \"some\" / \"ref\" / \"name\" / \"ruleset\" / \"use\" / \"override\" / \"languages\" / \"when\"\n\n # -- string literals ----------------------------------------------------\n\n esc_nl = (\"n\") as newline\n esc_cr = (\"r\") as carriage_return\n esc_tab = (\"t\") as tab\n esc_dq = \"\\\"\" as dquote\n esc_bs = \"\\\\\" as backslash\n esc_uni4 = \"u\" (4hexd) as unicode\n esc_uni8 = \"U\" (4*8hexd) as unicode\n esc_u_lone = \"U\" as u_lone\n escape_sequence = \"\\\\\" (esc_nl / esc_cr / esc_tab / esc_dq / esc_bs / esc_uni4 / esc_uni8 / esc_u_lone)\n\n raw_run = 1*(!(\"\\\\\" / \"\\\"\") chr)\n dq_parts = *(escape_sequence / (raw_run as run))\n double_quoted = \"\\\"\" (dq_parts as string) \"\\\"\"\n sq_body = *(!\"'\" chr)\n single_quoted = \"'\" (sq_body as string) \"'\"\n quoted_string = double_quoted / single_quoted\n\n arrow = [whitespace] \"->\" [whitespace]\n comma_ws = \",\" [whitespace]\n\n # -- metadata -----------------------------------------------------------\n\n md_authority = \"authority\" whitespace ((quoted_string) as authority)\n md_source_spelling = \"source_spelling\" whitespace ((quoted_string) as source_spelling)\n md_target_spelling = \"target_spelling\" whitespace ((quoted_string) as target_spelling)\n md_identifying = \"identifying\" whitespace ((quoted_string) as identifying)\n md_name = \"name\" whitespace ((quoted_string) as name)\n md_spec_value = quoted_string as specification\n md_specification = \"specification\" whitespace ((md_spec_value *(comma_ws md_spec_value)) as specification)\n md_description = \"description\" [whitespace] \"{\" [ws] (raw_text as description) [ws] \"}\"\n md_system_status = \"system_status\" whitespace ((\"current\" / \"former\" / \"inactive\") as system_status)\n md_code_status = \"code_status\" whitespace ((\"preferred\" / \"proposed\" / \"deprecated\") as code_status)\n\n relation_type = \"supersedes\" / \"superseded_by\" / \"based_on\" / \"basis_for\" / \"alias_of\" / \"adopted_from\" / \"related_to\"\n relation_note = whitespace \"note\" whitespace (quoted_string as note)\n relation_item = [whitespace] (relation_type as type) whitespace (quoted_string as system) [(relation_note)] [whitespace]\n md_relations = \"relations\" [whitespace] \"{\" [ws] ((*(relation_item)) as relations) [ws] \"}\"\n\n note_item = [whitespace] \"note\" [whitespace] (quoted_string as note) [whitespace]\n md_notes = \"notes\" [whitespace] \"{\" [ws] ((*(note_item)) as notes) [ws] \"}\"\n\n md_provenance_value = quoted_string as provenance\n md_provenance = \"provenance\" [whitespace] ((md_provenance_value *(comma_ws md_provenance_value)) as provenance)\n\n md_empty_field = &(newline)\n md_raw_field_value = 1*(!%x0A !\"}\" !\"{\" chr)\n md_field_value = quoted_string / (md_raw_field_value as raw)\n md_field_block = \"{\" [ws] (raw_text as field_block) [ws] \"}\"\n md_generic_field = (identifier as field_name) inline_ws ((md_field_value as field_value) / md_field_block / md_empty_field)\n\n metadata_field = [whitespace] (md_description / md_relations / md_system_status / md_code_status / md_specification / md_notes / md_provenance / md_generic_field) [whitespace]\n md_items = *(metadata_field)\n metadata_block = \"metadata\" [whitespace] \"{\" [ws] (md_items as metadata) [ws] \"}\"\n\n raw_text = *(\"\\\\\" chr / (!\"}\" chr))\n\n # -- aliases ------------------------------------------------------------\n\n alias_decl = [whitespace] (identifier as name) [whitespace] \"=\" [whitespace] (item as value) [whitespace]\n alias_items = *(alias_decl)\n aliases_block = \"aliases\" [whitespace] \"{\" [ws] (alias_items as aliases) [ws] \"}\"\n\n # -- dependencies -------------------------------------------------------\n\n dep_alias = whitespace \"as\" whitespace (identifier as alias)\n dependency_decl = \"dependency\" whitespace (quoted_string as target) [(dep_alias)]\n\n # -- item expressions ---------------------------------------------------\n\n zw_primitive = ((\"boundary\") / (\"line_start\") / (\"line_end\") / (\"word_boundary\") / (\"space\") / (\"non_boundary\")) as primitive\n fn_lit = ((\"upcase\") / (\"downcase\") / (\"title_case\") / (\"reverse\") / (\"strip\") / (\"swapcase\")) as function\n any_char_lit = (\"any_character\") as any_char\n none_lit = (\"none\") as none\n\n digit_cap = digit as digit\n capture_reference_body = \"ref\" \"(\" [ws] digit_cap [ws] \")\"\n capture_reference = capture_reference_body as ref\n\n item_ref = identifier \".\" (identifier as qualified_name)\n alias_reference = (!(keyword) identifier [(\".\" (identifier as qualified_name))] !\"{\" ) as alias\n\n item_seq = item_atom\n item_sep = ([ws] \"+\" [ws]) / whitespace\n item_cont = &item_atom\n\n range_arg = (quoted_string as lo) [ws] \"..\" [ws] (quoted_string as hi)\n list_item = item\n list_items = (list_item *((comma_ws / whitespace) list_item))\n set_arg = ((quoted_string as single)) / (\"[\" [ws] ((list_item *((comma_ws / whitespace) list_item)) as list) [ws] \"]\")\n alias_arg = (!zw_primitive !(keyword) identifier) as alias_ref\n any_arg = range_arg / set_arg / alias_arg\n any_ctor = \"any\" \"(\" [ws] (any_arg as any) [ws] \")\"\n capture_ctor = \"capture\" \"(\" [ws] (item as capture_inner) [ws] \")\"\n maybe_ctor = \"maybe\" \"(\" [ws] (item as maybe_inner) [ws] \")\"\n some_ctor = \"some\" \"(\" [ws] (item as some_inner) [ws] \")\"\n\n item_atom_start = \"\\\"\" / \"'\" / ident_first\n cont_stop = \"to\" / \"before\" / \"after\" / \"not_before\" / \"not_after\" / \"}\"\n alias_decl_stop = identifier [ws] \"=\"\n item_atom = quoted_string / none_lit / zw_primitive / any_char_lit / any_ctor / capture_ctor / maybe_ctor / some_ctor / fn_lit / capture_reference / alias_reference\n item = (item_atom 0*(item_sep !cont_stop !(alias_decl_stop) &item_atom_start item_atom)) as concatenation\n\n # -- rules and stages ---------------------------------------------------\n\n constraint_after = \"after\" whitespace (item as after)\n constraint_before = \"before\" whitespace (item as before)\n constraint_not_before = \"not_before\" whitespace (item as not_before)\n constraint_not_after = \"not_after\" whitespace (item as not_after)\n constraint = constraint_after / constraint_before / constraint_not_before / constraint_not_after\n constraints = *(whitespace constraint)\n\n compact_rule = \"sub\" whitespace (item_atom as from) whitespace (item_atom as to) ((*(whitespace constraint)) as constraints) [(when_guard)]\n\n block_rule = \"sub\" [ws] \"{\" [ws] \"from\" whitespace (item as from) [ws] \"to\" whitespace (item as to) ((*(whitespace constraint)) as constraints) [(when_guard)] [ws] \"}\"\n\n when_lang = (!(keyword) identifier) as when_lang\n when_guard = (whitespace \"when\" whitespace (when_lang) *(((comma_ws / whitespace) (when_lang)))) as when\n\n rule = block_rule / compact_rule\n\n comment_item = ((\"#\" *(!%x0A chr)) as comment) / ((!(keyword) identifier) as noop)\n # ISC-WF-1 §3.2: a `use` directive is a rule-line item — items inside a\n # parallel/sequence block participate in that block's single pass, and\n # the expansion flattens the referenced ruleset's rules at this\n # position (mirrors interscript-rs grammar/isc.parg rule_line).\n rule_line = [ws] (rule / use_directive / comment_item) [ws]\n rule_items = *(rule_line)\n sequence_block = \"sequence\" [ws] \"{\" [ws] (rule_items as sequence) [ws] \"}\"\n parallel_block = \"parallel\" [ws] \"{\" [ws] (rule_items as parallel) [ws] \"}\"\n\n separator_part = whitespace \"separator\" whitespace (item_atom as separator)\n separate_directive = (\"separate\") as separate [(separator_part)]\n case_directive = ((\"downcase\") / (\"upcase\")) as case\n case_kwargs_part = whitespace (kwarg_list as case_kwargs)\n title_case_directive = (\"title_case\") as case [(case_kwargs_part)]\n string_case_directive = case_directive / title_case_directive\n compose_directive = ((\"compose\") / (\"decompose\")) as compose\n kwarg = (identifier as kwarg_name) [ws] \":\" [ws] ((quoted_string) as kwarg_value)\n kwarg_item = (kwarg) as kwarg\n kwarg_list = (kwarg_item *(comma_ws kwarg_item))\n funcall_kwargs_part = whitespace (kwarg_list as funcall_kwargs)\n rababa_directive = (\"rababa\") as funcall_name [(funcall_kwargs_part)]\n run_dep = \"map.\" (identifier as dep) \".stage.\" (identifier as stage)\n run_stage_only = (\"stage.\" (identifier as stage)) as run_stage_only\n run_rule = \"run\" whitespace ((run_dep) / run_stage_only)\n\n bare_rule = (rule) as bare_rule\n\n use_alias = (identifier) as use_alias\n use_qualified = \".\" (identifier as qualified_name)\n use_overrides_part = whitespace \"override\" [ws] \"{\" [ws] ((*(rule_line)) as use_overrides) [ws] \"}\"\n use_directive = ((\"use\" whitespace (use_alias) [(use_qualified)] [(use_overrides_part)]) as use)\n\n stage_item = [ws] (sequence_block / parallel_block / run_rule / separate_directive / string_case_directive / compose_directive / rababa_directive / use_directive / bare_rule / comment_item) [ws]\n stage_items = *(stage_item)\n stage_name_paren = \"(\" (identifier as stage_name) \")\"\n stage_name_ws = whitespace (identifier as stage_name)\n stage_block = \"stage\" (stage_name_paren / stage_name_ws) [ws] \"{\" [ws] (stage_items as stage) [ws] \"}\"\n\n ruleset_name_ws = whitespace (identifier as ruleset_name)\n ruleset_block = \"ruleset\" (ruleset_name_ws) [ws] \"{\" [ws] (stage_items as ruleset) [ws] \"}\"\n\n # -- tests ---------------------------------------------------------------\n\n test_note = whitespace \"note\" whitespace (quoted_string as note)\n test_line = [whitespace] (quoted_string as input) arrow (quoted_string as expected) [(test_note)] [whitespace]\n test_items = *(test_line)\n tests_block = \"tests\" [whitespace] \"{\" [ws] (test_items as tests) [ws] \"}\"\n\n # -- system --------------------------------------------------------------\n\n language_ident = (!(keyword) identifier) as language\n languages_decl = (\"languages\" whitespace ((language_ident *(((comma_ws / whitespace) (language_ident))))) as languages)\n\n block_item = [whitespace] (metadata_block / aliases_block / tests_block / languages_decl / ruleset_block / stage_block / dependency_decl) [whitespace]\n body_items = *(block_item)\n system_block = \"system\" whitespace ((quoted_string) as system_code) [whitespace] \"{\" [ws] ((*(block_item)) as body) [ws] \"}\" [whitespace]\n isc_source = [whitespace] ((system_block) as system) [whitespace]\n\n entry isc: isc_source\n}\n" as string +export const ISC_PARG_SOURCE = + '# Interscript ISC grammar — parsanol grammar language (PG).\n#\n# Line-oriented port of lib/interscript/isc/grammar/concerns/*.rb.\n# The capture tree must reproduce the Ruby-DSL parser\'s tree exactly:\n# - repetitions are ABNF prefixes (1*x, *x)\n# - negation is !x, positive lookahead is &x\n# - captures at use sites (rule_ref as name) nest inner captures\n# the same way parslet .as does\n#\n# Consumed by the interscript gem (artifact parse) and parsanol npm.\n\ngrammar InterscriptIsc version "0.1.0" {\n\n # -- lexical primitives -------------------------------------------------\n\n chr = %x00-10FFFF\n space_char = %x20 / %x09 / %x0A / %x0B / %x0C / %x0D\n newline = %x0D.0A / %x0A / %x0D\n line_comment = "#" *(!(newline) chr)\n whitespace = 1*(space_char / line_comment)\n ws = *(space_char / line_comment)\n inline_space = 1*(%x20 / %x09)\n inline_ws = *(inline_space / line_comment)\n hexd = %x30-39 / %x41-46 / %x61-66\n digit = %x30-39\n\n ident_first = %x41-5A / %x61-7A / %x5F\n ident_rest = %x41-5A / %x61-7A / %x30-39 / %x5F\n identifier = (ident_first 0*ident_rest) as identifier\n\n keyword = "parallel" / "sequence" / "stage" / "compose" / "separate" / "system" / "metadata" / "aliases" / "tests" / "notes" / "description" / "any_character" / "authority" / "dependency" / "run" / "sub" / "before" / "after" / "not_before" / "not_after" / "any" / "none" / "boundary" / "line_start" / "line_end" / "word_boundary" / "downcase" / "upcase" / "title_case" / "capture" / "maybe" / "some" / "ref" / "name" / "ruleset" / "use" / "override" / "languages" / "when"\n\n # -- string literals ----------------------------------------------------\n\n esc_nl = ("n") as newline\n esc_cr = ("r") as carriage_return\n esc_tab = ("t") as tab\n esc_dq = "\\"" as dquote\n esc_bs = "\\\\" as backslash\n esc_uni4 = "u" (4hexd) as unicode\n esc_uni8 = "U" (4*8hexd) as unicode\n esc_u_lone = "U" as u_lone\n escape_sequence = "\\\\" (esc_nl / esc_cr / esc_tab / esc_dq / esc_bs / esc_uni4 / esc_uni8 / esc_u_lone)\n\n raw_run = 1*(!("\\\\" / "\\"") chr)\n dq_parts = *(escape_sequence / (raw_run as run))\n double_quoted = "\\"" (dq_parts as string) "\\""\n sq_body = *(!"\'" chr)\n single_quoted = "\'" (sq_body as string) "\'"\n quoted_string = double_quoted / single_quoted\n\n arrow = [whitespace] "->" [whitespace]\n comma_ws = "," [whitespace]\n\n # -- metadata -----------------------------------------------------------\n\n md_authority = "authority" whitespace ((quoted_string) as authority)\n md_source_spelling = "source_spelling" whitespace ((quoted_string) as source_spelling)\n md_target_spelling = "target_spelling" whitespace ((quoted_string) as target_spelling)\n md_identifying = "identifying" whitespace ((quoted_string) as identifying)\n md_name = "name" whitespace ((quoted_string) as name)\n md_spec_value = quoted_string as specification\n md_specification = "specification" whitespace ((md_spec_value *(comma_ws md_spec_value)) as specification)\n md_description = "description" [whitespace] "{" [ws] (raw_text as description) [ws] "}"\n md_system_status = "system_status" whitespace (("current" / "former" / "inactive") as system_status)\n md_code_status = "code_status" whitespace (("preferred" / "proposed" / "deprecated") as code_status)\n\n relation_type = "supersedes" / "superseded_by" / "based_on" / "basis_for" / "alias_of" / "adopted_from" / "related_to"\n relation_note = whitespace "note" whitespace (quoted_string as note)\n relation_item = [whitespace] (relation_type as type) whitespace (quoted_string as system) [(relation_note)] [whitespace]\n md_relations = "relations" [whitespace] "{" [ws] ((*(relation_item)) as relations) [ws] "}"\n\n note_item = [whitespace] "note" [whitespace] (quoted_string as note) [whitespace]\n md_notes = "notes" [whitespace] "{" [ws] ((*(note_item)) as notes) [ws] "}"\n\n md_provenance_value = quoted_string as provenance\n md_provenance = "provenance" [whitespace] ((md_provenance_value *(comma_ws md_provenance_value)) as provenance)\n\n md_empty_field = &(newline)\n md_raw_field_value = 1*(!%x0A !"}" !"{" chr)\n md_field_value = quoted_string / (md_raw_field_value as raw)\n md_field_block = "{" [ws] (raw_text as field_block) [ws] "}"\n md_generic_field = (identifier as field_name) inline_ws ((md_field_value as field_value) / md_field_block / md_empty_field)\n\n metadata_field = [whitespace] (md_description / md_relations / md_system_status / md_code_status / md_specification / md_notes / md_provenance / md_generic_field) [whitespace]\n md_items = *(metadata_field)\n metadata_block = "metadata" [whitespace] "{" [ws] (md_items as metadata) [ws] "}"\n\n raw_text = *("\\\\" chr / (!"}" chr))\n\n # -- aliases ------------------------------------------------------------\n\n alias_decl = [whitespace] (identifier as name) [whitespace] "=" [whitespace] (item as value) [whitespace]\n alias_items = *(alias_decl)\n aliases_block = "aliases" [whitespace] "{" [ws] (alias_items as aliases) [ws] "}"\n\n # -- dependencies -------------------------------------------------------\n\n dep_alias = whitespace "as" whitespace (identifier as alias)\n dependency_decl = "dependency" whitespace (quoted_string as target) [(dep_alias)]\n\n # -- item expressions ---------------------------------------------------\n\n zw_primitive = (("boundary") / ("line_start") / ("line_end") / ("word_boundary") / ("space") / ("non_boundary")) as primitive\n fn_lit = (("upcase") / ("downcase") / ("title_case") / ("reverse") / ("strip") / ("swapcase")) as function\n any_char_lit = ("any_character") as any_char\n none_lit = ("none") as none\n\n digit_cap = digit as digit\n capture_reference_body = "ref" "(" [ws] digit_cap [ws] ")"\n capture_reference = capture_reference_body as ref\n\n item_ref = identifier "." (identifier as qualified_name)\n alias_reference = (!(keyword) identifier [("." (identifier as qualified_name))] !"{" ) as alias\n\n item_seq = item_atom\n item_sep = ([ws] "+" [ws]) / whitespace\n item_cont = &item_atom\n\n range_arg = (quoted_string as lo) [ws] ".." [ws] (quoted_string as hi)\n list_item = item\n list_items = (list_item *((comma_ws / whitespace) list_item))\n set_arg = ((quoted_string as single)) / ("[" [ws] ((list_item *((comma_ws / whitespace) list_item)) as list) [ws] "]")\n alias_arg = (!zw_primitive !(keyword) identifier) as alias_ref\n any_arg = range_arg / set_arg / alias_arg\n any_ctor = "any" "(" [ws] (any_arg as any) [ws] ")"\n capture_ctor = "capture" "(" [ws] (item as capture_inner) [ws] ")"\n maybe_ctor = "maybe" "(" [ws] (item as maybe_inner) [ws] ")"\n some_ctor = "some" "(" [ws] (item as some_inner) [ws] ")"\n\n item_atom_start = "\\"" / "\'" / ident_first\n cont_stop = "to" / "before" / "after" / "not_before" / "not_after" / "}"\n alias_decl_stop = identifier [ws] "="\n item_atom = quoted_string / none_lit / zw_primitive / any_char_lit / any_ctor / capture_ctor / maybe_ctor / some_ctor / fn_lit / capture_reference / alias_reference\n item = (item_atom 0*(item_sep !cont_stop !(alias_decl_stop) &item_atom_start item_atom)) as concatenation\n\n # -- rules and stages ---------------------------------------------------\n\n constraint_after = "after" whitespace (item as after)\n constraint_before = "before" whitespace (item as before)\n constraint_not_before = "not_before" whitespace (item as not_before)\n constraint_not_after = "not_after" whitespace (item as not_after)\n constraint = constraint_after / constraint_before / constraint_not_before / constraint_not_after\n constraints = *(whitespace constraint)\n\n compact_rule = "sub" whitespace (item_atom as from) whitespace (item_atom as to) ((*(whitespace constraint)) as constraints) [(when_guard)]\n\n block_rule = "sub" [ws] "{" [ws] "from" whitespace (item as from) [ws] "to" whitespace (item as to) ((*(whitespace constraint)) as constraints) [(when_guard)] [ws] "}"\n\n when_lang = (!(keyword) identifier) as when_lang\n when_guard = (whitespace "when" whitespace (when_lang) *(((comma_ws / whitespace) (when_lang)))) as when\n\n rule = block_rule / compact_rule\n\n comment_item = (("#" *(!%x0A chr)) as comment) / ((!(keyword) identifier) as noop)\n # ISC-WF-1 §3.2: a `use` directive is a rule-line item — items inside a\n # parallel/sequence block participate in that block\'s single pass, and\n # the expansion flattens the referenced ruleset\'s rules at this\n # position (mirrors interscript-rs grammar/isc.parg rule_line).\n rule_line = [ws] (rule / use_directive / comment_item) [ws]\n rule_items = *(rule_line)\n sequence_block = "sequence" [ws] "{" [ws] (rule_items as sequence) [ws] "}"\n parallel_block = "parallel" [ws] "{" [ws] (rule_items as parallel) [ws] "}"\n\n separator_part = whitespace "separator" whitespace (item_atom as separator)\n separate_directive = ("separate") as separate [(separator_part)]\n case_directive = (("downcase") / ("upcase")) as case\n case_kwargs_part = whitespace (kwarg_list as case_kwargs)\n title_case_directive = ("title_case") as case [(case_kwargs_part)]\n string_case_directive = case_directive / title_case_directive\n compose_directive = (("compose") / ("decompose")) as compose\n kwarg = (identifier as kwarg_name) [ws] ":" [ws] ((quoted_string) as kwarg_value)\n kwarg_item = (kwarg) as kwarg\n kwarg_list = (kwarg_item *(comma_ws kwarg_item))\n funcall_kwargs_part = whitespace (kwarg_list as funcall_kwargs)\n rababa_directive = ("rababa") as funcall_name [(funcall_kwargs_part)]\n run_dep = "map." (identifier as dep) ".stage." (identifier as stage)\n run_stage_only = ("stage." (identifier as stage)) as run_stage_only\n run_rule = "run" whitespace ((run_dep) / run_stage_only)\n\n bare_rule = (rule) as bare_rule\n\n use_alias = (identifier) as use_alias\n use_qualified = "." (identifier as qualified_name)\n use_overrides_part = whitespace "override" [ws] "{" [ws] ((*(rule_line)) as use_overrides) [ws] "}"\n use_directive = (("use" whitespace (use_alias) [(use_qualified)] [(use_overrides_part)]) as use)\n\n stage_item = [ws] (sequence_block / parallel_block / run_rule / separate_directive / string_case_directive / compose_directive / rababa_directive / use_directive / bare_rule / comment_item) [ws]\n stage_items = *(stage_item)\n stage_name_paren = "(" (identifier as stage_name) ")"\n stage_name_ws = whitespace (identifier as stage_name)\n stage_block = "stage" (stage_name_paren / stage_name_ws) [ws] "{" [ws] (stage_items as stage) [ws] "}"\n\n ruleset_name_ws = whitespace (identifier as ruleset_name)\n ruleset_block = "ruleset" (ruleset_name_ws) [ws] "{" [ws] (stage_items as ruleset) [ws] "}"\n\n # -- tests ---------------------------------------------------------------\n\n test_note = whitespace "note" whitespace (quoted_string as note)\n test_line = [whitespace] (quoted_string as input) arrow (quoted_string as expected) [(test_note)] [whitespace]\n test_items = *(test_line)\n tests_block = "tests" [whitespace] "{" [ws] (test_items as tests) [ws] "}"\n\n # -- system --------------------------------------------------------------\n\n language_ident = (!(keyword) identifier) as language\n languages_decl = ("languages" whitespace ((language_ident *(((comma_ws / whitespace) (language_ident))))) as languages)\n\n block_item = [whitespace] (metadata_block / aliases_block / tests_block / languages_decl / ruleset_block / stage_block / dependency_decl) [whitespace]\n body_items = *(block_item)\n system_block = "system" whitespace ((quoted_string) as system_code) [whitespace] "{" [ws] ((*(block_item)) as body) [ws] "}" [whitespace]\n isc_source = [whitespace] ((system_block) as system) [whitespace]\n\n entry isc: isc_source\n}\n' as string