chore: Clean up parse logic for Value
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
/target
|
/target
|
||||||
|
/expand.rs
|
||||||
|
|||||||
31
src/cmd.rs
31
src/cmd.rs
@@ -1,5 +1,10 @@
|
|||||||
use quote::{quote, ToTokens};
|
use quote::{quote, ToTokens};
|
||||||
use syn::{braced, bracketed, parse::Parse, punctuated::Punctuated, token, Token};
|
use syn::{
|
||||||
|
braced, bracketed,
|
||||||
|
parse::{discouraged::Speculative, Parse},
|
||||||
|
punctuated::Punctuated,
|
||||||
|
token, Token,
|
||||||
|
};
|
||||||
|
|
||||||
pub struct Command {
|
pub struct Command {
|
||||||
program: Value,
|
program: Value,
|
||||||
@@ -376,15 +381,23 @@ impl Parse for Value {
|
|||||||
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
||||||
let expr_fork = input.fork();
|
let expr_fork = input.fork();
|
||||||
expr_fork
|
expr_fork
|
||||||
.parse::<syn::Expr>()
|
.parse()
|
||||||
.and_then(|_| input.parse().map(Self::Expr))
|
.map(|expr| {
|
||||||
.or_else(|_| {
|
input.advance_to(&expr_fork);
|
||||||
let ident_fork = input.fork();
|
Self::Expr(expr)
|
||||||
ident_fork
|
})
|
||||||
.parse::<syn::Ident>()
|
.or_else(|_| {
|
||||||
.and_then(|_| input.parse().map(Self::Ident))
|
if input.peek(syn::Ident) {
|
||||||
|
input.parse().map(Self::Ident)
|
||||||
|
} else if input.peek(syn::Lit) {
|
||||||
|
input.parse().map(Self::Lit)
|
||||||
|
} else {
|
||||||
|
Err(syn::Error::new(
|
||||||
|
input.span(),
|
||||||
|
"Expected an expression, ident, or literal",
|
||||||
|
))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.or_else(|_| input.parse().map(Self::Lit))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user