From fe8a644d96a1bfdb1f7c0accd0182698118daf6b Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Tue, 14 Aug 2018 06:44:44 +0200 Subject: [PATCH] Fix parsing of double CRLF newline. (#791) --- src/Utilities/Utilities.jl | 10 ++++------ test/utilities.jl | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Utilities/Utilities.jl b/src/Utilities/Utilities.jl index f7becebd7a..9a189ed009 100644 --- a/src/Utilities/Utilities.jl +++ b/src/Utilities/Utilities.jl @@ -117,19 +117,17 @@ function parseblock(code::AbstractString, doc, page; skip = 0, keywords = true) # Drop `skip` leading lines from the code block. Needed for deprecated `{docs}` syntax. code = string(code, '\n') code = last(split(code, '\n', limit = skip + 1)) - # Check whether we have windows-style line endings. - offset = occursin("\n\r", code) ? 2 : 1 endofstr = lastindex(code) results = [] cursor = 1 while cursor < endofstr # Check for keywords first since they will throw parse errors if we `parse` them. - line = match(r"^(.+)$"m, SubString(code, cursor)).captures[1] + line = match(r"^(.*)\r?\n"m, SubString(code, cursor)).match keyword = Symbol(strip(line)) (ex, ncursor) = - if keywords && haskey(Docs.keywords, keyword) - # adding offset below should be OK, as `\n` and `\r` are single byte - (QuoteNode(keyword), cursor + lastindex(line) + offset) + # TODO: On 0.7 Symbol("") is in Docs.keywords, remove that check when dropping 0.6 + if keywords && (haskey(Docs.keywords, keyword) || keyword == Symbol("")) + (QuoteNode(keyword), cursor + lastindex(line)) else try Meta.parse(code, cursor) diff --git a/test/utilities.jl b/test/utilities.jl index 903c451f87..b3b4c0883f 100644 --- a/test/utilities.jl +++ b/test/utilities.jl @@ -180,6 +180,20 @@ end @test startswith(output, "println\n[ Info: @info\n┌ Warning: depwarn\n") end end + + @testset "issue #749, #790" begin + let parse(x) = Documenter.Utilities.parseblock(x, nothing, nothing) + for LE in ("\r\n", "\n") + l1, l2, l3 = parse("x = Int[]$(LE)$(LE)push!(x, 1)$(LE)") + @test l1[1] == :(x = Int[]) + @test l1[2] == "x = Int[]$(LE)" + @test l2[1] == QuoteNode(Symbol("")) + @test l2[2] == "$(LE)" + @test l3[1] == :(push!(x, 1)) + @test l3[2] == "push!(x, 1)$(LE)" + end + end + end end end