Rewrite the AST to be a bit more user-friendly
This commit is a relatively large rewrite of the AST that `syn` exposes. The
main change is to expose enums-of-structs rather than
enums-with-huge-tuple-variants. The best example of this is `ItemKind::Fn` which
changed from:
enum ItemKind {
Fn(Box<FnDecl>, Unsafety, Constness, Option<Abi>, Generics, Box<Block>),
...
}
to
enum ItemKind {
Fn(ItemFn),
...
}
struct ItemFn {
decl: Box<FnDecl>,
unsafety: Unsafety,
constness: Constness,
abi: Option<Abi>,
generics: Generics,
block: Box<Block>,
}
This change serves a few purposes:
* It's now much easier to add fields to each variant of the ast, ast struct
fields tend to be "by default ignored" in most contexts.
* It's much easier to document what each field is, as each field can have
dedicated documentation.
* There's now canonicalized names for each field (the name of the field) which
can help match `match` statements more consistent across a codebase.
A downside of this representation is that it can be a little more verbose to
work with in `match` statements and during constructions. Overall though I'd
feel at least that the readability improved significantly despite the extra
words required to do various operations.
Closes #136
diff --git a/src/lib.rs b/src/lib.rs
index 3f7f0df..f30683f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -15,11 +15,16 @@
#[cfg(feature = "aster")]
pub mod aster;
+#[macro_use]
+mod macros;
+
mod attr;
-pub use attr::{Attribute, AttrStyle, MetaItem, NestedMetaItem};
+pub use attr::{Attribute, AttrStyle, MetaItem, NestedMetaItem, MetaItemList,
+ MetaNameValue};
mod constant;
-pub use constant::ConstExpr;
+pub use constant::{ConstExpr, ConstCall, ConstBinary, ConstUnary, ConstCast,
+ ConstIndex, ConstParen};
mod data;
pub use data::{Field, Variant, VariantData, Visibility};
@@ -31,7 +36,13 @@
mod expr;
#[cfg(feature = "full")]
pub use expr::{Arm, BindingMode, Block, CaptureBy, Expr, ExprKind, FieldPat, FieldValue, Local,
- MacStmtStyle, Pat, RangeLimits, Stmt};
+ MacStmtStyle, Pat, RangeLimits, Stmt, ExprBox, ExprInPlace,
+ ExprArray, ExprCall, ExprMethodCall, ExprTup, ExprBinary, ExprUnary,
+ ExprCast, ExprType, ExprIf, ExprIfLet, ExprWhile, ExprWhileLet,
+ ExprForLoop, ExprLoop, ExprMatch, ExprClosure, ExprBlock,
+ ExprAssign, ExprAssignOp, ExprField, ExprTupField, ExprIndex,
+ ExprRange, ExprPath, ExprAddrOf, ExprBreak, ExprContinue,
+ ExprRet, ExprStruct, ExprRepeat, ExprParen, ExprTry, ExprCatch};
mod generics;
pub use generics::{Generics, Lifetime, LifetimeDef, TraitBoundModifier, TyParam, TyParamBound,
@@ -46,9 +57,15 @@
#[cfg(feature = "full")]
mod item;
#[cfg(feature = "full")]
-pub use item::{Constness, Defaultness, FnArg, FnDecl, ForeignItemKind, ForeignItem, ForeignMod,
+pub use item::{Constness, Defaultness, FnArg, FnDecl, ForeignItemKind, ForeignItem, ItemForeignMod,
ImplItem, ImplItemKind, ImplPolarity, Item, ItemKind, MethodSig, PathListItem,
- TraitItem, TraitItemKind, ViewPath};
+ TraitItem, TraitItemKind, ViewPath, ItemExternCrate, ItemUse,
+ ItemStatic, ItemConst, ItemFn, ItemMod, ItemTy, ItemEnum,
+ ItemStruct, ItemUnion, ItemTrait, ItemDefaultImpl, ItemImpl,
+ PathSimple, PathGlob, PathList, ForeignItemFn, ForeignItemStatic,
+ TraitItemConst, TraitItemMethod, TraitItemType,
+ ImplItemConst, ImplItemMethod, ImplItemType, ArgSelfRef,
+ ArgSelf, ArgCaptured};
#[cfg(feature = "full")]
mod krate;
@@ -75,7 +92,9 @@
mod ty;
pub use ty::{Abi, AngleBracketedParameterData, BareFnArg, BareFnTy, FunctionRetTy, MutTy,
Mutability, ParenthesizedParameterData, Path, PathParameters, PathSegment,
- PolyTraitRef, QSelf, Ty, TypeBinding, Unsafety};
+ PolyTraitRef, QSelf, Ty, TypeBinding, Unsafety, TySlice, TyArray,
+ TyPtr, TyRptr, TyBareFn, TyNever, TyTup, TyPath, TyTraitObject,
+ TyImplTrait, TyParen, TyInfer};
#[cfg(feature = "visit")]
pub mod visit;