1- __precompile__ (true )
1+ """
2+ YAML
23
4+ A package to treat YAML.
5+ https://github.com/JuliaData/YAML.jl
6+
7+ Reading:
8+
9+ * `YAML.load` parses the first YAML document of a YAML file as a Julia object.
10+ * `YAML.load_all` parses the all YAML documents of a YAML file.
11+ * `YAML.load_file` is same with `YAML.load` except it reads from a file.
12+ * `YAML.load_all_file` is same with `YAML.load_all` except it reads from a file.
13+
14+ Writing:
15+
16+ * `YAML.write` prints a Julia object as a YAML file.
17+ * `YAML.write_file` is same with `YAML.write` except it writes to a file.
18+ * `YAML.yaml` converts a given Julia object to a YAML-formatted string.
19+ """
320module YAML
421
522import Base: isempty, length, show, peek
@@ -10,8 +27,14 @@ using Dates
1027using Printf
1128using StringEncodings
1229
30+ include (" queue.jl" )
31+ include (" buffered_input.jl" )
32+ include (" tokens.jl" )
1333include (" scanner.jl" )
34+ include (" events.jl" )
1435include (" parser.jl" )
36+ include (" nodes.jl" )
37+ include (" resolver.jl" )
1538include (" composer.jl" )
1639include (" constructor.jl" )
1740include (" writer.jl" ) # write Julia dictionaries to YAML files
@@ -21,7 +44,7 @@ const _dicttype = Union{Type,Function}
2144
2245# add a dicttype-aware version of construct_mapping to the constructors
2346function _patch_constructors (more_constructors:: _constructor , dicttype:: _dicttype )
24- if more_constructors == nothing
47+ if more_constructors === nothing
2548 more_constructors = Dict {String,Function} ()
2649 else
2750 more_constructors = copy (more_constructors) # do not change the outside world
@@ -35,6 +58,12 @@ function _patch_constructors(more_constructors::_constructor, dicttype::_dicttyp
3558end
3659
3760
61+ """
62+ load(x::Union{AbstractString, IO})
63+
64+ Parse the string or stream `x` as a YAML file, and return the first YAML document as a
65+ Julia object.
66+ """
3867load (ts:: TokenStream , constructor:: Constructor ) =
3968 construct_document (constructor, compose (EventStream (ts)))
4069
@@ -47,6 +76,12 @@ load(ts::TokenStream, more_constructors::_constructor = nothing, multi_construct
4776load (input:: IO , more_constructors:: _constructor = nothing , multi_constructors:: Dict = Dict (); kwargs... ) =
4877 load (TokenStream (input), more_constructors, multi_constructors ; kwargs... )
4978
79+ """
80+ YAMLDocIterator
81+
82+ An iterator type to represent multiple YAML documents. You can retrieve each YAML document
83+ as a Julia object by iterating.
84+ """
5085mutable struct YAMLDocIterator
5186 input:: IO
5287 ts:: TokenStream
@@ -85,6 +120,11 @@ iterate(it::YAMLDocIterator, s) = done(it, s) ? nothing : next(it, s)
85120Base. IteratorSize (:: Type{YAMLDocIterator} ) = Base. SizeUnknown ()
86121Base. IteratorEltype (:: Type{YAMLDocIterator} ) = Base. EltypeUnknown ()
87122
123+ """
124+ load_all(x::Union{AbstractString, IO}) -> YAMLDocIterator
125+
126+ Parse the string or stream `x` as a YAML file, and return corresponding YAML documents.
127+ """
88128load_all (input:: IO , args... ; kwargs... ) =
89129 YAMLDocIterator (input, args... ; kwargs... )
90130
@@ -94,11 +134,21 @@ load(input::AbstractString, args...; kwargs...) =
94134load_all (input:: AbstractString , args... ; kwargs... ) =
95135 load_all (IOBuffer (input), args... ; kwargs... )
96136
137+ """
138+ load_file(filename::AbstractString)
139+
140+ Parse the YAML file `filename`, and return the first YAML document as a Julia object.
141+ """
97142load_file (filename:: AbstractString , args... ; kwargs... ) =
98143 open (filename, " r" ) do input
99144 load (input, args... ; kwargs... )
100145 end
101146
147+ """
148+ load_all_file(filename::AbstractString) -> YAMLDocIterator
149+
150+ Parse the YAML file `filename`, and return corresponding YAML documents.
151+ """
102152load_all_file (filename:: AbstractString , args... ; kwargs... ) =
103153 load_all (open (filename, " r" ), args... ; kwargs... )
104154end # module
0 commit comments