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/parse_stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ function peek_full_token(stream::ParseStream, n::Integer=1;
end

"""
peek_behind(ps; skip_trivia=true)
peek_behind(ps; skip_trivia=true, skip_parens=true)
peek_behind(ps, pos::ParseStreamPosition)

Return information about a span which was previously inserted into the output,
Expand Down
8 changes: 7 additions & 1 deletion src/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2097,7 +2097,8 @@ function parse_function_signature(ps::ParseState, is_function::Bool)
is_empty_tuple = peek(ps, skip_newlines=true) == K")"
opts = parse_brackets(ps, K")") do _, _, _, _
_parsed_call = was_eventually_call(ps)
_is_anon_func = peek(ps, 2) ∉ KSet"( ." && !_parsed_call
t2 = peek_token(ps, 2)
_is_anon_func = kind(t2) ∉ KSet"( ." && !_parsed_call
return (needs_parameters = _is_anon_func,
is_anon_func = _is_anon_func,
parsed_call = _parsed_call)
Expand Down Expand Up @@ -3178,7 +3179,12 @@ function parse_string(ps::ParseState, raw::Bool)
if k == K"("
# "a $(x + y) b" ==> (string "a " (parens (call-i x + y)) " b")
# "hi$("ho")" ==> (string "hi" (parens (string "ho")))
m = position(ps)
parse_atom(ps)
if peek_behind(ps, skip_parens=false).kind != K"parens"
# "$(x,y)" ==> (string (error (tuple-p x y)))
emit(ps, m, K"error", error="invalid interpolation syntax")
end
elseif k == K"var"
# var identifiers disabled in strings
# "$var" ==> (string var)
Expand Down
2 changes: 2 additions & 0 deletions test/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,8 @@ tests = [
"\"\"\"\n\$x\n a\"\"\"" => "(string-s x \"\\n\" \" a\")"
"\"a \$(x + y) b\"" => "(string \"a \" (parens (call-i x + y)) \" b\")"
"\"hi\$(\"ho\")\"" => "(string \"hi\" (parens (string \"ho\")))"
"\"\$(x,y)\"" => "(string (error (tuple-p x y)))"
"\"\$(x;y)\"" => "(string (error (block-p x y)))"
"\"a \$foo b\"" => "(string \"a \" foo \" b\")"
"\"\$var\"" => "(string var)"
"\"\$outer\"" => "(string outer)"
Expand Down