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
27 changes: 14 additions & 13 deletions src/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2064,6 +2064,7 @@ end
function parse_function_signature(ps::ParseState, is_function::Bool)
is_anon_func = false
parsed_call = false
needs_parse_call = true

mark = position(ps)
if !is_function
Expand All @@ -2082,29 +2083,28 @@ function parse_function_signature(ps::ParseState, is_function::Bool)
end
else
if peek(ps) != K"("
# function f() end ==> (function (call f))
parse_unary_prefix(ps)
else
# When an initial parenthesis is present, we might either have
# * the function name in parens, followed by (args...)
# * an anonymous function argument list in parens
# * the whole function declaration in parens
#
# This should somewhat parse as in parse_paren() (this is what
# the flisp parser does), but that results in weird parsing of
# keyword parameters. So we peek at a following `(` instead to
# distinguish the cases here.
# When an initial parenthesis is present, we need to distinguish
# between
# * The function name in parens, followed by (args...)
# * An anonymous function argument list in parens
# * The whole function declaration, in parens
bump(ps, TRIVIA_FLAG)
is_empty_tuple = peek(ps, skip_newlines=true) == K")"
opts = parse_brackets(ps, K")") do _, _, _, _
_parsed_call = was_eventually_call(ps)
t2 = peek_token(ps, 2)
_is_anon_func = kind(t2) ∉ KSet"( ." && !_parsed_call
_needs_parse_call = peek(ps, 2) ∈ KSet"( ."
_is_anon_func = !_needs_parse_call && !_parsed_call
return (needs_parameters = _is_anon_func,
is_anon_func = _is_anon_func,
parsed_call = _parsed_call)
parsed_call = _parsed_call,
needs_parse_call = _needs_parse_call)
end
is_anon_func = opts.is_anon_func
parsed_call = opts.parsed_call
needs_parse_call = opts.needs_parse_call
if is_anon_func
# function (x) body end ==> (function (tuple-p x) (block body))
# function (x::f()) end ==> (function (tuple-p (::-i x (call f))) (block))
Expand All @@ -2122,6 +2122,7 @@ function parse_function_signature(ps::ParseState, is_function::Bool)
# function (:)() end ==> (function (call (parens :)) (block))
# function (x::T)() end ==> (function (call (parens (::-i x T))) (block))
# function (::T)() end ==> (function (call (parens (::-pre T))) (block))
# function (:*=(f))() end ==> (function (call (parens (call (quote-: *=) f))) (block))
emit(ps, mark, K"parens", PARENS_FLAG)
end
end
Expand All @@ -2142,7 +2143,7 @@ function parse_function_signature(ps::ParseState, is_function::Bool)
if peek(ps, skip_newlines=true) == K"end" && !is_anon_func && !parsed_call
return false
end
if !is_anon_func && !parsed_call
if needs_parse_call
# Parse function argument list
# function f(x,y) end ==> (function (call f x y) (block))
# function f{T}() end ==> (function (call (curly f T)) (block))
Expand Down
1 change: 1 addition & 0 deletions test/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ tests = [
"function (::g(x))() end" => "(function (call (parens (::-pre (call g x)))) (block))"
"function (f::T{g(i)})() end" => "(function (call (parens (::-i f (curly T (call g i))))) (block))"
"function (::T)() end" => "(function (call (parens (::-pre T))) (block))"
"function (:*=(f))() end" => "(function (call (parens (call (quote-: *=) f))) (block))"
"function begin() end" => "(function (call (error begin)) (block))"
"function f() end" => "(function (call f) (block))"
"function type() end" => "(function (call type) (block))"
Expand Down
4 changes: 2 additions & 2 deletions tools/check_all_packages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ using JuliaSyntax, Logging, TerminalLoggers, ProgressLogging, Serialization
include("../test/test_utils.jl")
include("../test/fuzz_test.jl")

srcpath = isempty(ARGS) ? joinpath(@__DIR__, "pkgs") : ARGS[1]
source_paths = find_source_in_path(srcpath)
srcpaths = isempty(ARGS) ? [joinpath(@__DIR__, "pkgs")] : abspath.(ARGS)
source_paths = vcat(find_source_in_path.(srcpaths)...)

file_count = length(source_paths)

Expand Down