fix: Properly parse Expressions, Idents, and Literals

This commit is contained in:
2025-01-11 11:16:23 -05:00
parent 295623efb2
commit ebc4cc0bd4
4 changed files with 80 additions and 9 deletions

View File

@@ -374,13 +374,17 @@ enum Value {
impl Parse for Value {
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
if input.peek(syn::Lit) {
input.parse().map(Self::Lit)
} else if input.peek(syn::Ident) {
input.parse().map(Self::Ident)
} else {
input.parse().map(Self::Expr)
}
let expr_fork = input.fork();
expr_fork
.parse::<syn::Expr>()
.and_then(|_| input.parse().map(Self::Expr))
.or_else(|_| {
let ident_fork = input.fork();
ident_fork
.parse::<syn::Ident>()
.and_then(|_| input.parse().map(Self::Ident))
})
.or_else(|_| input.parse().map(Self::Lit))
}
}