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

Error with safe navigation operator after newline. #240

Closed
6temes opened this issue Jan 6, 2017 · 2 comments
Closed

Error with safe navigation operator after newline. #240

6temes opened this issue Jan 6, 2017 · 2 comments

Comments

@6temes
Copy link

6temes commented Jan 6, 2017

RubyParser fails when there is a newline before the Safe Navigation Operator:

irb(main):005:0>  RubyParser.new.parse "a\n&.b"
Racc::ParseError: (string):2 :: parse error on value "&." (error)
	from /Users/daniel/.rbenv/versions/2.3.1/lib/ruby/2.3.0/racc/parser.rb:528:in `on_error'
	from /Users/daniel/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/ruby_parser-3.8.3/lib/ruby_parser_extras.rb:1227:in `on_error'
	from /Users/daniel/.rbenv/versions/2.3.1/lib/ruby/2.3.0/racc/parser.rb:259:in `_racc_do_parse_c'
	from /Users/daniel/.rbenv/versions/2.3.1/lib/ruby/2.3.0/racc/parser.rb:259:in `do_parse'
	from /Users/daniel/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/ruby_parser-3.8.3/lib/ruby_parser_extras.rb:1139:in `block in process'
	from /Users/daniel/.rbenv/versions/2.3.1/lib/ruby/2.3.0/timeout.rb:91:in `block in timeout'
	from /Users/daniel/.rbenv/versions/2.3.1/lib/ruby/2.3.0/timeout.rb:33:in `block in catch'
	from /Users/daniel/.rbenv/versions/2.3.1/lib/ruby/2.3.0/timeout.rb:33:in `catch'
	from /Users/daniel/.rbenv/versions/2.3.1/lib/ruby/2.3.0/timeout.rb:33:in `catch'
	from /Users/daniel/.rbenv/versions/2.3.1/lib/ruby/2.3.0/timeout.rb:106:in `timeout'
	from /Users/daniel/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/ruby_parser-3.8.3/lib/ruby_parser_extras.rb:1127:in `process'
	from /Users/daniel/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/ruby_parser-3.8.3/lib/ruby_parser_extras.rb:1470:in `block in process'
	from /Users/daniel/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/ruby_parser-3.8.3/lib/ruby_parser_extras.rb:1468:in `each'
	from /Users/daniel/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/ruby_parser-3.8.3/lib/ruby_parser_extras.rb:1468:in `process'
	from (irb):5
	from /Users/daniel/.rbenv/versions/2.3.1/bin/irb:11:in `<main>'
irb(main):006:0>

In contrast, this works:

irb(main):002:0>  RubyParser.new.parse "a.b"
=> s(:call, s(:call, nil, :a), :b)
irb(main):003:0>  RubyParser.new.parse "a&.b"
=> s(:safe_call, s(:call, nil, :a), :b)
irb(main):004:0>  RubyParser.new.parse "a\n.b"
=> s(:call, s(:call, nil, :a), :b)

Ruby version: 2.3.1
RubyParser version: 3.8.3

presidentbeef added a commit to presidentbeef/ruby_parser that referenced this issue Mar 9, 2017
@zenspider
Copy link
Member

For the record, I think that is hideous... But I've merged #245.

@6temes
Copy link
Author

6temes commented Mar 13, 2017

Thanks for merging! And thanks @presidentbeef for the PR.

For the record, I think that is hideous...

You mean, the existence of the safe navigation operator or to put it after a new line?

Either way is valid Ruby.

@seattlerb seattlerb locked and limited conversation to collaborators Jan 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants