Skip to content

Widen the definable position of parameterizing rules - #420

Merged
ydah merged 1 commit into
ruby:masterfrom
ydah:definable-position-rule
Jun 29, 2024
Merged

Widen the definable position of parameterizing rules#420
ydah merged 1 commit into
ruby:masterfrom
ydah:definable-position-rule

Conversation

@ydah

@ydah ydah commented May 17, 2024

Copy link
Copy Markdown
Member

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

yui-knk commented May 25, 2024

Copy link
Copy Markdown
Collaborator

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

ydah commented Jun 9, 2024

Copy link
Copy Markdown
Member Author

@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 from dbddd7b to cd3f686 Compare June 11, 2024 14:16
@ydah
ydah force-pushed the definable-position-rule branch 2 times, most recently from 84059b4 to 65f739e Compare June 26, 2024 01:33
@ydah

ydah commented Jun 26, 2024

Copy link
Copy Markdown
Member Author

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 force-pushed the definable-position-rule branch from 65f739e to b9c69de Compare June 26, 2024 01:37
@ydah
ydah merged commit a4f89d1 into ruby:master Jun 29, 2024
@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