Skip to content

Commit b2baf00

Browse files
committed
Add definitions for internal TOML methods in Base
Despite being internal, these interfaces are used in a number of places downstream, so it's best for TOML's parser type to have their interface defined.
1 parent 085cea0 commit b2baf00

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

stdlib/TOML/src/TOML.jl

+18-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module Internals
2525
end
2626

2727
# https://github.com/JuliaLang/julia/issues/36605
28-
readstring(f::AbstractString) = isfile(f) ? read(f, String) : error(repr(f), ": No such file")
28+
_readstring(f::AbstractString) = isfile(f) ? read(f, String) : error(repr(f), ": No such file")
2929

3030
"""
3131
Parser()
@@ -55,9 +55,9 @@ Parse file `f` and return the resulting table (dictionary). Throw a
5555
See also [`TOML.tryparsefile`](@ref).
5656
"""
5757
parsefile(f::AbstractString) =
58-
Internals.parse(Internals.Parser{Dates}(readstring(f); filepath=abspath(f)))
58+
Internals.parse(Internals.Parser{Dates}(_readstring(f); filepath=abspath(f)))
5959
parsefile(p::Parser, f::AbstractString) =
60-
Internals.parse(Internals.reinit!(p._p, readstring(f); filepath=abspath(f)))
60+
Internals.parse(Internals.reinit!(p._p, _readstring(f); filepath=abspath(f)))
6161

6262
"""
6363
tryparsefile(f::AbstractString)
@@ -69,9 +69,9 @@ Parse file `f` and return the resulting table (dictionary). Return a
6969
See also [`TOML.parsefile`](@ref).
7070
"""
7171
tryparsefile(f::AbstractString) =
72-
Internals.tryparse(Internals.Parser{Dates}(readstring(f); filepath=abspath(f)))
72+
Internals.tryparse(Internals.Parser{Dates}(_readstring(f); filepath=abspath(f)))
7373
tryparsefile(p::Parser, f::AbstractString) =
74-
Internals.tryparse(Internals.reinit!(p._p, readstring(f); filepath=abspath(f)))
74+
Internals.tryparse(Internals.reinit!(p._p, _readstring(f); filepath=abspath(f)))
7575

7676
"""
7777
parse(x::Union{AbstractString, IO})
@@ -135,4 +135,17 @@ supported type.
135135
"""
136136
const print = Internals.Printer.print
137137

138+
public Parser, parsefile, tryparsefile, parse, tryparse, ParserError, print
139+
140+
# These methods are private Base interfaces, but we do our best to support them over
141+
# the TOML stdlib types anyway to minimize downstream breakage.
142+
Base.TOMLCache(p::Parser) = Base.TOMLCache(p._p, Dict{String, Base.CachedTOMLDict}())
143+
Base.TOMLCache(p::Parser, d::Base.CachedTOMLDict) = Base.TOMLCache(p._p, d)
144+
Base.TOMLCache(p::Parser, d::Dict{String, Dict{String, Any}}) = Base.TOMLCache(p._p, d)
145+
146+
Internals.reinit!(p::Parser, str::String; filepath::Union{Nothing, String}=nothing) =
147+
Internals.reinit!(p._p, str; filepath)
148+
Internals.parse(p::Parser) = Internals.parse(p._p)
149+
Internals.tryparse(p::Parser) = Internals.tryparse(p._p)
150+
138151
end

0 commit comments

Comments
 (0)