diff options
Diffstat (limited to 'crates/mbe/src/lib.rs')
-rw-r--r-- | crates/mbe/src/lib.rs | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/crates/mbe/src/lib.rs b/crates/mbe/src/lib.rs index 56c632665..d80bd7a33 100644 --- a/crates/mbe/src/lib.rs +++ b/crates/mbe/src/lib.rs | |||
@@ -92,18 +92,11 @@ struct Rule { | |||
92 | } | 92 | } |
93 | 93 | ||
94 | #[derive(Clone, Debug, PartialEq, Eq)] | 94 | #[derive(Clone, Debug, PartialEq, Eq)] |
95 | struct MetaTemplate { | 95 | struct MetaTemplate(Vec<Op>); |
96 | delimiter: Option<Delimiter>, | ||
97 | tokens: Vec<Op>, | ||
98 | } | ||
99 | 96 | ||
100 | impl<'a> MetaTemplate { | 97 | impl<'a> MetaTemplate { |
101 | fn iter(&self) -> impl Iterator<Item = &Op> { | 98 | fn iter(&self) -> impl Iterator<Item = &Op> { |
102 | self.tokens.iter() | 99 | self.0.iter() |
103 | } | ||
104 | |||
105 | fn delimiter_kind(&self) -> Option<DelimiterKind> { | ||
106 | self.delimiter.map(|it| it.kind) | ||
107 | } | 100 | } |
108 | } | 101 | } |
109 | 102 | ||
@@ -288,8 +281,8 @@ impl Rule { | |||
288 | .expect_subtree() | 281 | .expect_subtree() |
289 | .map_err(|()| ParseError::Expected("expected subtree".to_string()))?; | 282 | .map_err(|()| ParseError::Expected("expected subtree".to_string()))?; |
290 | 283 | ||
291 | let lhs = MetaTemplate { tokens: parse_pattern(&lhs)?, delimiter: None }; | 284 | let lhs = MetaTemplate(parse_pattern(&lhs)?); |
292 | let rhs = MetaTemplate { tokens: parse_template(&rhs)?, delimiter: None }; | 285 | let rhs = MetaTemplate(parse_template(&rhs)?); |
293 | 286 | ||
294 | Ok(crate::Rule { lhs, rhs }) | 287 | Ok(crate::Rule { lhs, rhs }) |
295 | } | 288 | } |
@@ -298,8 +291,8 @@ impl Rule { | |||
298 | fn validate(pattern: &MetaTemplate) -> Result<(), ParseError> { | 291 | fn validate(pattern: &MetaTemplate) -> Result<(), ParseError> { |
299 | for op in pattern.iter() { | 292 | for op in pattern.iter() { |
300 | match op { | 293 | match op { |
301 | Op::Subtree(subtree) => validate(&subtree)?, | 294 | Op::Subtree { tokens, .. } => validate(&tokens)?, |
302 | Op::Repeat { subtree, separator, .. } => { | 295 | Op::Repeat { tokens: subtree, separator, .. } => { |
303 | // Checks that no repetition which could match an empty token | 296 | // Checks that no repetition which could match an empty token |
304 | // https://github.com/rust-lang/rust/blob/a58b1ed44f5e06976de2bdc4d7dc81c36a96934f/src/librustc_expand/mbe/macro_rules.rs#L558 | 297 | // https://github.com/rust-lang/rust/blob/a58b1ed44f5e06976de2bdc4d7dc81c36a96934f/src/librustc_expand/mbe/macro_rules.rs#L558 |
305 | 298 | ||
@@ -319,7 +312,7 @@ fn validate(pattern: &MetaTemplate) -> Result<(), ParseError> { | |||
319 | ) | 312 | ) |
320 | } | 313 | } |
321 | Op::Leaf(_) => {} | 314 | Op::Leaf(_) => {} |
322 | Op::Subtree(_) => {} | 315 | Op::Subtree { .. } => {} |
323 | } | 316 | } |
324 | false | 317 | false |
325 | }) { | 318 | }) { |