Commit graph

242 commits

Author SHA1 Message Date
Paul Stemmet 7d90804cc5 ci/github: add matrix targets for test_lazy 2021-09-17 17:03:13 +01:00
Paul Stemmet c977815ddc scalar/block: module documentation updates 2021-09-17 17:03:13 +01:00
Paul Stemmet 9ed1bcc00e scalar/plain: fix subtle slice error in scan_plain_scalar_lazy
When checking for a terminating sequence in plain scalars, we either
need a flow indicator (in flow contexts only), or a ': ' byte sequence,
where the space can be any valid YAML whitespace.

The issue here is that the lazy variant was correctly identifying the
terminating sequence, _but not recording it_ for the Deferred's slice.
This commit fixes that, ensuring we always record the final 1 or 2 bytes
before exiting the main loop.
2021-09-17 17:03:13 +01:00
Paul Stemmet 1cdad01126 scalar/flow: add unit test for escaped double quote 2021-09-17 17:03:13 +01:00
Paul Stemmet 0c38dda908 scalar/flow: fixes to scan_flow_scalar_lazy's chomping
1. Handle linebreaks separately from other characters (for stats)
2. Don't quit early on an escaped double quote (\")
2021-09-17 17:03:13 +01:00
Paul Stemmet 0a4a7930a5 scalar/*/tests: rename TEST_OPTS -> TEST_FLAGS
to remain consistent with scanner/tests, also derive the base TEST_FLAGS
from scanner/tests.TEST_FLAGS, minus options that do not make sense for
the test battery (O_EXTENDABLE)
2021-09-17 17:03:13 +01:00
Paul Stemmet 8d01532b1f Cargo: add feature.test_lazy
For testing the Scanner with O_LAZY active
2021-09-17 17:03:13 +01:00
Paul Stemmet 9c75400697 scanner/tests: update ScanIter to use TEST_FLAGS always 2021-09-17 17:03:13 +01:00
Paul Stemmet f8dc375d14 scanner/tests: add test_flags and const TEST_FLAGS
These additively apply flags according to the controlling feature flag
2021-09-17 17:03:13 +01:00
Paul Stemmet 522d38b665 scanner/context: add Indent.as_usize
This makes explicit what was happening under the hood with the
'cxt.indent() + 0' expression. It also clearly describes the
circumstances in which it is possible to use the function safely
2021-09-17 17:03:13 +01:00
Paul Stemmet 4c63c0c047 scalar/*/tests: refactor shared functions/consts
this will allow us to easily manipulate the TEST_FLAGS for each scalar
type's tests, using a feature.
2021-09-17 17:03:13 +01:00
Paul Stemmet bfdb0d78a7 scalar/block: fix tests 2021-09-17 17:03:13 +01:00
Paul Stemmet 64adcb10b7 scanner/entry: add ScalarB variant to MaybeToken for block scalars 2021-09-17 17:03:13 +01:00
Paul Stemmet 34144344fc scalar/block: add scan_block_scalar_lazy, return MaybeToken 2021-09-17 17:03:13 +01:00
Paul Stemmet fc669a6e92 scalar/plain: fix tests 2021-09-17 17:03:13 +01:00
Paul Stemmet 3e6e04c3b2 scanner/entry: add ScalarP variant to MaybeToken for plain scalars 2021-09-17 17:03:13 +01:00
Paul Stemmet 5786cc159f scalar/plain: add scan_plain_scalar_lazy, return MaybeToken 2021-09-17 17:03:13 +01:00
Paul Stemmet 0f7d65ee7d scalar/flow: fix tests 2021-09-17 17:03:13 +01:00
Paul Stemmet 0268ccf463 scalar/flow: add scan_flow_scalar_lazy, return a MaybeToken
Here we refactor the main functionality of the module into
scan_flow_scalar_eager, with scan_flow_scalar delegating to it
-- or scan_flow_scalar_lazy -- depending on whether O_LAZY is set.
2021-09-17 17:03:13 +01:00
Paul Stemmet 6880c673dd scanner/entry: add MaybeToken wrapper to allow for deferred tokens 2021-09-17 17:03:13 +01:00
Paul Stemmet 6259a31c66 scalar/flow: normalize scan_flow_scalar's return value
It returned a range because of earlier experiments
2021-09-17 17:03:13 +01:00
Paul Stemmet 98f6eb9a86 ci/prtasks: add matrix test for feature.test_buffer_small 2021-09-09 20:29:29 +01:00
Paul Stemmet 68d3de8342 lib/scanner: add feature gated test harness for tokens!
In essence, this allows us to test the Scanner's ability to handle
chunked byte streams, hooking directly into the existing test suite.

It has three levels large, medium and small where large is probably the
smallest buffer size + increment that could be considered reasonable
(4k/64), with the smaller two testing absurd buffers (8/8 and 1/1).
2021-09-09 20:29:29 +01:00
Paul Stemmet 70fea619cb Cargo: dev-dependencies.cfg-if = 1 2021-09-09 20:29:29 +01:00
Paul Stemmet 550bff999b lib/scanner: place state mutation after any O_EXTENDABLE events
this simply prevents state corruption in the Scanner by waiting to make
the changes until _after_ any errors would have been returned.

