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

Widen the definable position of parameterizing rules #420

Merged
merged 1 commit into from
Jun 29, 2024

Conversation

ydah
Copy link
Collaborator

@ydah ydah commented May 17, 2024

We came to this decision after discussion at RubyKaigi 2024. Definitions are also possible in the following positions:

%rule defined_option(X): /* empty */
                       | X
                       ;

%%

program         : defined_option(number) <i>
                | defined_list(number) <i>
                ;

%rule defined_list(X): /* empty */  /* <--- here */
                     | defined_list(X) number
                     ;

@ydah ydah force-pushed the definable-position-rule branch from f358bde to bdeb91f Compare May 22, 2024 11:04
@ydah ydah requested a review from yui-knk May 22, 2024 11:51
@yui-knk
Copy link
Collaborator

yui-knk commented May 25, 2024

I'm wondering which syntax is better for parameterizing rules definitions in grammar part, the part after %%.

Option 1. With %rule

Current syntax then requires %rule even so in grammar part.

Option 2. Without %rule

Like defined_list(X): /* empty */ /* <--- here */ ... in grammar part.

I prefer Option 2 because in bison_declarations part, it's not clear without %rule but in grammar part, it seems verbose to write %rule. Especially, if we treat normal rule as a "function without argument", it's natural for me to not require %rule.
What do you think about it?

@ydah ydah force-pushed the definable-position-rule branch from bdeb91f to dbddd7b Compare June 6, 2024 16:50
@ydah
Copy link
Collaborator Author

ydah commented Jun 9, 2024

@yui-knk I also thought Option2 was the way to go, but there was one annoying problem with Option2.
Since the ; can be omitted in the case of generating rules, there is an SR conflict between the Parameterizing Rules at the end of the RHS and the Parameterizing Rules in the LHS.

The solution seems to be to either change the ; in the generating rules to be non omittable or to make the %rule mandatory.

As a concrete example, the Option 2 correspondence allows us to write the following, so the part shown in the calet is conflicted.

foo(X): bar(X)
        ^^^^^^

bar(Y): baz(Y)
^^^^^^

@ydah ydah force-pushed the definable-position-rule branch 2 times, most recently from 84059b4 to 65f739e Compare June 26, 2024 01:33
@ydah
Copy link
Collaborator Author

ydah commented Jun 26, 2024

On 6/25 (Wed) we discussed it face to face and decided that keeping compatibility was more important. %rule is now mandatory. cc/ @yui-knk @junk0612

We came to this decision after discussion at RubyKaigi 2024.
Definitions are also possible in the following positions:

```
%rule defined_option(X): /* empty */
                       | X
                       ;

%%

program         : defined_option(number) <i>
                | defined_list(number) <i>
                ;

%rule defined_list(X): /* empty */  /* <--- here */
                     | defined_list(X) number
                     ;
```
@ydah ydah merged commit a4f89d1 into ruby:master Jun 29, 2024
16 checks passed
@ydah ydah deleted the definable-position-rule branch June 29, 2024 06:04
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