Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/mbe/src/parser.rs')
-rw-r--r--crates/mbe/src/parser.rs21
1 files changed, 11 insertions, 10 deletions
diff --git a/crates/mbe/src/parser.rs b/crates/mbe/src/parser.rs
index ddf9afbf98..796ee62d48 100644
--- a/crates/mbe/src/parser.rs
+++ b/crates/mbe/src/parser.rs
@@ -192,7 +192,7 @@ impl PartialEq for Separator {
match (self, other) {
(Ident(a), Ident(b)) => a.sym == b.sym,
- (Literal(a), Literal(b)) => a.symbol == b.symbol,
+ (Literal(a), Literal(b)) => a.text_and_suffix == b.text_and_suffix,
(Puncts(a), Puncts(b)) if a.len() == b.len() => {
let a_iter = a.iter().map(|a| a.char);
let b_iter = b.iter().map(|b| b.char);
@@ -224,7 +224,7 @@ fn next_op(
None => {
return Ok(Op::Punct({
let mut res = ArrayVec::new();
- res.push(*p);
+ res.push(p);
Box::new(res)
}));
}
@@ -268,9 +268,9 @@ fn next_op(
let id = ident.span;
Op::Var { name, kind, id }
}
- tt::Leaf::Literal(lit) if is_boolean_literal(lit) => {
+ tt::Leaf::Literal(lit) if is_boolean_literal(&lit) => {
let kind = eat_fragment_kind(edition, src, mode)?;
- let name = lit.symbol.clone();
+ let name = lit.text_and_suffix.clone();
let id = lit.span;
Op::Var { name, kind, id }
}
@@ -282,7 +282,7 @@ fn next_op(
}
Mode::Template => Op::Punct({
let mut res = ArrayVec::new();
- res.push(*punct);
+ res.push(punct);
Box::new(res)
}),
},
@@ -364,7 +364,7 @@ fn eat_fragment_kind(
}
fn is_boolean_literal(lit: &tt::Literal) -> bool {
- matches!(lit.symbol.as_str(), "true" | "false")
+ lit.text_and_suffix == sym::true_ || lit.text_and_suffix == sym::false_
}
fn parse_repeat(src: &mut TtIter<'_>) -> Result<(Option<Separator>, RepeatKind), ParseError> {
@@ -400,7 +400,7 @@ fn parse_repeat(src: &mut TtIter<'_>) -> Result<(Option<Separator>, RepeatKind),
'?' => RepeatKind::ZeroOrOne,
_ => match &mut separator {
Separator::Puncts(puncts) if puncts.len() < 3 => {
- puncts.push(*punct);
+ puncts.push(punct);
continue;
}
_ => return Err(ParseError::InvalidRepeat),
@@ -478,11 +478,12 @@ fn parse_metavar_expr(src: &mut TtIter<'_>) -> Result<Op, ()> {
fn parse_depth(src: &mut TtIter<'_>) -> Result<usize, ()> {
if src.is_empty() {
Ok(0)
- } else if let tt::Leaf::Literal(tt::Literal { symbol: text, suffix: None, .. }) =
- src.expect_literal()?
+ } else if let tt::Leaf::Literal(lit) = src.expect_literal()?
+ && let (text, suffix) = lit.text_and_suffix()
+ && suffix.is_empty()
{
// Suffixes are not allowed.
- text.as_str().parse().map_err(|_| ())
+ text.parse().map_err(|_| ())
} else {
Err(())
}