aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_mbe/src/tt_cursor.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_mbe/src/tt_cursor.rs')
-rw-r--r--crates/ra_mbe/src/tt_cursor.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/crates/ra_mbe/src/tt_cursor.rs b/crates/ra_mbe/src/tt_cursor.rs
index 484437b0e..741b5ea1c 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()
@@ -104,11 +118,37 @@ impl<'a> TtCursor<'a> {
104 parser.parse_stmt() 118 parser.parse_stmt()
105 } 119 }
106 120
121 pub(crate) fn eat_block(&mut self) -> Option<tt::TokenTree> {
122 let parser = Parser::new(&mut self.pos, self.subtree);
123 parser.parse_block()
124 }
125
126 pub(crate) fn eat_meta(&mut self) -> Option<tt::TokenTree> {
127 let parser = Parser::new(&mut self.pos, self.subtree);
128 parser.parse_meta()
129 }
130
107 pub(crate) fn eat_item(&mut self) -> Option<tt::TokenTree> { 131 pub(crate) fn eat_item(&mut self) -> Option<tt::TokenTree> {
108 let parser = Parser::new(&mut self.pos, self.subtree); 132 let parser = Parser::new(&mut self.pos, self.subtree);
109 parser.parse_item() 133 parser.parse_item()
110 } 134 }
111 135
136 pub(crate) fn eat_lifetime(&mut self) -> Option<tt::TokenTree> {
137 // check if it start from "`"
138 if let Some(ident) = self.at_ident() {
139 if ident.text.chars().next()? != '\'' {
140 return None;
141 }
142 }
143
144 self.eat_ident().cloned().map(|ident| tt::Leaf::from(ident).into())
145 }
146
147 pub(crate) fn eat_vis(&mut self) -> Option<tt::TokenTree> {
148 let parser = Parser::new(&mut self.pos, self.subtree);
149 parser.parse_vis()
150 }
151
112 pub(crate) fn expect_char(&mut self, char: char) -> Result<(), ParseError> { 152 pub(crate) fn expect_char(&mut self, char: char) -> Result<(), ParseError> {
113 if self.at_char(char) { 153 if self.at_char(char) {
114 self.bump(); 154 self.bump();