Skip to content

Commit ee771f8

Browse files
authored
Fix @ doc parsing for triple strings with trailing whitespace trivia (#13)
1 parent cc660d1 commit ee771f8

File tree

4 files changed

+6
-2
lines changed

4 files changed

+6
-2
lines changed

src/parse_stream.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ function peek_behind(stream::ParseStream; skip_trivia::Bool=true)
341341
if skip_trivia
342342
for i = length(stream.ranges):-1:1
343343
r = stream.ranges[i]
344-
if !is_trivia(head(r))
344+
if !is_trivia(head(r)) && kind(r) != K"TOMBSTONE"
345345
return _peek_behind_fields(stream.ranges, i)
346346
end
347347
end

src/parser.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,8 @@ function parse_docstring(ps::ParseState, down=parse_eq)
501501
else
502502
# "doc" foo ==> (macrocall core_@doc "doc" foo)
503503
# "doc $x" foo ==> (macrocall core_@doc (string "doc " x) foo)
504+
# Allow docstrings with embedded trailing whitespace trivia
505+
# """\n doc\n """ foo ==> (macrocall core_@doc "doc\n" foo)
504506
end
505507
if is_doc
506508
reset_node!(ps, atdoc_mark, kind=K"core_@doc")

test/parser.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,8 @@ tests = [
721721
""" "doc" \n foo """ => """(macrocall :(Core.var"@doc") "doc" foo)"""
722722
""" "doc" foo """ => """(macrocall :(Core.var"@doc") "doc" foo)"""
723723
""" "doc \$x" foo """ => """(macrocall :(Core.var"@doc") (string "doc " x) foo)"""
724+
# Allow docstrings with embedded trailing whitespace trivia
725+
"\"\"\"\n doc\n \"\"\" foo" => """(macrocall :(Core.var"@doc") "doc\\n" foo)"""
724726
],
725727
]
726728

test/test_utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ function itest_parse(production, code; version::VersionNumber=v"1.6")
236236
println("------------------------------------")
237237
dump(f_ex)
238238
end
239-
return (ex, f_ex)
239+
# return (ex, f_ex)
240240
# return (code, stream, t, s, ex)
241241
end
242242
nothing

0 commit comments

Comments
 (0)