1
Fork 0

asm: Unify pseudo-keyword parsing using eat, rather than a final expect

Currently, `asm!` parsing uses an `expect` for the last parsed
pseudo-keyword (`sym`), which makes it difficult to extend without
simultaneously refactoring. Use `eat` for the last pseudo-keyword, and
then add an `else` that fails parsing. No change to error output.
This commit is contained in:
Josh Triplett 2020-06-14 14:17:51 -07:00
parent 4fb54ed484
commit 840176ab6f

View file

@ -135,8 +135,7 @@ fn parse_args<'a>(
} else if p.eat(&token::Ident(kw::Const, false)) {
let expr = p.parse_expr()?;
ast::InlineAsmOperand::Const { expr }
} else {
p.expect(&token::Ident(sym::sym, false))?;
} else if p.eat(&token::Ident(sym::sym, false)) {
let expr = p.parse_expr()?;
match expr.kind {
ast::ExprKind::Path(..) => {}
@ -147,6 +146,8 @@ fn parse_args<'a>(
}
}
ast::InlineAsmOperand::Sym { expr }
} else {
return Err(p.expect_one_of(&[], &[]).unwrap_err());
};
let span = span_start.to(p.prev_token.span);