aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_mbe/src/subtree_parser.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-04-14 15:16:42 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-04-14 15:16:42 +0100
commit5d35f284f5ac70cde5d758e7c63a38eae0fb0b55 (patch)
tree4cde8df0f4a496bb1f38b3e3479ce462fc1f7426 /crates/ra_mbe/src/subtree_parser.rs
parentfcbd0269545f2b6687a64a868654c74f876b7851 (diff)
parent6646d49f238bb92d55fcb4900830f19faa2994a5 (diff)
Merge #1138
1138: Add L_DOLLAR and R_DOLLAR r=matklad a=edwin0cheng As discussion in issue https://github.com/rust-analyzer/rust-analyzer/issues/1132 and PR #1125 , this PR add 2 `Syntax::Kind` : `L_DOLLAR` and `R_DOLLAR` for representing `Delimiter::None` in mbe and proc_marco. By design, It should not affect the final syntax tree, and will be discard in `TreeSink`. My original idea is handling these 2 tokens case by case, but i found that they will appear in every place in the parser (imagine `tt` matcher). So this PR only handle it in `Parser::do_bump` and `Parser::start`, although It will not fix the `expr` matcher executing order problem in original idea. Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/ra_mbe/src/subtree_parser.rs')
-rw-r--r--crates/ra_mbe/src/subtree_parser.rs15
1 files changed, 13 insertions, 2 deletions
diff --git a/crates/ra_mbe/src/subtree_parser.rs b/crates/ra_mbe/src/subtree_parser.rs
index ce39a40bb..13d5d2169 100644
--- a/crates/ra_mbe/src/subtree_parser.rs
+++ b/crates/ra_mbe/src/subtree_parser.rs
@@ -30,12 +30,23 @@ impl<'a> Parser<'a> {
30 self.parse(ra_parser::parse_path) 30 self.parse(ra_parser::parse_path)
31 } 31 }
32 32
33 pub fn parse_expr(self) -> Option<tt::TokenTree> {
34 self.parse(ra_parser::parse_expr)
35 }
36
37 pub fn parse_ty(self) -> Option<tt::TokenTree> {
38 self.parse(ra_parser::parse_ty)
39 }
40
41 pub fn parse_pat(self) -> Option<tt::TokenTree> {
42 self.parse(ra_parser::parse_pat)
43 }
44
33 fn parse<F>(self, f: F) -> Option<tt::TokenTree> 45 fn parse<F>(self, f: F) -> Option<tt::TokenTree>
34 where 46 where
35 F: FnOnce(&dyn TokenSource, &mut dyn TreeSink), 47 F: FnOnce(&dyn TokenSource, &mut dyn TreeSink),
36 { 48 {
37 let mut src = SubtreeTokenSource::new(self.subtree); 49 let mut src = SubtreeTokenSource::new(&self.subtree.token_trees[*self.cur_pos..]);
38 src.start_from_nth(*self.cur_pos);
39 let mut sink = OffsetTokenSink { token_pos: 0 }; 50 let mut sink = OffsetTokenSink { token_pos: 0 };
40 51
41 f(&src, &mut sink); 52 f(&src, &mut sink);