David Tolnay | ad2836d | 2017-04-20 10:11:43 -0700 | [diff] [blame] | 1 | #![doc(html_root_url = "https://dtolnay.github.io/syn")] |
| 2 | |
David Tolnay | 02a8d47 | 2017-02-19 12:59:44 -0800 | [diff] [blame] | 3 | #![cfg_attr(feature = "cargo-clippy", allow(large_enum_variant))] |
David Tolnay | aed77b0 | 2016-09-23 20:50:31 -0700 | [diff] [blame] | 4 | |
David Tolnay | 87d0b44 | 2016-09-04 11:52:12 -0700 | [diff] [blame] | 5 | #[cfg(feature = "printing")] |
| 6 | extern crate quote; |
| 7 | |
David Tolnay | b5a7b14 | 2016-09-13 22:46:39 -0700 | [diff] [blame] | 8 | #[cfg(feature = "parsing")] |
David Tolnay | 10413f0 | 2016-09-30 09:12:02 -0700 | [diff] [blame] | 9 | extern crate unicode_xid; |
| 10 | |
| 11 | #[cfg(feature = "parsing")] |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 12 | #[macro_use] |
David Tolnay | 5fe14fc | 2017-01-27 16:22:08 -0800 | [diff] [blame] | 13 | extern crate synom; |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 14 | |
David Tolnay | 631cb8c | 2016-11-10 17:16:41 -0800 | [diff] [blame] | 15 | #[cfg(feature = "aster")] |
| 16 | pub mod aster; |
David Tolnay | 886d8ea | 2016-09-13 08:34:07 -0700 | [diff] [blame] | 17 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame^] | 18 | #[macro_use] |
| 19 | mod macros; |
| 20 | |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 21 | mod attr; |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame^] | 22 | pub use attr::{Attribute, AttrStyle, MetaItem, NestedMetaItem, MetaItemList, |
| 23 | MetaNameValue}; |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 24 | |
David Tolnay | 3cb23a9 | 2016-10-07 23:02:21 -0700 | [diff] [blame] | 25 | mod constant; |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame^] | 26 | pub use constant::{ConstExpr, ConstCall, ConstBinary, ConstUnary, ConstCast, |
| 27 | ConstIndex, ConstParen}; |
David Tolnay | 3cb23a9 | 2016-10-07 23:02:21 -0700 | [diff] [blame] | 28 | |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame] | 29 | mod data; |
David Tolnay | 3cb23a9 | 2016-10-07 23:02:21 -0700 | [diff] [blame] | 30 | pub use data::{Field, Variant, VariantData, Visibility}; |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame] | 31 | |
David Tolnay | 631cb8c | 2016-11-10 17:16:41 -0800 | [diff] [blame] | 32 | #[cfg(feature = "parsing")] |
| 33 | mod escape; |
| 34 | |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 35 | #[cfg(feature = "full")] |
| 36 | mod expr; |
| 37 | #[cfg(feature = "full")] |
David Tolnay | 05120ef | 2017-03-12 18:29:26 -0700 | [diff] [blame] | 38 | pub use expr::{Arm, BindingMode, Block, CaptureBy, Expr, ExprKind, FieldPat, FieldValue, Local, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame^] | 39 | MacStmtStyle, Pat, RangeLimits, Stmt, ExprBox, ExprInPlace, |
| 40 | ExprArray, ExprCall, ExprMethodCall, ExprTup, ExprBinary, ExprUnary, |
| 41 | ExprCast, ExprType, ExprIf, ExprIfLet, ExprWhile, ExprWhileLet, |
| 42 | ExprForLoop, ExprLoop, ExprMatch, ExprClosure, ExprBlock, |
| 43 | ExprAssign, ExprAssignOp, ExprField, ExprTupField, ExprIndex, |
| 44 | ExprRange, ExprPath, ExprAddrOf, ExprBreak, ExprContinue, |
| 45 | ExprRet, ExprStruct, ExprRepeat, ExprParen, ExprTry, ExprCatch}; |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 46 | |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 47 | mod generics; |
David Tolnay | daaf774 | 2016-10-03 11:11:43 -0700 | [diff] [blame] | 48 | pub use generics::{Generics, Lifetime, LifetimeDef, TraitBoundModifier, TyParam, TyParamBound, |
David Tolnay | fa23f57 | 2017-01-23 00:19:11 -0800 | [diff] [blame] | 49 | WhereBoundPredicate, WhereClause, WhereEqPredicate, WherePredicate, |
| 50 | WhereRegionPredicate}; |
David Tolnay | e767892 | 2016-10-13 20:44:03 -0700 | [diff] [blame] | 51 | #[cfg(feature = "printing")] |
David Tolnay | c879a50 | 2017-01-25 15:51:32 -0800 | [diff] [blame] | 52 | pub use generics::{ImplGenerics, Turbofish, TyGenerics}; |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 53 | |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 54 | mod ident; |
David Tolnay | daaf774 | 2016-10-03 11:11:43 -0700 | [diff] [blame] | 55 | pub use ident::Ident; |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 56 | |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame] | 57 | #[cfg(feature = "full")] |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 58 | mod item; |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame] | 59 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame^] | 60 | pub use item::{Constness, Defaultness, FnArg, FnDecl, ForeignItemKind, ForeignItem, ItemForeignMod, |
David Tolnay | c1fea50 | 2016-10-30 17:54:02 -0700 | [diff] [blame] | 61 | ImplItem, ImplItemKind, ImplPolarity, Item, ItemKind, MethodSig, PathListItem, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame^] | 62 | TraitItem, TraitItemKind, ViewPath, ItemExternCrate, ItemUse, |
| 63 | ItemStatic, ItemConst, ItemFn, ItemMod, ItemTy, ItemEnum, |
| 64 | ItemStruct, ItemUnion, ItemTrait, ItemDefaultImpl, ItemImpl, |
| 65 | PathSimple, PathGlob, PathList, ForeignItemFn, ForeignItemStatic, |
| 66 | TraitItemConst, TraitItemMethod, TraitItemType, |
| 67 | ImplItemConst, ImplItemMethod, ImplItemType, ArgSelfRef, |
| 68 | ArgSelf, ArgCaptured}; |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 69 | |
David Tolnay | 631cb8c | 2016-11-10 17:16:41 -0800 | [diff] [blame] | 70 | #[cfg(feature = "full")] |
| 71 | mod krate; |
| 72 | #[cfg(feature = "full")] |
| 73 | pub use krate::Crate; |
| 74 | |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 75 | mod lit; |
David Tolnay | daaf774 | 2016-10-03 11:11:43 -0700 | [diff] [blame] | 76 | pub use lit::{FloatTy, IntTy, Lit, StrStyle}; |
David Tolnay | 1f16b60 | 2017-02-07 20:06:55 -0500 | [diff] [blame] | 77 | #[cfg(feature = "parsing")] |
| 78 | pub use lit::{ByteStrLit, FloatLit, IntLit, StrLit}; |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 79 | |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 80 | mod mac; |
David Tolnay | daaf774 | 2016-10-03 11:11:43 -0700 | [diff] [blame] | 81 | pub use mac::{BinOpToken, DelimToken, Delimited, Mac, Token, TokenTree}; |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 82 | |
David Tolnay | 0e83740 | 2016-12-22 17:25:55 -0500 | [diff] [blame] | 83 | mod derive; |
| 84 | pub use derive::{Body, DeriveInput}; |
David Tolnay | c28a4a5 | 2017-02-04 09:50:57 -0800 | [diff] [blame] | 85 | // Deprecated. Use `DeriveInput` instead. |
David Tolnay | 0e83740 | 2016-12-22 17:25:55 -0500 | [diff] [blame] | 86 | #[doc(hidden)] |
| 87 | pub type MacroInput = DeriveInput; |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame] | 88 | |
David Tolnay | 3cb23a9 | 2016-10-07 23:02:21 -0700 | [diff] [blame] | 89 | mod op; |
| 90 | pub use op::{BinOp, UnOp}; |
| 91 | |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 92 | mod ty; |
David Tolnay | b8d8ef5 | 2016-10-29 14:30:08 -0700 | [diff] [blame] | 93 | pub use ty::{Abi, AngleBracketedParameterData, BareFnArg, BareFnTy, FunctionRetTy, MutTy, |
| 94 | Mutability, ParenthesizedParameterData, Path, PathParameters, PathSegment, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame^] | 95 | PolyTraitRef, QSelf, Ty, TypeBinding, Unsafety, TySlice, TyArray, |
| 96 | TyPtr, TyRptr, TyBareFn, TyNever, TyTup, TyPath, TyTraitObject, |
| 97 | TyImplTrait, TyParen, TyInfer}; |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 98 | |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 99 | #[cfg(feature = "visit")] |
| 100 | pub mod visit; |
| 101 | |
gnzlbg | 9ae88d8 | 2017-01-26 20:45:17 +0100 | [diff] [blame] | 102 | #[cfg(feature = "fold")] |
| 103 | pub mod fold; |
| 104 | |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 105 | #[cfg(feature = "parsing")] |
| 106 | pub use parsing::*; |
| 107 | |
| 108 | #[cfg(feature = "parsing")] |
| 109 | mod parsing { |
Ted Driggs | 054abbb | 2017-05-01 12:20:52 -0700 | [diff] [blame] | 110 | use std::str::FromStr; |
| 111 | |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 112 | use super::*; |
Colin Kiegel | 108a7fe | 2017-03-06 13:29:57 +0100 | [diff] [blame] | 113 | use {derive, generics, ident, mac, ty, attr}; |
David Tolnay | 5fe14fc | 2017-01-27 16:22:08 -0800 | [diff] [blame] | 114 | use synom::{space, IResult}; |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 115 | |
David Tolnay | edf2b99 | 2016-09-23 20:43:45 -0700 | [diff] [blame] | 116 | #[cfg(feature = "full")] |
David Tolnay | c879a50 | 2017-01-25 15:51:32 -0800 | [diff] [blame] | 117 | use {expr, item, krate}; |
David Tolnay | edf2b99 | 2016-09-23 20:43:45 -0700 | [diff] [blame] | 118 | |
Ted Driggs | 054abbb | 2017-05-01 12:20:52 -0700 | [diff] [blame] | 119 | /// Parse the stringified representation of a struct or enum passed |
| 120 | /// to a `proc_macro_derive` function. |
David Tolnay | 0e83740 | 2016-12-22 17:25:55 -0500 | [diff] [blame] | 121 | pub fn parse_derive_input(input: &str) -> Result<DeriveInput, String> { |
| 122 | unwrap("derive input", derive::parsing::derive_input, input) |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 123 | } |
| 124 | |
David Tolnay | edf2b99 | 2016-09-23 20:43:45 -0700 | [diff] [blame] | 125 | #[cfg(feature = "full")] |
David Tolnay | 4a51dc7 | 2016-10-01 00:40:31 -0700 | [diff] [blame] | 126 | pub fn parse_crate(input: &str) -> Result<Crate, String> { |
| 127 | unwrap("crate", krate::parsing::krate, input) |
| 128 | } |
| 129 | |
| 130 | #[cfg(feature = "full")] |
David Tolnay | edf2b99 | 2016-09-23 20:43:45 -0700 | [diff] [blame] | 131 | pub fn parse_item(input: &str) -> Result<Item, String> { |
| 132 | unwrap("item", item::parsing::item, input) |
| 133 | } |
| 134 | |
David Tolnay | b9c8e32 | 2016-09-23 20:48:37 -0700 | [diff] [blame] | 135 | #[cfg(feature = "full")] |
David Tolnay | 453cfd1 | 2016-10-23 11:00:14 -0700 | [diff] [blame] | 136 | pub fn parse_items(input: &str) -> Result<Vec<Item>, String> { |
| 137 | unwrap("items", item::parsing::items, input) |
| 138 | } |
| 139 | |
| 140 | #[cfg(feature = "full")] |
David Tolnay | b9c8e32 | 2016-09-23 20:48:37 -0700 | [diff] [blame] | 141 | pub fn parse_expr(input: &str) -> Result<Expr, String> { |
| 142 | unwrap("expression", expr::parsing::expr, input) |
| 143 | } |
| 144 | |
David Tolnay | 32a112e | 2016-09-11 17:46:15 -0700 | [diff] [blame] | 145 | pub fn parse_type(input: &str) -> Result<Ty, String> { |
David Tolnay | b5a7b14 | 2016-09-13 22:46:39 -0700 | [diff] [blame] | 146 | unwrap("type", ty::parsing::ty, input) |
David Tolnay | 32a112e | 2016-09-11 17:46:15 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Ted Driggs | 054abbb | 2017-05-01 12:20:52 -0700 | [diff] [blame] | 149 | /// Parse a path, such as `std::str::FromStr` or `::syn::parse_path`. |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 150 | pub fn parse_path(input: &str) -> Result<Path, String> { |
David Tolnay | b5a7b14 | 2016-09-13 22:46:39 -0700 | [diff] [blame] | 151 | unwrap("path", ty::parsing::path, input) |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | pub fn parse_where_clause(input: &str) -> Result<WhereClause, String> { |
David Tolnay | b5a7b14 | 2016-09-13 22:46:39 -0700 | [diff] [blame] | 155 | unwrap("where clause", generics::parsing::where_clause, input) |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Simon Sapin | 095a42b | 2016-10-20 15:54:23 +0200 | [diff] [blame] | 158 | pub fn parse_token_trees(input: &str) -> Result<Vec<TokenTree>, String> { |
| 159 | unwrap("token trees", mac::parsing::token_trees, input) |
| 160 | } |
| 161 | |
David Tolnay | a822836 | 2016-12-22 15:21:54 -0500 | [diff] [blame] | 162 | pub fn parse_ident(input: &str) -> Result<Ident, String> { |
| 163 | unwrap("identifier", ident::parsing::ident, input) |
| 164 | } |
| 165 | |
David Tolnay | 23d83f9 | 2017-01-25 15:41:47 -0800 | [diff] [blame] | 166 | pub fn parse_ty_param_bound(input: &str) -> Result<TyParamBound, String> { |
David Tolnay | 05120ef | 2017-03-12 18:29:26 -0700 | [diff] [blame] | 167 | unwrap("type parameter bound", |
| 168 | generics::parsing::ty_param_bound, |
| 169 | input) |
David Tolnay | 23d83f9 | 2017-01-25 15:41:47 -0800 | [diff] [blame] | 170 | } |
| 171 | |
Ted Driggs | 054abbb | 2017-05-01 12:20:52 -0700 | [diff] [blame] | 172 | /// Parse an attribute declared outside the item it annotates, such as |
| 173 | /// a struct annotation. They are written as `#[...]`. |
Colin Kiegel | cb72443 | 2017-03-06 12:59:18 +0100 | [diff] [blame] | 174 | pub fn parse_outer_attr(input: &str) -> Result<Attribute, String> { |
| 175 | unwrap("outer attribute", attr::parsing::outer_attr, input) |
| 176 | } |
| 177 | |
Ted Driggs | 054abbb | 2017-05-01 12:20:52 -0700 | [diff] [blame] | 178 | /// Parse an attribute declared inside the item it annotates. These are used |
| 179 | /// for crate annotations or for mod-level declarations when modules are in |
| 180 | /// their own files. They are written as `#![...]`. |
Colin Kiegel | cb72443 | 2017-03-06 12:59:18 +0100 | [diff] [blame] | 181 | #[cfg(feature = "full")] |
| 182 | pub fn parse_inner_attr(input: &str) -> Result<Attribute, String> { |
| 183 | unwrap("inner attribute", attr::parsing::inner_attr, input) |
| 184 | } |
| 185 | |
Ted Driggs | 054abbb | 2017-05-01 12:20:52 -0700 | [diff] [blame] | 186 | /// Deprecated: Use `parse_derive_input` instead. |
David Tolnay | 0e83740 | 2016-12-22 17:25:55 -0500 | [diff] [blame] | 187 | #[doc(hidden)] |
Ted Driggs | 054abbb | 2017-05-01 12:20:52 -0700 | [diff] [blame] | 188 | #[deprecated(since="0.11.0", note = "Use `parse_derive_input` instead")] |
David Tolnay | 0e83740 | 2016-12-22 17:25:55 -0500 | [diff] [blame] | 189 | pub fn parse_macro_input(input: &str) -> Result<MacroInput, String> { |
| 190 | parse_derive_input(input) |
| 191 | } |
| 192 | |
Ted Driggs | 054abbb | 2017-05-01 12:20:52 -0700 | [diff] [blame] | 193 | /// Alias for `syn::parse_derive_input`. |
| 194 | impl FromStr for DeriveInput { |
| 195 | type Err = String; |
| 196 | |
| 197 | fn from_str(s: &str) -> Result<Self, Self::Err> { |
| 198 | parse_derive_input(s) |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | /// Alias for `syn::parse_crate`. |
| 203 | #[cfg(feature = "full")] |
| 204 | impl FromStr for Crate { |
| 205 | type Err = String; |
| 206 | |
| 207 | fn from_str(s: &str) -> Result<Self, Self::Err> { |
| 208 | parse_crate(s) |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | /// Alias for `syn::parse_item`. |
| 213 | #[cfg(feature = "full")] |
| 214 | impl FromStr for Item { |
| 215 | type Err = String; |
| 216 | |
| 217 | fn from_str(s: &str) -> Result<Self, Self::Err> { |
| 218 | parse_item(s) |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | /// Alias for `syn::parse_expr`. |
| 223 | #[cfg(feature = "full")] |
| 224 | impl FromStr for Expr { |
| 225 | type Err = String; |
| 226 | |
| 227 | fn from_str(s: &str) -> Result<Self, Self::Err> { |
| 228 | parse_expr(s) |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | /// Alias for `syn::parse_type`. |
| 233 | impl FromStr for Ty { |
| 234 | type Err = String; |
| 235 | |
| 236 | fn from_str(s: &str) -> Result<Self, Self::Err> { |
| 237 | parse_type(s) |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | /// Alias for `syn::parse_path`. |
| 242 | impl FromStr for Path { |
| 243 | type Err = String; |
| 244 | |
| 245 | fn from_str(s: &str) -> Result<Self, Self::Err> { |
| 246 | parse_path(s) |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | /// Alias for `syn::parse_where_clause`. |
| 251 | impl FromStr for WhereClause { |
| 252 | type Err = String; |
| 253 | |
| 254 | fn from_str(s: &str) -> Result<Self, Self::Err> { |
| 255 | parse_where_clause(s) |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | /// Alias for `syn::parse_ident`. |
| 260 | impl FromStr for Ident { |
| 261 | type Err = String; |
| 262 | |
| 263 | fn from_str(s: &str) -> Result<Self, Self::Err> { |
| 264 | parse_ident(s) |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | /// Alias for `syn::parse_ty_param_bound`. |
| 269 | impl FromStr for TyParamBound { |
| 270 | type Err = String; |
| 271 | |
| 272 | fn from_str(s: &str) -> Result<Self, Self::Err> { |
| 273 | parse_ty_param_bound(s) |
| 274 | } |
| 275 | } |
| 276 | |
David Tolnay | daaf774 | 2016-10-03 11:11:43 -0700 | [diff] [blame] | 277 | fn unwrap<T>(name: &'static str, |
| 278 | f: fn(&str) -> IResult<&str, T>, |
| 279 | input: &str) |
| 280 | -> Result<T, String> { |
David Tolnay | b5a7b14 | 2016-09-13 22:46:39 -0700 | [diff] [blame] | 281 | match f(input) { |
David Tolnay | f5fdfa0 | 2016-10-23 15:25:17 -0700 | [diff] [blame] | 282 | IResult::Done(mut rest, t) => { |
David Tolnay | def6637 | 2016-10-24 21:51:32 -0700 | [diff] [blame] | 283 | rest = space::skip_whitespace(rest); |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 284 | if rest.is_empty() { |
| 285 | Ok(t) |
David Tolnay | 2e73736 | 2016-10-05 23:44:15 -0700 | [diff] [blame] | 286 | } else if rest.len() == input.len() { |
| 287 | // parsed nothing |
David Tolnay | ba8947b | 2016-10-05 23:31:12 -0700 | [diff] [blame] | 288 | Err(format!("failed to parse {}: {:?}", name, rest)) |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 289 | } else { |
David Tolnay | f2222f0 | 2017-01-27 17:09:20 -0800 | [diff] [blame] | 290 | Err(format!("unparsed tokens after {}: {:?}", name, rest)) |
David Tolnay | c94c38a | 2016-09-05 17:02:03 -0700 | [diff] [blame] | 291 | } |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 292 | } |
David Tolnay | 14cbdeb | 2016-10-01 12:13:59 -0700 | [diff] [blame] | 293 | IResult::Error => Err(format!("failed to parse {}: {:?}", name, input)), |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 294 | } |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 295 | } |
| 296 | } |
Michael Layzell | 5e107ff | 2017-01-24 19:58:39 -0500 | [diff] [blame] | 297 | |
| 298 | #[cfg(feature = "parsing")] |
David Tolnay | 5fe14fc | 2017-01-27 16:22:08 -0800 | [diff] [blame] | 299 | pub mod parse { |
Michael Layzell | 5e107ff | 2017-01-24 19:58:39 -0500 | [diff] [blame] | 300 | //! This module contains a set of exported nom parsers which can be used to |
David Tolnay | 5fe14fc | 2017-01-27 16:22:08 -0800 | [diff] [blame] | 301 | //! parse custom grammars when used alongside the `synom` crate. |
Michael Layzell | 5e107ff | 2017-01-24 19:58:39 -0500 | [diff] [blame] | 302 | //! |
David Tolnay | 5fe14fc | 2017-01-27 16:22:08 -0800 | [diff] [blame] | 303 | //! Internally, `syn` uses a fork of `nom` called `synom` which resolves a |
| 304 | //! persistent pitfall of using `nom` to parse Rust by eliminating the |
| 305 | //! `IResult::Incomplete` variant. The `synom` crate should be used instead |
| 306 | //! of `nom` when working with the parsers in this module. |
Michael Layzell | 5e107ff | 2017-01-24 19:58:39 -0500 | [diff] [blame] | 307 | |
David Tolnay | 0a8972b | 2017-02-27 02:10:01 -0800 | [diff] [blame] | 308 | pub use synom::IResult; |
| 309 | |
Michael Layzell | 5e107ff | 2017-01-24 19:58:39 -0500 | [diff] [blame] | 310 | #[cfg(feature = "full")] |
| 311 | pub use item::parsing::item; |
| 312 | |
| 313 | #[cfg(feature = "full")] |
David Tolnay | 1bf1913 | 2017-02-19 22:54:25 -0800 | [diff] [blame] | 314 | pub use expr::parsing::{expr, pat, block, stmt}; |
Michael Layzell | 5e107ff | 2017-01-24 19:58:39 -0500 | [diff] [blame] | 315 | |
David Tolnay | 0ee4189 | 2017-02-19 22:52:59 -0800 | [diff] [blame] | 316 | pub use lit::parsing::{lit, string, byte_string, byte, character, float, int, boolean}; |
Michael Layzell | 5e107ff | 2017-01-24 19:58:39 -0500 | [diff] [blame] | 317 | |
David Tolnay | 0ee4189 | 2017-02-19 22:52:59 -0800 | [diff] [blame] | 318 | pub use ty::parsing::{ty, path}; |
Michael Layzell | 5e107ff | 2017-01-24 19:58:39 -0500 | [diff] [blame] | 319 | |
David Tolnay | 5fe14fc | 2017-01-27 16:22:08 -0800 | [diff] [blame] | 320 | pub use mac::parsing::token_tree as tt; |
Michael Layzell | 5e107ff | 2017-01-24 19:58:39 -0500 | [diff] [blame] | 321 | |
| 322 | pub use ident::parsing::ident; |
David Tolnay | 1f16b60 | 2017-02-07 20:06:55 -0500 | [diff] [blame] | 323 | |
| 324 | pub use generics::parsing::lifetime; |
Michael Layzell | 5e107ff | 2017-01-24 19:58:39 -0500 | [diff] [blame] | 325 | } |