Commit graph

305 commits

Author SHA1 Message Date
Paul Stemmet 76c547717d scanner/error: add From impl for ScanError to public Error 2022-03-27 11:51:02 +01:00
Paul Stemmet 04e07125e6 lib/scanner: make most types crate private 2022-03-27 11:51:02 +01:00
Paul Stemmet 742386b177 lib/reader: hide private types in Read methods
We place a small wrapper around all of the arguments provided to
Read::drive(), and return a wrapped error, both of which are opaque to
external libraries.
2022-03-27 11:51:02 +01:00
Paul Stemmet c2f20d7883 lib: move Slice, ScalarStyle, StreamEncoding enums
from lib/token to event/types, and add Copy derives for ScalarStyle +
StreamEncoding.
2022-03-27 11:51:02 +01:00
Paul Stemmet 51c7529f75 event/parser: use array_iterator() over ArrayIter::new
as the latter has been deprecated in a future Rust version, and is
causing lots of spurious warnings in CI.
2022-03-26 15:49:50 +00:00
Paul Stemmet 4f402ee38e lib/event: use public Error type for returned errors 2022-03-26 15:29:54 +00:00
Paul Stemmet b5fa2acc9e event/error: impl From local error type to public Error 2022-03-26 15:29:54 +00:00
Paul Stemmet 62f9cf53e0 lib/event: ensure private types are private
Including the local error type -- we'll be using that which is provided
in lib/error.
2022-03-26 15:29:54 +00:00
Paul Stemmet 2793e4cc00 lib/event: add error conversion to ErrorKind 2022-03-26 15:29:54 +00:00
Paul Stemmet fe09d7aa27 lib/reader: add top level public API
- from_utf8()
- from_read()
- try_from_bytes()

These cover the major areas we expect a user to use when handing us a
(potential) YAML stream.
2022-03-26 15:29:54 +00:00
Paul Stemmet 4a48ac1735 reader/error: impl From local error type to public Error 2022-03-26 15:29:54 +00:00
Paul Stemmet 46d088fa2d lib/reader: hide local error type 2022-03-26 15:29:54 +00:00
Paul Stemmet 519482f798 lib/reader: add error conversion to ErrorKind 2022-03-26 15:29:54 +00:00
Paul Stemmet fba5f934f5 lib/scanner: add error conversion to ErrorCode 2022-03-26 15:29:54 +00:00
Paul Stemmet a2741447ac lib/scanner: fix visibility of modules
pub -> pub(crate)
2022-03-26 15:29:54 +00:00
Paul Stemmet c8496b0216 lib/error: add mkError! macro
For internal use, handles the conversion chain up to a real external
Error, from other types.
2022-03-26 15:29:54 +00:00
Paul Stemmet ff1925fdd0 lib/error: add library error type for all public APIs
This type obscures the underlying classifications, providing a stable
enum, Category, for classification.

This doesn't particularly change the various module level errors, though
will will have to implement From<Self> for yary::Error.

I'll also need to make private and public versions of the initializer
functions for fallible public methods that can be used internally, e.g
lib/reader.
2022-03-26 15:29:54 +00:00
Paul Stemmet 8d20962640 lib: clippy lints 2022-03-26 15:29:54 +00:00
Paul Stemmet 8ee7b7bff6 docs: fix rustdoc links in lib/scanner & lib/token 2022-03-26 15:29:14 +00:00
Paul Stemmet fa821cbf81 build: add pre-publish fields to Cargo.toml
- readme
- description
- repository
- keywords
- categories

