Commit 36794530
367945306092Merged
Ryan Seys <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
feat(parse): support implicit it block parameter (Ruby 3.4+)
Numbered block params _1, _2 were already supported through
Prism's NumberedParametersNode + a regular LocalVariableReadNode at
the use site; the codegen has handled them since v1. Implicit it
(Ruby 3.4) was emitted as PM_IT_PARAMETERS_NODE for the parameter
declaration and PM_IT_LOCAL_VARIABLE_READ_NODE for each use, which
the codegen treated as an unknown node and silently ignored.
Fix lowers both at the AST serializer boundary:
PM_IT_PARAMETERS_NODE → NumberedParametersNode { maximum: 1 } PM_IT_LOCAL_VARIABLE_READ_NODE → LocalVariableReadNode { name: "_1" }
This piggybacks on the existing _1 path in get_block_param at
spinel_codegen.rb:23015 — it and _1 produce identical generated
C, which matches Ruby's semantics (they're interchangeable references
to the same implicit parameter).
Test exercises six shapes:
_1ineachandmap+eachchainsitineachandmap+eachchainsitwith arithmetic, comparison, andselectitover a string array
Multi-arg numbered params (_2, _3) destructured from array-of-array
or hash entries remain unsupported — the codegen's block-iteration
path doesn't yet split a single int element into multiple block
slots. Out of scope here.
Bootstrap: gen2.c == gen3.c. Tests: 192 pass.
Details
- Commit
- 367945306092
- Parent
- 02005f26deba
spinel_parse.cmodifiedView file
break; } case PM_IT_PARAMETERS_NODE: N("ItParametersNode"); /* Ruby 3.4 implicit `it` is semantically `_1` — lower to a NumberedParametersNode so the codegen's existing NumberedParametersNode arity path (get_block_param) handles it transparently. The block body's `it` references separately become PM_IT_LOCAL_VARIABLE_READ_NODE, also lowered below. */ N("NumberedParametersNode"); I("maximum", 1); break; case PM_IT_LOCAL_VARIABLE_READ_NODE: /* `it` inside the block body. Lowered to a regular LocalVariableReadNode named "_1" so it pairs with the lowered NumberedParametersNode { maximum: 1 } above. */ N("LocalVariableReadNode"); S("name", escape_str((const uint8_t *)"_1", 2)); break; default: { /* Fallback: emit unknown node type */test/numbered_block_params.rbaddedView file
Loading diff…