aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-31 08:30:21 +0000
committerAleksey Kladov <[email protected]>2019-01-31 20:23:30 +0000
commitf3489e8111e02bbd4e882d05d2fffe29962aef71 (patch)
treec6d54d7e08e6adfaf1782eba58ce8726fead6aa3
parente28a5e048a9da3091897c86e48bc7d4fb2cf601c (diff)
add eat methods
-rw-r--r--crates/ra_hir/src/macros/mbe.rs29
1 files changed, 23 insertions, 6 deletions
diff --git a/crates/ra_hir/src/macros/mbe.rs b/crates/ra_hir/src/macros/mbe.rs
index 2e7f9cbf4..3d6dcefa8 100644
--- a/crates/ra_hir/src/macros/mbe.rs
+++ b/crates/ra_hir/src/macros/mbe.rs
@@ -85,16 +85,15 @@ pub(crate) fn parse(tt: &tt::Subtree) -> Option<MacroRules> {
85} 85}
86 86
87fn parse_rule(p: &mut RulesParser) -> Option<Rule> { 87fn parse_rule(p: &mut RulesParser) -> Option<Rule> {
88 let lhs = match p.current()? { 88 let lhs = parse_subtree(p.eat_subtree()?)?;
89 tt::TokenTree::Subtree(sub) => parse_subtree(sub)?, 89 p.eat_punct('=');
90 _ => return None, 90 p.eat_punct('>');
91 }; 91 let rhs = parse_subtree(p.eat_subtree()?)?;
92 let rhs = unimplemented!();
93 Some(Rule { lhs, rhs }) 92 Some(Rule { lhs, rhs })
94} 93}
95 94
96fn parse_subtree(tt: &tt::Subtree) -> Option<Subtree> { 95fn parse_subtree(tt: &tt::Subtree) -> Option<Subtree> {
97 unimplemented!() 96 None
98} 97}
99 98
100struct RulesParser<'a> { 99struct RulesParser<'a> {
@@ -118,4 +117,22 @@ impl<'a> RulesParser<'a> {
118 fn bump(&mut self) { 117 fn bump(&mut self) {
119 self.pos += 1; 118 self.pos += 1;
120 } 119 }
120 fn eat_subtree(&mut self) -> Option<&'a tt::Subtree> {
121 match self.current()? {
122 tt::TokenTree::Subtree(sub) => {
123 self.bump();
124 Some(sub)
125 }
126 _ => return None,
127 }
128 }
129 fn eat_punct(&mut self, char: char) -> Option<()> {
130 match self.current()? {
131 tt::TokenTree::Leaf(tt::Leaf::Punct(tt::Punct { char: c })) if *c == char => {
132 self.bump();
133 Some(())
134 }
135 _ => None,
136 }
137 }
121} 138}