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: unexpected token kDO #466

Closed
znz opened this issue Mar 6, 2018 · 10 comments
Closed

error: unexpected token kDO #466

znz opened this issue Mar 6, 2018 · 10 comments
Assignees

Comments

@znz
Copy link

znz commented Mar 6, 2018

I found similar issue at rubocop/rubocop#5573, and I think this is bug of parser instead of rubocop.

% ruby-parse -v
ruby-parse based on parser version 2.5.0.2
% cat test.rb
foo "#{(1+1).to_i}" do
end
% ruby-parse test.rb
warning: parser/current is loading parser/ruby24, which recognizes
warning: 2.4.0-compliant syntax, but you are running 2.4.3.
warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
test.rb:1:21: error: unexpected token kDO
test.rb:1: foo "#{(1+1).to_i}" do
test.rb:1:                     ^~
% ruby-parse _2.4.0.2_ test.rb
warning: parser/current is loading parser/ruby24, which recognizes
warning: 2.4.0-compliant syntax, but you are running 2.4.3.
warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
(block
  (send nil :foo
    (dstr
      (begin
        (send
          (begin
            (send
              (int 1) :+
              (int 1))) :to_i))))
  (args) nil)
@whitequark whitequark assigned iliabylich and unassigned iliabylich Mar 6, 2018
@whitequark
Copy link
Owner

Released 2.5.0.3 that has this fixed.

@znz
Copy link
Author

znz commented Mar 6, 2018

It seems nothing changed.

% ruby-parse -v
ruby-parse based on parser version 2.5.0.3
% ruby-parse test.rb
test.rb:1:21: error: unexpected token kDO
test.rb:1: foo "#{(1+1).to_i}" do
test.rb:1:                     ^~

@whitequark
Copy link
Owner

Works for me:

$ cat test.rb
foo "#{(1+1).to_i}" do
end
$ ./bin/ruby-parse --version
ruby-parse based on parser version 2.5.0.3
$ ./bin/ruby-parse test.rb
(block
  (send nil :foo
    (dstr
      (begin
        (send
          (begin
            (send
              (int 1) :+
              (int 1))) :to_i))))
  (args) nil)

@pocke
Copy link
Collaborator

pocke commented Mar 6, 2018

ruby-parse can parse it in Ruby 2.3, but it cannot parse in newer.

$ ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
$ bin/ruby-parse test.rb
(block
  (send nil :foo
    (dstr
      (begin
        (send
          (begin
            (send
              (int 1) :+
              (int 1))) :to_i))))
  (args) nil)
$ ruby -v
ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-linux]

$ bin/ruby-parse test.rb
test.rb:1:21: error: unexpected token kDO
test.rb:1: foo "#{(1+1).to_i}" do
test.rb:1:                     ^~

@dmarcoux
Copy link

dmarcoux commented Apr 11, 2018

Hi, this issue is still occuring with Ruby 2.5.0 and parser 2.5.0.5. To investigate, please refer to the issue linked just above my comment. You can see in Travis CI's output that parser 2.5.0.5 is really the version installed

Thank you!

@iliabylich
Copy link
Collaborator

I can confirm it, 2.5.0.5 fails, but master branch parses it properly. @whitequark could you cut a release please?

@dmarcoux
Copy link

Is there a way around it for now? I ask as it's blocking a pull request. It's not urgent, I'm simply curious. Thank you for confirming it so quickly.

@iliabylich
Copy link
Collaborator

Yes, 2.5.0.5 cannot parse any code like:

post params: "#{(DateTime.now + 1.day)}"
m(1) do

end

Basically avoid constructions like "#{(expression)}" because they leave garbage in the stack that is used to distinguish kDO and kDO_BLOCK.

So the workaround is to change the code to "#{DateTime.now + 1.day}".

@whitequark
Copy link
Owner

I'll cut a release soon.

@whitequark
Copy link
Owner

2.5.1.0

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

No branches or pull requests

5 participants