aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_mbe/src/tt_iter.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-08-13 09:08:11 +0100
committerAleksey Kladov <[email protected]>2020-08-13 09:36:04 +0100
commit2f45cfc415626cfae5cba89c88a25fb3225486f7 (patch)
treee04c21d108582a89efd2d3e5a680a0ed35156912 /crates/ra_mbe/src/tt_iter.rs
parentd42ba6397668fe28bd9cd92db829755905469a69 (diff)
Rename ra_mbe -> mbe
Diffstat (limited to 'crates/ra_mbe/src/tt_iter.rs')
-rw-r--r--crates/ra_mbe/src/tt_iter.rs75
1 files changed, 0 insertions, 75 deletions
diff --git a/crates/ra_mbe/src/tt_iter.rs b/crates/ra_mbe/src/tt_iter.rs
deleted file mode 100644
index 46c420718..000000000
--- a/crates/ra_mbe/src/tt_iter.rs
+++ /dev/null
@@ -1,75 +0,0 @@
1//! FIXME: write short doc here
2
3#[derive(Debug, Clone)]
4pub(crate) struct TtIter<'a> {
5 pub(crate) inner: std::slice::Iter<'a, tt::TokenTree>,
6}
7
8impl<'a> TtIter<'a> {
9 pub(crate) fn new(subtree: &'a tt::Subtree) -> TtIter<'a> {
10 TtIter { inner: subtree.token_trees.iter() }
11 }
12
13 pub(crate) fn expect_char(&mut self, char: char) -> Result<(), ()> {
14 match self.next() {
15 Some(tt::TokenTree::Leaf(tt::Leaf::Punct(tt::Punct { char: c, .. }))) if *c == char => {
16 Ok(())
17 }
18 _ => Err(()),
19 }
20 }
21
22 pub(crate) fn expect_subtree(&mut self) -> Result<&'a tt::Subtree, ()> {
23 match self.next() {
24 Some(tt::TokenTree::Subtree(it)) => Ok(it),
25 _ => Err(()),
26 }
27 }
28
29 pub(crate) fn expect_leaf(&mut self) -> Result<&'a tt::Leaf, ()> {
30 match self.next() {
31 Some(tt::TokenTree::Leaf(it)) => Ok(it),
32 _ => Err(()),
33 }
34 }
35
36 pub(crate) fn expect_ident(&mut self) -> Result<&'a tt::Ident, ()> {
37 match self.expect_leaf()? {
38 tt::Leaf::Ident(it) => Ok(it),
39 _ => Err(()),
40 }
41 }
42
43 pub(crate) fn expect_literal(&mut self) -> Result<&'a tt::Leaf, ()> {
44 let it = self.expect_leaf()?;
45 match it {
46 tt::Leaf::Literal(_) => Ok(it),
47 tt::Leaf::Ident(ident) if ident.text == "true" || ident.text == "false" => Ok(it),
48 _ => Err(()),
49 }
50 }
51
52 pub(crate) fn expect_punct(&mut self) -> Result<&'a tt::Punct, ()> {
53 match self.expect_leaf()? {
54 tt::Leaf::Punct(it) => Ok(it),
55 _ => Err(()),
56 }
57 }
58
59 pub(crate) fn peek_n(&self, n: usize) -> Option<&tt::TokenTree> {
60 self.inner.as_slice().get(n)
61 }
62}
63
64impl<'a> Iterator for TtIter<'a> {
65 type Item = &'a tt::TokenTree;
66 fn next(&mut self) -> Option<Self::Item> {
67 self.inner.next()
68 }
69
70 fn size_hint(&self) -> (usize, Option<usize>) {
71 self.inner.size_hint()
72 }
73}
74
75impl<'a> std::iter::ExactSizeIterator for TtIter<'a> {}