Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose resolver to load #197

Merged
merged 4 commits into from
Jun 16, 2024
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
9 changes: 6 additions & 3 deletions src/YAML.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,18 @@ function _patch_constructors(more_constructors::_constructor, dicttype::_dicttyp
return more_constructors
end


"""
load(x::Union{AbstractString, IO})

Parse the string or stream `x` as a YAML file, and return the first YAML document as a
Julia object.
"""
load(ts::TokenStream, constructor::Constructor) =
construct_document(constructor, compose(EventStream(ts)))
function load(tokenstream::TokenStream, constructor::Constructor)
resolver = Resolver()
eventstream = EventStream(tokenstream)
node = compose(eventstream, resolver)
construct_document(constructor, node)
end

load(input::IO, constructor::Constructor) =
load(TokenStream(input), constructor)
Expand Down
4 changes: 2 additions & 2 deletions src/composer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ mutable struct Composer
resolver::Resolver
end

function compose(events::EventStream)
composer = Composer(events, Dict{String, Node}(), Resolver())
function compose(events::EventStream, resolver::Resolver)
composer = Composer(events, Dict{String, Node}(), resolver)
@assert forward!(composer.input) isa StreamStartEvent
node = compose_document(composer)
if peek(composer.input) isa StreamEndEvent
Expand Down
Loading