aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bin/gen.rs8
-rw-r--r--src/parser/event_parser/mod.rs47
-rw-r--r--src/syntax_kinds.rs8
3 files changed, 59 insertions, 4 deletions
diff --git a/src/bin/gen.rs b/src/bin/gen.rs
index 4b8a5afec..89609bd77 100644
--- a/src/bin/gen.rs
+++ b/src/bin/gen.rs
@@ -51,8 +51,12 @@ impl Grammar {
51 write!(acc, " {},\n", scream(kind)).unwrap(); 51 write!(acc, " {},\n", scream(kind)).unwrap();
52 } 52 }
53 acc.push_str("\n"); 53 acc.push_str("\n");
54 acc.push_str(" TOMBSTONE = !0 - 1,\n"); 54 acc.push_str(" // Technical SyntaxKinds: they appear temporally during parsing,\n");
55 acc.push_str(" EOF = !0,\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");
56 acc.push_str("}\n"); 60 acc.push_str("}\n");
57 acc.push_str("pub(crate) use self::SyntaxKind::*;\n"); 61 acc.push_str("pub(crate) use self::SyntaxKind::*;\n");
58 acc.push_str("\n"); 62 acc.push_str("\n");
diff --git a/src/parser/event_parser/mod.rs b/src/parser/event_parser/mod.rs
index 65aea017b..7823c476c 100644
--- a/src/parser/event_parser/mod.rs
+++ b/src/parser/event_parser/mod.rs
@@ -4,17 +4,64 @@ use {SyntaxKind, Token};
4mod parser; 4mod parser;
5mod grammar; 5mod grammar;
6 6
7/// `Parser` produces a flat list of `Event`s.
8/// They are converted to a tree-structure in
9/// a separate pass, via `TreeBuilder`.
7#[derive(Debug)] 10#[derive(Debug)]
8pub(crate) enum Event { 11pub(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`.
9 Start { 48 Start {
10 kind: SyntaxKind, 49 kind: SyntaxKind,
11 forward_parent: Option<u32>, 50 forward_parent: Option<u32>,
12 }, 51 },
52
53 /// Complete the previous `Start` event
13 Finish, 54 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 `>>`.
14 Token { 60 Token {
15 kind: SyntaxKind, 61 kind: SyntaxKind,
16 n_raw_tokens: u8, 62 n_raw_tokens: u8,
17 }, 63 },
64
18 Error { 65 Error {
19 message: String, 66 message: String,
20 }, 67 },
diff --git a/src/syntax_kinds.rs b/src/syntax_kinds.rs
index aa19c2adf..cc9e74f8e 100644
--- a/src/syntax_kinds.rs
+++ b/src/syntax_kinds.rs
@@ -92,8 +92,12 @@ pub enum SyntaxKind {
92 ALIAS, 92 ALIAS,
93 VISIBILITY, 93 VISIBILITY,
94 94
95 TOMBSTONE = !0 - 1, 95 // Technical SyntaxKinds: they appear temporally during parsing,
96 EOF = !0, 96 // but never end up in the final tree
97 #[doc(hidden)]
98 TOMBSTONE,
99 #[doc(hidden)]
100 EOF,
97} 101}
98pub(crate) use self::SyntaxKind::*; 102pub(crate) use self::SyntaxKind::*;
99 103