Skip to content

Add support for Named Reference in parameterizing rules callers - #414

Merged
yui-knk merged 2 commits into
ruby:masterfrom
ydah:parameterizing-result-meets-named-refs-aliased
May 27, 2024
Merged

Add support for Named Reference in parameterizing rules callers#414
yui-knk merged 2 commits into
ruby:masterfrom
ydah:parameterizing-result-meets-named-refs-aliased

Conversation

@ydah

@ydah ydah commented May 4, 2024

Copy link
Copy Markdown
Member

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

ydah commented May 6, 2024

Copy link
Copy Markdown
Member Author

@ydah
ydah force-pushed the parameterizing-result-meets-named-refs-aliased branch from 2715342 to 5e86b03 Compare May 22, 2024 11:06
@ydah
ydah requested a review from yui-knk May 22, 2024 11:51
Comment thread parser.y
result = builder
}
| rhs symbol parameterizing_suffix TAG?
| rhs symbol parameterizing_suffix named_ref_opt TAG?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add test cases for this patten?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Add test case: effe94a

@yui-knk

yui-knk commented May 25, 2024

Copy link
Copy Markdown
Collaborator

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

@ydah
ydah force-pushed the parameterizing-result-meets-named-refs-aliased branch from 5e86b03 to effe94a Compare May 26, 2024 16:56
@ydah
ydah requested a review from yui-knk May 26, 2024 16:56
@yui-knk
yui-knk merged commit 4a07a4f into ruby:master May 27, 2024
@ydah
ydah deleted the parameterizing-result-meets-named-refs-aliased branch May 27, 2024 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants