Touch up the exposed parsers
diff --git a/src/attr.rs b/src/attr.rs
index eadbe58..8eac137 100644
--- a/src/attr.rs
+++ b/src/attr.rs
@@ -99,7 +99,7 @@
use super::*;
use ident::parsing::ident;
use lit::parsing::lit;
- use nom::space::{block_comment, whitespace};
+ use synom::space::{block_comment, whitespace};
#[cfg(feature = "full")]
named!(pub inner_attr -> Attribute, alt!(
diff --git a/src/escape.rs b/src/escape.rs
index d8831eb..1c9c6ed 100644
--- a/src/escape.rs
+++ b/src/escape.rs
@@ -1,6 +1,6 @@
use std::{char, str};
use std::num::ParseIntError;
-use nom::IResult;
+use synom::IResult;
pub fn cooked_string(input: &str) -> IResult<&str, String> {
let mut s = String::new();
diff --git a/src/expr.rs b/src/expr.rs
index 7b6602a..9eae723 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -315,7 +315,7 @@
use item::parsing::item;
use lit::parsing::{digits, lit};
use mac::parsing::{mac, token_trees};
- use nom::IResult::{self, Error};
+ use synom::IResult::{self, Error};
use op::parsing::{assign_op, binop, unop};
use ty::parsing::{mutability, path, qpath, ty, unsafety};
@@ -323,7 +323,7 @@
// https://github.com/rust-lang/rfcs/pull/92
macro_rules! named_ambiguous_expr {
($name:ident -> $o:ty, $allow_struct:ident, $submac:ident!( $($args:tt)* )) => {
- fn $name(i: &str, $allow_struct: bool) -> $crate::nom::IResult<&str, $o> {
+ fn $name(i: &str, $allow_struct: bool) -> $crate::synom::IResult<&str, $o> {
$submac!(i, $($args)*)
}
};
diff --git a/src/ident.rs b/src/ident.rs
index aa0d11f..c658d1a 100644
--- a/src/ident.rs
+++ b/src/ident.rs
@@ -57,8 +57,8 @@
#[cfg(feature = "parsing")]
pub mod parsing {
use super::*;
- use nom::IResult;
- use nom::space::skip_whitespace;
+ use synom::IResult;
+ use synom::space::skip_whitespace;
use unicode_xid::UnicodeXID;
pub fn ident(input: &str) -> IResult<&str, Ident> {
diff --git a/src/lib.rs b/src/lib.rs
index e18e7e6..38ebc90 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -9,7 +9,7 @@
#[cfg(feature = "parsing")]
#[macro_use]
-extern crate syn_nom as nom;
+extern crate synom;
#[cfg(feature = "aster")]
pub mod aster;
@@ -84,7 +84,7 @@
mod parsing {
use super::*;
use {derive, generics, ident, mac, ty};
- use nom::{space, IResult};
+ use synom::{space, IResult};
#[cfg(feature = "full")]
use {expr, item, krate};
@@ -165,51 +165,42 @@
}
#[cfg(feature = "parsing")]
-pub mod parser {
+pub mod parse {
//! This module contains a set of exported nom parsers which can be used to
- //! build nom parsers for custom grammars when used alongside the `syn_nom`
- //! crate.
+ //! parse custom grammars when used alongside the `synom` crate.
//!
- //! `syn` uses its own custom fork of `nom`, `syn_nom`, which is smaller, and
- //! thus improves build speeds. This should be used instead of `nom` when
- //! building parsers using these parsers.
-
- #[cfg(feature = "full")]
- pub use krate::parsing::krate;
+ //! Internally, `syn` uses a fork of `nom` called `synom` which resolves a
+ //! persistent pitfall of using `nom` to parse Rust by eliminating the
+ //! `IResult::Incomplete` variant. The `synom` crate should be used instead
+ //! of `nom` when working with the parsers in this module.
#[cfg(feature = "full")]
pub use item::parsing::item;
#[cfg(feature = "full")]
- pub use item::parsing::items;
-
- #[cfg(feature = "full")]
pub use expr::parsing::expr;
pub use lit::parsing::lit;
- pub use lit::parsing::string as str_lit;
+ pub use lit::parsing::string;
- pub use lit::parsing::byte_string as byte_str_lit;
+ pub use lit::parsing::byte_string;
- pub use lit::parsing::byte as byte_lit;
+ pub use lit::parsing::byte;
- pub use lit::parsing::character as char_lit;
+ pub use lit::parsing::character;
- pub use lit::parsing::float as float_lit;
+ pub use lit::parsing::float;
- pub use lit::parsing::int as int_lit;
+ pub use lit::parsing::int;
- pub use lit::parsing::boolean as bool_lit;
+ pub use lit::parsing::boolean;
pub use ty::parsing::ty;
pub use ty::parsing::path;
- pub use generics::parsing::where_clause;
-
- #[cfg(feature = "full")]
- pub use mac::parsing::token_trees;
+ pub use mac::parsing::token_tree as tt;
pub use ident::parsing::ident;
}
diff --git a/src/lit.rs b/src/lit.rs
index aba020a..f846f66 100644
--- a/src/lit.rs
+++ b/src/lit.rs
@@ -127,36 +127,64 @@
]}
#[cfg(feature = "parsing")]
+#[derive(Debug, Clone)]
+pub struct StrLit {
+ value: String,
+ style: StrStyle,
+}
+
+#[cfg(feature = "parsing")]
+#[derive(Debug, Clone)]
+pub struct ByteStrLit {
+ value: Vec<u8>,
+ style: StrStyle,
+}
+
+#[cfg(feature = "parsing")]
+#[derive(Debug, Clone)]
+pub struct IntLit {
+ value: u64,
+ suffix: IntTy,
+}
+
+#[cfg(feature = "parsing")]
+#[derive(Debug, Clone)]
+pub struct FloatLit {
+ value: String,
+ suffix: FloatTy,
+}
+
+#[cfg(feature = "parsing")]
pub mod parsing {
use super::*;
use escape::{cooked_byte, cooked_byte_string, cooked_char, cooked_string, raw_string};
- use nom::space::skip_whitespace;
- use nom::IResult;
+ use synom::space::skip_whitespace;
+ use synom::IResult;
use unicode_xid::UnicodeXID;
named!(pub lit -> Lit, alt!(
- string => { |(value, style)| Lit::Str(value, style) }
+ string => { |StrLit { value, style }| Lit::Str(value, style) }
|
- byte_string => { |(value, style)| Lit::ByteStr(value, style) }
+ byte_string => { |ByteStrLit { value, style }| Lit::ByteStr(value, style) }
|
byte => { |b| Lit::Byte(b) }
|
character => { |ch| Lit::Char(ch) }
|
- float => { |(value, suffix)| Lit::Float(value, suffix) } // must be before int
+ float => { |FloatLit { value, suffix }| Lit::Float(value, suffix) } // must be before int
|
- int => { |(value, ty)| Lit::Int(value, ty) }
+ int => { |IntLit { value, suffix }| Lit::Int(value, suffix) }
|
boolean => { |value| Lit::Bool(value) }
));
- named!(pub string -> (String, StrStyle), alt!(
- quoted_string => { |s| (s, StrStyle::Cooked) }
+ named!(pub string -> StrLit, alt!(
+ quoted_string => { |s| StrLit { value: s, style: StrStyle::Cooked } }
|
preceded!(
punct!("r"),
raw_string
- ) => { |(s, n)| (s, StrStyle::Raw(n)) }
+ ) => { |(s, n)| StrLit { value: s, style: StrStyle::Raw(n) }}
));
named!(pub quoted_string -> String, delimited!(
@@ -165,17 +193,17 @@
tag!("\"")
));
- named!(pub byte_string -> (Vec<u8>, StrStyle), alt!(
+ named!(pub byte_string -> ByteStrLit, alt!(
delimited!(
punct!("b\""),
cooked_byte_string,
tag!("\"")
- ) => { |vec| (vec, StrStyle::Cooked) }
+ ) => { |vec| ByteStrLit { value: vec, style: StrStyle::Cooked } }
|
preceded!(
punct!("br"),
raw_string
- ) => { |(s, n): (String, _)| (s.into_bytes(), StrStyle::Raw(n)) }
+ ) => { |(s, n): (String, _)| ByteStrLit { value: s.into_bytes(), style: StrStyle::Raw(n) } }
));
named!(pub byte -> u8, do_parse!(
@@ -193,20 +221,21 @@
(ch)
));
- named!(pub float -> (String, FloatTy), tuple!(
- float_string,
- alt!(
+ named!(pub float -> FloatLit, do_parse!(
+ value: float_string >>
+ suffix: alt!(
tag!("f32") => { |_| FloatTy::F32 }
|
tag!("f64") => { |_| FloatTy::F64 }
|
epsilon!() => { |_| FloatTy::Unsuffixed }
- )
+ ) >>
+ (FloatLit { value: value, suffix: suffix })
));
- named!(pub int -> (u64, IntTy), tuple!(
- digits,
- alt!(
+ named!(pub int -> IntLit, do_parse!(
+ value: digits >>
+ suffix: alt!(
tag!("isize") => { |_| IntTy::Isize }
|
tag!("i8") => { |_| IntTy::I8 }
@@ -228,7 +257,8 @@
tag!("u64") => { |_| IntTy::U64 }
|
epsilon!() => { |_| IntTy::Unsuffixed }
- )
+ ) >>
+ (IntLit { value: value, suffix: suffix })
));
named!(pub boolean -> bool, alt!(
diff --git a/src/mac.rs b/src/mac.rs
index c83f77d..9a648d4 100644
--- a/src/mac.rs
+++ b/src/mac.rs
@@ -116,7 +116,7 @@
use generics::parsing::lifetime;
use ident::parsing::word;
use lit::parsing::lit;
- use nom::space::{block_comment, whitespace};
+ use synom::space::{block_comment, whitespace};
use ty::parsing::path;
named!(pub mac -> Mac, do_parse!(
@@ -151,7 +151,7 @@
) => { |tts| Delimited { delim: DelimToken::Brace, tts: tts } }
));
- named!(token_tree -> TokenTree, alt!(
+ named!(pub token_tree -> TokenTree, alt!(
map!(token, TokenTree::Token)
|
map!(delimited, TokenTree::Delimited)