Skip to content

Commit 3621603

Browse files
authored
Fix SyntaxNode->Expr conversions of unterminated cmd strings (#367)
1 parent ca2b8e3 commit 3621603

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

src/expr.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,9 @@ function _string_to_Expr(k, args)
138138
# If there's a single string remaining after joining, we unwrap
139139
# to give a string literal.
140140
# """\n a\n b""" ==> "a\nb"
141-
# k == K"cmdstring" follows this branch
142141
return only(args2)
143142
else
144-
@check k == K"string"
143+
# This only happens when k == K"string" or when an error has occurred.
145144
return Expr(:string, args2...)
146145
end
147146
end

src/parser.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,8 @@ end
349349
# Parser
350350
#
351351
# The definitions and top-level comments here were copied to match the
352-
# structure of Julia's official flisp-based parser.
353-
#
354-
# This is to make both codebases mutually understandable and make porting
355-
# changes simple.
352+
# structure of Julia's previous flisp-based parser to make both codebases
353+
# mutually understandable and make porting changes simple.
356354
#
357355
# The `parse_*` functions are listed here roughly in order of increasing
358356
# precedence (lowest to highest binding power). A few helper functions are

test/expr.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,13 @@
286286
"a\nb")
287287
@test parsestmt("\"\"\"\n a\n \$x\n b\n c\"\"\"") ==
288288
Expr(:string, "a\n", :x, "\nb\nc")
289+
# Incomplete cases
290+
@test parsestmt("`x", ignore_errors=true) ==
291+
Expr(:macrocall, GlobalRef(Core, Symbol("@cmd")), LineNumberNode(1),
292+
Expr(:string, "x", Expr(:error)))
293+
@test parsestmt("`", ignore_errors=true) ==
294+
Expr(:macrocall, GlobalRef(Core, Symbol("@cmd")), LineNumberNode(1),
295+
Expr(:string, Expr(:error)))
289296
end
290297

291298
@testset "Char conversions" begin

0 commit comments

Comments
 (0)