Skip to content

Commit bec9f09

Browse files
committed
Merge #18
18: Comments r=matklad a=matklad
2 parents 092f9a6 + d3dedca commit bec9f09

File tree

3 files changed

+59
-4
lines changed

3 files changed

+59
-4
lines changed

src/bin/gen.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,12 @@ impl Grammar {
5151
write!(acc, " {},\n", scream(kind)).unwrap();
5252
}
5353
acc.push_str("\n");
54-
acc.push_str(" TOMBSTONE = !0 - 1,\n");
55-
acc.push_str(" EOF = !0,\n");
54+
acc.push_str(" // Technical SyntaxKinds: they appear temporally during parsing,\n");
55+
acc.push_str(" // but never end up in the final tree\n");
56+
acc.push_str(" #[doc(hidden)]\n");
57+
acc.push_str(" TOMBSTONE,\n");
58+
acc.push_str(" #[doc(hidden)]\n");
59+
acc.push_str(" EOF,\n");
5660
acc.push_str("}\n");
5761
acc.push_str("pub(crate) use self::SyntaxKind::*;\n");
5862
acc.push_str("\n");

src/parser/event_parser/mod.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,64 @@ use {SyntaxKind, Token};
44
mod parser;
55
mod grammar;
66

7+
/// `Parser` produces a flat list of `Event`s.
8+
/// They are converted to a tree-structure in
9+
/// a separate pass, via `TreeBuilder`.
710
#[derive(Debug)]
811
pub(crate) enum Event {
12+
/// This event signifies the start of the node.
13+
/// It should be either abandoned (in which case the
14+
/// `kind` is `TOMBSTONE`, and the event is ignored),
15+
/// or completed via a `Finish` event.
16+
///
17+
/// All tokens between a `Start` and a `Finish` would
18+
/// become the children of the respective node.
19+
///
20+
/// For left-recursive syntactic constructs, the parser produces
21+
/// a child node before it sees a parent. `forward_parent`
22+
/// exists to allow to tweak parent-child relationships.
23+
///
24+
/// Consider this path
25+
///
26+
/// foo::bar
27+
///
28+
/// The events for it would look like this:
29+
///
30+
///
31+
/// START(PATH) IDENT('foo') FINISH START(PATH) COLONCOLON IDENT('bar') FINISH
32+
/// | /\
33+
/// | |
34+
/// +------forward-parent------+
35+
///
36+
/// And the tree would look like this
37+
///
38+
/// +--PATH---------+
39+
/// | | |
40+
/// | | |
41+
/// | '::' 'bar'
42+
/// |
43+
/// PATH
44+
/// |
45+
/// 'foo'
46+
///
47+
/// See also `CompleteMarker::precede`.
948
Start {
1049
kind: SyntaxKind,
1150
forward_parent: Option<u32>,
1251
},
52+
53+
/// Complete the previous `Start` event
1354
Finish,
55+
56+
/// Produce a single leaf-element.
57+
/// `n_raw_tokens` is used to glue complex contextual tokens.
58+
/// For example, lexer tokenizes `>>` as `>`, `>`, and
59+
/// `n_raw_tokens = 2` is used to produced a single `>>`.
1460
Token {
1561
kind: SyntaxKind,
1662
n_raw_tokens: u8,
1763
},
64+
1865
Error {
1966
message: String,
2067
},

src/syntax_kinds.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,12 @@ pub enum SyntaxKind {
9292
ALIAS,
9393
VISIBILITY,
9494

95-
TOMBSTONE = !0 - 1,
96-
EOF = !0,
95+
// Technical SyntaxKinds: they appear temporally during parsing,
96+
// but never end up in the final tree
97+
#[doc(hidden)]
98+
TOMBSTONE,
99+
#[doc(hidden)]
100+
EOF,
97101
}
98102
pub(crate) use self::SyntaxKind::*;
99103

0 commit comments

Comments
 (0)