aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_mbe/src/subtree_parser.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_mbe/src/subtree_parser.rs')
-rw-r--r--crates/ra_mbe/src/subtree_parser.rs13
1 files changed, 10 insertions, 3 deletions
diff --git a/crates/ra_mbe/src/subtree_parser.rs b/crates/ra_mbe/src/subtree_parser.rs
index 528aa0f8a..f07107414 100644
--- a/crates/ra_mbe/src/subtree_parser.rs
+++ b/crates/ra_mbe/src/subtree_parser.rs
@@ -5,6 +5,7 @@ use ra_syntax::{SyntaxKind};
5 5
6struct OffsetTokenSink { 6struct OffsetTokenSink {
7 token_pos: usize, 7 token_pos: usize,
8 error: bool,
8} 9}
9 10
10impl TreeSink for OffsetTokenSink { 11impl TreeSink for OffsetTokenSink {
@@ -13,7 +14,9 @@ impl TreeSink for OffsetTokenSink {
13 } 14 }
14 fn start_node(&mut self, _kind: SyntaxKind) {} 15 fn start_node(&mut self, _kind: SyntaxKind) {}
15 fn finish_node(&mut self) {} 16 fn finish_node(&mut self) {}
16 fn error(&mut self, _error: ra_parser::ParseError) {} 17 fn error(&mut self, _error: ra_parser::ParseError) {
18 self.error = true;
19 }
17} 20}
18 21
19pub(crate) struct Parser<'a> { 22pub(crate) struct Parser<'a> {
@@ -67,11 +70,15 @@ impl<'a> Parser<'a> {
67 F: FnOnce(&dyn TokenSource, &mut dyn TreeSink), 70 F: FnOnce(&dyn TokenSource, &mut dyn TreeSink),
68 { 71 {
69 let mut src = SubtreeTokenSource::new(&self.subtree.token_trees[*self.cur_pos..]); 72 let mut src = SubtreeTokenSource::new(&self.subtree.token_trees[*self.cur_pos..]);
70 let mut sink = OffsetTokenSink { token_pos: 0 }; 73 let mut sink = OffsetTokenSink { token_pos: 0, error: false };
71 74
72 f(&src, &mut sink); 75 f(&src, &mut sink);
73 76
74 self.finish(sink.token_pos, &mut src) 77 let r = self.finish(sink.token_pos, &mut src);
78 if sink.error {
79 return None;
80 }
81 r
75 } 82 }
76 83
77 fn finish(self, parsed_token: usize, src: &mut SubtreeTokenSource) -> Option<tt::TokenTree> { 84 fn finish(self, parsed_token: usize, src: &mut SubtreeTokenSource) -> Option<tt::TokenTree> {