From f3489e8111e02bbd4e882d05d2fffe29962aef71 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 31 Jan 2019 11:30:21 +0300 Subject: add eat methods --- crates/ra_hir/src/macros/mbe.rs | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'crates/ra_hir/src') 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 { } fn parse_rule(p: &mut RulesParser) -> Option { - let lhs = match p.current()? { - tt::TokenTree::Subtree(sub) => parse_subtree(sub)?, - _ => return None, - }; - let rhs = unimplemented!(); + let lhs = parse_subtree(p.eat_subtree()?)?; + p.eat_punct('='); + p.eat_punct('>'); + let rhs = parse_subtree(p.eat_subtree()?)?; Some(Rule { lhs, rhs }) } fn parse_subtree(tt: &tt::Subtree) -> Option { - unimplemented!() + None } struct RulesParser<'a> { @@ -118,4 +117,22 @@ impl<'a> RulesParser<'a> { fn bump(&mut self) { self.pos += 1; } + fn eat_subtree(&mut self) -> Option<&'a tt::Subtree> { + match self.current()? { + tt::TokenTree::Subtree(sub) => { + self.bump(); + Some(sub) + } + _ => return None, + } + } + fn eat_punct(&mut self, char: char) -> Option<()> { + match self.current()? { + tt::TokenTree::Leaf(tt::Leaf::Punct(tt::Punct { char: c })) if *c == char => { + self.bump(); + Some(()) + } + _ => None, + } + } } -- cgit v1.2.3