Unify the error modules
diff --git a/src/next/error.rs b/src/next/error.rs
deleted file mode 100644
index 05473f3..0000000
--- a/src/next/error.rs
+++ /dev/null
@@ -1,86 +0,0 @@
-use std;
-use std::fmt::{self, Display};
-use std::iter::FromIterator;
-
-use proc_macro2::{
- Delimiter, Group, Ident, LexError, Literal, Punct, Spacing, Span, TokenStream, TokenTree,
-};
-
-use buffer::Cursor;
-
-/// The result of a Syn parser.
-pub type Result<T> = std::result::Result<T, Error>;
-
-/// Error returned when a Syn parser cannot parse the input tokens.
-#[derive(Debug)]
-pub struct Error {
- span: Span,
- message: String,
-}
-
-impl Error {
- pub fn new<T: Display>(span: Span, message: T) -> Self {
- Error {
- span: span,
- message: message.to_string(),
- }
- }
-
- /// Render the error as an invocation of [`compile_error!`].
- ///
- /// The [`parse_macro_input!`] macro provides a convenient way to invoke
- /// this method correctly in a procedural macro.
- ///
- /// [`compile_error!`]: https://doc.rust-lang.org/std/macro.compile_error.html
- /// [`parse_macro_input!`]: ../macro.parse_macro_input.html
- pub fn into_compile_error(self) -> TokenStream {
- // compile_error!($message)
- TokenStream::from_iter(vec![
- TokenTree::Ident(Ident::new("compile_error", self.span)),
- TokenTree::Punct({
- let mut punct = Punct::new('!', Spacing::Alone);
- punct.set_span(self.span);
- punct
- }),
- TokenTree::Group({
- let mut group = Group::new(Delimiter::Brace, {
- TokenStream::from_iter(vec![TokenTree::Literal({
- let mut string = Literal::string(&self.message);
- string.set_span(self.span);
- string
- })])
- });
- group.set_span(self.span);
- group
- }),
- ])
- }
-}
-
-// Not public API.
-#[doc(hidden)]
-pub fn new_at<T: Display>(scope: Span, cursor: Cursor, message: T) -> Error {
- if cursor.eof() {
- Error::new(scope, format!("unexpected end of input, {}", message))
- } else {
- Error::new(cursor.span(), message)
- }
-}
-
-impl Display for Error {
- fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
- formatter.write_str(&self.message)
- }
-}
-
-impl std::error::Error for Error {
- fn description(&self) -> &str {
- "parse error"
- }
-}
-
-impl From<LexError> for Error {
- fn from(err: LexError) -> Self {
- Error::new(Span::call_site(), format!("{:?}", err))
- }
-}
diff --git a/src/next/group.rs b/src/next/group.rs
index 35aa5af..7493050 100644
--- a/src/next/group.rs
+++ b/src/next/group.rs
@@ -1,6 +1,7 @@
use proc_macro2::Delimiter;
-use super::parse::{ParseBuffer, Result};
+use error::Result;
+use super::parse::ParseBuffer;
use token;
pub struct Braces<'a> {
diff --git a/src/next/lookahead.rs b/src/next/lookahead.rs
index c051a8d..433cbaf 100644
--- a/src/next/lookahead.rs
+++ b/src/next/lookahead.rs
@@ -1,11 +1,10 @@
use std::cell::RefCell;
-use buffer::Cursor;
use proc_macro2::Span;
+use buffer::Cursor;
+use error::{self, Error};
use span::IntoSpans;
-use super::error;
-use super::parse::Error;
use 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
index 8815570..27612e8 100644
--- a/src/next/mod.rs
+++ b/src/next/mod.rs
@@ -7,8 +7,6 @@
#[macro_use]
mod group;
-mod error;
-
use std::str::FromStr;
use buffer::TokenBuffer;
@@ -16,7 +14,8 @@
use proc_macro;
use proc_macro2::{self, Span};
-use self::parse::{Parse, ParseBuffer, Result};
+use error::Result;
+use self::parse::{Parse, ParseBuffer};
/// Parse tokens of source code into the chosen syntax tree node.
#[cfg(feature = "proc-macro")]
diff --git a/src/next/parse.rs b/src/next/parse.rs
index ed275ef..7e5f310 100644
--- a/src/next/parse.rs
+++ b/src/next/parse.rs
@@ -7,11 +7,9 @@
use std::ops::Deref;
use buffer::Cursor;
+use error::{self, Error, Result};
use proc_macro2::{Ident, Span};
-use super::error;
-
-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