Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Named Reference in parameterizing rules callers #414

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ydah
Copy link
Collaborator

@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
Collaborator 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
@@ -444,17 +444,17 @@ rule
builder.add_rhs(token)
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?

@yui-knk
Copy link
Collaborator

yui-knk commented May 25, 2024

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

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.

None yet

2 participants