diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/macros/mbe.rs | 29 |
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 | ||
87 | fn parse_rule(p: &mut RulesParser) -> Option<Rule> { | 87 | fn 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 | ||
96 | fn parse_subtree(tt: &tt::Subtree) -> Option<Subtree> { | 95 | fn parse_subtree(tt: &tt::Subtree) -> Option<Subtree> { |
97 | unimplemented!() | 96 | None |
98 | } | 97 | } |
99 | 98 | ||
100 | struct RulesParser<'a> { | 99 | struct 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 | } |