Skip to content

Commit

Permalink
Expose resolver to load (#197)
Browse files Browse the repository at this point in the history
* Add type assertions for function arguments in `src/composer.jl`.

* Add missing type annotations.

* Expose resolver to the function `load`. This is required to inform a resolver when loading by users.
  • Loading branch information
Paalon committed Jun 16, 2024
1 parent 41ac452 commit 06b5aed
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
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

0 comments on commit 06b5aed

Please sign in to comment.