tame/tamer/src
Mike Gerwitz bd783ac08b tamer: Replace ParseStatus::Dead with generic lookahead
Oh what a tortured journey.  I had originally tried to avoid formalizing
lookahead for all parsers by pretending that it was only needed for dead
state transitions (that is---states that have no transitions for a given
input token), but then I needed to yield information for aggregation.  So I
added the ability to override the token for `Dead` to yield that, in
addition to the token.  But then I also needed to yield lookahead for error
conditions.  It was a mess that didn't make sense.

This eliminates `ParseStatus::Dead` entirely and fully integrates the
lookahead token in `Parser` that was previously implemented.

Notably, the lookahead token is encapsulated in `TransitionResult` and
unavailable to `ParseState` implementations, forcing them to rely on
`Parser` for recursion.  This not only prevents `ParseState` from recursing,
but also simplifies delegation by removing the need to manually handle
tokens of lookahead.

The awkward case here is XIRT, which does not follow the streaming parsing
convention, because it was conceived before the parsing framework.  It needs
to go away, but doing so right now would be a lot of work, so it has to
stick around for a little bit longer until the new parser generators can be
used instead.  It is a persistent thorn in my side, going against the grain.

`Parser` will immediately recurse if it sees a token of lookahead with an
incomplete parse.  This is because stitched parsers will frequently yield a
dead state indication when they're done parsing, and there's no use in
propagating an `Incomplete` status down the entire lowering pipeline.  But,
that does mean that the toplevel is not the only thing recursing.  _But_,
the behavior doesn't really change, in the sense that it would infinitely
recurse down the entire lowering stack (though there'd be an opportunity to
detect that).  This should never happen with a correct parser, but it's not
worth the effort right now to try to force such a thing with Rust's type
system.  Something like TLA+ is better suited here as an aid, but it
shouldn't be necessary with clear implementations and proper test
cases.  Parser generators will also ensure such a thing cannot occur.

I had hoped to remove ParseStatus entirely in favor of Parsed, but there's a
lot of type inference that happens based on the fact that `ParseStatus` has
a `ParseState` type parameter; `Parsed` has only `Object`.  It is desirable
for a public-facing `Parsed` to not be tied to `ParseState`, since consumers
need not be concerned with such a heavy type; however, we _do_ want that
heavy type internally, as it carries a lot of useful information that allows
for significant and powerful type inference, which in turn creates
expressive and convenient APIs.

DEV-7145
2022-07-12 00:11:45 -04:00
..
asg tamer: asg::ident: {prolog=>prologue} typo fix 2022-06-23 09:19:12 -04:00
bin tamer: Integrate xir::reader as a parser in the lowering pipeline 2022-06-02 10:30:44 -04:00
diagnose tamer: Consistent span diagram representation 2022-06-06 11:32:35 -04:00
iter tamer: iter::trip: Flatten Result 2022-05-20 16:08:16 -04:00
ld tamer: xir: Introduce {Ele,Open,Close}Span 2022-06-24 14:16:29 -04:00
obj tamer: Replace ParseStatus::Dead with generic lookahead 2022-07-12 00:11:45 -04:00
parse tamer: Replace ParseStatus::Dead with generic lookahead 2022-07-12 00:11:45 -04:00
sym Copyright year update 2022 2022-05-03 14:14:29 -04:00
test tamer: Ensure debug_assert! takes effect in test profile 2022-07-05 14:59:35 -04:00
xir tamer: Replace ParseStatus::Dead with generic lookahead 2022-07-12 00:11:45 -04:00
convert.rs Copyright year update 2022 2022-05-03 14:14:29 -04:00
diagnose.rs tamer: xir::parse: Attribute parser generator 2022-06-21 13:23:02 -04:00
fmt.rs tamer: fmt: New type-based formatting system 2022-06-10 16:28:15 -04:00
fs.rs Copyright year update 2022 2022-05-03 14:14:29 -04:00
global.rs Copyright year update 2022 2022-05-03 14:14:29 -04:00
iter.rs tamer: iter::trip: Flatten Result 2022-05-20 16:08:16 -04:00
ld.rs Copyright year update 2022 2022-05-03 14:14:29 -04:00
lib.rs tamer: xir: Introduce {Ele,Open,Close}Span 2022-06-24 14:16:29 -04:00
num.rs tamer: num: Header typo correction 2022-05-19 12:02:38 -04:00
parse.rs tamer: Replace ParseStatus::Dead with generic lookahead 2022-07-12 00:11:45 -04:00
span.rs tamer: Consistent span diagram representation 2022-06-06 11:32:35 -04:00
xir.rs Revert "tamer: xir: Initial re-introduction of AttrEnd" 2022-06-29 11:25:44 -04:00