pub(crate) enum Event {
Start {
kind: SyntaxKind,
forward_parent: Option<u32>,
},
Finish,
Token {
kind: SyntaxKind,
n_raw_tokens: u8,
},
FloatSplitHack {
ends_in_dot: bool,
},
Error {
msg: String,
},
}Expand description
Parser produces a flat list of Events.
They are converted to a tree-structure in
a separate pass, via TreeBuilder.
Variants§
Start
This event signifies the start of the node.
It should be either abandoned (in which case the
kind is TOMBSTONE, and the event is ignored),
or completed via a Finish event.
All tokens between a Start and a Finish would
become the children of the respective node.
For left-recursive syntactic constructs, the parser produces
a child node before it sees a parent. forward_parent
saves the position of current event’s parent.
Consider this path
foo::bar
The events for it would look like this:
START(PATH) IDENT('foo') FINISH START(PATH) T![::] IDENT('bar') FINISH
| /\
| |
+------forward-parent------+And the tree would look like this
+--PATH---------+
| | |
| | |
| '::' 'bar'
|
PATH
|
'foo'See also CompletedMarker::precede.
Finish
Complete the previous Start event
Token
Produce a single leaf-element.
n_raw_tokens is used to glue complex contextual tokens.
For example, lexer tokenizes >> as >, >, and
n_raw_tokens = 2 is used to produced a single >>.
FloatSplitHack
When we parse foo.0.0 or foo. 0. 0 the lexer will hand us a float literal
instead of an integer literal followed by a dot as the lexer has no contextual knowledge.
This event instructs whatever consumes the events to split the float literal into
the corresponding parts.