Skip to content

Commit 96137ed

Browse files
authored
Better recovery when parsing empty characters (#369)
Consume the trailing ' in empty characters '' for better error recovery when `ignore_errors=true` is set.
1 parent b941fc0 commit 96137ed

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/parser.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3402,6 +3402,7 @@ function parse_atom(ps::ParseState, check_identifiers=true)
34023402
if k == K"'"
34033403
# '' ==> (char (error))
34043404
bump_invisible(ps, K"error", error="empty character literal")
3405+
bump(ps, TRIVIA_FLAG)
34053406
elseif k == K"EndMarker"
34063407
# ' ==> (char (error))
34073408
bump_invisible(ps, K"error", error="unterminated character literal")

test/parser.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -990,15 +990,19 @@ parsestmt_test_specs = [
990990
"x in'c'" => "(call-i x in (char 'c'))"
991991
"1where'c'" => "(where 1 (char 'c'))"
992992
":+'y'" => "(juxtapose (call-post (quote-: +) ') (call-post y '))"
993+
# Empty character consumes trailing ' delimiter (ideally this could be
994+
# tested above but we don't require the input stream to be consumed in the
995+
# unit tests there.
996+
"''" => "(char (error))"
993997

994998
# The following may not be ideal error recovery! But at least the parser
995999
# shouldn't crash
9961000
"@(x y)" => "(macrocall (parens @x (error-t y)))"
9971001
"|(&\nfunction" => "(call | (& (function (error (error)) (block (error)) (error-t))) (error-t))"
9981002

999-
# The following are currently broken but at least the parser shouldn't
1003+
# The following is currently broken but at least the parser shouldn't
10001004
# crash.
1001-
"x in' '" => "(wrapper (call-i x in (char (error))) (error-t '))"
1005+
"x in' '" => "(call-i x in (char (error)))"
10021006
]
10031007

10041008
@testset "Parser does not crash on broken code" begin

0 commit comments

Comments
 (0)