Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Melbourne parser has issues with syntax in 1.9 mode #1614

Closed
rkh opened this Issue · 10 comments

5 participants

@dbussink
Owner

Hmm, it looks to me that 1.9.3 has the same issue:

1.9.3p125 :001 > length - index -1
SyntaxError: (irb):1: syntax error, unexpected tUMINUS_NUM, expecting keyword_do or '{' or '('
length - index -1
                ^
    from /Users/dirkjan/.rvm/rubies/ruby-1.9.3-p125/bin/irb:16:in `'

Or did they fix this in a later patch level?

@rkh
Collaborator

tests pase on p318

@rkh
Collaborator

Ah, wait, this is not leading to a test failure, I have to investigate.

@rkh
Collaborator

OK, so, both 1.9.2-p318 and 1.9.3-p125 are able to load that version of liquid, but do complain if I just run the snippet.

@dbussink
Owner

Oh, fun, so it means that this stuff is context dependent and it's mostly luck that it doesn't fail on MRI then...

@headius

The snipit fails on JRuby too. I tried stuffing in a literal hash, but that doesn't help.

system ~/projects/jruby $ jruby --1.9 -e "{'rindex0' => length - index -1}"
SyntaxError: -e:1: syntax error, unexpected tUMINUS_NUM

{'rindex0' => length - index -1}
                              ^

system ~/projects/jruby $ ruby1.9.2 -e "{'rindex0' => length - index -1}"
-e:1: syntax error, unexpected tUMINUS_NUM, expecting keyword_do or '{' or '('
{'rindex0' => length - index -1}
                              ^

system ~/projects/jruby $ ruby1.9.3 -e "{'rindex0' => length - index -1}"
-e:1: syntax error, unexpected tUMINUS_NUM, expecting keyword_do or '{' or '('
{'rindex0' => length - index -1}
                              ^

system ~/projects/jruby $ ../rubinius/bin/rbx -e "{'rindex0' => length - index -1}"
A syntax error has occurred:
    expecting kDO or '{' or '('
    near line -e:1, column 30

Code:
{'rindex0' => length - index -1}

If it's a bug, I think it's a bug in MRI's parser that it doesn't fail or accept this syntax consistently. In other words, probably nothing for us to do until MRI decides which way they want it to go.

@jaustinhughey

I ran into this issue today with rbx-head installed via rvm. I was receiving errors stating that there was a syntax error in melbourne.rbc line 81 which was just the number 12 :) I had to switch over to MRI for a minute and there I found at least part of the issue for me: I had a block missing an end statement in a controller. Once I fixed that I went back to rbx-head and everything works perfectly fine. So at least in my case, it was -my- fault something was broken, I just couldn't see it until I switched to MRI 1.9.3. Hope this helps the Rubinius project and/or anyone Googling for a similar answer.

@cpuguy83

I believe I had the same/similar issue where:

count = 1
count2 = count -1
NoMethodError: undefined method `count' on an instance of Object

Except Object was the class I was working in.
Fixed by putting a space after the minus.

Would have been nice to get a syntax error here instead of the NoMethodError

@dbussink
Owner

Looks like the parser is confused by block variables:

def method1(length)
  1.times do |i|
    {'rindex0' => length - i -1}
  end
end

def method2(length)
  i = 1
  {'rindex0' => length - i -1}
end

p method1(1)
p method2(2)
@dbussink
Owner

Fixed in 5b80eb4

@dbussink dbussink closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.