David Tolnay | aed77b0 | 2016-09-23 20:50:31 -0700 | [diff] [blame] | 1 | #![cfg_attr(feature = "clippy", feature(plugin))] |
| 2 | #![cfg_attr(feature = "clippy", plugin(clippy))] |
| 3 | |
David Tolnay | 87d0b44 | 2016-09-04 11:52:12 -0700 | [diff] [blame] | 4 | #[cfg(feature = "printing")] |
| 5 | extern crate quote; |
| 6 | |
David Tolnay | b5a7b14 | 2016-09-13 22:46:39 -0700 | [diff] [blame] | 7 | #[cfg(feature = "parsing")] |
David Tolnay | 10413f0 | 2016-09-30 09:12:02 -0700 | [diff] [blame] | 8 | extern crate unicode_xid; |
| 9 | |
| 10 | #[cfg(feature = "parsing")] |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 11 | #[macro_use] |
David Tolnay | b5a7b14 | 2016-09-13 22:46:39 -0700 | [diff] [blame] | 12 | mod nom; |
David Tolnay | 6b7aaf0 | 2016-09-04 10:39:25 -0700 | [diff] [blame] | 13 | |
| 14 | #[macro_use] |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 15 | mod helper; |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 16 | |
David Tolnay | 886d8ea | 2016-09-13 08:34:07 -0700 | [diff] [blame] | 17 | mod escape; |
| 18 | |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 19 | mod attr; |
| 20 | pub use attr::{ |
| 21 | Attribute, |
| 22 | MetaItem, |
| 23 | }; |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 24 | |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame] | 25 | mod data; |
| 26 | pub use data::{ |
| 27 | Discriminant, |
| 28 | Field, |
| 29 | Variant, |
| 30 | VariantData, |
| 31 | Visibility, |
| 32 | }; |
| 33 | |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 34 | #[cfg(feature = "full")] |
| 35 | mod expr; |
| 36 | #[cfg(feature = "full")] |
| 37 | pub use expr::{ |
| 38 | Arm, |
| 39 | BinOp, |
| 40 | BindingMode, |
| 41 | Block, |
| 42 | BlockCheckMode, |
| 43 | CaptureBy, |
| 44 | Expr, |
| 45 | FieldPat, |
| 46 | Local, |
| 47 | MacStmtStyle, |
| 48 | Pat, |
| 49 | RangeLimits, |
| 50 | Stmt, |
| 51 | UnOp, |
| 52 | }; |
| 53 | |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 54 | mod generics; |
| 55 | pub use generics::{ |
| 56 | Generics, |
| 57 | Lifetime, |
| 58 | LifetimeDef, |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 59 | TraitBoundModifier, |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 60 | TyParam, |
| 61 | TyParamBound, |
| 62 | WhereBoundPredicate, |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 63 | WhereClause, |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 64 | WherePredicate, |
| 65 | WhereRegionPredicate, |
| 66 | }; |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 67 | |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 68 | mod ident; |
| 69 | pub use ident::{ |
| 70 | Ident, |
| 71 | }; |
| 72 | |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame] | 73 | #[cfg(feature = "full")] |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 74 | mod item; |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame] | 75 | #[cfg(feature = "full")] |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 76 | pub use item::{ |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame] | 77 | Abi, |
| 78 | Constness, |
| 79 | Defaultness, |
| 80 | ForeignItemKind, |
| 81 | ForeignItem, |
| 82 | ForeignMod, |
| 83 | ImplItem, |
| 84 | ImplItemKind, |
| 85 | ImplPolarity, |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 86 | Item, |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame] | 87 | ItemKind, |
| 88 | MethodSig, |
| 89 | PathListItem, |
| 90 | TraitItem, |
| 91 | TraitItemKind, |
| 92 | Unsafety, |
| 93 | ViewPath, |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 94 | }; |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 95 | |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 96 | mod lit; |
| 97 | pub use lit::{ |
| 98 | FloatTy, |
| 99 | IntTy, |
| 100 | Lit, |
| 101 | StrStyle, |
| 102 | }; |
| 103 | |
| 104 | #[cfg(feature = "full")] |
| 105 | mod mac; |
| 106 | #[cfg(feature = "full")] |
| 107 | pub use mac::{ |
| 108 | BinOpToken, |
| 109 | DelimToken, |
| 110 | Delimited, |
| 111 | Mac, |
| 112 | SequenceRepetition, |
| 113 | Token, |
| 114 | TokenTree, |
| 115 | }; |
| 116 | |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame] | 117 | mod macro_input; |
| 118 | pub use macro_input::{ |
| 119 | Body, |
| 120 | MacroInput, |
| 121 | }; |
| 122 | |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 123 | mod ty; |
| 124 | pub use ty::{ |
| 125 | AngleBracketedParameterData, |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 126 | BareFnTy, |
David Tolnay | 66daf74 | 2016-09-07 08:21:49 -0700 | [diff] [blame] | 127 | FnArg, |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 128 | FnDecl, |
| 129 | FunctionRetTy, |
| 130 | MutTy, |
| 131 | Mutability, |
| 132 | ParenthesizedParameterData, |
| 133 | Path, |
| 134 | PathParameters, |
| 135 | PathSegment, |
| 136 | PolyTraitRef, |
| 137 | QSelf, |
| 138 | Ty, |
| 139 | TypeBinding, |
| 140 | }; |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 141 | |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 142 | #[cfg(feature = "aster")] |
| 143 | pub mod aster; |
David Tolnay | 7ebb9fb | 2016-09-03 12:07:47 -0700 | [diff] [blame] | 144 | |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 145 | #[cfg(feature = "visit")] |
| 146 | pub mod visit; |
| 147 | |
| 148 | #[cfg(feature = "parsing")] |
| 149 | pub use parsing::*; |
| 150 | |
| 151 | #[cfg(feature = "parsing")] |
| 152 | mod parsing { |
| 153 | use super::*; |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame] | 154 | use {generics, macro_input, ty}; |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 155 | use nom; |
| 156 | |
David Tolnay | edf2b99 | 2016-09-23 20:43:45 -0700 | [diff] [blame] | 157 | #[cfg(feature = "full")] |
David Tolnay | b9c8e32 | 2016-09-23 20:48:37 -0700 | [diff] [blame] | 158 | use {expr, item}; |
David Tolnay | edf2b99 | 2016-09-23 20:43:45 -0700 | [diff] [blame] | 159 | |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame] | 160 | pub fn parse_macro_input(input: &str) -> Result<MacroInput, String> { |
| 161 | unwrap("macro input", macro_input::parsing::macro_input, input) |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 162 | } |
| 163 | |
David Tolnay | edf2b99 | 2016-09-23 20:43:45 -0700 | [diff] [blame] | 164 | #[cfg(feature = "full")] |
| 165 | pub fn parse_item(input: &str) -> Result<Item, String> { |
| 166 | unwrap("item", item::parsing::item, input) |
| 167 | } |
| 168 | |
David Tolnay | b9c8e32 | 2016-09-23 20:48:37 -0700 | [diff] [blame] | 169 | #[cfg(feature = "full")] |
| 170 | pub fn parse_expr(input: &str) -> Result<Expr, String> { |
| 171 | unwrap("expression", expr::parsing::expr, input) |
| 172 | } |
| 173 | |
David Tolnay | 32a112e | 2016-09-11 17:46:15 -0700 | [diff] [blame] | 174 | pub fn parse_type(input: &str) -> Result<Ty, String> { |
David Tolnay | b5a7b14 | 2016-09-13 22:46:39 -0700 | [diff] [blame] | 175 | unwrap("type", ty::parsing::ty, input) |
David Tolnay | 32a112e | 2016-09-11 17:46:15 -0700 | [diff] [blame] | 176 | } |
| 177 | |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 178 | pub fn parse_path(input: &str) -> Result<Path, String> { |
David Tolnay | b5a7b14 | 2016-09-13 22:46:39 -0700 | [diff] [blame] | 179 | unwrap("path", ty::parsing::path, input) |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | pub fn parse_where_clause(input: &str) -> Result<WhereClause, String> { |
David Tolnay | b5a7b14 | 2016-09-13 22:46:39 -0700 | [diff] [blame] | 183 | unwrap("where clause", generics::parsing::where_clause, input) |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 184 | } |
| 185 | |
David Tolnay | b5a7b14 | 2016-09-13 22:46:39 -0700 | [diff] [blame] | 186 | fn unwrap<T>(name: &'static str, f: fn(&str) -> nom::IResult<&str, T>, input: &str) -> Result<T, String> { |
| 187 | match f(input) { |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 188 | nom::IResult::Done(rest, t) => { |
| 189 | if rest.is_empty() { |
| 190 | Ok(t) |
| 191 | } else { |
| 192 | Err(format!("remaining tokens after {}: {:?}", name, rest)) |
David Tolnay | c94c38a | 2016-09-05 17:02:03 -0700 | [diff] [blame] | 193 | } |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 194 | } |
David Tolnay | b5a7b14 | 2016-09-13 22:46:39 -0700 | [diff] [blame] | 195 | nom::IResult::Error => Err(format!("failed to parse {}: {:?}", name, input)), |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 196 | } |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 197 | } |
| 198 | } |