Commit graph

78 commits

Author SHA1 Message Date
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
Paul Stemmet f6f7102a16 lib/scanner: add InvalidAnchorName error variant 2021-06-06 10:54:28 +01:00
Paul Stemmet 8ce016f320 lib/scanner: clippy lints 2021-06-06 08:44:15 +01:00
Paul Stemmet 5240cb7330 lib/scanner: scan tag directives
+ add unit tests for tag directives
2021-06-06 08:44:15 +01:00
Paul Stemmet a66664dd27 lib/scanner: mv cow! to normal macros, add check!
- cow! is useful for non test
- check! is a macro for determining if a buffer has the given byte at
  the given pos (default 0)
- also add an advance! variant that returns the removed slice
2021-06-06 08:44:15 +01:00
Paul Stemmet e852509921 lib/scanner: add InvalidTagHandle, InvalidTagPrefix variants 2021-06-06 08:44:15 +01:00
Paul Stemmet 2596a79e3f lib/scanner: improve version directive parsing
- handle multibyte version numbers correctly
- only advance Scanner.buffer on Token boundaries
- Unit tests for the above items
2021-06-06 08:44:15 +01:00