mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 21:28:51 +00:00
Document events a bit
This commit is contained in:
parent
52104f7d25
commit
cd4e13f10a
1 changed files with 48 additions and 0 deletions
|
@ -4,17 +4,65 @@ use {SyntaxKind, Token};
|
||||||
mod parser;
|
mod parser;
|
||||||
mod grammar;
|
mod grammar;
|
||||||
|
|
||||||
|
|
||||||
|
/// `Parser` produces a flat list of `Event`s.
|
||||||
|
/// They are converted to a tree-structure in
|
||||||
|
/// a separate pass, via `TreeBuilder`.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) enum Event {
|
pub(crate) enum Event {
|
||||||
|
/// 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`
|
||||||
|
/// exists to allow to tweak parent-child relationships.
|
||||||
|
///
|
||||||
|
/// Consider this path
|
||||||
|
///
|
||||||
|
/// foo::bar
|
||||||
|
///
|
||||||
|
/// The events for it would look like this:
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// START(PATH) IDENT('foo') FINISH START(PATH) COLONCOLON IDENT('bar') FINISH
|
||||||
|
/// | /\
|
||||||
|
/// | |
|
||||||
|
/// +------forward-parent------+
|
||||||
|
///
|
||||||
|
/// And the tree would look like this
|
||||||
|
///
|
||||||
|
/// +--PATH---------+
|
||||||
|
/// | | |
|
||||||
|
/// | | |
|
||||||
|
/// | '::' 'bar'
|
||||||
|
/// |
|
||||||
|
/// PATH
|
||||||
|
/// |
|
||||||
|
/// 'foo'
|
||||||
|
///
|
||||||
|
/// See also `CompleteMarker::precede`.
|
||||||
Start {
|
Start {
|
||||||
kind: SyntaxKind,
|
kind: SyntaxKind,
|
||||||
forward_parent: Option<u32>,
|
forward_parent: Option<u32>,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/// Complete the previous `Start` event
|
||||||
Finish,
|
Finish,
|
||||||
|
|
||||||
|
/// 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 `>>`.
|
||||||
Token {
|
Token {
|
||||||
kind: SyntaxKind,
|
kind: SyntaxKind,
|
||||||
n_raw_tokens: u8,
|
n_raw_tokens: u8,
|
||||||
},
|
},
|
||||||
|
|
||||||
Error {
|
Error {
|
||||||
message: String,
|
message: String,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue