@@ -24,10 +24,24 @@ struct ToplevelTupleH <: ToplevelItem
2424 lines:: UnitRange{Int}
2525end
2626
27- function toplevelitems (
28- expr, text, # necessary
27+ """
28+ toplevelitems(text; kwargs...)
29+
30+ Returns [`ToplevelItem`](@ref)s in `text`.
31+
32+ keyword arguments:
33+ - `mod::Union{Nothing, String}`: if not `nothing` don't return items within modules
34+ other than `mod`, otherwise enter into every module.
35+ """
36+ function toplevelitems (text; kwargs... )
37+ parsed = CSTParser. parse (text, true )
38+ _toplevelitems (text, parsed; kwargs... )
39+ end
40+
41+ function _toplevelitems (
42+ text, expr,
2943 items:: Vector{ToplevelItem} = Vector {ToplevelItem} (), line = 1 , pos = 1 ;
30- mod:: Union{Nothing, String} = nothing , # if given, don't enter into modules other than `mod`
44+ mod:: Union{Nothing, String} = nothing ,
3145)
3246 # binding
3347 bind = CSTParser. bindingof (expr)
@@ -50,7 +64,7 @@ function toplevelitems(
5064 if shouldenter (expr, mod)
5165 if expr. args != = nothing
5266 for arg in expr. args
53- toplevelitems (arg, text , items, line, pos; mod = mod)
67+ _toplevelitems (text, arg , items, line, pos; mod = mod)
5468 line += countlines (arg, text, pos)
5569 pos += arg. fullspan
5670 end
0 commit comments