and reorganize field layout, better grouping important fields together.
2022-03-19 10:04:02 +00:00
Paul Stemmet 790b9b55d5 docs: add README, explaining library purpose and status 2022-03-18 15:40:12 +00:00
Paul Stemmet a8230f86f2 lib: stub library documentation 2022-03-18 15:26:45 +00:00
Paul Stemmet ba41069dc6 event/error: document ParseError variants 2022-03-18 15:26:45 +00:00
Paul Stemmet 95eeec30f5 lib: expose reader and event modules 2022-03-18 15:26:45 +00:00
Paul Stemmet 183dbc3b1b lib/event: expose public API for YAML event streams
This commit surfaces a public API for streaming YAML events from a read
source. It provides callers an Events{} type that can be generated from
any reader::Read implementation -- so for the moment, OwnedReader(s) and
BorrowReader(s) -- via the module functions from_reader() and
from_reader_with(). This type implements IntoIterator, and thus can be
integrated with any iterator based flows, and benefits from the entire,
extensive ecosystem around them.

That said, I expect this to be a relatively unused part of this library
in the long term, being the lowest level public API exposed by this
library.
2022-03-18 15:26:45 +00:00
Paul Stemmet 65f990872f event/flag: add public Flags exposed to callers
These define the configuration that library users are allowed to set
when iterating over Events.

It currently only has one meaningful option, O_LAZY which reflects the
behavior exposed by lib/scanner. This will likely change in the future,
if more customization is desired when working with Event streams.
2022-03-18 15:26:45 +00:00
Paul Stemmet 44759d458d event/parser: use relative paths in test macros 2022-03-18 15:26:45 +00:00
Paul Stemmet bdfafc057f event/parser: module doc 2022-03-18 15:26:45 +00:00
Paul Stemmet d2c25e2bd0 lib/event: add module doc
A large portion of this was split out from event/parser's module doc to
coerce git to rename files.
2022-03-18 15:26:45 +00:00
Paul Stemmet 76824e9db7 lib/event: move Parser to lib/event/parser 2022-03-18 15:26:45 +00:00
Paul Stemmet 2e77556dd1 reader: fix visibility of public readers 2022-03-18 15:26:45 +00:00
Paul Stemmet f7d75b836f lib: pin rust version to 1.53
This isn't a hard guarantee, if a new version of Rust offers something
useful, this will be moved with no warnings.
2022-03-18 15:26:45 +00:00
Paul Stemmet d3fd96ea31 ci/github: add MSRV == 1.52
This can be bumped as needed but I'd like to stop checking it myself
2022-01-09 21:45:59 +00:00
Paul Stemmet f288b71f83 ci/github: improve test naming
- Remove unnecessary words from task names
- Add rust version to action name :: [$os/$rustv] $taskname
2022-01-09 21:45:59 +00:00
Paul Stemmet c14ba7829c ci/github: improve toolchain install task
- set default rust version

instead of a folder override, as we always expect to use the provided
version globally per run.

- explicitly declare extra rustup components

rather than implicitly rely on the current defaults
2022-01-09 21:45:59 +00:00
Paul Stemmet 056b9e27be lib/event: add module documentation 2021-12-29 15:07:26 +00:00
Paul Stemmet fcfb870583 lib/event/tests: add Parser tests 2021-12-29 15:07:26 +00:00
Paul Stemmet 2239a884fd event/tests/macros: add tokens!, events!, event!, node!, scalar!
These macros make op the test harness used by module tests. They allow
us to declare a set of tokens! which will be matched against the expected
events! that the tokens should produce.

The others simplify the process of declaring some of the more nested
event structures quickly
2021-12-29 15:07:26 +00:00
Paul Stemmet 2024724d04 lib/event: add handler for YAML nodes
- node

Note that this function must never call any other handlers, so the
Parser remains non-recursive.
2021-12-29 15:07:26 +00:00
Paul Stemmet 5dc521c278 lib/event: add handlers for flow_sequence->mappings
- flow_sequence_entry_mapping_key
- flow_sequence_entry_mapping_value
- flow_sequence_entry_mapping_end

