Skip to content
Closed
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
29 changes: 16 additions & 13 deletions src/hooks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,22 @@ end
const _debug_log = Ref{Union{Nothing,IO}}(nothing)

function core_parser_hook(code, filename::String, lineno::Int, offset::Int, options::Symbol)
# TODO: Check that we do all this input wrangling without copying the
# code buffer
if code isa Core.SimpleVector
# The C entry points will pass us this form.
(ptr,len) = code
code = String(unsafe_wrap(Array, ptr, len))
elseif !(code isa String || code isa SubString || code isa Vector{UInt8})
# For non-Base string types, convert to UTF-8 encoding, using an
# invokelatest to avoid world age issues.
code = Base.invokelatest(String, code)::String
end
core_parser_hook(code, filename, lineno, offset, options)
end

function core_parser_hook(code::String, filename::String, lineno::Int, offset::Int, options::Symbol)::Core.SimpleVector
try
# TODO: Check that we do all this input wrangling without copying the
# code buffer
if code isa Core.SimpleVector
# The C entry points will pass us this form.
(ptr,len) = code
code = String(unsafe_wrap(Array, ptr, len))
elseif !(code isa String || code isa SubString || code isa Vector{UInt8})
# For non-Base string types, convert to UTF-8 encoding, using an
# invokelatest to avoid world age issues.
code = Base.invokelatest(String, code)
end
if !isnothing(_debug_log[])
print(_debug_log[], """
#-#-#-------------------------------
Expand Down Expand Up @@ -213,7 +217,7 @@ function core_parser_hook(code, filename::String, lineno::Int, offset::Int, opti
# * appends the error message
topex = Expr(tree)
@assert topex.head == :toplevel
i = findfirst(_has_nested_error, topex.args)
i = findfirst(_has_nested_error, topex.args)::Int
if i > 1 && topex.args[i-1] isa LineNumberNode
i -= 1
end
Expand Down Expand Up @@ -399,4 +403,3 @@ end
# Convenience functions to mirror `JuliaSyntax.parsestmt(Expr, ...)` in simple cases.
fl_parse(::Type{Expr}, args...; kws...) = fl_parse(args...; kws...)
fl_parseall(::Type{Expr}, args...; kws...) = fl_parseall(args...; kws...)

1 change: 1 addition & 0 deletions src/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ let filename = joinpath(@__DIR__, "literal_parsing.jl")
if _has_v1_6_hooks
enable_in_core!()
Meta.parse("1 + 2")
Meta.parse(SubString("1+2"))
enable_in_core!(false)
end
end
Loading