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

Provide standard library as stdlib.y #344

Merged
merged 9 commits into from
Jan 24, 2024

Conversation

ydah
Copy link
Collaborator

@ydah ydah commented Jan 11, 2024

@ydah ydah force-pushed the provide-standard-library-standardy branch 5 times, most recently from c8dccbc to 2ca1f91 Compare January 12, 2024 15:06
@ydah ydah changed the title [WIP] Provide standard library as standard.y Provide standard library as stdlib.y Jan 12, 2024
@ydah ydah marked this pull request as ready for review January 12, 2024 15:22
stdlib.y Outdated Show resolved Hide resolved
stdlib.y Outdated Show resolved Hide resolved
stdlib.y Outdated Show resolved Hide resolved
stdlib.y Outdated Show resolved Hide resolved
@yui-knk
Copy link
Collaborator

yui-knk commented Jan 13, 2024

I agree to the direction to define standard library in "stdlib.y" file, it makes clear for us what's each standard rule means.
However I have concerns for current design.

standard library by default or not

I think it's better to enable standard library by default. If some rules don't match with user's expectation, user can (or should be able to) overwrite the rule by themselves with writing same name parameterizing rule in their grammar file.

I aslo concern about the location where %include-stdlib can be written is very limited. As a user of parser generator, I don't want to take care of the location of each directive.

My suggestion is to make standard library by default.
In current design, grammar file parse and evaluation are separated. Parser#do_parse parsers grammar file and stores the structure into Grammar instance, Grammar#prepare is the method to instantiate rules. Both of them are called within Parser#parse but it's ok to move @grammar.prepare (and @grammar.validate!) outside Parser#parse.
We can merge the result of "stdlib.y" parse and grammar file parse before before instantiate rules.

The location of "stdlib.y"

"stdlib.y" needs to be included into gem package and https://github.com/ruby/ruby/tree/master/tool/lrama. We can manage both of them by configuring "lrama.gemspec" and changing install script. But I feel it's good to put "stdlib.y" under "lib", e.g. "lib/lrama/grammar/".

@ydah ydah force-pushed the provide-standard-library-standardy branch 2 times, most recently from 2d39c5b to 20aa05d Compare January 16, 2024 16:53
@ydah ydah requested a review from yui-knk January 16, 2024 17:02
@ydah
Copy link
Collaborator Author

ydah commented Jan 16, 2024

Thank you for the review. I agree that it should be enabled by default.
I have indeed made the modifications as I found that if I design it as you suggested, it will not be a problem.

The documentation has also been updated as per the current design.

lib/lrama/grammar/stdlib.y Outdated Show resolved Hide resolved
lib/lrama/grammar/stdlib.y Outdated Show resolved Hide resolved
lib/lrama/grammar/stdlib.y Outdated Show resolved Hide resolved
lib/lrama/option_parser.rb Outdated Show resolved Hide resolved
@yui-knk
Copy link
Collaborator

yui-knk commented Jan 21, 2024

Left some comments, others seems good to me!

@ydah ydah force-pushed the provide-standard-library-standardy branch 2 times, most recently from 5b92f08 to 6786de3 Compare January 22, 2024 02:58
@ydah
Copy link
Collaborator Author

ydah commented Jan 22, 2024

Thank you for the review! I have updated this PR.

@ydah ydah requested a review from yui-knk January 22, 2024 07:39
@ydah ydah force-pushed the provide-standard-library-standardy branch from 6786de3 to 7ac1f17 Compare January 23, 2024 09:30
@ydah
Copy link
Collaborator Author

ydah commented Jan 23, 2024

Thank you for the review! I have updated this PR.

@yui-knk
Copy link
Collaborator

yui-knk commented Jan 24, 2024

Excellent job 💯

@yui-knk yui-knk merged commit c7c9725 into ruby:master Jan 24, 2024
17 checks passed
@ydah ydah deleted the provide-standard-library-standardy branch January 24, 2024 01:47
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