These are special cased due to how some of the implied values can pop
up, and because we need far fewer rules then in the transition from
block_{sequence,mapping}->flow_mapping.
2021-12-29 15:07:26 +00:00
Paul Stemmet 34d893f4b3 lib/event: add handlers for sequences/mappings
- block_sequence_entry
- block_mapping_key
- block_mapping_value
- flow_sequence_entry
- flow_mapping_key
- flow_mapping_value

These were mostly straightforward, only tricky bit is handling all the
cases in which YAML allows a (scalar) node to be "implied".
2021-12-29 15:07:26 +00:00
Paul Stemmet 89c5b2df5e lib/event: add handlers for YAML document state
- document_start
- document_end
- explicit_document_content

Note that we guarantee at least one (DocumentStart, DocumentEnd) event
pair in the event stream, regardless of whether these tokens exist or
not.

We also guarantee that each DocumentStart _will_ have a DocumentEnd
eventually, again regardless of whether such exists in the token stream.

This isn't explicitly required by the YAML spec, but makes usage of the
Parser more pleasant to callers, as all "indentation" events --
documents, sequences, mappings -- have a guaranteed start and end event,
without the caller needing to infer this behavior from the stream
itself.

If the caller is interested, each DocumentStart and DocumentEnd event
records whether it was implicit (missing from the byte stream), or not.
2021-12-29 15:07:26 +00:00
Paul Stemmet d33c7daf4e lib/event: add stream_start, stream_end, empty_scalar handlers 2021-12-29 15:07:26 +00:00
Paul Stemmet 36bf2fef52 lib/event: add state handler skeletons 2021-12-29 15:07:26 +00:00
Paul Stemmet f086975a63 lib/event: add Parser, EventIter skeletons
This commit defines the public API of this module: the Parser. Next
steps are to finish out all of the todo! methods on the StateMachine
branches.
2021-12-29 15:07:26 +00:00
Paul Stemmet 763400291e event/macros: add peek!, pop!, state!, consume!, initEvent!
These macros will be used in the module proper, when operating the event
state machine.
2021-12-29 15:07:26 +00:00
Paul Stemmet 5ddbd93ce7 event/types: add Event, EventData and child structures
The most notable of the types included in this commit is EventData. Its
parent, Event, is a small wrapper with some additional stream information
encoded -- the approximate start and end bytes covered.

EventData has 10 variants:

 1. StreamStart
 2. StreamEnd
 3. DocumentStart
 4. DocumentEnd
 5. Alias
 6. Scalar
 7. MappingStart
 8. MappingEnd
 9. SequenceStart
10. SequenceEnd

Combined, they allow us to express a stream of YAML in an iterative
event model, that should hopefully be easy (at least compared to YAML
proper) to consume.

Expressed in pseudo backus-naur, this is the expected form of any
given event stream:

=== Event Stream ===
stream          := StreamStart document+ StreamEnd
document        := DocumentStart content? DocumentEnd
content         := Scalar | collection
collection      := sequence | mapping
sequence        := SequenceStart node* SequenceEnd
mapping         := MappingStart (node node)* MappingEnd
node            := Alias | content
=== Syntax ===
?               => 0 or 1 of prefix
*               => 0 or more of prefix
+               => 1 or more of prefix
()              => production grouping
|               => production logical OR
=== End ===
2021-12-29 15:07:26 +00:00
Paul Stemmet a21385e92c event/error: add module Error, Result typedef
Plus some From impls for Reader, and Scanner error types.
2021-12-29 15:07:26 +00:00
Paul Stemmet 0f6fb62cb7 event/state: add StateMachine, Flags
This module describes the various states that we can reach in a YAML
Token stream, and provides the machinery for manipulating it.
2021-12-29 15:07:26 +00:00
Paul Stemmet 19f294cb1c lib/event: add module stub
This module will house the first, lowest level public API of this
library, eventually exposing a structure that allows callers to consume
high level YAML 'Events', likely with an Iterator interface.
2021-12-29 15:07:26 +00:00