From 2e881bd59e12cb33e868be93af34cb1e2d5475d1 Mon Sep 17 00:00:00 2001 From: drbrain Date: Tue, 18 Dec 2012 07:31:36 +0000 Subject: * lib/rdoc/ruby_lex.rb: Return a TkHEREDOC instead of a TkSTRING when the heredoc identifier is followed by a line-end. This allows proper display of some HEREDOCs in source view. * lib/rdoc/ruby_token.rb: Added TkHEREDOC * test/rdoc/test_rdoc_ruby_lex.rb: Test for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38443 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 ++++++ lib/rdoc/ruby_lex.rb | 24 +++++++++++++++--- lib/rdoc/ruby_token.rb | 1 + test/rdoc/test_rdoc_ruby_lex.rb | 56 +++++++++++++++++++++++++++++++++++++---- 4 files changed, 80 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 906a1cd23e..2332c99727 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Tue Dec 18 16:31:20 2012 Eric Hodel + + * lib/rdoc/ruby_lex.rb: Return a TkHEREDOC instead of a TkSTRING when + the heredoc identifier is followed by a line-end. This allows proper + display of some HEREDOCs in source view. + * lib/rdoc/ruby_token.rb: Added TkHEREDOC + * test/rdoc/test_rdoc_ruby_lex.rb: Test for above. + Tue Dec 18 09:45:14 2012 CHIKANAGA Tomoyuki * vm.c (rb_vm_make_jump_tag_but_local_jump): take care of the case diff --git a/lib/rdoc/ruby_lex.rb b/lib/rdoc/ruby_lex.rb index 313e69ea47..e6e0b41aab 100644 --- a/lib/rdoc/ruby_lex.rb +++ b/lib/rdoc/ruby_lex.rb @@ -982,12 +982,13 @@ class RDoc::RubyLex indent = true end if /['"`]/ =~ ch - lt = ch + user_quote = lt = ch quoted = "" while (c = getc) && c != lt quoted.concat c end else + user_quote = nil lt = '"' quoted = ch.dup while (c = getc) && c =~ /\w/ @@ -1007,8 +1008,17 @@ class RDoc::RubyLex end end + output_heredoc = reserve.join =~ /\A\r?\n\z/ + + if output_heredoc then + doc = '<<' + doc << '-' if indent + doc << "#{user_quote}#{quoted}#{user_quote}\n" + else + doc = '"' + end + @here_header = false - doc = '"' while l = gets l = l.sub(/(:?\r)?\n\z/, "\n") if (indent ? l.strip : l.chomp) == quoted @@ -1016,7 +1026,12 @@ class RDoc::RubyLex end doc << l end - doc << '"' + + if output_heredoc then + doc << l.chomp + else + doc << '"' + end @here_header = true @here_readed.concat reserve @@ -1024,9 +1039,10 @@ class RDoc::RubyLex ungetc ch end + token_class = output_heredoc ? RDoc::RubyLex::TkHEREDOC : Ltype2Token[lt] @ltype = ltback @lex_state = EXPR_END - Token(Ltype2Token[lt], doc) + Token(token_class, doc) end def identify_quotation diff --git a/lib/rdoc/ruby_token.rb b/lib/rdoc/ruby_token.rb index 571ea70404..7878e4c22a 100644 --- a/lib/rdoc/ruby_token.rb +++ b/lib/rdoc/ruby_token.rb @@ -331,6 +331,7 @@ module RDoc::RubyToken [:TkINTEGER, TkVal], [:TkFLOAT, TkVal], [:TkSTRING, TkVal], + [:TkHEREDOC, TkVal], [:TkXSTRING, TkVal], [:TkREGEXP, TkVal], [:TkSYMBOL, TkVal], diff --git a/test/rdoc/test_rdoc_ruby_lex.rb b/test/rdoc/test_rdoc_ruby_lex.rb index dfa350e018..0dcb42565d 100644 --- a/test/rdoc/test_rdoc_ruby_lex.rb +++ b/test/rdoc/test_rdoc_ruby_lex.rb @@ -70,7 +70,8 @@ end @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::TkHEREDOC .new( 8, 2, 2, + %Q{<