aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/parsing/reparsing.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-05-27 08:28:13 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-05-27 08:28:13 +0100
commitce694ae11854a806031db98c51c068253f927519 (patch)
tree2996ecd85ff9aa57b6f208e83d42dd03a7370d1e /crates/ra_syntax/src/parsing/reparsing.rs
parent4f4e50db908ba44f113faeb356ae2b3d0788d308 (diff)
parent90764fc54b2be1e0fc5d6ac9c9e960d7bb059b14 (diff)
Merge #1328
1328: Change TokenSource to iteration based r=matklad a=edwin0cheng This PR change the `TokenSource` trait from random access to be an iteration based trait: ```rust /// `TokenSource` abstracts the source of the tokens parser operates one. /// /// Hopefully this will allow us to treat text and token trees in the same way! pub trait TokenSource { fn current(&self) -> Token; /// Lookahead n token fn lookahead_nth(&self, n: usize) -> Token; /// bump cursor to next token fn bump(&mut self); /// Is the current token a specified keyword? fn is_keyword(&self, kw: &str) -> bool; } /// `TokenCursor` abstracts the cursor of `TokenSource` operates one. #[derive(Debug, Copy, Clone, Eq, PartialEq)] pub struct Token { /// What is the current token? pub kind: SyntaxKind, /// Is the current token joined to the next one (`> >` vs `>>`). pub is_jointed_to_next: bool, } ``` Note that the refactoring based on this new trait will be separated to incoming PRs Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/parsing/reparsing.rs')
-rw-r--r--crates/ra_syntax/src/parsing/reparsing.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/crates/ra_syntax/src/parsing/reparsing.rs b/crates/ra_syntax/src/parsing/reparsing.rs
index 6de02a15a..3b6687f61 100644
--- a/crates/ra_syntax/src/parsing/reparsing.rs
+++ b/crates/ra_syntax/src/parsing/reparsing.rs
@@ -85,9 +85,9 @@ fn reparse_block<'node>(
85 if !is_balanced(&tokens) { 85 if !is_balanced(&tokens) {
86 return None; 86 return None;
87 } 87 }
88 let token_source = TextTokenSource::new(&text, &tokens); 88 let mut token_source = TextTokenSource::new(&text, &tokens);
89 let mut tree_sink = TextTreeSink::new(&text, &tokens); 89 let mut tree_sink = TextTreeSink::new(&text, &tokens);
90 reparser.parse(&token_source, &mut tree_sink); 90 reparser.parse(&mut token_source, &mut tree_sink);
91 let (green, new_errors) = tree_sink.finish(); 91 let (green, new_errors) = tree_sink.finish();
92 Some((node.replace_with(green), new_errors, node.range())) 92 Some((node.replace_with(green), new_errors, node.range()))
93} 93}