1use syn::parse::{Error, Parse, ParseStream, Result};
2use syn::{LitInt, Path, Token};
3
4pub enum Args {
5 None,
6 Path(Path),
7 PathPos(Path, usize),
8}
9
10impl Parse for Args {
11 fn parse(input: ParseStream) -> Result<Self> {
12 if input.is_empty() {
13 return Ok(Args::None);
14 }
15 let path: Path = input.parse()?;
16 if input.is_empty() {
17 return Ok(Args::Path(path));
18 }
19 input.parse::<Token![,]>()?;
20 let lit: LitInt = input.parse()?;
21 let pos: usize = lit.base10_parse()?;
22 if pos > 9999 {
23 return Err(Error::new(lit.span(), "maximum 9999 is supported"));
24 }
25 Ok(Args::PathPos(path, pos))
26 }
27}