aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_syntax/src/parser_api.rs4
-rw-r--r--crates/ra_syntax/src/parser_impl.rs15
-rw-r--r--crates/ra_syntax/src/parser_impl/event.rs12
-rw-r--r--crates/ra_syntax/src/yellow/builder.rs4
4 files changed, 23 insertions, 12 deletions
diff --git a/crates/ra_syntax/src/parser_api.rs b/crates/ra_syntax/src/parser_api.rs
index 02421def1..0f740963d 100644
--- a/crates/ra_syntax/src/parser_api.rs
+++ b/crates/ra_syntax/src/parser_api.rs
@@ -61,7 +61,7 @@ impl<'t> Parser<'t> {
61 Marker::new(self.0.start()) 61 Marker::new(self.0.start())
62 } 62 }
63 63
64 /// Advances the parser by one token. 64 /// Advances the parser by one token unconditionally.
65 pub(crate) fn bump(&mut self) { 65 pub(crate) fn bump(&mut self) {
66 self.0.bump(); 66 self.0.bump();
67 } 67 }
@@ -91,7 +91,7 @@ impl<'t> Parser<'t> {
91 self.0.error(message.into()) 91 self.0.error(message.into())
92 } 92 }
93 93
94 /// Consume the next token if it is `kind`. 94 /// Consume the next token if `kind` matches.
95 pub(crate) fn eat(&mut self, kind: SyntaxKind) -> bool { 95 pub(crate) fn eat(&mut self, kind: SyntaxKind) -> bool {
96 if !self.at(kind) { 96 if !self.at(kind) {
97 return false; 97 return false;
diff --git a/crates/ra_syntax/src/parser_impl.rs b/crates/ra_syntax/src/parser_impl.rs
index cb6e370ac..d4032a6d9 100644
--- a/crates/ra_syntax/src/parser_impl.rs
+++ b/crates/ra_syntax/src/parser_impl.rs
@@ -22,10 +22,21 @@ use crate::SyntaxKind::{self, EOF, TOMBSTONE};
22pub(crate) trait Sink { 22pub(crate) trait Sink {
23 type Tree; 23 type Tree;
24 24
25 /// Adds new leaf to the current branch.
25 fn leaf(&mut self, kind: SyntaxKind, text: SmolStr); 26 fn leaf(&mut self, kind: SyntaxKind, text: SmolStr);
26 fn start_internal(&mut self, kind: SyntaxKind); 27
27 fn finish_internal(&mut self); 28 /// Start new branch and make it current.
29 fn start_branch(&mut self, kind: SyntaxKind);
30
31 /// Finish current branch and restore previous
32 /// branch as current.
33 fn finish_branch(&mut self);
34
28 fn error(&mut self, error: SyntaxError); 35 fn error(&mut self, error: SyntaxError);
36
37 /// Complete tree building. Make sure that
38 /// `start_branch` and `finish_branch` calls
39 /// are paired!
29 fn finish(self) -> Self::Tree; 40 fn finish(self) -> Self::Tree;
30} 41}
31 42
diff --git a/crates/ra_syntax/src/parser_impl/event.rs b/crates/ra_syntax/src/parser_impl/event.rs
index 3d8b062d5..d6299b5e3 100644
--- a/crates/ra_syntax/src/parser_impl/event.rs
+++ b/crates/ra_syntax/src/parser_impl/event.rs
@@ -154,7 +154,7 @@ impl<'a, S: Sink> EventProcessor<'a, S> {
154 self.finish(last); 154 self.finish(last);
155 } 155 }
156 Event::Token { kind, n_raw_tokens } => { 156 Event::Token { kind, n_raw_tokens } => {
157 self.eat_ws(); 157 self.eat_trivias();
158 let n_raw_tokens = n_raw_tokens as usize; 158 let n_raw_tokens = n_raw_tokens as usize;
159 let len = self.tokens[self.token_pos..self.token_pos + n_raw_tokens] 159 let len = self.tokens[self.token_pos..self.token_pos + n_raw_tokens]
160 .iter() 160 .iter()
@@ -173,7 +173,7 @@ impl<'a, S: Sink> EventProcessor<'a, S> {
173 173
174 fn start(&mut self, kind: SyntaxKind) { 174 fn start(&mut self, kind: SyntaxKind) {
175 if kind == SOURCE_FILE { 175 if kind == SOURCE_FILE {
176 self.sink.start_internal(kind); 176 self.sink.start_branch(kind);
177 return; 177 return;
178 } 178 }
179 let n_trivias = self.tokens[self.token_pos..] 179 let n_trivias = self.tokens[self.token_pos..]
@@ -194,18 +194,18 @@ impl<'a, S: Sink> EventProcessor<'a, S> {
194 n_attached_trivias(kind, leading_trivias) 194 n_attached_trivias(kind, leading_trivias)
195 }; 195 };
196 self.eat_n_trivias(n_trivias - n_attached_trivias); 196 self.eat_n_trivias(n_trivias - n_attached_trivias);
197 self.sink.start_internal(kind); 197 self.sink.start_branch(kind);
198 self.eat_n_trivias(n_attached_trivias); 198 self.eat_n_trivias(n_attached_trivias);
199 } 199 }
200 200
201 fn finish(&mut self, last: bool) { 201 fn finish(&mut self, last: bool) {
202 if last { 202 if last {
203 self.eat_ws() 203 self.eat_trivias()
204 } 204 }
205 self.sink.finish_internal(); 205 self.sink.finish_branch();
206 } 206 }
207 207
208 fn eat_ws(&mut self) { 208 fn eat_trivias(&mut self) {
209 while let Some(&token) = self.tokens.get(self.token_pos) { 209 while let Some(&token) = self.tokens.get(self.token_pos) {
210 if !token.kind.is_trivia() { 210 if !token.kind.is_trivia() {
211 break; 211 break;
diff --git a/crates/ra_syntax/src/yellow/builder.rs b/crates/ra_syntax/src/yellow/builder.rs
index 9fcebfb93..37ae6329b 100644
--- a/crates/ra_syntax/src/yellow/builder.rs
+++ b/crates/ra_syntax/src/yellow/builder.rs
@@ -26,11 +26,11 @@ impl Sink for GreenBuilder {
26 self.inner.leaf(kind, text); 26 self.inner.leaf(kind, text);
27 } 27 }
28 28
29 fn start_internal(&mut self, kind: SyntaxKind) { 29 fn start_branch(&mut self, kind: SyntaxKind) {
30 self.inner.start_internal(kind) 30 self.inner.start_internal(kind)
31 } 31 }
32 32
33 fn finish_internal(&mut self) { 33 fn finish_branch(&mut self) {
34 self.inner.finish_internal(); 34 self.inner.finish_internal();
35 } 35 }
36 36