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

Fix an error when str.length is greater than length #477

Merged
merged 1 commit into from
Dec 19, 2024

Conversation

ydah
Copy link
Collaborator

@ydah ydah commented Oct 12, 2024

This PR fix an error when str.length is greater than length.

Reproduced by parse.y below:
https://gist.github.com/ydah/70186de8a1ff14fa2cd16b338b9fc0e0

@yui-knk
Copy link
Collaborator

yui-knk commented Oct 31, 2024

Could you add test case?

This PR fix an error when `str.length` is greater than `length`.
Reproduced by parse.y below:
https://gist.github.com/ydah/70186de8a1ff14fa2cd16b338b9fc0e0
@@ -299,6 +299,92 @@
4: digit '+' digit •
STR
end

context "when the grammar has a long rule name" do
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

memo) Before the modification, the following error occurs:

❯ bundle exec rake
bundle exec racc parser.y --embedded -o lib/lrama/parser.rb -t --log-file=parser.output
/ydah/.rbenv/versions/3.4-dev/bin/ruby -I/ydah/.rbenv/versions/3.4-dev/lib/ruby/gems/3.4.0+1/gems/rspec-core-3.13.1/lib:/ydah/.rbenv/versions/3.4-dev/lib/ruby/gems/3.4.0+1/gems/rspec-support-3.13.1/lib /ydah/.rbenv/versions/3.4-dev/lib/ruby/gems/3.4.0+1/gems/rspec-core-3.13.1/exe/rspec spec/lrama/bitmap_spec.rb spec/lrama/command_spec.rb spec/lrama/context_spec.rb spec/lrama/counterexamples_spec.rb spec/lrama/diagnostics_spec.rb spec/lrama/grammar/code_spec.rb spec/lrama/grammar/rule_builder_spec.rb spec/lrama/grammar/symbol_spec.rb spec/lrama/grammar/symbols/resolver_spec.rb spec/lrama/grammar_validator_spec.rb spec/lrama/integration_spec.rb spec/lrama/lexer/location_spec.rb spec/lrama/lexer/token/user_code_spec.rb spec/lrama/lexer_spec.rb spec/lrama/option_parser_spec.rb spec/lrama/output_spec.rb spec/lrama/parser_spec.rb spec/lrama/states_spec.rb
.............F...................................................................................................................................................................................................................................

Failures:

  1) Lrama::Counterexamples#compute R/R conflicts when the grammar has a long rule name build counterexamples of R/R conflicts
     Failure/Error: str << " " * (length - str.length)
     
     ArgumentError:
       negative argument
     # ./lib/lrama/counterexamples/derivation.rb:47:in 'String#*'
     # ./lib/lrama/counterexamples/derivation.rb:47:in 'Lrama::Counterexamples::Derivation#_render_for_report'
     # ./lib/lrama/counterexamples/derivation.rb:45:in 'Lrama::Counterexamples::Derivation#_render_for_report'
     # ./lib/lrama/counterexamples/derivation.rb:22:in 'Lrama::Counterexamples::Derivation#render_strings_for_report'
     # ./lib/lrama/counterexamples/derivation.rb:27:in 'Lrama::Counterexamples::Derivation#render_for_report'
     # ./spec/lrama/counterexamples_spec.rb:381:in 'block (5 levels) in <top (required)>'

Finished in 11.89 seconds (files took 0.13841 seconds to load)
241 examples, 1 failure

@ydah
Copy link
Collaborator Author

ydah commented Dec 7, 2024

@yui-knk I added a test case that reproduces the error.

@ydah ydah requested a review from yui-knk December 16, 2024 06:24
@ydah ydah merged commit d6946ec into ruby:master Dec 19, 2024
18 checks passed
@ydah ydah deleted the fix-an-error branch December 19, 2024 07:29
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