Permalink
Browse files

Fix parsing bug in non-indented HEREDOCs

  • Loading branch information...
1 parent 1a305f4 commit 528974a5e65ac82d86be1a8f26ac2c2f444e0109 @drbrain drbrain committed Nov 28, 2011
Showing with 30 additions and 3 deletions.
  1. +1 −0 History.rdoc
  2. +1 −0 TODO.rdoc
  3. +2 −2 lib/rdoc/ruby_lex.rb
  4. +26 −1 test/test_rdoc_ruby_lex.rb
View
@@ -8,6 +8,7 @@
* Bug fixes
* Fix title on HTML output for pages.
+ * Fixed parsing of non-indented HEREDOC.
=== 3.11 / 2011/10-17
View
@@ -17,6 +17,7 @@ Forward Looking Statements applies.
* Global variable support
* Page support for ri
* Provide the code_object to directive handlers
+* Add markup parser documentation to DEVELOPERS.rdoc
=== 4
View
@@ -491,7 +491,7 @@ def lex_init()
|op, io|
tk = nil
if @lex_state != EXPR_END && @lex_state != EXPR_CLASS &&
- (@lex_state != EXPR_ARG || @space_seen)
+ (@lex_state != EXPR_ARG || @space_seen)
c = peek(0)
if /\S/ =~ c && (/["'`]/ =~ c || /\w/ =~ c || c == "-")
tk = identify_here_document
@@ -1013,7 +1013,7 @@ def identify_here_document
doc = '"'
while l = gets
l = l.sub(/(:?\r)?\n\z/, "\n")
- if (indent ? l.strip : l) == quoted
+ if (indent ? l.strip : l.chomp) == quoted
break
end
doc << l
View
@@ -30,7 +30,32 @@ def test_class_tokenize
assert_equal expected, tokens
end
- def test_class_tokenize_heredoc
+ def test_class_tokenize_def_heredoc
+ tokens = RDoc::RubyLex.tokenize <<-'RUBY', nil
+def x
+ <<E
+Line 1
+Line 2
+E
+end
+ RUBY
+
+ expected = [
+ @TK::TkDEF .new( 0, 1, 0, 'def'),
+ @TK::TkSPACE .new( 3, 1, 3, ' '),
+ @TK::TkIDENTIFIER.new( 4, 1, 4, 'x'),
+ @TK::TkNL .new( 5, 1, 5, "\n"),
+ @TK::TkSPACE .new( 6, 2, 0, ' '),
+ @TK::TkSTRING .new( 8, 2, 2, %Q{"Line 1\nLine 2\n"}),
+ @TK::TkNL .new(27, 5, 28, "\n"),
+ @TK::TkEND .new(28, 6, 0, 'end'),
+ @TK::TkNL .new(31, 6, 28, "\n"),
+ ]
+
+ assert_equal expected, tokens
+ end
+
+ def test_class_tokenize_heredoc_indent
tokens = RDoc::RubyLex.tokenize <<-'RUBY', nil
string = <<-STRING
Line 1

0 comments on commit 528974a

Please sign in to comment.