Prepare for merge
diff --git a/src/ast.rs b/src/ast.rs
deleted file mode 100644
index 2c51a80..0000000
--- a/src/ast.rs
+++ /dev/null
@@ -1,102 +0,0 @@
-use proc_macro2::Ident;
-
-use parse::{Parse, ParseStream, Result};
-use token;
-
-/// Things that can appear directly inside of a module or scope.
-#[derive(Debug)]
-pub enum Item {
- Struct(ItemStruct),
- Enum(ItemEnum),
-}
-
-/// A struct definition: `struct S { a: A, b: B }`.
-#[derive(Debug)]
-pub struct ItemStruct {
- pub struct_token: Token![struct],
- pub ident: Ident,
- pub brace_token: token::Brace,
- pub fields: Vec<Field>,
-}
-
-/// An enum definition: `enum E { A, B, C }`.
-#[derive(Debug)]
-pub struct ItemEnum {
- pub enum_token: Token![enum],
- pub ident: Ident,
- pub brace_token: token::Brace,
- pub variants: Vec<Variant>,
-}
-
-/// A named field of a braced struct.
-#[derive(Debug)]
-pub struct Field {
- pub name: Ident,
- pub colon_token: Token![:],
- pub ty: Ident,
- pub comma_token: Token![,],
-}
-
-/// An enum variant.
-#[derive(Debug)]
-pub struct Variant {
- pub name: Ident,
- pub comma_token: token::Comma,
-}
-
-impl Parse for Item {
- fn parse(input: ParseStream) -> Result<Self> {
- let lookahead = input.lookahead1();
- if lookahead.peek(Token![struct]) {
- input.parse().map(Item::Struct)
- } else if lookahead.peek(Token![enum]) {
- input.parse().map(Item::Enum)
- } else {
- Err(lookahead.error())
- }
- }
-}
-
-impl Parse for ItemStruct {
- fn parse(input: ParseStream) -> Result<Self> {
- let content;
- Ok(ItemStruct {
- struct_token: input.parse()?,
- ident: input.parse()?,
- brace_token: braced!(content in input),
- fields: content.parse()?,
- })
- }
-}
-
-impl Parse for ItemEnum {
- fn parse(input: ParseStream) -> Result<Self> {
- let content;
- Ok(ItemEnum {
- enum_token: input.parse()?,
- ident: input.parse()?,
- brace_token: braced!(content in input),
- variants: content.parse()?,
- })
- }
-}
-
-impl Parse for Field {
- fn parse(input: ParseStream) -> Result<Self> {
- Ok(Field {
- name: input.parse()?,
- colon_token: input.parse()?,
- ty: input.parse()?,
- comma_token: input.parse()?,
- })
- }
-}
-
-impl Parse for Variant {
- fn parse(input: ParseStream) -> Result<Self> {
- Ok(Variant {
- name: input.parse()?,
- comma_token: input.parse()?,
- })
- }
-}
diff --git a/src/lib.rs b/src/lib.rs
index 57f5d4a..028ae2e 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -6,98 +6,4 @@
#[cfg(feature = "proc-macro")]
extern crate proc_macro;
-#[macro_use]
-pub mod token;
-
-#[macro_use]
-pub mod parse;
-
-#[macro_use]
-mod group;
-
-mod ast;
-mod error;
-mod lookahead;
-mod span;
-
-pub use ast::*;
-pub use proc_macro2::Ident;
-
-// Not public API.
-#[doc(hidden)]
-pub mod export;
-
-use std::str::FromStr;
-
-use proc_macro2::Span;
-use syn::buffer::TokenBuffer;
-
-use parse::{Parse, ParseBuffer, Result};
-
-/// Parse tokens of source code into the chosen syntax tree node.
-#[cfg(feature = "proc-macro")]
-pub fn parse<T: Parse>(input: proc_macro::TokenStream) -> Result<T> {
- parse2(proc_macro2::TokenStream::from(input))
-}
-
-/// Parse a proc-macro2 token stream into the chosen syntax tree node.
-pub fn parse2<T: Parse>(input: proc_macro2::TokenStream) -> Result<T> {
- let buf = TokenBuffer::new2(input);
- let state = ParseBuffer::new(Span::call_site(), buf.begin());
- T::parse(&state)
-}
-
-/// Parse a string of Rust code into the chosen syntax tree node.
-pub fn parse_str<T: Parse>(input: &str) -> Result<T> {
- let tokens = proc_macro2::TokenStream::from_str(input)?;
- parse2(tokens)
-}
-
-/// Parse the input TokenStream of a macro, triggering a compile error if the
-/// tokens fail to parse.
-///
-/// # Intended usage
-///
-/// ```rust
-/// # extern crate proc_macro;
-/// # extern crate syn_error_experiment;
-/// #
-/// use proc_macro::TokenStream;
-/// use syn_error_experiment::parse_macro_input;
-/// use syn_error_experiment::parse::{Parse, ParseStream, Result};
-///
-/// struct MyMacroInput {
-/// /* ... */
-/// }
-///
-/// impl Parse for MyMacroInput {
-/// fn parse(input: ParseStream) -> Result<Self> {
-/// /* ... */
-/// # Ok(MyMacroInput {})
-/// }
-/// }
-///
-/// # const IGNORE: &str = stringify! {
-/// #[proc_macro]
-/// # };
-/// pub fn my_macro(tokens: TokenStream) -> TokenStream {
-/// let input = parse_macro_input!(tokens as MyMacroInput);
-///
-/// /* ... */
-/// # "".parse().unwrap()
-/// }
-/// #
-/// # fn main() {}
-/// ```
-#[cfg(feature = "proc-macro")]
-#[macro_export]
-macro_rules! parse_macro_input {
- ($tokenstream:ident as $ty:ty) => {
- match $crate::parse::<$ty>($tokenstream) {
- $crate::export::Ok(data) => data,
- $crate::export::Err(err) => {
- return $crate::export::TokenStream::from(err.into_compile_error());
- }
- };
- };
-}
+pub mod next;
diff --git a/src/main.rs b/src/main.rs
deleted file mode 100644
index e6f0840..0000000
--- a/src/main.rs
+++ /dev/null
@@ -1,11 +0,0 @@
-extern crate syn_error_experiment;
-
-use syn_error_experiment::*;
-
-fn main() {
- let input = "struct S { a: A, b: B, }";
- println!("{:#?}", parse_str::<Item>(input).unwrap());
-
- let input = "enum E { A, B, }";
- println!("{:#?}", parse_str::<Item>(input).unwrap());
-}
diff --git a/src/error.rs b/src/next/error.rs
similarity index 100%
rename from src/error.rs
rename to src/next/error.rs
diff --git a/src/export.rs b/src/next/export.rs
similarity index 100%
rename from src/export.rs
rename to src/next/export.rs
diff --git a/src/group.rs b/src/next/group.rs
similarity index 86%
rename from src/group.rs
rename to src/next/group.rs
index da8a7fc..dca4d1c 100644
--- a/src/group.rs
+++ b/src/next/group.rs
@@ -1,7 +1,7 @@
use proc_macro2::Delimiter;
-use parse::{ParseBuffer, Result};
-use token;
+use super::parse::{ParseBuffer, Result};
+use super::token;
pub struct Braces<'a> {
pub token: token::Brace,
@@ -63,13 +63,13 @@
#[macro_export]
macro_rules! braced {
($content:ident in $cursor:expr) => {
- match $crate::parse::ParseBuffer::parse_braces(&$cursor) {
- $crate::export::Ok(braces) => {
+ match $crate::next::parse::ParseBuffer::parse_braces(&$cursor) {
+ $crate::next::export::Ok(braces) => {
$content = braces.content;
braces.token
}
- $crate::export::Err(error) => {
- return $crate::export::Err(error);
+ $crate::next::export::Err(error) => {
+ return $crate::next::export::Err(error);
}
}
};
diff --git a/src/lookahead.rs b/src/next/lookahead.rs
similarity index 96%
rename from src/lookahead.rs
rename to src/next/lookahead.rs
index cbaa68e..db0fa63 100644
--- a/src/lookahead.rs
+++ b/src/next/lookahead.rs
@@ -3,9 +3,9 @@
use proc_macro2::Span;
use syn::buffer::Cursor;
-use error;
-use parse::Error;
-use token::Token;
+use super::error;
+use super::parse::Error;
+use super::token::Token;
/// Support for checking the next token in a stream to decide how to parse.
///
diff --git a/src/next/mod.rs b/src/next/mod.rs
new file mode 100644
index 0000000..aff318d
--- /dev/null
+++ b/src/next/mod.rs
@@ -0,0 +1,95 @@
+#[macro_use]
+pub mod token;
+
+#[macro_use]
+pub mod parse;
+
+#[macro_use]
+mod group;
+
+mod error;
+mod lookahead;
+mod span;
+
+pub use proc_macro2::Ident;
+
+// Not public API.
+#[doc(hidden)]
+pub mod export;
+
+use std::str::FromStr;
+
+#[cfg(feature = "proc-macro")]
+use proc_macro;
+use proc_macro2::{self, Span};
+use syn::buffer::TokenBuffer;
+
+use self::parse::{Parse, ParseBuffer, Result};
+
+/// Parse tokens of source code into the chosen syntax tree node.
+#[cfg(feature = "proc-macro")]
+pub fn parse<T: Parse>(input: proc_macro::TokenStream) -> Result<T> {
+ parse2(proc_macro2::TokenStream::from(input))
+}
+
+/// Parse a proc-macro2 token stream into the chosen syntax tree node.
+pub fn parse2<T: Parse>(input: proc_macro2::TokenStream) -> Result<T> {
+ let buf = TokenBuffer::new2(input);
+ let state = ParseBuffer::new(Span::call_site(), buf.begin());
+ T::parse(&state)
+}
+
+/// Parse a string of Rust code into the chosen syntax tree node.
+pub fn parse_str<T: Parse>(input: &str) -> Result<T> {
+ let tokens = proc_macro2::TokenStream::from_str(input)?;
+ parse2(tokens)
+}
+
+/// Parse the input TokenStream of a macro, triggering a compile error if the
+/// tokens fail to parse.
+///
+/// # Intended usage
+///
+/// ```rust
+/// # extern crate proc_macro;
+/// # extern crate syn_error_experiment;
+/// #
+/// use proc_macro::TokenStream;
+/// use syn_error_experiment::parse_macro_input;
+/// use syn_error_experiment::parse::{Parse, ParseStream, Result};
+///
+/// struct MyMacroInput {
+/// /* ... */
+/// }
+///
+/// impl Parse for MyMacroInput {
+/// fn parse(input: ParseStream) -> Result<Self> {
+/// /* ... */
+/// # Ok(MyMacroInput {})
+/// }
+/// }
+///
+/// # const IGNORE: &str = stringify! {
+/// #[proc_macro]
+/// # };
+/// pub fn my_macro(tokens: TokenStream) -> TokenStream {
+/// let input = parse_macro_input!(tokens as MyMacroInput);
+///
+/// /* ... */
+/// # "".parse().unwrap()
+/// }
+/// #
+/// # fn main() {}
+/// ```
+#[cfg(feature = "proc-macro")]
+#[macro_export]
+macro_rules! parse_macro_input {
+ ($tokenstream:ident as $ty:ty) => {
+ match $crate::next::parse::<$ty>($tokenstream) {
+ $crate::next::export::Ok(data) => data,
+ $crate::next::export::Err(err) => {
+ return $crate::next::export::TokenStream::from(err.into_compile_error());
+ }
+ };
+ };
+}
diff --git a/src/parse.rs b/src/next/parse.rs
similarity index 96%
rename from src/parse.rs
rename to src/next/parse.rs
index 922da08..5aa5505 100644
--- a/src/parse.rs
+++ b/src/next/parse.rs
@@ -9,10 +9,10 @@
use proc_macro2::{Ident, Span};
use syn::buffer::Cursor;
-use error;
+use super::error;
-pub use error::{Error, Result};
-pub use lookahead::{Lookahead1, Peek};
+pub use super::error::{Error, Result};
+pub use super::lookahead::{Lookahead1, Peek};
/// Parsing interface implemented by all types that can be parsed in a default
/// way from a token stream.
diff --git a/src/span.rs b/src/next/span.rs
similarity index 96%
rename from src/span.rs
rename to src/next/span.rs
index d734dee..77d4448 100644
--- a/src/span.rs
+++ b/src/next/span.rs
@@ -1,6 +1,6 @@
use proc_macro2::Span;
-use lookahead::TokenMarker;
+use super::lookahead::TokenMarker;
pub trait IntoSpans<S> {
// Not public API.
diff --git a/src/token.rs b/src/next/token.rs
similarity index 91%
rename from src/token.rs
rename to src/next/token.rs
index 7305408..d26f504 100644
--- a/src/token.rs
+++ b/src/next/token.rs
@@ -4,10 +4,10 @@
use proc_macro2::{Spacing, Span};
-use error::Error;
-use lookahead;
-use parse::{Lookahead1, Parse, ParseStream, Result};
-use span::{FromSpans, IntoSpans};
+use super::error::Error;
+use super::lookahead;
+use super::parse::{Lookahead1, Parse, ParseStream, Result};
+use super::span::{FromSpans, IntoSpans};
/// Marker trait for types that represent single tokens.
///
@@ -31,11 +31,11 @@
#[macro_export]
#[cfg_attr(rustfmt, rustfmt_skip)]
macro_rules! Token {
- (struct) => { $crate::token::Struct };
- (enum) => { $crate::token::Enum };
- (:) => { $crate::token::Colon };
- (,) => { $crate::token::Comma };
- (..) => { $crate::token::Dot2 };
+ (struct) => { $crate::next::token::Struct };
+ (enum) => { $crate::next::token::Enum };
+ (:) => { $crate::next::token::Colon };
+ (,) => { $crate::next::token::Comma };
+ (..) => { $crate::next::token::Dot2 };
}
macro_rules! impl_token {