diff --git a/src/parse_stream.jl b/src/parse_stream.jl index d21260ba..f37a1f59 100644 --- a/src/parse_stream.jl +++ b/src/parse_stream.jl @@ -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, diff --git a/src/parser.jl b/src/parser.jl index 72fbd1d3..385c0da2 100644 --- a/src/parser.jl +++ b/src/parser.jl @@ -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) @@ -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) diff --git a/test/parser.jl b/test/parser.jl index b6a8d836..a1e71ce4 100644 --- a/test/parser.jl +++ b/test/parser.jl @@ -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)"