diff options
author | Edwin Cheng <[email protected]> | 2019-04-19 14:21:47 +0100 |
---|---|---|
committer | Edwin Cheng <[email protected]> | 2019-04-19 14:21:47 +0100 |
commit | c5983b85fc9e520208684a8c625cdb96bb219b31 (patch) | |
tree | a990c96f3c973656663ab49d3f292dfca95a97b2 /crates/ra_mbe/src/tt_cursor.rs | |
parent | 313854c728c45ce236f23ff7a8834690e06d8306 (diff) |
Add literal matcher
Diffstat (limited to 'crates/ra_mbe/src/tt_cursor.rs')
-rw-r--r-- | crates/ra_mbe/src/tt_cursor.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/crates/ra_mbe/src/tt_cursor.rs b/crates/ra_mbe/src/tt_cursor.rs index 9c49648fa..6184fb31f 100644 --- a/crates/ra_mbe/src/tt_cursor.rs +++ b/crates/ra_mbe/src/tt_cursor.rs | |||
@@ -41,6 +41,13 @@ impl<'a> TtCursor<'a> { | |||
41 | } | 41 | } |
42 | } | 42 | } |
43 | 43 | ||
44 | pub(crate) fn at_literal(&mut self) -> Option<&'a tt::Literal> { | ||
45 | match self.current() { | ||
46 | Some(tt::TokenTree::Leaf(tt::Leaf::Literal(i))) => Some(i), | ||
47 | _ => None, | ||
48 | } | ||
49 | } | ||
50 | |||
44 | pub(crate) fn bump(&mut self) { | 51 | pub(crate) fn bump(&mut self) { |
45 | self.pos += 1; | 52 | self.pos += 1; |
46 | } | 53 | } |
@@ -79,6 +86,13 @@ impl<'a> TtCursor<'a> { | |||
79 | }) | 86 | }) |
80 | } | 87 | } |
81 | 88 | ||
89 | pub(crate) fn eat_literal(&mut self) -> Option<&'a tt::Literal> { | ||
90 | self.at_literal().map(|i| { | ||
91 | self.bump(); | ||
92 | i | ||
93 | }) | ||
94 | } | ||
95 | |||
82 | pub(crate) fn eat_path(&mut self) -> Option<tt::TokenTree> { | 96 | pub(crate) fn eat_path(&mut self) -> Option<tt::TokenTree> { |
83 | let parser = Parser::new(&mut self.pos, self.subtree); | 97 | let parser = Parser::new(&mut self.pos, self.subtree); |
84 | parser.parse_path() | 98 | parser.parse_path() |