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/synom/src/helper.rs b/synom/src/helper.rs
index a488359..5bae69b 100644
--- a/synom/src/helper.rs
+++ b/synom/src/helper.rs
@@ -227,14 +227,17 @@
/// extern crate syn;
/// #[macro_use] extern crate synom;
///
-/// use syn::{Expr, ExprKind};
+/// use syn::{Expr, ExprCall};
/// use syn::parse::expr;
///
/// named!(expr_with_arrow_call -> Expr, do_parse!(
/// mut e: expr >>
/// many0!(tap!(arg: tuple!(punct!("=>"), expr) => {
/// e = Expr {
-/// node: ExprKind::Call(Box::new(e), vec![arg.1]),
+/// node: ExprCall {
+/// func: Box::new(e),
+/// args: vec![arg.1],
+/// }.into(),
/// attrs: Vec::new(),
/// };
/// })) >>