Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ function peek_initial_reserved_words(ps::ParseState)
if is_initial_reserved_word(ps, k)
return true
elseif is_contextual_keyword(k)
k2 = peek(ps,2)
k2 = peek(ps, 2, skip_newlines=false)
return (k == K"mutable" && k2 == K"struct") ||
(k == K"primitive" && k2 == K"type") ||
(k == K"abstract" && k2 == K"type")
Expand Down
6 changes: 6 additions & 0 deletions test/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,9 @@ end
parsestmt_test_specs = [
# whitespace before keywords in space-insensitive mode
"(y::\nif x z end)" => "(parens (::-i y (if x (block z))))"
# Contextual keyword pairs inside parentheses
"(abstract type X end)" => "(parens (abstract X))"
"(mutable struct X end)" => "(parens (struct-mut X (block)))"
# parsing of tricky primes
"x in'c'" => "(call-i x in (char 'c'))"
"1where'c'" => "(where 1 (char 'c'))"
Expand All @@ -1001,6 +1004,9 @@ parsestmt_test_specs = [
"|(&\nfunction" => "(call | (& (function (error (error)) (block (error)) (error-t))) (error-t))"
"@(" => "(macrocall (parens (error-t)))"
"x = @(" => "(= x (macrocall (parens (error-t))))"
# Contextual keyword pairs must not be separated by newlines even within parens
"(abstract\ntype X end)" => "(wrapper (parens abstract (error-t type X)) (error-t end ✘))"
"(mutable\nstruct X end)" => "(wrapper (parens mutable (error-t struct X)) (error-t end ✘))"

# The following is currently broken but at least the parser shouldn't
# crash.
Expand Down