diff options
Diffstat (limited to 'src/parser/event_parser/mod.rs')
-rw-r--r-- | src/parser/event_parser/mod.rs | 74 |
1 files changed, 0 insertions, 74 deletions
diff --git a/src/parser/event_parser/mod.rs b/src/parser/event_parser/mod.rs deleted file mode 100644 index 7823c476c..000000000 --- a/src/parser/event_parser/mod.rs +++ /dev/null | |||
@@ -1,74 +0,0 @@ | |||
1 | use {SyntaxKind, Token}; | ||
2 | |||
3 | #[macro_use] | ||
4 | mod parser; | ||
5 | mod grammar; | ||
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`. | ||
10 | #[derive(Debug)] | ||
11 | 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`. | ||
48 | Start { | ||
49 | kind: SyntaxKind, | ||
50 | forward_parent: Option<u32>, | ||
51 | }, | ||
52 | |||
53 | /// Complete the previous `Start` event | ||
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 `>>`. | ||
60 | Token { | ||
61 | kind: SyntaxKind, | ||
62 | n_raw_tokens: u8, | ||
63 | }, | ||
64 | |||
65 | Error { | ||
66 | message: String, | ||
67 | }, | ||
68 | } | ||
69 | |||
70 | pub(crate) fn parse<'t>(text: &'t str, raw_tokens: &'t [Token]) -> Vec<Event> { | ||
71 | let mut parser = parser::Parser::new(text, raw_tokens); | ||
72 | grammar::file(&mut parser); | ||
73 | parser.into_events() | ||
74 | } | ||