-
Notifications
You must be signed in to change notification settings - Fork 743
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
ruby: treat % like /: no space after method call = infix #1563
Conversation
This is consistent with what I've tested locally with `ruby -e ...`
This is unfortunately another one of those bizarre cases where ruby's parsing behaviour inexplicably depends on what variables happen to be in scope...?
|
Those examples cleaned up a bit: def x(arr)
arr
end
puts (x %w]reverse])
# => prints "reverse" and x = 1
w = 2
puts (x %w]reverse])
# => syntax error |
A really good read re: the zaniness of ruby's parser: https://whitequark.org/blog/2013/04/01/ruby-hacking-guide-ch-11-finite-state-lexer/ |
/me buckles up |
I FOUND IT BY GOD I FOUND IT https://github.com/ruby/ruby/blob/master/parse.y#L8966 This is the line where Ruby checks what variables are in scope and changes its parsing behaviour. Found by running x=1; puts (x %w]reverse])
# vs
w=1; puts (x %w]reverse]) and diffing the output. |
Anyways, the moral of the story is:
|
The Ruby lexer only treats `%` consistently as the modulo operator if it is followed by whitespace. This is not consistent with Ruby itself which treats this use of `%` as the modulo operator: if board[i/w][i%s] == 'O' region << i end This is a difficult problem to solve because Ruby's parser categorises `%` based on the variables which are in scope (which is not something Rouge can do). This commit improves the handling of `%` by treating it in a similar way to `/`.
This is consistent with what I've tested locally with
ruby -e ...
Fixes #1562
Thanks @0x7ffc for the report!