aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/parsing.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/parsing.rs')
-rw-r--r--crates/ra_syntax/src/parsing.rs22
1 files changed, 12 insertions, 10 deletions
diff --git a/crates/ra_syntax/src/parsing.rs b/crates/ra_syntax/src/parsing.rs
index 138d1394a..7e1b32035 100644
--- a/crates/ra_syntax/src/parsing.rs
+++ b/crates/ra_syntax/src/parsing.rs
@@ -9,11 +9,11 @@ mod grammar;
9mod reparsing; 9mod reparsing;
10 10
11use crate::{ 11use crate::{
12 SyntaxKind, SmolStr, SyntaxError, 12 SyntaxKind, SyntaxError,
13 parsing::{ 13 parsing::{
14 builder::GreenBuilder, 14 builder::TreeBuilder,
15 input::ParserInput, 15 input::ParserInput,
16 event::EventProcessor, 16 event::process,
17 parser::Parser, 17 parser::Parser,
18 }, 18 },
19 syntax_node::GreenNode, 19 syntax_node::GreenNode,
@@ -28,22 +28,24 @@ pub(crate) use self::reparsing::incremental_reparse;
28 28
29pub(crate) fn parse_text(text: &str) -> (GreenNode, Vec<SyntaxError>) { 29pub(crate) fn parse_text(text: &str) -> (GreenNode, Vec<SyntaxError>) {
30 let tokens = tokenize(&text); 30 let tokens = tokenize(&text);
31 parse_with(GreenBuilder::default(), text, &tokens, grammar::root) 31 let tree_sink = TreeBuilder::new(text, &tokens);
32 parse_with(tree_sink, text, &tokens, grammar::root)
32} 33}
33 34
34fn parse_with<S: TreeSink>( 35fn parse_with<S: TreeSink>(
35 tree_sink: S, 36 mut tree_sink: S,
36 text: &str, 37 text: &str,
37 tokens: &[Token], 38 tokens: &[Token],
38 f: fn(&mut Parser), 39 f: fn(&mut Parser),
39) -> S::Tree { 40) -> S::Tree {
40 let mut events = { 41 let events = {
41 let input = ParserInput::new(text, &tokens); 42 let input = ParserInput::new(text, &tokens);
42 let mut p = Parser::new(&input); 43 let mut p = Parser::new(&input);
43 f(&mut p); 44 f(&mut p);
44 p.finish() 45 p.finish()
45 }; 46 };
46 EventProcessor::new(tree_sink, text, tokens, &mut events).process().finish() 47 process(&mut tree_sink, events);
48 tree_sink.finish()
47} 49}
48 50
49/// `TreeSink` abstracts details of a particular syntax tree implementation. 51/// `TreeSink` abstracts details of a particular syntax tree implementation.
@@ -51,14 +53,14 @@ trait TreeSink {
51 type Tree; 53 type Tree;
52 54
53 /// Adds new leaf to the current branch. 55 /// Adds new leaf to the current branch.
54 fn leaf(&mut self, kind: SyntaxKind, text: SmolStr); 56 fn leaf(&mut self, kind: SyntaxKind, n_tokens: u8);
55 57
56 /// Start new branch and make it current. 58 /// Start new branch and make it current.
57 fn start_branch(&mut self, kind: SyntaxKind); 59 fn start_branch(&mut self, kind: SyntaxKind, root: bool);
58 60
59 /// Finish current branch and restore previous 61 /// Finish current branch and restore previous
60 /// branch as current. 62 /// branch as current.
61 fn finish_branch(&mut self); 63 fn finish_branch(&mut self, root: bool);
62 64
63 fn error(&mut self, error: ParseError); 65 fn error(&mut self, error: ParseError);
64 66