A few changes have had to be made to `LoadableYamlNode`:
* The `From<Yaml>` requirement has been removed as it can be
error-prone. It was not a direct conversion as it is unable to
handle `Yaml::Hash` or `Yaml::Array` with a non-empty array/map.
* Instead, `from_bare_yaml` was added, which does essentially the same
as `From` but does not leak for users of the library.
* `with_marker` has been added to populate the marker for the `Node`.
The function is empty for `Yaml`.
`load_from_*` methods have been added to `MarkedYaml` for convenience.
They load YAML using the markers.
The markers returned from `saphyr-parser` are not all correct, meaning
that tests are kind of useless for now as they will fail due to bugs
outside of the scope of this library.
* Make `YamlLoader` generic on the type of the `Node`. This is required
because deeper node need to have annotations too.
* Add a `LoadableYamlNode` trait, required for YAML node types to be
loaded by `YamlLoader`. It contains methods required by `YamlLoader`
during loading.
* Implement `LoadableYamlNode` for `Yaml`.
* Take `load_from_str` out of `YamlLoader` for parsing non-annotated
nodes. This avoids every user to specify the generics in
`YamlLoader::<Yaml>::load_from_str`.
This implements the IndexMut trait for Yaml. This allows indexing the
Yaml type while having a mutable reference.
Unlike the Index, this will panic on a failure. That is allowed as per
the Rust documentation [1]. We don't have the option of returning a
mutable reference to BAD_VALUE as that is unsafe. So instead we just
panic.
1: https://doc.rust-lang.org/std/ops/trait.IndexMut.html#tymethod.index_mut
Resolves: https://github.com/chyh1990/yaml-rust/issues/123
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Co-authored-by: Ethiraric <ethiraric@gmail.com>
Documents are self-contained and tags defined in the first document are not
visible to subsequent documents.
Add support for having tags that span across all documents by making the
clearing of tags in the parser opt-out.
Closes: #10
Also helps in some cases with #142, when the BOM is at the beginning of
the file (common), but not in corner case where the BOM is at the start
of a document which is not the first one.
Closes: #155
This removes all allocations in the `Scanner` code. The downside is that
the buffer is now stored in the `Scanner` structure, making it 48 bytes
larger. This however makes the code much more performant.
`self.buffer` is a `VecDeque<char>`, meaning that characters are stored
on 4B. When reading as we used to do, this means that every 1 byte
character we read was turned into 4 bytes, which was turned into 1 byte
in `String::extend`.
Instead of going through `self.buffer`, use a local `String` to store
the characters before pushing them to `string`.
Instead of doing a loop that goes:
* fetch from input stream
* push char into string
Make a loop that fetches characters while they're not a breakz and
_then_ extend the string. This avoids a bunch of reallocations.
If building release mode, remove debug code. Now, the `debug_print!`
macro resolves to nothing in release build.
In debug build, don't check the environment for each print. This has a
huge overhead. The environment is only checked once and next checks are
made against a simple boolean value.