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