Commit Graph

120 Commits

Author SHA1 Message Date
Paul Stemmet e24fe38a7e lib/scanner: add unit tests for flow_collection_* methods
though only for the naive cases, e.g '{}' and '[]'.
More to come...
2021-08-01 08:12:47 +01:00
Paul Stemmet a84f64e2b7 lib/scanner: track YAML context, add flow_collection_* methods
Also improve the various self.key.possible calls to calculate more
correctly whether a key is required.

This commit adds support for the Scanner to pick up
Flow{Mapping,Sequence}{Start,End} tokens, but _does not_ yet allow for
FlowEntry tokens.
2021-08-01 08:12:47 +01:00
Paul Stemmet c2734e33e1 scanner/context: add Context
Context handles tracking the current YAML context, and provides the
mechanisms to update it efficiently
2021-08-01 08:12:47 +01:00
Paul Stemmet 93470734ba scanner/error: add IntOverflow variant 2021-08-01 08:12:47 +01:00
Paul Stemmet d32fc77b17 lib/scanner: rename key.impossible -> key.forbidden 2021-08-01 08:12:47 +01:00
Paul Stemmet 0fe2e99426 lib/token: cmp with marker by ref (clippy) 2021-07-25 12:41:57 +01:00
Paul Stemmet e35a1e87db lib/scanner: fix check_is_key, correct test
I misunderstood YAML key semantics around implicit keys, thinking that
only plain (e.g non flow / block) scalars required length and line limit
checking, but it turns out that _all_ possible implicit key variants
have these limits, so I've added checks here, and corrected a bad test
2021-07-25 12:41:57 +01:00
Paul Stemmet dd04944fe9 lib/scanner: clippy, fmt 2021-07-25 12:41:57 +01:00
Paul Stemmet eee164caa1 scanner/key: remove old code
From before I had decided to use a token array for token storage.
2021-07-25 12:41:57 +01:00
Paul Stemmet b1713c73f6 lib/scanner: allow multi token calls
The external Scanner API now requires a .tokens list to add tokens
into.

Where possible, it will still attempt to only store one token per call,
however it may store more if the situation requires, typically when
calculating if a given scalar is a key, or when handling indentation
tokens.
2021-07-25 12:41:57 +01:00
Paul Stemmet 53a8c8eccb scanner/key: adjustments for the API changes 2021-07-25 12:41:57 +01:00
Paul Stemmet 8986f36f00 scanner/tag: remove ref, return owned Slice variants
This is a part of an API changes I"ll be making, which will allow
allocations in the scanner code. This change is being made for a few
reasons.

1. Allows me to make the Scanner API nicer, as callers will only need
   to pass in the underlying data being scanned, and will not be tied to
   a mutable lifetime which limits them to scanning tokens one at a
   time.
2. Makes the code simpler, as I no longer need to ensure the mutable
   'owned' lifetime is honored throughout the call stack.
3. I'll need to allocate anyway for the indentation stack, and thus not
   allocating in other places that are sensible is less important.
2021-07-25 12:41:57 +01:00
Paul Stemmet 8f84972cd5 scalar: tidy syntax / includes 2021-07-25 12:41:57 +01:00
Paul Stemmet ea64559444 lib/token: add marker
This commit adds a Marker enum which mirrors the variants of Token, but
is data-less.
2021-07-25 12:41:57 +01:00
Paul Stemmet 37278ab219 WIP 2021-07-25 12:41:57 +01:00
Paul Stemmet cd7859f3d4 lib/scanner: save the scanned scalar's stats 2021-07-25 12:41:57 +01:00
Paul Stemmet 696b71b083 lib/scanner: remove reset_stale_keys, dbgs 2021-07-25 12:41:57 +01:00
Paul Stemmet edc70ed81a WIP 2021-07-25 12:41:57 +01:00
Paul Stemmet 7857839d6c scanner/scalar: add tests to catch trailing ws bugs 2021-07-25 12:41:57 +01:00
Paul Stemmet e416e3d0ab scanner/scalar: bugfix always count whitespace 2021-07-25 12:41:57 +01:00
Paul Stemmet a59527944b lib/scanner: add value token scanner, track keys 2021-07-25 12:41:57 +01:00
Paul Stemmet a0e184431f scanner/key: add, structs for managing key tokens
This module contains the beginnings of the state required to track and
store tokens which may be "found" out of sequence, notably when we first
need to parse a scalar (Token #1) then check if a value sequence follows
it (Token #2), and if so, return a key token first (Token #3), where the
correct order of tokens is:

    Token #3 -> Token #1 -> Token #2

We also need to track in the scanner whether a key is even possible, e.g
if we just parsed a value token, the next scalar _is not_ a key
2021-07-25 12:41:57 +01:00
Paul Stemmet 81975e197f scanner/scalar: return ScalarRange over Ref
this allows callers to decide when to convert the range into a Token
ref, which will be important when we need to save a scalar because we
need to return a Key Token first
2021-07-25 12:41:57 +01:00
Paul Stemmet ffcdce5961 lib/token: derive clone on style 2021-07-25 12:41:57 +01:00
Paul Stemmet cebd1d6e7d lib/scanner: add test for implicit key
So I can have a case to test my implementation against
2021-07-25 12:41:57 +01:00
Paul Stemmet 17f09e4d30
scanner/token: fix primary branch in scan_node_tag
we were double consuming a character, add a unit test to catch this
issue in the future
2021-06-29 22:50:19 +00:00
Paul Stemmet 298b15cad7 lib/scanner: document MStats 2021-06-29 23:14:30 +01:00
Paul Stemmet 6490de8974 lib/scanner: add stats test to unit tests 2021-06-29 23:14:30 +01:00
Paul Stemmet 393ce6372b scalar/flow: fix unit tests 2021-06-29 23:14:30 +01:00
Paul Stemmet 5e025374cc lib/scanner, scalar/flow: track stats in flow_scalar
Also fix the incorrect document stream indicator check now that we have
a column to check against
2021-06-29 23:14:30 +01:00
Paul Stemmet 32ada94850 lib/scanner: track stats in anchor 2021-06-29 23:14:30 +01:00
Paul Stemmet de2960a325 lib/scanner, scanner/tag: track stats in node,directive tags 2021-06-29 23:14:30 +01:00
Paul Stemmet 46fcd61aec lib/scanner: track stats in version directive 2021-06-29 23:14:30 +01:00
Paul Stemmet 911f861320 lib/scanner: track stats in document_marker 2021-06-29 23:14:30 +01:00
Paul Stemmet f2399e0eb4 lib/scanner: track stats in eat_whitespace 2021-06-29 23:14:30 +01:00
Paul Stemmet 69574b3628 scanner/macros: allow advance! to optionally update :stats 2021-06-29 23:14:30 +01:00
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