Skip to content

Commit

Permalink
one less src.pos modification
Browse files Browse the repository at this point in the history
fixed empty =begin/end
[git-p4: depot-paths = "//src/ruby_parser/dev/": change = 5953]
  • Loading branch information
zenspider committed Nov 11, 2010
1 parent 5d832ba commit bc25807
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/ruby_lexer.rb
Expand Up @@ -231,7 +231,7 @@ def int_with_base base
end

def lex_state= o
raise "wtf?" unless Symbol === o
raise "wtf\?" unless Symbol === o
@lex_state = o
end

Expand Down Expand Up @@ -655,7 +655,7 @@ def yylex # 826 lines
self.lineno = nil
c = src.matched
if c == '#' then
src.unread c # ok
src.pos -= 1

while src.scan(/\s*#.*(\n+|\z)/) do
@comments << src.matched.gsub(/^ +#/, '#').gsub(/^ +$/, '')
Expand Down Expand Up @@ -723,7 +723,7 @@ def yylex # 826 lines
self.fix_arg_lex_state
tok = self.yacc_value = src.matched
return TOKENS[tok]
elsif src.was_begin_of_line and src.scan(/\=begin(?=\s)/) then
elsif src.scan(/\=begin(?=\s)/) then
# @comments << '=' << src.matched
@comments << src.matched

Expand Down
9 changes: 9 additions & 0 deletions test/test_ruby_parser.rb
Expand Up @@ -175,6 +175,15 @@ def test_do_bug # TODO: rename
assert_equal pt, @processor.parse(rb)
end

def test_bug_comment_eq_begin
rb = "\n\n#\n=begin\nblah\n=end\n\n"
pt = nil
exp = rb[2..-1]

assert_equal pt, @processor.parse(rb)
assert_equal exp, @processor.lexer.comments
end

def test_dstr_evstr
rb = "\"#\{'a'}#\{b}\""
pt = s(:dstr, "a", s(:evstr, s(:call, nil, :b, s(:arglist))))
Expand Down

0 comments on commit bc25807

Please sign in to comment.