Rewrite tokenization with `proc-macro2` tokens
This ended up being a bit larger of a commit than I intended! I imagine that
this'll be one of the larger of the commits working towards #142. The purpose of
this commit is to use an updated version of the `quote` crate which doesn't work
with strings but rather works with tokens form the `proc-macro2` crate. The
`proc-macro2` crate itself is based on the proposed API for `proc_macro` itself,
and will continue to mirror it. The hope is that we'll flip an easy switch
eventually to use compiler tokens, whereas for now we'll stick to string parsing
at the lowest layer.
The largest change here is the addition of span information to the AST. Building
on the previous PRs to refactor the AST this makes it relatively easy from a
user perspective to digest and use the AST still, it's just a few extra fields
on the side. The fallout from this was then quite large throughout the
`printing` feature of the crate. The `parsing`, `fold`, and `visit` features
then followed suit to get updated as well.
This commit also changes the the semantics of the AST somewhat as well.
Previously it was inferred what tokens should be printed, for example if you
have a closure argument `syn` would automatically not print the colon in `a: b`
if the type listed was "infer this type". Now the colon is a separate field and
must be in sync with the type listed as the colon/type will be printed
unconditionally (emitting no output if both are `None`).
diff --git a/src/lib.rs b/src/lib.rs
index f30683f..b422c6c 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -2,14 +2,15 @@
#![cfg_attr(feature = "cargo-clippy", allow(large_enum_variant))]
+extern crate proc_macro2;
+
#[cfg(feature = "printing")]
extern crate quote;
#[cfg(feature = "parsing")]
extern crate unicode_xid;
-#[cfg(feature = "parsing")]
-#[macro_use]
+#[cfg_attr(feature = "parsing", macro_use)]
extern crate synom;
#[cfg(feature = "aster")]
@@ -27,7 +28,8 @@
ConstIndex, ConstParen};
mod data;
-pub use data::{Field, Variant, VariantData, Visibility};
+pub use data::{Field, Variant, VariantData, Visibility, VisRestricted, VisCrate,
+ VisPublic, VisInherited};
#[cfg(feature = "parsing")]
mod escape;
@@ -42,12 +44,14 @@
ExprForLoop, ExprLoop, ExprMatch, ExprClosure, ExprBlock,
ExprAssign, ExprAssignOp, ExprField, ExprTupField, ExprIndex,
ExprRange, ExprPath, ExprAddrOf, ExprBreak, ExprContinue,
- ExprRet, ExprStruct, ExprRepeat, ExprParen, ExprTry, ExprCatch};
+ ExprRet, ExprStruct, ExprRepeat, ExprParen, ExprTry, ExprCatch,
+ PatIdent, PatWild, PatStruct, PatTuple, PatTupleStruct, PatPath,
+ PatBox, PatRef, PatLit, PatRange, PatSlice};
mod generics;
pub use generics::{Generics, Lifetime, LifetimeDef, TraitBoundModifier, TyParam, TyParamBound,
WhereBoundPredicate, WhereClause, WhereEqPredicate, WherePredicate,
- WhereRegionPredicate};
+ WhereRegionPredicate, BoundLifetimes};
#[cfg(feature = "printing")]
pub use generics::{ImplGenerics, Turbofish, TyGenerics};
@@ -73,15 +77,13 @@
pub use krate::Crate;
mod lit;
-pub use lit::{FloatTy, IntTy, Lit, StrStyle};
-#[cfg(feature = "parsing")]
-pub use lit::{ByteStrLit, FloatLit, IntLit, StrLit};
+pub use lit::{Lit, LitKind};
mod mac;
-pub use mac::{BinOpToken, DelimToken, Delimited, Mac, Token, TokenTree};
+pub use mac::{Mac, TokenTree};
mod derive;
-pub use derive::{Body, DeriveInput};
+pub use derive::{Body, DeriveInput, BodyEnum, BodyStruct};
// Deprecated. Use `DeriveInput` instead.
#[doc(hidden)]
pub type MacroInput = DeriveInput;
@@ -95,6 +97,14 @@
PolyTraitRef, QSelf, Ty, TypeBinding, Unsafety, TySlice, TyArray,
TyPtr, TyRptr, TyBareFn, TyNever, TyTup, TyPath, TyTraitObject,
TyImplTrait, TyParen, TyInfer};
+#[cfg(feature = "printing")]
+pub use ty::PathTokens;
+
+mod span;
+pub use span::Span;
+
+pub mod tokens;
+pub use synom::delimited;
#[cfg(feature = "visit")]
pub mod visit;