Commit graph

908 commits

Author SHA1 Message Date
Ethiraric
7275141203 Add run_bench to Cargo.toml. 2024-07-14 17:01:44 +02:00
Ethiraric
93b7e55bcf Move scanning low-level functions to Input. 2024-07-14 17:01:44 +02:00
Ethiraric
696ca59a16 Move next_can_be_plain_scalar to Input trait. 2024-07-14 17:01:44 +02:00
Ethiraric
8d7c3a1c1b Move skip_ws_to_eol to Input trait. 2024-07-14 17:01:44 +02:00
Ethiraric
db4f26da42 Add StrInput. 2024-07-14 17:01:44 +02:00
Ethiraric
0e9cee18f2 Move buffered_input to an input module. 2024-07-14 17:01:44 +02:00
Ethiraric
65fcb6fde3 Move next_can_be_plain_scalar as free fn.
This is, for some reason, a huge pessimization. `rustc` fails to
optimize it as well as it did when it was part of `Scanner`.

This is however kinda needed if I want to avoid having this code
duplicated in every implementation of the input.
2024-07-14 17:01:44 +02:00
Ethiraric
986c45a8b4 Add custom commands I don't want to forget. 2024-07-14 17:01:44 +02:00
Ethiraric
693cc19042 Avoid too many lookaheads in scan_plain_scalar. 2024-07-14 17:00:10 +02:00
Ethiraric
d27bae9fa5 Fix debug_prints in release mode. 2024-07-14 17:00:10 +02:00
Ethiraric
93a35ab6f7 Move document indicator detection to Input. 2024-07-14 17:00:10 +02:00
Ethiraric
afa1b2319f Remove 1 line wrappers. 2024-07-14 17:00:08 +02:00
Ethiraric
f8b6d849d3 Performance improvement.
The refactoring added `next_is` which takes a `&str` as parameter, while
we only use it with strings of lengths 2 and 3. Replacing this by 2
dedicated methods (which can be added to the trait interface and only
specialized if needed) removes almost all the overhead that was added by
`Input`.
2024-07-14 16:59:10 +02:00
Ethiraric
d9bb7a1693 Add Input interface.
Hiding character fetching behind this interface allows us to create more
specific implementations when is appropriate. For instance, an instance
of `Input` can be created for a `&str`, allowing for borrowing and more
efficient peeking and traversing than if we were to fetch characters one
at a time and placing them into a temporary buffer.
2024-07-14 16:59:09 +02:00
Ethiraric
11cffc6df8 Fix issue with deeply indented block scalars.
Fixes #2
2024-07-14 16:57:26 +02:00
Chris Gunn
1fc46923ef Fix multiline string emit.
Use `|-` instead of `|` when there is not a trailing newline
in the string value.
2024-07-09 16:27:58 +02:00
Ethiraric
d582b0fec9 Refactor to remove unnecessary unwrap. 2024-07-03 00:55:41 +02:00
Ethiraric
23c0b3c547 Move load_from_* functions in Yaml.
This would make more sense in user code:
```rs
Yaml::load_from_str("foo"); // Explicit that we're parsing YAML
load_from_str("foo"); // Too implicit, too generic, may be from another
                         lib
```

Plus, this mirrors `MarkedYaml`'s behavior.
2024-07-03 00:55:41 +02:00
Ethiraric
842d536cb0 Implement LoadableYamlNode for MarkedYaml.
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.
2024-07-03 00:55:41 +02:00
Ethiraric
9ab8dd7c07 Update doccomments. 2024-07-03 00:55:41 +02:00
Ethiraric
d2caaf2ab3 Prepare the ground for annotated parsing.
* 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`.
2024-07-03 00:55:41 +02:00
Ethiraric
425f00ceb8 Add base support for annotated YAML objects. 2024-07-03 00:55:41 +02:00
Ethiraric
750c992121 Add support for nested implicit flow mappings.
These are corner cases not tested by the `yaml-test-suite`.
Parsing for the reported input has been fixed, as well as other
similar-looking inputs which make use of nested implicit flow mappings
and implicit null keys and values.

Fixes #1.
2024-07-02 01:56:34 +02:00
Ethiraric
60f8919565 v0.0.2 2024-06-13 22:18:27 +02:00
Ethiraric
f8f6281e41 Add Marker::default and pub to new. 2024-06-13 22:17:54 +02:00
Ethiraric
c3d83fbfe1 Fix warnings. 2024-06-13 22:05:43 +02:00
Ethiraric
2b8eb3f62b Split yaml.rs into sizeable files. 2024-06-10 20:28:13 +02:00
Ethiraric
777fdaa17d Add time_parse binary to Cargo.toml. 2024-04-16 17:31:06 +02:00
Ethiraric
9ee2d113bc Fix error with comments after tags. 2024-04-16 12:03:42 +02:00
David Aguilar
976007017d garden: yaml-rust2 -> saphyr 2024-04-08 23:37:22 -07:00
Ethiraric
cbba46fa72 Have ScanError::new take a String.
Internally, `ScanError` stores a `String`. Having `new` take a `&str`
misleadingly indicates that it stores a `&str`. This commit changes
`new` so that it takes a `String`, and adds a convenience method,
`new_str` that takes a `&str` and allocates a `String` for it.
2024-04-07 02:04:45 +02:00
Ethiraric
3b1dee5ef7 Remove deprecated method implementations of Error. 2024-04-07 02:01:26 +02:00
maddymakesgames
5b3fa958b8 add Error and Display impls for LoadError 2024-04-07 01:52:24 +02:00
Ethiraric
8967f050f7 Convert to standalone repository. 2024-04-03 20:25:59 +02:00
Ethiraric
bdcf7f48f9 Remove yaml-rust2 dependency from tests. 2024-04-02 23:08:39 +02:00
Ethiraric
737f9d0ab1 Improve Parser's next() option handling. 2024-04-02 23:06:15 +02:00
Ethiraric
40670f3c48 Minor improvements. 2024-04-02 23:06:08 +02:00
Ethiraric
3365ccadb6 Readability improvement in tag handling. 2024-04-02 23:00:33 +02:00
Ethiraric
30b713d7a7 yaml-rust2 -> saphyr 2024-04-02 18:49:52 +02:00
Ethiraric
6b01b554e0 yaml-rust2 -> saphyr-parser
* Drop non-parser files
* Rename everything
* Fix tests
* Start rewriting a bit of docs
2024-04-02 17:14:06 +02:00
Ethiraric
d618d06061 Messed up the MSRV. 2024-03-30 19:39:53 +01:00
Ethiraric
787403daa1 Messed up the MSRV. 2024-03-30 19:39:53 +01:00
Ethiraric
f166970a3e Use cargo features. 2024-03-30 19:24:54 +01:00
Ethiraric
c90c1ed1fb Use cargo features. 2024-03-30 19:24:54 +01:00
Alistair Francis
0f1dedc584 yaml: Implement IndexMut
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>
2024-03-30 18:52:39 +01:00
Alistair Francis
1fb76ae745 yaml: Implement IndexMut
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>
2024-03-30 18:52:39 +01:00
Ethiraric
2642252f7f Add doc checks to before_commit. 2024-03-28 21:06:32 +01:00
Ethiraric
bf2aaf8044 Add doc checks to before_commit. 2024-03-28 21:06:32 +01:00
Ethiraric
bb3cc83120 Add doc checks to before_commit. 2024-03-28 21:03:14 +01:00
David Aguilar
2dc9e2c13f maint: version-up and minimize where we mention the version
Remove the version number from tools/gen_large_yaml so that we
can avoid needing to update the version in two places.
2024-03-25 22:25:46 -07:00