A simple crate for reducing the boilerplate when writing parsers with [syn].
Structs
#[syn([parenthesized])],
#[syn([braced])],
#[syn([bracketed])]:
Corresponds to the isonymous macros in syn.
Must be attached to [struct@Paren], [struct@Brace], and [struct@Bracket] fields, respectively.
#[syn(in = [struct@Ident])]:
The field is read from inside the named delimiter pair.
#[parse(fn([ParseStream]) -> [syn::Result]<T>)]:
A function used to parse the field,
often used with [Punctuated::parse_terminated]
or [Attribute::parse_outer].
#[to_tokens(fn(&mut [TokenStream], &T)]:
A function used to tokenize the field.
Often used with [TokenStreamExt::append_all],
though for type resolution reasons this needs to be indirected through a closure expression.
Enums
#[parse(peek = [Token])]:
Checks whether the variant should be parsed.
Even if multiple peeks succeed, only the first successful variant is attempted.
#[parse(peek_func = fn([ParseStream]) -> [bool])]:
More powerful than peek (such as allowing peek2), but gives worse error messages on failure.
peek should be preferred when possible.
Alternatives
derive-syn-parsedoes not handle [ToTokens]. It also seems to encourage throwing tokens away with itsprefixandpostfixattributes.parseluses its own types for parentheses, meaning the AST types have different API from [syn]'s own.