Skip to content

Commit

Permalink
- 1.9: Fixed parsing of unary plus on literals. (whitequark)
Browse files Browse the repository at this point in the history
       - 1.9: Fixed lexing of "0o". (whitequark)

[git-p4: depot-paths = "//src/ruby_parser/dev/": change = 8085]
  • Loading branch information
zenspider committed Dec 19, 2012
1 parent 90abb39 commit 1d19aa1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
6 changes: 1 addition & 5 deletions lib/ruby19_parser.y
Expand Up @@ -671,11 +671,7 @@ rule
}
| tUPLUS arg
{
if val[1][0] == :lit then
result = val[1]
else
result = new_call val[1], :"+@"
end
result = new_call val[1], :"+@"
}
| tUMINUS arg
{
Expand Down
7 changes: 5 additions & 2 deletions lib/ruby_lexer.rb
Expand Up @@ -188,7 +188,7 @@ def heredoc_identifier # 51 lines
self.string_buffer = []

case
when src.scan(/(-?)(['"`])(.*?)\2/) then
when src.scan(/(-?)([\'\"\`])(.*?)\2/) then
term = src[2]
func |= STR_FUNC_INDENT unless src[1].empty?
func |= case term
Expand All @@ -200,7 +200,7 @@ def heredoc_identifier # 51 lines
STR_XQUOTE
end
string_buffer << src[3]
when src.scan(/-?(['"`])(?!\1*\Z)/) then
when src.scan(/-?([\'\"\`])(?!\1*\Z)/) then
rb_compile_error "unterminated here document identifier"
when src.scan(/(-?)(\w+)/) then
term = '"'
Expand Down Expand Up @@ -249,6 +249,9 @@ def initialize v = 18

def int_with_base base
rb_compile_error "Invalid numeric format" if src.matched =~ /__/
rb_compile_error "numeric literal without digits" if
ruby19 and src.matched =~ /0o/i

self.yacc_value = src.matched.to_i(base)
return :tINTEGER
end
Expand Down
7 changes: 7 additions & 0 deletions test/test_ruby_parser.rb
Expand Up @@ -1764,4 +1764,11 @@ def test_thingy
rb = "f::(42)"
assert_parse rb, pt
end

def test_unary_plus_on_literal
rb = "+:a"
pt = s(:call, s(:lit, :a), :+@)

assert_parse rb, pt
end
end

0 comments on commit 1d19aa1

Please sign in to comment.