While this works, its not immediately obvious in the code why the
operations are ordered the way they are. I should document this
probably.
2021-09-09 20:29:29 +01:00
Paul Stemmet 4b79e98048 lib/scanner: save any changes that may occur after a ScanError::Extend
before there was a subtle error when eating whitespace wherein the
whitespace could be eaten twice, which corrupts the Scanner.stats.

Now we ensure that any movement is captured before returning the error
to the caller
2021-09-09 20:29:29 +01:00
Paul Stemmet 3856f69a84 lib/scanner: clippy 2021-09-09 20:29:29 +01:00
Paul Stemmet 5e7f349803 scalar/block: cache! before fetch
also fix call stack in lib/scanner
2021-09-09 20:29:29 +01:00
Paul Stemmet 836716f5a3 scalar/plain: cache! before fetch
also fix the call stack in lib/scanner
2021-09-09 20:29:29 +01:00
Paul Stemmet 1f22f9d609 scanner/anchor: cache! before fetch 2021-09-09 20:29:29 +01:00
Paul Stemmet 564ee1476e scalar/escape: fix tests 2021-09-09 20:29:29 +01:00
Paul Stemmet f1fa8a6620 scalar/flow: cache! before fetch
also fixes the call stack in lib/scanner
2021-09-09 20:29:29 +01:00
Paul Stemmet 13ff795bf3 scanner/tag: cache! before fetch
note that this commit also fixes code that fetch_directive uses
2021-09-09 20:29:29 +01:00
Paul Stemmet 6d82e8b045 scanner/directive: cache! before fetch 2021-09-09 20:29:29 +01:00
Paul Stemmet 86cc5e72d9 lib/scanner: cache! before fetch in scan_next_token 2021-09-09 20:29:29 +01:00
Paul Stemmet 69e202a4cb lib/scanner: add opts to scan_tokens, eat_whitespace cache!
This commit adds initial support for cache!-ing characters in the
Scanner, starting with eat_whitespace.
2021-09-09 20:29:29 +01:00
Paul Stemmet 9b13d54e44 scanner/macros: add cache!
cache! allows the Scanner to state that it requires 'N' more codepoints
before it can correctly process the byte stream.

Its primary purpose is its interaction with O_EXTENDABLE, which allows
the caller to hint to the Scanner that the buffer could grow, likewise
cache! returns an error that hints to the caller that they should extend
the byte stream before calling the Scanner again -- or pass opts without
O_EXTENDABLE.
2021-09-09 20:29:29 +01:00
Paul Stemmet 0663bebd0c scanner/error: add variant Extend
This variant suggests to the caller that they should extend the byte
stream before calling the Scanner again.
2021-09-09 20:29:29 +01:00
Paul Stemmet 0b023bd062 scanner/flag: add Flags for Scanner control
This struct is a C style bitflag container, which controls various
aspects of Scanner functionality.

The initial flags available are O_ZEROED, O_EXTENDABLE and O_LAZY. Read
each's documentation for an explanation.
2021-09-09 20:29:29 +01:00
Paul Stemmet 6147424c30 Cargo: add dependencies.bitflags = 1 2021-09-09 20:29:29 +01:00
Paul Stemmet c1aeb0d3f0 Cargo: dependencies.anyhow -> dev-dependencies.anyhow
anyhow is used for testing, not in library code.
2021-09-07 18:32:26 +01:00
Paul Stemmet da15105e1d lib: prune dead module reader
The code here was from earlier experiments and is not relevant or useful
anymore.
2021-09-07 18:32:26 +01:00
Paul Stemmet 82a6e70d8b lib/scanner: prune dead documentation 2021-09-07 18:18:53 +01:00
Paul Stemmet c24f9ef286 lib/scanner: move Scanner.eat_whitespace out of fetch_* methods
put with the other various "helper" functions
2021-09-07 18:18:53 +01:00
Paul Stemmet 2afc2b2606 lib/scanner: rename Scanner token retrieval methods to fetch_*
This split allows future maintainers (i.e: me) to quickly know whether a
function handles the conversion of bytes into tokens -- scan_* function
family -- or handles updating the Scanner's state -- the fetch_*
function family.

Typically one might thing of the call stack as:

1. a Scanner
2. fetches a token
3. by scanning the byte stream
2021-09-07 18:18:53 +01:00
Paul Stemmet 0f76f9bb08 lib/scanner: move test code into scanner/tests
ScanIter was never supposed to be used outside of tests
2021-09-07 18:18:53 +01:00
Paul Stemmet 633e461f4a scanner/anchor: refactor anchor scanning into its own module
and add scan_anchor which the relevant Scanner method calls to scan the
anchor, bringing it more inline with other scan_* functions
2021-09-07 18:18:53 +01:00
Paul Stemmet 829f5c0e81 lib/scanner: merge crate:: and self:: use statements
Not sure why rustfmt decided to do imports that way, but I prefer a
single block.
2021-09-07 18:18:53 +01:00
Paul Stemmet 4bc2eb5c9f scanner/directive: move directive scanning to a separate module
and refactor out the scanning code into scan_directive which is called
from the relevant Scanner method. This makes directive scanning more
consistent with the other scanning functions
2021-09-07 18:18:53 +01:00
Paul Stemmet 842ed7cacb scanner/stats: move MStats into its own module
and update the various use statements, plus better documentation on the
fields / methods
2021-09-07 18:18:53 +01:00