lrama icon indicating copy to clipboard operation
lrama copied to clipboard

Add support for Named Reference in parameterizing rules callers

Open ydah opened this issue 1 year ago • 1 comments

This PR add support for Named Reference in parameterizing rules callers.

Motivation

In some cases I wanted to use alias when we defined compstmt as parameterizing rules: https://github.com/ruby/ruby/blob/96710a3139fecda4bc12cd4f321399f71887535c/parse.y#L3263-L3275

| k_END allow_exits '{' compstmt '}' <--- when we want to replace compstmt with parameterizing rules
    {
        if (p->ctxt.in_def) {
            rb_warn0("END in method; use at_exit");
        }
        restore_block_exit(p, $allow_exits);
        p->ctxt = $k_END;
        {
            NODE *scope = NEW_SCOPE2(0 /* tbl */, 0 /* args */, $compstmt /* body */, &@$); <--- For example, it would be nice if parameterizing rules could be accessed as compstmt using alias, even if the name is not compstmt.
            $$ = NEW_POSTEXE(scope, &@$);
        }
    /*% ripper: END!($:compstmt) %*/
    }

ydah avatar May 04 '24 12:05 ydah

This change eliminates the following parsing error: https://github.com/ruby/ruby/pull/10726/files#r1590905311 https://github.com/ruby/ruby/actions/runs/8968514207/job/24628084248?pr=10726

ydah avatar May 06 '24 11:05 ydah

LGTM, let's add test cases and rebase recent master branch.

yui-knk avatar May 25 '24 01:05 yui-knk