From 0b9dde5ab4db98ff7099707526d54e11b259d72c Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Wed, 30 Nov 2022 22:44:04 +0900 Subject: [PATCH 1/3] Use Tempfile --- lib/rdoc/rd/block_parser.ry | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/rdoc/rd/block_parser.ry b/lib/rdoc/rd/block_parser.ry index 675d437208..9f51efe0f2 100644 --- a/lib/rdoc/rd/block_parser.ry +++ b/lib/rdoc/rd/block_parser.ry @@ -230,8 +230,6 @@ end # :stopdoc: -TMPFILE = ["rdtmp", $$, 0] - MARK_TO_LEVEL = { '=' => 1, '==' => 2, @@ -360,11 +358,10 @@ def next_token # :nodoc: if @tree.filter[@in_part].mode == :rd # if output is RD formatted subtree = parse_subtree(part_out.to_a) else # if output is target formatted - basename = TMPFILE.join('.') - TMPFILE[-1] += 1 - tmpfile = open(@tree.tmp_dir + "/" + basename + ".#{@in_part}", "w") - tmpfile.print(part_out) - tmpfile.close + basename = Tempfile.create(["rdtmp", ".#{@in_part}"], @tree.tmp_dir) do |tmpfile| + tmpfile.print(part_out) + File.basename(tmpfile.path) + end subtree = parse_subtree(["=begin\n", "<<< #{basename}\n", "=end\n"]) end @in_part = nil From fe0159de2f5c6d836755ccde549b87f2f83eae11 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Wed, 30 Nov 2022 22:59:15 +0900 Subject: [PATCH 2/3] Non-RD part feature has not been imported to RDoc --- lib/rdoc/rd/block_parser.ry | 7 +++++++ test/rdoc/test_rdoc_rd_block_parser.rb | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/lib/rdoc/rd/block_parser.ry b/lib/rdoc/rd/block_parser.ry index 9f51efe0f2..7c330f8c5a 100644 --- a/lib/rdoc/rd/block_parser.ry +++ b/lib/rdoc/rd/block_parser.ry @@ -339,15 +339,19 @@ def next_token # :nodoc: # non-RD part begin when /^=begin\s+(\w+)/ part = $1 +=begin # not imported to RDoc if @in_part # if in non-RD part @part_content.push(line) else @in_part = part if @tree.filter[part] # if filter exists # p "BEGIN_PART: #{@in_part}" # DEBUG end +=end + @in_part = part # non-RD part end when /^=end/ if @in_part # if in non-RD part +=begin # not imported to RDoc # p "END_PART: #{@in_part}" # DEBUG # make Part-in object part = RDoc::RD::Part.new(@part_content.join(""), @tree, "r") @@ -366,11 +370,14 @@ def next_token # :nodoc: end @in_part = nil return [:SUBTREE, subtree] +=end end else +=begin # not imported to RDoc if @in_part # if in non-RD part @part_content.push(line) end +=end end end diff --git a/test/rdoc/test_rdoc_rd_block_parser.rb b/test/rdoc/test_rdoc_rd_block_parser.rb index 22f432eaf4..ca0ac9f9e9 100644 --- a/test/rdoc/test_rdoc_rd_block_parser.rb +++ b/test/rdoc/test_rdoc_rd_block_parser.rb @@ -168,6 +168,27 @@ def test_parse_include_subtree tf.close! end +=begin + def test_parse_include_other_format + @block_parser.include_path = [Dir.tmpdir] + + expected = + doc( + blank_line, + para("include ((*worked*))"), + blank_line, + blank_line) + + str = <<~STR + =begin nonrd + <<< worked + =end + STR + + assert_equal(expected, @block_parser.parse str.lines.to_a) + end +=end + def test_parse_heading assert_equal doc(head(1, "H")), parse("= H") assert_equal doc(head(2, "H")), parse("== H") From e1679fa7e4a3951e0e33d9b35e617928ca81af73 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Wed, 30 Nov 2022 23:04:45 +0900 Subject: [PATCH 3/3] Fix `=end` delimiter --- lib/rdoc/rd/block_parser.ry | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rdoc/rd/block_parser.ry b/lib/rdoc/rd/block_parser.ry index 7c330f8c5a..a56a866593 100644 --- a/lib/rdoc/rd/block_parser.ry +++ b/lib/rdoc/rd/block_parser.ry @@ -349,7 +349,7 @@ def next_token # :nodoc: =end @in_part = part # non-RD part end - when /^=end/ + when /^=end(?:$|[\s\0\C-d\C-z])/ if @in_part # if in non-RD part =begin # not imported to RDoc # p "END_PART: #{@in_part}" # DEBUG