Commit graph

84 commits

Author SHA1 Message Date
Paul Stemmet cb6d64dfc7 lib/scanner: add MStats
A struct for doing book keeping about where we are in the buffer:

1. How much we've read
2. How many lines we've seen
3. The current column

I'll likely add variants to advance!, as its the primary method used to
traverse the buffer

This will likely be passed as an extra argument down the various scan
call stacks, and care will need to be taken to ensure we're handling
line breaks correctly (because I bet we're not currently)

Tests will need to be updated to test that we're getting the stats we
expect.
2021-06-29 23:14:30 +01:00
Paul Stemmet 8be1ca8329 lib/scanner: fix tokens! ScanIter lifetimes 2021-06-29 23:14:30 +01:00
Paul Stemmet af8b18c781 lib/scanner: clippy lints 2021-06-29 16:01:11 +01:00
Paul Stemmet 5eb1e739c0 lib/scanner: add unit tests for tag + flow scalar scanning
and fix two tests relating to Scanner.eat_whitespace
2021-06-29 16:01:11 +01:00
Paul Stemmet 13d7091939 lib/scanner: add flow scalar to next_token
both double and single quoted variants
2021-06-29 16:01:11 +01:00
Paul Stemmet 26cd16403b lib/scanner: add tag scan to next_token
An unfortunate glitch in the compiler requires that I use a match
statement over fall through if guards, as the borrow checker is to
restrictive, and will not allow the code to compile despite being
clearly correct.

This required me to lift the stream checks into next_token, which means
we now have a redundant check.  Hopefully in the future the borrow
checker will become smarter.

This commit also refactors stream checks to use a const identifier shared
between the call site in next_token and the function proper, and misc
changes to Scanner.eat_whitespace
2021-06-29 16:01:11 +01:00
Paul Stemmet e5dda1467d scalar/flow: make scan_flow_scalar public in lib/scanner 2021-06-29 16:01:11 +01:00
Paul Stemmet 2654799739 lib/scanner: refactor tag directive scan to use scan_tag_directive 2021-06-29 16:01:11 +01:00
Paul Stemmet 09fc128545 scanner/tag: add scan_tag_directive, scan_node_tag
For scanning %TAG directive handle/prefixes and node !!tag
handle/suffixes.
2021-06-29 16:01:11 +01:00
Paul Stemmet 1f2f9b507e scanner/error: add InvalidTagSuffix variant 2021-06-29 16:01:11 +01:00
Paul Stemmet 07fda2c8a2 lib/scanner: refactor eat_whitespace into a free function
As we'll be using it throughout the various scanner/* modules, not just
on the scanner struct itself.

This commit also improves eat_whitespace to chomp any valid YAML
whitespace, not just newlines and spaces.
2021-06-29 16:01:11 +01:00
Paul Stemmet 9db21c0e23 scanner/macros: add advance! @line variant
for chomping a YAML line break
2021-06-29 16:01:11 +01:00
Paul Stemmet 157040bff0 lib/scanner: refactor tag directive scanner to use scanner/tag functions
This change to is made to allow reuse of the underlying functions
between tag directive and node tag scanning.
2021-06-29 16:01:11 +01:00
Paul Stemmet f14a843549 scanner/tag: add scan_tag_uri, scan_tag_handle
Split out tag scanning functions into their own module.

This commit includes two functions scan_tag_uri, and scan_tag_handle for
process prefix/suffix'es and handles respectively.

Note that these functions by themselves cannot properly parse either %TAG
directives or YAML node tags; but higher level functions can use these to
correctly scan both.
2021-06-29 16:01:11 +01:00
Paul Stemmet 206ef90575 scalar/flow: update isBlankZ! -> isWhiteSpaceZ! 2021-06-29 16:01:11 +01:00
Paul Stemmet 6a4649c10f scanner/macros: rename isBlankZ! -> isWhiteSpaceZ!, add isWhiteSpace!
This makes the naming more consistent, we now have isBreak! variants for
line breaks, isBlank! variants for space and isWhiteSpace! variants for
both.

This commit also adds $error variants to isBlank! and isBreak! to remain
consistent with isWhiteSpace!.
2021-06-29 16:01:11 +01:00
Paul Stemmet 95af7eb5b0 lib/scanner: clippy fixes 2021-06-27 17:35:02 +01:00
Paul Stemmet 89b7480cde lib/scanner: add unit test for tag directive escapes 2021-06-27 17:35:02 +01:00
Paul Stemmet 9a29c29f59 lib/scanner: update tokens! to use ScanIter
as we can no longer uphold the Iterator contract on Scanner directly, as
next_token now requires it be given a scratch space handle; we move the
iterator impl onto a separate struct, ScanIter.

For the moment, this struct is private but this may change in the
future.
2021-06-27 17:35:02 +01:00
Paul Stemmet 2dd5042fd6 lib/scanner: rewrite tag directive scan, return Ref over Token
This commit takes the first steps towards the final API of Scanner,
wherein it returns Result<Ref>s over Result<Token>s. This change allows
the struct to access a scratch space which it can and will use when
borrowing from the underlying data is impossible, such as when
encountering escape sequences (which must be unescaped), line joining,
or data (type) transformation.

Regardless, these changes were required to correctly handle escape
sequences in tag directives.

Note that the test suite for lib/scanner is broken as of this commit, it
will be fixed in the next.
2021-06-27 17:35:02 +01:00
Paul Stemmet d6f0c71e71 scanner/scalar: make submodules public (to scanner) 2021-06-27 17:35:02 +01:00
Paul Stemmet cd3e7beb1e lib/token: add helper methods to Token + Ref
- Token.borrowed + Token.copied for wrapping into Ref::Borrowed/Copied
- Ref.PartialEq<Token> for comparisons
2021-06-27 17:35:02 +01:00
Paul Stemmet da9e4f14e8 scalar/escape: clippy lints 2021-06-26 09:24:08 +01:00
Paul Stemmet e1d79d4851 scalar/escape: add more unit tests for tag_uri_unescape 2021-06-26 09:24:08 +01:00
Paul Stemmet 5be9c9fb1d scalar/escape: fix flow_unescape documentation 2021-06-26 09:24:08 +01:00
Paul Stemmet 54614aafd0 scalar/escape: move exported fns to top, document tag_uri_unescape 2021-06-26 09:24:08 +01:00
Paul Stemmet cb7d622b98 scalar/escape: add tag_uri_unescape
This function unescapes percent encoded tag URIs, in accordance with
Section 5.6 Miscellaneous Characters #ns-uri-char

- Also add unit test for function
2021-06-26 09:24:08 +01:00
Paul Stemmet fb5619c638 scalar/escape: as_hex returns u8
This allows the caller to decide if a cast is necessary
2021-06-26 09:24:08 +01:00
Paul Stemmet b00970e2f4 scanner/macros: add isHex! 2021-06-26 09:24:08 +01:00
Paul Stemmet 56ea9f6921 scanner/macros: fix error path syntax 2021-06-26 09:24:08 +01:00
Paul Stemmet c4e514f6c2 lib/token: move Ref to token
Ref is a type that allows us to discriminate between different lifetimes
specifically, whether the underlying Token is borrowed from the data, or
borrowed from the scratch space.

This buys us the ability to attempt zero copy deserialization, but fall
back to copying if required.
2021-06-23 21:51:33 +01:00
Paul Stemmet 70d2f3a2e5 git: ignore .vim/ 2021-06-23 21:51:33 +01:00
Paul Stemmet 82d27199b5 docs/flow-logic: notes from scalar line joining
This doc is incorrect, but kept for posterity
2021-06-23 21:51:33 +01:00
Paul Stemmet 0de27e1092 ci/clippy: fix error, allow styles
- On suspicious else, this is simply part of how I format this repo,
  so this style lint will be ignored
- On the manual range impl, inclusive ranges in Rust are slower than
  writing them out by hand by a significant amount
2021-06-23 21:51:33 +01:00
Paul Stemmet b4245b0936 scanner/scalar: implement double quote handling
- and add unit tests covering double quoted scalars
2021-06-23 21:51:33 +01:00
Paul Stemmet fa8988213e scanner/scalar: implement line break handling/joining 2021-06-23 21:51:33 +01:00
Paul Stemmet fd409a8f20 scanner/macros: check! handle EOF checks gracefully 2021-06-23 21:51:33 +01:00
Paul Stemmet ab668c7e3e scanner/macros: standardize documentation 2021-06-23 21:51:33 +01:00
Paul Stemmet 3b012f461d scanner/scalar: further improvements
- Improved docs
- Expand unit tests
- Slight improvements to code
2021-06-23 21:51:33 +01:00
Paul Stemmet 4dc5efae33 scalar/escape: various touchups
- Renamed fn flow_double_unescape -> flow_unescape
- Added unit tests for flow_unescape return
- Improved existing test coverage for hex escapes
- Documented module + flow_unescape
- Slight refactoring of module layout for readability
2021-06-23 21:51:33 +01:00
Paul Stemmet a750275b47 scalar/escape: add flow_double_unescape, unit tests
- partial coverage on units tests, need more
2021-06-23 21:51:33 +01:00
Paul Stemmet 5117961b23 scanner/scalar: implement skeleton for flow scalar scanning 2021-06-23 21:51:33 +01:00
Paul Stemmet 9cf1600088 scanner/macros: add unit tests for isBlank!, isBreak!, isBlankZ! 2021-06-23 21:51:33 +01:00
Paul Stemmet c478e26281 scanner/macros: isLineBreak! -> isBreak, add isBlank!, isBlankZ!
- isBlank checks for spaces or tabs
- isBlankZ = isBreak! || isBlank! || empty

names need some work
2021-06-23 21:51:33 +01:00
Paul Stemmet ba10beb0c6 scanner/macros: rewrite check! to be simpler to use, add isLineBreak! 2021-06-23 21:51:33 +01:00
Paul Stemmet 3526cd29c4 scanner/macros: allow advance! to update a var with $amount consumed 2021-06-23 21:51:33 +01:00
Paul Stemmet aa2dec094e scanner/error: add InvalidFlowScalar, UnknownEscape variants
for the coming work on scalars
2021-06-23 21:51:33 +01:00
Paul Stemmet 4bf4b50e3d lib/scanner: fix macro propagation to submodules 2021-06-23 21:51:33 +01:00
Paul Stemmet e7882ed599
ci/fmt: move rustfmt.toml to repo root 2021-06-22 21:14:34 +00:00
Paul Stemmet 93e3ff8f76 lib/scanner: allow YAML anchors (*ref, &ref) to be tokenized
- add units tests for anchors
2021-06-06 10:54:28 +01:00