Permalink
Browse files

+ 1.9: Added leading dot support eg "a\n.b".

[git-p4: depot-paths = "//src/ruby_parser/dev/": change = 7835]
  • Loading branch information...
1 parent 29ecca9 commit 758d298008b1f6c02d3561931538a6b2ded341f2 @zenspider zenspider committed Oct 17, 2012
Showing with 22 additions and 5 deletions.
  1. +8 −5 lib/ruby_lexer.rb
  2. +14 −0 test/test_ruby_parser.rb
View
@@ -688,17 +688,13 @@ def yylex # 826 lines
self.lineno = nil
c = src.matched
if c == '#' then
- # TODO: add magic comment handling?
-
src.pos -= 1
while src.scan(/\s*#.*(\n+|\z)/) do
@comments << src.matched.gsub(/^ +#/, '#').gsub(/^ +$/, '')
end
- if src.eos? then
- return RubyLexer::EOF
- end
+ return RubyLexer::EOF if src.eos?
end
# Replace a string of newlines with a single one
@@ -707,6 +703,13 @@ def yylex # 826 lines
next if in_lex_state?(:expr_beg, :expr_fname, :expr_dot, :expr_class,
:expr_value)
+ if src.scan(/([\ \t\r\f\v]*)\./) then
+ self.space_seen = true unless src[1].empty?
+
+ src.pos -= 1
+ next unless src.check(/\.\./)
+ end
+
self.command_start = true
self.lex_state = :expr_beg
return :tNL
View
@@ -1382,4 +1382,18 @@ def test_i_have_no_freakin_clue
assert_parse rb, pt
end
+
+ def test_motherfuckin_leading_dots
+ rb = "a\n.b"
+ pt = s(:call, s(:call, nil, :a), :b)
+
+ assert_parse rb, pt
+ end
+
+ def test_motherfuckin_leading_dots2
+ rb = "a\n..b"
+ pt = s(:call, s(:call, nil, :a), :b)
+
+ assert_parse_error rb, 'parse error on value ".." (tDOT2)'
+ end
end

0 comments on commit 758d298

Please sign in to comment.