From cd66421ce80a8b7bce1cf31c2ed1b44f6eba9647 Mon Sep 17 00:00:00 2001 From: Ronald Tse Date: Sat, 14 Nov 2026 19:48:48 +0800 Subject: [PATCH 1/2] Adopt the WO19 G6 rulings: escapes decode, keyword table, fn directives MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Item 4: both \uXXXX and \UXXXX escape spellings decode in the string assembly (the former hand-parser-parity deviation carried gki-bel's sub "\U040E" "Ŭ" as the literal text "U040E" and the row never fired; ruby/rs always decoded). Item 1: the grammar-source sync carries the six fn-literal keyword table (sha pin 169596431e066ec762b69ceb5a21383154e97ed7f3630888032e0b7122a1750e). Item 3: reverse/strip/swapcase join the builtin function registry — they execute as stage directives and inline to-funcalls with the plain String semantics of ruby Stdlib::Functions. Item 2: a fn literal in FROM position raises MapLogicError at compile (the former alias-fallback said "Alias downcase not found"); any_character keeps its alias path (it is the primitive spelled as a function atom). Item 5: the outside-form block-rule when extension is retired — canonical rs binds the guard inside the braces and ruby parses the inside form only; the inside form is pinned and the outside form rejects. --- src/isc/converter.ts | 19 +++++-- src/isc/grammar/actions.ts | 23 +++----- src/isc/grammar/grammar-source.ts | 7 ++- src/isc/grammar/isc-parser.ts | 38 +++++++------ src/runtime/executor.ts | 9 ++++ src/stdlib.ts | 32 +++++++++++ test/isc/fail-loud.test.ts | 89 +++++++++++++++++++++++++++++++ test/isc/parser.test.ts | 11 ++++ test/isc/wf1.test.ts | 13 ++++- 9 files changed, 196 insertions(+), 45 deletions(-) diff --git a/src/isc/converter.ts b/src/isc/converter.ts index db2c339..dd87c80 100644 --- a/src/isc/converter.ts +++ b/src/isc/converter.ts @@ -19,6 +19,7 @@ import type { IscDocument, IscItem, IscRule, IscStageItem } from "./types.js" import { IscLoadError } from "./types.js" +import { MapLogicError } from "../errors.js" import { expandDocument, type DependencyDocResolver } from "./expand.js" import type { AliasItem, @@ -220,10 +221,20 @@ function convertItem(item: IscItem): Item { return r } case "function": { - // Functions in non-`to` positions are unexpected — fall back to alias - // lookup so a clear error surfaces at runtime. - const r: AliasItem = { kind: "alias", name: item.name } - return r + // `any_character` is the primitive spelled as a function atom + // (actions.ts lowers it this way; rs lowers it to the + // any_character stdlib alias) — keep the alias path. + if (item.name === "any_character") { + const r: AliasItem = { kind: "alias", name: item.name } + return r + } + // WO19 G6 item 2: a fn literal in FROM position is map-logic + // damage — ruby raises (canon), rs raises at build. The former + // alias-fallback degraded to a misleading "Alias not + // found"; raise the named error at compile instead. + throw new MapLogicError( + `function literal "${item.name}" in from position (fn literals are directives or to-funcalls, not from values)`, + ) } case "alias_ref": { const r: AliasItem = { kind: "alias", name: item.name } diff --git a/src/isc/grammar/actions.ts b/src/isc/grammar/actions.ts index 6474225..2828649 100644 --- a/src/isc/grammar/actions.ts +++ b/src/isc/grammar/actions.ts @@ -155,21 +155,14 @@ export class TreeToDocument { else if (h.u_lone !== undefined) out += "U" else if (h.unicode !== undefined) { const digits = (h.unicode as Slice).content - // DEVIATION (hand-parser parity): the grammar cannot distinguish - // `\uXXXX` from `\UXXXX` (both captures are named :unicode), but the - // hand parser only decodes lowercase \u and renders a capital \U as - // a literal "U" followed by the raw digits. The slice offset tells - // us which spelling the source used (the escape letter sits one - // position before the digits). Six corpus maps use `\U`; mirroring - // the hand parser keeps their documents — and therefore their - // transliteration output — byte-identical across the swap. The ruby - // artifact parser decodes both spellings; aligning ts/py/ruby on the - // grammar behavior is an owner decision, not this parser's to make. - if (this.src.charCodeAt((h.unicode as Slice).offset - 1) === 0x55) { - out += "U" + digits - } else { - out += String.fromCharCode(parseInt(digits, 16)) - } + // WO19 G6 ruling: BOTH escape spellings decode. The former hand + // parser only decoded lowercase \u and rendered a capital \U as a + // literal "U" followed by the raw digits, so gki-bel's + // `sub "\U040E" "Ŭ"` carried the from-value "U040E" and the row + // never fired. The grammar captures both spellings under :unicode + // and the tree carries the decoded code point (ruby/rs always + // decoded both). + out += String.fromCodePoint(parseInt(digits, 16)) } else { throw new Error(`unknown string part ${JSON.stringify(Object.keys(h))}`) } diff --git a/src/isc/grammar/grammar-source.ts b/src/isc/grammar/grammar-source.ts index 194cee0..3b7116b 100644 --- a/src/isc/grammar/grammar-source.ts +++ b/src/isc/grammar/grammar-source.ts @@ -3,7 +3,7 @@ * 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 (sha256 52949cb3170554071c8085bc5388553fde3d9a7feb590109d4543478d3561bb7) so the TypeScript parser + * module embeds it verbatim (sha256 169596431e066ec762b69ceb5a21383154e97ed7f3630888032e0b7122a1750e) so the TypeScript parser * compiles the same grammar text the Ruby runtime ships. Update procedure: * * node scripts/sync-isc-grammar.mjs @@ -14,8 +14,7 @@ */ /** sha256 of the grammar text embedded below (pin for drift detection). */ -export const ISC_PARG_SHA256 = "52949cb3170554071c8085bc5388553fde3d9a7feb590109d4543478d3561bb7" +export const ISC_PARG_SHA256 = "169596431e066ec762b69ceb5a21383154e97ed7f3630888032e0b7122a1750e" /** 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 — WO19 G6 ruling: the six fn-literal names are reserved\n # words (upcase/downcase/title_case were already here; reverse/strip/\n # swapcase join). A bare fn name is never an alias reference or an\n # alias(...) argument: item-position uses parse as fn_lit (function\n # capture). `downcase = any(...)` still declares an alias NAMED\n # downcase (alias_decl has no keyword guard), matching the ruby\n # concern grammar; the name is simply not reachable via a bare\n # reference. Keyword is used only under negative lookahead, where any\n # matching branch suffices.\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\" / \"reverse\" / \"strip\" / \"swapcase\" / \"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 # WO19 G6 ruling: all six fn-literal names are stage DIRECTIVES.\n # downcase/upcase keep the keywordless bare form; reverse/strip/\n # swapcase join with plain String semantics as the reference (ruby\n # Stdlib::Functions: String#reverse / String#strip / String#swapcase).\n case_directive = ((\"downcase\") / (\"upcase\") / (\"reverse\") / (\"strip\") / (\"swapcase\")) 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/grammar/isc-parser.ts b/src/isc/grammar/isc-parser.ts index 4c96440..4ee96fe 100644 --- a/src/isc/grammar/isc-parser.ts +++ b/src/isc/grammar/isc-parser.ts @@ -11,7 +11,7 @@ * Single-sourcing contract: the grammar TEXT embedded in grammar-source.ts * is the semantic source of truth (synced from interscript-ruby's * lib/interscript/isc/grammar/isc.parg via scripts/sync-isc-grammar.mjs). - * The three documented grammar-table extensions below (GRAMMAR_EXTENSIONS) + * The two documented grammar-table extensions below (GRAMMAR_EXTENSIONS) * restore hand-parser/py behaviors the canonical .parg rejects — each is * spelled in the grammar language, named, and corpus-proven dormant. */ @@ -31,8 +31,8 @@ interface Compiled { let compiled: Compiled | undefined /** - * Grammar-table extensions — the three places where the former hand - * parser (and the python runtime) accept syntax the canonical .parg + * Grammar-table extensions — the two places where the former hand + * parser (and the python runtime) accepted syntax the canonical .parg * rejects, pinned by the ts unit suite and absent from the corpus. Each * extension is spelled in the grammar language itself and merged into * the rule table, so the .parg remains the only semantic source and @@ -42,29 +42,27 @@ let compiled: Compiled | undefined * fallback (concerns/items.rb any_constructor), which the canonical * .parg dropped; the interscript-rs vendored copy keeps it. * (`any(space)`, `any(space + line_end)` — parser.test.ts pins both.) - * 2. `block_rule` — accept the `when` guard AFTER the closing brace of - * the block form. The ruby DSL places the guard inside the braces; - * the ts and py runtimes both place it outside, and the ts suite pins - * the outside form (wf1.test.ts). The outside branch is tried first - * (it is the greedy one; its mandatory `}` keeps it from shadowing - * the inside form). - * 3. `run_dep` — allow hyphenated dependency names (`run map.some-dep.…`, + * 2. `run_dep` — allow hyphenated dependency names (`run map.some-dep.…`, * wf1.test.ts). The grammar's identifier is [A-Za-z_][A-Za-z0-9_]*; * the former hand parser's identifier admitted `-` in structural * positions. Only the dependency slot is widened; the corpus is * hyphen-free in every identifier position. * - * Ruby rejects (1)'s absence aside, the outside-when and hyphen-dep - * forms are cross-runtime divergences (ruby parses neither); aligning - * ruby/ts/py on one placement is an owner decision. None of the three - * extensions fires on any corpus map (proven: the corpus tree-diff and - * document-diff harnesses both pass with them in place, and corpus - * trees were byte-identical before they were added). + * The former `block_rule` extension (the `when` guard accepted AFTER + * the closing brace of the block form) was RETIRED by WO19 G6 item 5: + * canonical rs binds the guard inside the braces and ruby parses the + * inside form only, so ts/py now reject the outside form too (the + * inside form is the canonical grammar's own rule; corpus-proven + * dormant). Ruby rejects (1)'s absence aside, the hyphen-dep form + * remains a cross-runtime divergence (ruby parses neither); aligning + * ruby/ts/py on it is an owner decision. None of the extensions fires + * on any corpus map (proven: the corpus tree-diff and document-diff + * harnesses both pass with them in place, and corpus trees were + * byte-identical before they were added). */ const GRAMMAR_EXTENSIONS = ` grammar IscExtensions version "0.0.0" { any_arg = range_arg / set_arg / alias_arg / ((item) as any_item) - block_rule = ("sub" [ws] "{" [ws] "from" whitespace ((item) as from) [ws] "to" whitespace ((item) as to) ((*(whitespace constraint)) as constraints) [ws] "}" [(when_guard)]) / ("sub" [ws] "{" [ws] "from" whitespace ((item) as from) [ws] "to" whitespace ((item) as to) ((*(whitespace constraint)) as constraints) [(when_guard)] [ws] "}") run_dep = "map." (((identifier *("-" identifier)) / identifier) as dep) ".stage." (identifier as stage) } ` @@ -73,10 +71,10 @@ function compileGrammar(): Compiled { if (compiled !== undefined) return compiled const grammar = parseParg(ISC_PARG_SOURCE) const rules: RuleTable = { ...grammar.rules } - // Shape-guarded merge: if a future .parg edit renames any of the three - // rules, the merge throws instead of silently misparsing. + // Shape-guarded merge: if a future .parg edit renames any of the + // extension rules, the merge throws instead of silently misparsing. const ext = parseParg(GRAMMAR_EXTENSIONS) - for (const name of ["any_arg", "block_rule", "run_dep"]) { + for (const name of ["any_arg", "run_dep"]) { const replacement = ext.rules[name] if (rules[name] === undefined || replacement === undefined) { throw new Error( diff --git a/src/runtime/executor.ts b/src/runtime/executor.ts index bce4d4a..89304f2 100644 --- a/src/runtime/executor.ts +++ b/src/runtime/executor.ts @@ -28,6 +28,9 @@ import { separate, compose, decompose, + reverse, + strip, + swapcase, } from "../stdlib.js" type RuleKind = Rule["kind"] @@ -42,6 +45,12 @@ const BUILTIN_FUNCTIONS: Record titleCase(i, o ?? {}), + // WO19 G6: the three new fn literals execute as directives and + // inline to-funcalls with the plain String semantics of ruby + // Stdlib::Functions (String#reverse / String#strip / String#swapcase). + reverse, + strip, + swapcase, separate: (i, o) => separate(i, o ?? {}), compose, decompose, diff --git a/src/stdlib.ts b/src/stdlib.ts index 9912a67..ffff9e7 100644 --- a/src/stdlib.ts +++ b/src/stdlib.ts @@ -202,6 +202,38 @@ export function decompose(input: string): string { return input.normalize("NFD") } +/** + * Reverse a string by code point. Maps to + * `Interscript.functions.reverse` (ruby String#reverse) — WO19 G6. + */ +export function reverse(input: string): string { + return [...input].reverse().join("") +} + +/** + * Trim leading/trailing whitespace. Maps to `Interscript.functions.strip` + * (ruby String#strip: the ASCII whitespace + NUL set, both ends) — WO19 G6. + */ +export function strip(input: string): string { + // ruby String#strip's character set: NUL, tab, LF, VT, FF, CR, space. + return input.replace(/^[\0\t\n\v\f\r ]+/, "").replace(/[\0\t\n\v\f\r ]+$/, "") +} + +/** + * Swap the case of every character (full Unicode mapping, matching + * toUpperCase/toLowerCase semantics). Maps to + * `Interscript.functions.swapcase` (ruby String#swapcase) — WO19 G6. + */ +export function swapcase(input: string): string { + let out = "" + for (const ch of input) { + const lo = ch.toLowerCase() + const up = ch.toUpperCase() + out += lo !== ch ? lo : up !== ch ? up : ch + } + return out +} + /** * Megaregexp parallel replace — Ruby's fallback for parallel blocks * where any rule has `before`/`after`/`not_before`/`not_after` constraints. diff --git a/test/isc/fail-loud.test.ts b/test/isc/fail-loud.test.ts index 70203a6..2d3dc0d 100644 --- a/test/isc/fail-loud.test.ts +++ b/test/isc/fail-loud.test.ts @@ -73,3 +73,92 @@ describe("WO18 G4 — missing stage fails loud", () => { expect(transliterate(code, "a")).toBe("b") }) }) + +// --------------------------------------------------------------------------- +// WO19 G6 — fn-literal alignment +// --------------------------------------------------------------------------- + +const FN_FROM_MAP = `# G6 item 2: a fn literal in FROM position is map-logic damage. +system "T:tst-g6-fnfrom:1" { + stage main { + parallel { + sub downcase "X" + sub "k" "q" + } + } +}` + +const REVERSE_DIR_MAP = `# G6 item 3: the reverse directive executes (ruby String#reverse). +system "T:tst-g6-revdir:1" { + stage main { + sub "1" "2" + reverse + } +}` + +const STRIP_DIR_MAP = `# G6 item 3: the strip directive executes (ruby String#strip). +system "T:tst-g6-stripdir:1" { + stage main { + strip + } +}` + +const SWAPCASE_DIR_MAP = `# G6 item 3: the swapcase directive executes (ruby String#swapcase). +system "T:tst-g6-swapdir:1" { + stage main { + sub "a" "b" + swapcase + } +}` + +const REVERSE_TO_MAP = `# G6 item 3: a reverse fn literal as a \`to\` target. +system "T:tst-g6-revto:1" { + stage main { + sub "abc" reverse + } +}` + +const KEYWORD_ALIAS_MAP = `# G6 item 1: the six fn names are reserved — a bare name is never an +# alias reference, but \`downcase = any(...)\` still DECLARES an alias +# named downcase (alias_decl has no keyword guard). +system "T:tst-g6-keyword:1" { + aliases { downcase = any("a".."z") } + stage main { + sub "k" "K" + } +}` + +describe("WO19 G6 — fn literals", () => { + beforeEach(() => reset()) + + it("a fn literal in FROM position raises MapLogicError at compile (was: alias-lookup corruption)", () => { + const code = loadMap(FN_FROM_MAP) + expect(() => transliterate(code, "kak")).toThrow(MapLogicError) + expect(() => transliterate(code, "kak")).toThrow(/function literal "downcase" in from position/) + }) + + it("the reverse directive executes (String#reverse)", () => { + const code = loadMap(REVERSE_DIR_MAP) + expect(transliterate(code, "abc1")).toBe("2cba") + }) + + it("the strip directive executes (String#strip)", () => { + const code = loadMap(STRIP_DIR_MAP) + expect(transliterate(code, " x ")).toBe("x") + }) + + it("the swapcase directive executes (String#swapcase)", () => { + const code = loadMap(SWAPCASE_DIR_MAP) + expect(transliterate(code, "aBc")).toBe("BbC") + }) + + it("a reverse fn literal as the to target executes", () => { + const code = loadMap(REVERSE_TO_MAP) + expect(transliterate(code, "xabcy")).toBe("xcbay") + }) + + it("downcase = any(...) parses as an alias declaration", () => { + const code = loadMap(KEYWORD_ALIAS_MAP) + expect(transliterate(code, "kak")).toBe("KaK") + }) +}) diff --git a/test/isc/parser.test.ts b/test/isc/parser.test.ts index 701efb7..32edb47 100644 --- a/test/isc/parser.test.ts +++ b/test/isc/parser.test.ts @@ -10,6 +10,7 @@ import { describe, it, expect } from "vitest" import { parseIsc } from "../../src/isc/parser.ts" import { iscToCompiledMap } from "../../src/isc/converter.ts" import { IscParseError } from "../../src/isc/types.ts" +import type { IscStageItem } from "../../src/isc/types.ts" function minimalWrap(body: string): string { return `system "TEST:test:Latn:Latn:2026" {\n${body}\n}` @@ -438,6 +439,16 @@ describe("parseIsc — items", () => { expect(doc.aliases[0]?.value).toEqual({ type: "string", value: "é" }) }) + it("decodes the capital \\UXXXX escape spelling (WO19 G6 item 4)", () => { + // The gki-bel shape: `sub "\U040E" "Ŭ"` — the former hand parser + // carried the from as the literal text "U040E" and the row never + // fired. Both spellings decode now (ruby/rs always did). + const doc = parseIsc(minimalWrap(`stage main { sub "\\U040E" "Ŭ" }`)) + const rule = doc.stages[0]!.body[0] as Extract + expect(rule.rule.from).toEqual({ type: "string", value: "Ў" }) + expect(rule.rule.to).toEqual({ type: "string", value: "Ŭ" }) + }) + it("parses none", () => { const doc = parseIsc(minimalWrap(`aliases { x = none }`)) expect(doc.aliases[0]?.value).toEqual({ type: "none" }) diff --git a/test/isc/wf1.test.ts b/test/isc/wf1.test.ts index 6d82caf..1aa2078 100644 --- a/test/isc/wf1.test.ts +++ b/test/isc/wf1.test.ts @@ -175,12 +175,21 @@ describe("parseIsc — when guard suffix (W3)", () => { expect(rule.rule.when).toEqual(["kur"]) }) - it("parses the suffix on a block-form rule", () => { - const doc = parseIsc(minimalWrap(`stage main { sub { from "a" to "x" } when kur }`)) + it("parses the guard inside a block-form rule (canonical placement)", () => { + // WO19 G6 item 5: canonical rs binds the when guard inside the + // braces; ruby parses the inside form only. The former ts/py + // outside-form extension (`} when kur`) is retired. + const doc = parseIsc(minimalWrap(`stage main { sub { from "a" to "x" when kur } }`)) const rule = doc.stages[0]!.body[0] as Extract expect(rule.rule.when).toEqual(["kur"]) }) + it("rejects the outside-form when suffix on a block-form rule", () => { + expect(() => + parseIsc(minimalWrap(`stage main { sub { from "a" to "x" } when kur }`)), + ).toThrow(IscParseError) + }) + it("leaves unguarded rules untouched", () => { const doc = parseIsc(minimalWrap(`stage main { parallel { sub "a" "x" } }`)) const rules = doc.stages[0]!.body[0] as Extract From 391522265366032a201498711a0ec59bc2d6a97a Mon Sep 17 00:00:00 2001 From: Ronald Tse Date: Sat, 14 Nov 2026 19:53:25 +0800 Subject: [PATCH 2/2] style: prettier on the regenerated grammar source and the wf1 spec --- src/isc/grammar/grammar-source.ts | 3 ++- test/isc/wf1.test.ts | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/isc/grammar/grammar-source.ts b/src/isc/grammar/grammar-source.ts index 3b7116b..b676c4f 100644 --- a/src/isc/grammar/grammar-source.ts +++ b/src/isc/grammar/grammar-source.ts @@ -17,4 +17,5 @@ export const ISC_PARG_SHA256 = "169596431e066ec762b69ceb5a21383154e97ed7f3630888032e0b7122a1750e" /** 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 — WO19 G6 ruling: the six fn-literal names are reserved\n # words (upcase/downcase/title_case were already here; reverse/strip/\n # swapcase join). A bare fn name is never an alias reference or an\n # alias(...) argument: item-position uses parse as fn_lit (function\n # capture). `downcase = any(...)` still declares an alias NAMED\n # downcase (alias_decl has no keyword guard), matching the ruby\n # concern grammar; the name is simply not reachable via a bare\n # reference. Keyword is used only under negative lookahead, where any\n # matching branch suffices.\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\" / \"reverse\" / \"strip\" / \"swapcase\" / \"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 # WO19 G6 ruling: all six fn-literal names are stage DIRECTIVES.\n # downcase/upcase keep the keywordless bare form; reverse/strip/\n # swapcase join with plain String semantics as the reference (ruby\n # Stdlib::Functions: String#reverse / String#strip / String#swapcase).\n case_directive = ((\"downcase\") / (\"upcase\") / (\"reverse\") / (\"strip\") / (\"swapcase\")) 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 — WO19 G6 ruling: the six fn-literal names are reserved\n # words (upcase/downcase/title_case were already here; reverse/strip/\n # swapcase join). A bare fn name is never an alias reference or an\n # alias(...) argument: item-position uses parse as fn_lit (function\n # capture). `downcase = any(...)` still declares an alias NAMED\n # downcase (alias_decl has no keyword guard), matching the ruby\n # concern grammar; the name is simply not reachable via a bare\n # reference. Keyword is used only under negative lookahead, where any\n # matching branch suffices.\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" / "reverse" / "strip" / "swapcase" / "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 # WO19 G6 ruling: all six fn-literal names are stage DIRECTIVES.\n # downcase/upcase keep the keywordless bare form; reverse/strip/\n # swapcase join with plain String semantics as the reference (ruby\n # Stdlib::Functions: String#reverse / String#strip / String#swapcase).\n case_directive = (("downcase") / ("upcase") / ("reverse") / ("strip") / ("swapcase")) 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/test/isc/wf1.test.ts b/test/isc/wf1.test.ts index 1aa2078..600bad4 100644 --- a/test/isc/wf1.test.ts +++ b/test/isc/wf1.test.ts @@ -185,9 +185,9 @@ describe("parseIsc — when guard suffix (W3)", () => { }) it("rejects the outside-form when suffix on a block-form rule", () => { - expect(() => - parseIsc(minimalWrap(`stage main { sub { from "a" to "x" } when kur }`)), - ).toThrow(IscParseError) + expect(() => parseIsc(minimalWrap(`stage main { sub { from "a" to "x" } when kur }`))).toThrow( + IscParseError, + ) }) it("leaves unguarded rules untouched", () => {