use proc_macro2::{Group, Literal, Punct, TokenStream, TokenTree};
use syn::token::{
Abstract, And, AndAnd, AndEq, As, Async, At, Auto, Await, Become, Break, Caret, CaretEq, Colon,
Comma, Const, Continue, Crate, Do, Dollar, Dot, DotDot, DotDotDot, DotDotEq, Dyn, Else, Enum,
Eq, EqEq, Extern, FatArrow, Final, Fn, For, Ge, Gt, If, Impl, In, LArrow, Le, Let, Loop, Lt,
Match, Minus, MinusEq, Mod, Move, Mut, Ne, Not, Or, OrEq, OrOr, Override, PathSep, Percent,
PercentEq, Plus, PlusEq, Pound, Priv, Pub, Question, RArrow, Ref, Return, SelfType, SelfValue,
Semi, Shl, ShlEq, Shr, ShrEq, Slash, SlashEq, Star, StarEq, Static, Struct, Super, Tilde,
Trait, Try, Typeof, Underscore, Union, Unsafe, Unsized, Use, Virtual, Where, While, Yield,
};
use syn::{
Abi, AngleBracketedGenericArguments, BareFnArg, BinOp, BoundLifetimes, ConstParam, DeriveInput,
Expr, FieldsNamed, FieldsUnnamed, GenericArgument, GenericParam, Generics, Ident, Index,
Lifetime, Lit, LitBool, LitByteStr, LitChar, LitFloat, LitInt, LitStr, Member, Meta, MetaList,
MetaNameValue, ParenthesizedGenericArguments, Path, PathSegment, ReturnType, TraitBound,
TraitBoundModifier, Type, TypeArray, TypeBareFn, TypeGroup, TypeImplTrait, TypeInfer,
TypeMacro, TypeNever, TypeParam, TypeParamBound, TypeParen, TypePath, TypePtr, TypeReference,
TypeSlice, TypeTraitObject, TypeTuple, UnOp, Variant, Visibility, WhereClause, WherePredicate,
};
use crate::parsing::*;
use crate::*;
macro_rules! ParseToTokensAttribute {
($($type:ty),+ $(,)?) => {$(
impl AttributeBase for $type {
type Partial = Self;
}
impl AttributeValue for $type {
fn parse_value(input: syn::parse::ParseStream) -> Result<SpannedValue<Self::Partial>> {
input.parse().map(SpannedValue::from_to_tokens)
}
}
impl PositionalValue for $type {}
)*}
}
impl AttributeBase for TokenStream {
type Partial = Self;
}
impl AttributeMeta for TokenStream {
fn parse_inner(input: ParseStream) -> Result<Self::Partial> {
input.parse()
}
}
ParseToTokensAttribute!(Type);
ParseToTokensAttribute!(Path);
ParseToTokensAttribute!(Lit);
ParseToTokensAttribute![LitStr, LitByteStr, LitChar, LitInt, LitFloat, LitBool];
ParseToTokensAttribute!(Expr);
ParseToTokensAttribute![TokenTree, Group, Punct, Literal];
ParseToTokensAttribute![
Abi,
Abstract,
Plus,
PlusEq,
And,
AndAnd,
AndEq,
AngleBracketedGenericArguments,
As,
Async,
At,
Auto,
Await,
Not,
BareFnArg,
Become,
BinOp,
BoundLifetimes,
Break,
Caret,
CaretEq,
Colon,
PathSep,
Comma,
Const,
ConstParam,
Continue,
Crate,
DeriveInput,
Slash,
SlashEq,
Do,
Dollar,
Dot,
DotDot,
DotDotDot,
DotDotEq,
Dyn,
Else,
Enum,
Eq,
EqEq,
Extern,
FatArrow,
FieldsNamed,
FieldsUnnamed,
Final,
Fn,
For,
Ge,
GenericArgument,
GenericParam,
Generics,
Gt,
Ident,
If,
Impl,
In,
Index,
LArrow,
Le,
Let,
Lifetime,
Loop,
Lt,
Match,
Member,
Meta,
MetaList,
MetaNameValue,
Mod,
Move,
StarEq,
Mut,
Ne,
Or,
OrEq,
OrOr,
Override,
ParenthesizedGenericArguments,
PathSegment,
Pound,
Priv,
Pub,
Question,
RArrow,
Ref,
Percent,
PercentEq,
Return,
ReturnType,
SelfType,
SelfValue,
Semi,
Shl,
ShlEq,
Shr,
ShrEq,
Star,
Static,
Struct,
Minus,
MinusEq,
Super,
Tilde,
Trait,
TraitBound,
TraitBoundModifier,
Try,
TypeArray,
TypeBareFn,
TypeGroup,
TypeImplTrait,
TypeInfer,
TypeMacro,
TypeNever,
TypeParam,
TypeParamBound,
TypeParen,
TypePath,
TypePtr,
TypeReference,
TypeSlice,
TypeTraitObject,
TypeTuple,
Typeof,
UnOp,
Underscore,
Union,
Unsafe,
Unsized,
Use,
Variant,
Virtual,
Visibility,
Where,
WhereClause,
WherePredicate,
While,
Yield,
syn::Macro,
syn::token::Box,
syn::token::Default,
syn::token::Macro,
syn::token::Type,
];
#[cfg(feature = "syn-full")]
mod syn_full {
use syn::{
Arm, Block, ExprArray, ExprAssign, ExprAsync, ExprBinary, ExprBlock, ExprBreak, ExprCall,
ExprCast, ExprClosure, ExprContinue, ExprField, ExprForLoop, ExprIf, ExprIndex, ExprLet,
ExprLit, ExprLoop, ExprMacro, ExprMatch, ExprMethodCall, ExprParen, ExprPath, ExprRange,
ExprReference, ExprRepeat, ExprReturn, ExprStruct, ExprTry, ExprTryBlock, ExprTuple,
ExprUnary, ExprUnsafe, ExprWhile, ExprYield, FieldValue, File, FnArg, ForeignItem,
ForeignItemFn, ForeignItemMacro, ForeignItemStatic, ForeignItemType, ImplItem,
ImplItemConst, ImplItemMacro, ImplItemType, Item, ItemConst, ItemEnum, ItemExternCrate,
ItemFn, ItemForeignMod, ItemImpl, ItemMacro, ItemMod, ItemStatic, ItemStruct, ItemTrait,
ItemTraitAlias, ItemType, ItemUnion, ItemUse, Label, RangeLimits, Receiver, Signature,
Stmt, TraitItem, TraitItemConst, TraitItemMacro, TraitItemType, UseTree,
};
use super::*;
ParseToTokensAttribute![
Arm,
Block,
ExprArray,
ExprAssign,
ExprAsync,
ExprBinary,
ExprBlock,
ExprBreak,
ExprCall,
ExprCast,
ExprClosure,
ExprContinue,
ExprField,
ExprForLoop,
ExprIf,
ExprIndex,
ExprLet,
ExprLit,
ExprLoop,
ExprMacro,
ExprMatch,
ExprMethodCall,
ExprParen,
ExprPath,
ExprRange,
ExprReference,
ExprRepeat,
ExprReturn,
ExprStruct,
ExprTry,
ExprTryBlock,
ExprTuple,
ExprUnary,
ExprUnsafe,
ExprWhile,
ExprYield,
FieldValue,
File,
FnArg,
ForeignItem,
ForeignItemFn,
ForeignItemMacro,
ForeignItemStatic,
ForeignItemType,
ImplItem,
ImplItemConst,
ImplItemMacro,
ImplItemType,
Item,
ItemConst,
ItemEnum,
ItemExternCrate,
ItemFn,
ItemForeignMod,
ItemImpl,
ItemMacro,
ItemMod,
ItemStatic,
ItemStruct,
ItemTrait,
ItemTraitAlias,
ItemType,
ItemUnion,
ItemUse,
Label,
RangeLimits,
Receiver,
Signature,
Stmt,
TraitItem,
TraitItemConst,
TraitItemMacro,
TraitItemType,
UseTree,
];
}