diff --git a/interscript-py/src/interscript/grammar/actions.py b/interscript-py/src/interscript/grammar/actions.py index bdc87f8c..6b20a3af 100644 --- a/interscript-py/src/interscript/grammar/actions.py +++ b/interscript-py/src/interscript/grammar/actions.py @@ -241,20 +241,14 @@ def string(self, tree: Tree) -> str: out.append("U") elif "unicode" in h: digits = _text(h["unicode"]) # type: ignore[arg-type] - # DEVIATION (hand-parser parity): the grammar cannot - # distinguish `\uXXXX` from `\UXXXX` at the capture-name - # level (both are :unicode) — but the hand parser only - # DECODED lowercase \u and rendered 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). Mirroring - # the hand parser keeps documents byte-identical across - # the swap. (The ruby artifact parser decodes both - # spellings; aligning runtimes is an owner decision.) - if ord(self._src[h["unicode"].offset - 1]) == 0x55: - out.append("U" + digits) - else: - out.append(chr(int(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 codepoint (ruby/rs always decoded both). + out.append(chr(int(digits, 16))) else: raise ValueError(f"unknown string part {sorted(h.keys())}") return "".join(out) diff --git a/interscript-py/src/interscript/grammar/grammar_source.py b/interscript-py/src/interscript/grammar/grammar_source.py index cd649a55..25d76257 100644 --- a/interscript-py/src/interscript/grammar/grammar_source.py +++ b/interscript-py/src/interscript/grammar/grammar_source.py @@ -4,7 +4,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 Python parser compiles +module embeds it verbatim (sha256 169596431e066ec762b69ceb5a21383154e97ed7f3630888032e0b7122a1750e) so the Python parser compiles the same grammar text the Ruby runtime ships. Update procedure: python scripts/sync_isc_grammar.py @@ -21,7 +21,7 @@ from __future__ import annotations # sha256 of the grammar text embedded below (pin for drift detection). -ISC_PARG_SHA256 = "52949cb3170554071c8085bc5388553fde3d9a7feb590109d4543478d3561bb7" +ISC_PARG_SHA256 = "169596431e066ec762b69ceb5a21383154e97ed7f3630888032e0b7122a1750e" # The grammar text itself, byte-identical to the ruby checkout copy. -ISC_PARG_SOURCE = "# Interscript ISC grammar \u2014 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 \u00a73.2: a `use` directive is a rule-line item \u2014 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" +ISC_PARG_SOURCE = "# Interscript ISC grammar \u2014 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 \u2014 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 \u00a73.2: a `use` directive is a rule-line item \u2014 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" diff --git a/interscript-py/src/interscript/grammar/isc_parser.py b/interscript-py/src/interscript/grammar/isc_parser.py index 214d3aa2..32068f6c 100644 --- a/interscript-py/src/interscript/grammar/isc_parser.py +++ b/interscript-py/src/interscript/grammar/isc_parser.py @@ -12,7 +12,7 @@ Single-sourcing contract: the grammar TEXT embedded in grammar_source.py is the semantic source of truth (synced from interscript-ruby's lib/interscript/isc/grammar/isc.parg via scripts/sync_isc_grammar.py). -The three documented grammar-table extensions below (GRAMMAR_EXTENSIONS) +The two documented grammar-table extensions below (GRAMMAR_EXTENSIONS) restore hand-parser behaviors the canonical .parg rejects — each is spelled in the grammar language, named, and corpus-proven dormant. """ @@ -66,10 +66,10 @@ def compile_grammar() -> CompiledGrammar: grammar = parse_parg(ISC_PARG_SOURCE) rules = dict(grammar.rules) - # Shape-guarded merge: if a future .parg edit renames any of the three - # rules, the merge raises instead of silently misparsing. + # Shape-guarded merge: if a future .parg edit renames any of the + # extension rules, the merge raises instead of silently misparsing. ext = parse_parg(GRAMMAR_EXTENSIONS) - for name in ("any_arg", "block_rule", "run_dep"): + for name in ("any_arg", "run_dep"): if name not in rules or name not in ext.rules: raise RuntimeError( f"grammar extension target {name} missing from isc.parg — " @@ -139,7 +139,6 @@ def _hand_style_failure(source, c, interp, peg_error) -> tuple[str, int]: 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) } """ @@ -148,30 +147,29 @@ def _hand_style_failure(source, c, interp, peg_error) -> tuple[str, int]: # syntax the canonical .parg rejects. Each is spelled in the grammar # language itself and merged into the rule table, so the .parg remains # the only semantic source and every extension is one visible, named -# block (all three are the same extensions the ts generated parser -# ships): +# block (all remaining ones are the same extensions the ts generated +# parser ships): # # 1. `any_arg` — restore the ruby DSL's final `item as :any_item` # fallback (concerns/items.rb any_constructor), which the canonical # .parg dropped; the interscript-rs vendored copy keeps it. # (`any(space)`, `any(space + line_end)` — the ts suite 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 py suite pins -# the outside form (test_isc_parser.py::test_when_suffix_after_block_form). -# 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.…`). # 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 (proven by the corpus parity driver). -# The former fourth extension (`rule_items` accepting `use` inside +# The former third extension (`rule_items` accepting `use` inside # parallel/sequence blocks) was RETIRED by WO18 G5: the canonical .parg # now carries use_directive in rule_line (spec §3.2, mirroring the rs # grammar), so the extension is redundant and its merge-guard slot is # gone. The override block's rule_line accepts `use` rows for free — # the expansion flattens them (isc._Expander._expand_override_rows). +# The former fourth extension (block_rule accepting the `when` guard +# AFTER the closing brace) was RETIRED by WO19 item 5: the canonical +# binding is INSIDE the braces — rs (the golden executor) and the ruby +# DSL reject the outside form outright, and the generated grammar now +# matches them (test_isc_wf1.py::test_when_after_block_brace_rejected). # # Ruby rejects (1)'s absence aside, the outside-when and hyphen-dep # forms are cross-runtime divergences (ruby parses none); aligning diff --git a/interscript-py/src/interscript/grammar/peg.py b/interscript-py/src/interscript/grammar/peg.py index 8bda52ff..6054f32d 100644 --- a/interscript-py/src/interscript/grammar/peg.py +++ b/interscript-py/src/interscript/grammar/peg.py @@ -698,7 +698,14 @@ def rep(pos, I): def c_pred(body, positive): def pred(pos, I): + spans = I.spans + mark = len(spans) r = body(pos, I) + # A lookahead never contributes captures: drop any match + # spans its body recorded, success or failure (WO19: without + # this, a speculative rule re-parse inside a lookahead leaks + # from/to spans and desyncs the action layer's span walk). + del spans[mark:] if r[0] is not positive: return _FAIL return (True, None, pos) @@ -846,6 +853,32 @@ def seq(pos, I): return seq + def c_seq_final_span(children): + # c_seq_final with span rollback: when a child fails, spans any + # EARLIER sibling recorded must be dropped — the sequence never + # happened. (WO19: the bare variant let a failed speculative + # parse leak from/to spans, desyncing the action layer's span + # walk on block rules carrying a `when` guard.) + def seq(pos, I): + spans = I.spans + cur = pos + parts: list = [] + mark = len(spans) + for f, is_raw in children: + r = f(cur, I) + if not r[0]: + if len(spans) != mark: + del spans[mark:] + return _FAIL + if is_raw: + parts.append(flatten(r[1], False)) + else: + parts.append(r[1]) + cur = r[2] + return (True, _flatten_sequence(parts), cur) + + return seq + def c_rep_final(body, body_raw, mn, mx, maybe, named): # The repetition's value is the CanFlatten fold over its # flattened items (named flag: direct capture bodies fold an @@ -881,6 +914,44 @@ def rep(pos, I): return rep + def c_rep_final_span(body, body_raw, mn, mx, maybe, named): + # c_rep_final with span rollback: a failed iteration drops its + # own partial spans; a rep that fails outright (count < mn) drops + # every iteration's spans. (WO19, see c_seq_final_span.) + def rep(pos, I): + spans = I.spans + parts: list = [] + cur = pos + count = 0 + mark = len(spans) + while mx is None or count < mx: + mark_i = len(spans) + r = body(cur, I) + if not r[0]: + if len(spans) != mark_i: + del spans[mark_i:] + break + if body_raw: + parts.append(flatten(r[1], False)) + else: + parts.append(r[1]) + cur = r[2] + count += 1 + if count < mn: + if cur > I.farthest: + I.farthest = cur + if len(spans) != mark: + del spans[mark:] + return _FAIL + if maybe: + first = parts[0] if parts else None + if named or not (first is None or first == ""): + return (True, first, cur) + return (True, "", cur) + return (True, _flatten_repetition(parts, named), cur) + + return rep + def c_cap(body, name, is_span_cap, body_raw): # body_raw: the body's value is a tagged list (a raw-marked rule) # that CanFlatten must resolve, with the named flag, before the @@ -1239,6 +1310,10 @@ def build(node, raw=False, named=False): ranges = _merge_ranges([r for ch in branches for r in ch.ranges]) return c_cc(ranges, _charset_for(ranges)) children = tuple(build(ch, raw, named) for ch in branches) + # WO19: a spanning alternation whose branch fails after a + # later branch's span caps recorded must roll them back. + if node_spanning(node): + return c_alt_span(children) return c_alt(children) if t is Seq: if raw: @@ -1248,6 +1323,8 @@ def build(node, raw=False, named=False): (build(ch, False, False), type(ch) is Ref and ch.name in raw_rules) for ch in node.a ) + if node_spanning(node): + return c_seq_final_span(children) return c_seq_final(children) if t is Rep: body = node.a @@ -1261,6 +1338,7 @@ def build(node, raw=False, named=False): and node.min == 0 and node.max == 1 and type(body) is Ref + and not node_spanning(node) ): wrap = maybe_wrap_of(body.name) if wrap is not None: @@ -1295,6 +1373,10 @@ def build(node, raw=False, named=False): if raw: return c_rep(build(body, True, False), node.min, node.max, node.maybe) body_raw = type(body) is Ref and body.name in raw_rules + if node_spanning(node): + return c_rep_final_span( + build(body, False, False), body_raw, node.min, node.max, node.maybe, named + ) return c_rep_final( build(body, False, False), body_raw, node.min, node.max, node.maybe, named ) diff --git a/interscript-py/src/interscript/isc.py b/interscript-py/src/interscript/isc.py index 8a2e2a8a..32c85e3e 100644 --- a/interscript-py/src/interscript/isc.py +++ b/interscript-py/src/interscript/isc.py @@ -36,13 +36,21 @@ Parser fidelity notes: - The generated parser reproduces the former hand parser's documents - byte-for-byte across the whole maps corpus (434/434 through the + byte-for-byte across the whole maps corpus (432/435 through the py-vs-py parity driver, scripts/parse_parity_py.py), including the §4.2.6 trailing-parallel override join and byte-exact `from_source` override keys. Documented hand-parser quirks the grammar rejects (invalid `\\u` escapes, hyphenated identifiers outside run targets, - multi-digit capture refs, stage-level reverse/strip/swapcase) are - corpus-dormant; see grammar/actions.py for the full deviation list. + multi-digit capture refs) are corpus-dormant; see grammar/actions.py + for the full deviation list. (WO19 G6: stage-level + reverse/strip/swapcase moved from rejected quirk to IMPLEMENTED + directive; the capital `\\UXXXX` escape now decodes, and the + outside-form block-rule `when` extension was retired — canonical rs + binds the guard inside the braces, ruby parses the inside form only.) + The three py-vs-py holdouts (gki-bel, mvd-bel, odni-bel) are the + capital-`\\U` maps: the generated parser decodes the escape (ruby/rs + canon) where the hand parser carried the literal digits — the hand + side is the bug WO19 G6 item 4 fixes. - `languages` is declared once per map; a second declaration is a parse error. `use` may appear in stage bodies, ruleset bodies and inside `parallel`/`sequence` blocks (WO18 G5, spec §3.2): inside a pass block diff --git a/interscript-py/src/interscript/items.py b/interscript-py/src/interscript/items.py index 34de3c16..b2cd4787 100644 --- a/interscript-py/src/interscript/items.py +++ b/interscript-py/src/interscript/items.py @@ -25,6 +25,16 @@ from .errors import MapLogicError from .stdlib import regexp_escape +# WO19 G6: the six fn literals are never from/constraint values — they +# execute only as stage directives or `to` funcalls (FuncallInline). +# ruby raises (canon), rs raises at build; the former alias fallback +# degraded to a misleading "Alias not found". `any_character` is +# NOT in this set: it is the primitive spelled as a function atom +# (rs lowers it to the any_character stdlib alias). +FN_LITERALS = frozenset( + {"upcase", "downcase", "title_case", "reverse", "strip", "swapcase"} +) + @dataclass(frozen=True) class CompiledItem: @@ -96,6 +106,14 @@ def compile_item( if item.name in ALIAS_COMPILED: a = _alias_compiled(item.name) return _compiled(a.re, a.literal) + # WO19 G6 item 2: a fn literal in FROM position is map-logic + # damage — raise the named error instead of the misleading + # "Alias not found". + if item.name in FN_LITERALS: + raise MapLogicError( + f'function literal "{item.name}" in from position ' + "(fn literals are directives or to-funcalls, not from values)" + ) resolved = ctx.resolve_alias(item.name) # WO18 G3 (parity audit): an unresolved alias is map-logic # damage, not an empty matcher. Compiling re="" matched at every diff --git a/interscript-py/src/interscript/stdlib.py b/interscript-py/src/interscript/stdlib.py index 6b44ffbc..c268c857 100644 --- a/interscript-py/src/interscript/stdlib.py +++ b/interscript-py/src/interscript/stdlib.py @@ -194,6 +194,27 @@ def decompose(text: str, opts: dict | None = None) -> str: return unicodedata.normalize("NFD", text) +# Ruby String#strip's character set: null, horizontal tab, line feed, +# vertical tab, form feed, carriage return, space (ASCII set only — +# deliberately NOT python's default Unicode-whitespace strip). +_RUBY_STRIP_SET = "\0\t\n\v\f\r " + + +def reverse(text: str, opts: dict | None = None) -> str: + """Ruby Stdlib::Functions.reverse = String#reverse (WO19 G6).""" + return text[::-1] + + +def strip(text: str, opts: dict | None = None) -> str: + """Ruby Stdlib::Functions.strip = String#strip (WO19 G6).""" + return text.strip(_RUBY_STRIP_SET) + + +def swapcase(text: str, opts: dict | None = None) -> str: + """Ruby Stdlib::Functions.swapcase = String#swapcase (WO19 G6).""" + return text.swapcase() + + class Function(Protocol): def __call__(self, text: str, opts: dict | None = None) -> str: ... @@ -202,6 +223,12 @@ def __call__(self, text: str, opts: dict | None = None) -> str: ... "downcase": downcase, "upcase": upcase, "title_case": title_case, + # WO19 G6: the three new fn literals execute as directives and + # inline to-funcalls with the plain String semantics of ruby + # Stdlib::Functions. + "reverse": reverse, + "strip": strip, + "swapcase": swapcase, "separate": separate, "compose": compose, "decompose": decompose, diff --git a/interscript-py/tests/test_executor.py b/interscript-py/tests/test_executor.py index 4c90e228..0db9f935 100644 --- a/interscript-py/tests/test_executor.py +++ b/interscript-py/tests/test_executor.py @@ -22,6 +22,7 @@ Stage, StringItem, SubRule, + FuncallInline, ) from interscript.errors import AsyncFunctionError, MapLogicError from interscript.executor import execute_stage @@ -281,3 +282,45 @@ def test_repeat_maybe(self): ) m = make_map([stage("main", [rule])]) assert execute_stage(m, "main", "a ab abb") == "X X Xb" + + +class TestWO19G6FnLiterals: + """WO19 G6 — fn-literal alignment (items 1-3).""" + + def test_fn_literal_in_from_raises_named_error(self): + # Item 2: a fn literal in FROM position is map-logic damage — + # ruby raises (canon), rs raises at build; the former alias + # fallback said "Alias downcase not found". + m = make_map([stage("main", [sub(AliasItem(name="downcase"), "X")])]) + with pytest.raises( + MapLogicError, + match='function literal "downcase" in from position', + ): + execute_stage(m, "main", "abc") + + def test_reverse_directive_executes(self): + # Item 3: ruby String#reverse semantics. + m = make_map( + [stage("main", [sub("1", "2"), FuncallRule(name="reverse")])] + ) + assert execute_stage(m, "main", "abc1") == "2cba" + + def test_strip_directive_executes(self): + # Item 3: ruby String#strip semantics (ASCII whitespace + NUL). + m = make_map([stage("main", [FuncallRule(name="strip")])]) + assert execute_stage(m, "main", " x ") == "x" + assert execute_stage(m, "main", "\t y \n") == "y" + + def test_swapcase_directive_executes(self): + # Item 3: ruby String#swapcase semantics. + m = make_map( + [stage("main", [sub("a", "b"), FuncallRule(name="swapcase")])] + ) + assert execute_stage(m, "main", "aBc") == "BbC" + + def test_reverse_inline_to_funcall_executes(self): + # Item 3: a reverse fn literal as a `to` target. + m = make_map( + [stage("main", [SubRule(from_=StringItem(value="abc"), to=FuncallInline(name="reverse"))])] + ) + assert execute_stage(m, "main", "xabcy") == "xcbay" diff --git a/interscript-py/tests/test_isc_parser.py b/interscript-py/tests/test_isc_parser.py index 19dff2da..a1dea5bb 100644 --- a/interscript-py/tests/test_isc_parser.py +++ b/interscript-py/tests/test_isc_parser.py @@ -211,12 +211,41 @@ def test_when_list_does_not_swallow_next_rule(self): rows = [row(r) for r in bare_rules(doc)] assert rows == [("x", "y", ("kur",)), ("z", "w", None)] - def test_when_suffix_after_block_form(self): + def test_when_inside_block_form(self): + # WO19 G6 item 5: canonical rs binds the when guard inside the + # braces; ruby parses the inside form only. The former py/ts + # outside-form extension (`} when kur`) is retired. doc = parse( - 'system "s" { stage main { sub { from "x" to "y" } when kur } }' + 'system "s" { stage main { sub { from "x" to "y" when kur } } }' ) assert row(bare_rules(doc)[0]) == ("x", "y", ("kur",)) + def test_when_suffix_after_block_form_rejected(self): + # WO19 G6 item 5: the outside form is no longer accepted (the + # block_rule extension was retired with the alignment). + with pytest.raises(IscParseError): + parse( + 'system "s" { stage main { sub { from "x" to "y" } when kur } }' + ) + + def test_capital_u_escape_decodes(self): + # 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). + doc = parse('system "s" { stage main { sub "\\U040E" "Ŭ" } }') + assert row(bare_rules(doc)[0]) == ("Ў", "Ŭ", None) + + def test_keyword_alias_declaration_parses(self): + # WO19 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). + doc = parse( + 'system "s" { aliases { downcase = any("a".."z") } stage main { sub "k" "K" } }' + ) + assert row(bare_rules(doc)[0]) == ("k", "K", None) + def test_when_is_not_parsed_as_to(self): # §2: `when` joins the keyword table — `sub "x" when kur` must not # read `when` as the replacement string. diff --git a/interscript-py/tests/test_stdlib.py b/interscript-py/tests/test_stdlib.py index b4e6a1dc..7feaec50 100644 --- a/interscript-py/tests/test_stdlib.py +++ b/interscript-py/tests/test_stdlib.py @@ -154,6 +154,11 @@ def test_registry_has_all_builtins(self): "downcase", "upcase", "title_case", + # WO19 G6: the three new fn literals execute as directives + # and inline to-funcalls (ruby String semantics). + "reverse", + "strip", + "swapcase", "separate", "compose", "decompose", diff --git a/lib/interscript/isc/grammar/isc.parg b/lib/interscript/isc/grammar/isc.parg index 4cb51977..f8959291 100644 --- a/lib/interscript/isc/grammar/isc.parg +++ b/lib/interscript/isc/grammar/isc.parg @@ -28,7 +28,16 @@ grammar InterscriptIsc version "0.1.0" { ident_rest = %x41-5A / %x61-7A / %x30-39 / %x5F identifier = (ident_first 0*ident_rest) as identifier - 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" + # keyword — WO19 G6 ruling: the six fn-literal names are reserved + # words (upcase/downcase/title_case were already here; reverse/strip/ + # swapcase join). A bare fn name is never an alias reference or an + # alias(...) argument: item-position uses parse as fn_lit (function + # capture). `downcase = any(...)` still declares an alias NAMED + # downcase (alias_decl has no keyword guard), matching the ruby + # concern grammar; the name is simply not reachable via a bare + # reference. Keyword is used only under negative lookahead, where any + # matching branch suffices. + 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" # -- string literals ---------------------------------------------------- @@ -164,7 +173,11 @@ grammar InterscriptIsc version "0.1.0" { separator_part = whitespace "separator" whitespace (item_atom as separator) separate_directive = ("separate") as separate [(separator_part)] - case_directive = (("downcase") / ("upcase")) as case + # WO19 G6 ruling: all six fn-literal names are stage DIRECTIVES. + # downcase/upcase keep the keywordless bare form; reverse/strip/ + # swapcase join with plain String semantics as the reference (ruby + # Stdlib::Functions: String#reverse / String#strip / String#swapcase). + case_directive = (("downcase") / ("upcase") / ("reverse") / ("strip") / ("swapcase")) as case case_kwargs_part = whitespace (kwarg_list as case_kwargs) title_case_directive = ("title_case") as case [(case_kwargs_part)] string_case_directive = case_directive / title_case_directive