Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@ydah
Copy link
Member

@ydah ydah commented May 4, 2024

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
Copy link
Member Author

ydah commented May 6, 2024

@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
result = builder
}
| rhs symbol parameterizing_suffix TAG?
| rhs symbol parameterizing_suffix named_ref_opt TAG?
Copy link
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
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
Copy link
Collaborator

yui-knk commented May 25, 2024

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