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 | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 129 | mod ty; |
| 130 | pub use ty::{ |
| 131 | AngleBracketedParameterData, |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 132 | BareFnTy, |
David Tolnay | 66daf74 | 2016-09-07 08:21:49 -0700 | [diff] [blame] | 133 | FnArg, |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 134 | FnDecl, |
| 135 | FunctionRetTy, |
| 136 | MutTy, |
| 137 | Mutability, |
| 138 | ParenthesizedParameterData, |
| 139 | Path, |
| 140 | PathParameters, |
| 141 | PathSegment, |
| 142 | PolyTraitRef, |
| 143 | QSelf, |
| 144 | Ty, |
| 145 | TypeBinding, |
| 146 | }; |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 147 | |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 148 | #[cfg(feature = "aster")] |
| 149 | pub mod aster; |
David Tolnay | 7ebb9fb | 2016-09-03 12:07:47 -0700 | [diff] [blame] | 150 | |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 151 | #[cfg(feature = "visit")] |
| 152 | pub mod visit; |
| 153 | |
| 154 | #[cfg(feature = "parsing")] |
| 155 | pub use parsing::*; |
| 156 | |
| 157 | #[cfg(feature = "parsing")] |
| 158 | mod parsing { |
| 159 | use super::*; |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame] | 160 | use {generics, macro_input, ty}; |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 161 | use nom; |
| 162 | |
David Tolnay | edf2b99 | 2016-09-23 20:43:45 -0700 | [diff] [blame] | 163 | #[cfg(feature = "full")] |
David Tolnay | 4a51dc7 | 2016-10-01 00:40:31 -0700 | [diff] [blame^] | 164 | use {expr, item, krate}; |
David Tolnay | edf2b99 | 2016-09-23 20:43:45 -0700 | [diff] [blame] | 165 | |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame] | 166 | pub fn parse_macro_input(input: &str) -> Result<MacroInput, String> { |
| 167 | unwrap("macro input", macro_input::parsing::macro_input, input) |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 168 | } |
| 169 | |
David Tolnay | edf2b99 | 2016-09-23 20:43:45 -0700 | [diff] [blame] | 170 | #[cfg(feature = "full")] |
David Tolnay | 4a51dc7 | 2016-10-01 00:40:31 -0700 | [diff] [blame^] | 171 | pub fn parse_crate(input: &str) -> Result<Crate, String> { |
| 172 | unwrap("crate", krate::parsing::krate, input) |
| 173 | } |
| 174 | |
| 175 | #[cfg(feature = "full")] |
David Tolnay | edf2b99 | 2016-09-23 20:43:45 -0700 | [diff] [blame] | 176 | pub fn parse_item(input: &str) -> Result<Item, String> { |
| 177 | unwrap("item", item::parsing::item, input) |
| 178 | } |
| 179 | |
David Tolnay | b9c8e32 | 2016-09-23 20:48:37 -0700 | [diff] [blame] | 180 | #[cfg(feature = "full")] |
| 181 | pub fn parse_expr(input: &str) -> Result<Expr, String> { |
| 182 | unwrap("expression", expr::parsing::expr, input) |
| 183 | } |
| 184 | |
David Tolnay | 32a112e | 2016-09-11 17:46:15 -0700 | [diff] [blame] | 185 | pub fn parse_type(input: &str) -> Result<Ty, String> { |
David Tolnay | b5a7b14 | 2016-09-13 22:46:39 -0700 | [diff] [blame] | 186 | unwrap("type", ty::parsing::ty, input) |
David Tolnay | 32a112e | 2016-09-11 17:46:15 -0700 | [diff] [blame] | 187 | } |
| 188 | |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 189 | pub fn parse_path(input: &str) -> Result<Path, String> { |
David Tolnay | b5a7b14 | 2016-09-13 22:46:39 -0700 | [diff] [blame] | 190 | unwrap("path", ty::parsing::path, input) |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | pub fn parse_where_clause(input: &str) -> Result<WhereClause, String> { |
David Tolnay | b5a7b14 | 2016-09-13 22:46:39 -0700 | [diff] [blame] | 194 | unwrap("where clause", generics::parsing::where_clause, input) |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 195 | } |
| 196 | |
David Tolnay | b5a7b14 | 2016-09-13 22:46:39 -0700 | [diff] [blame] | 197 | fn unwrap<T>(name: &'static str, f: fn(&str) -> nom::IResult<&str, T>, input: &str) -> Result<T, String> { |
| 198 | match f(input) { |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 199 | nom::IResult::Done(rest, t) => { |
| 200 | if rest.is_empty() { |
| 201 | Ok(t) |
| 202 | } else { |
| 203 | Err(format!("remaining tokens after {}: {:?}", name, rest)) |
David Tolnay | c94c38a | 2016-09-05 17:02:03 -0700 | [diff] [blame] | 204 | } |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 205 | } |
David Tolnay | b5a7b14 | 2016-09-13 22:46:39 -0700 | [diff] [blame] | 206 | nom::IResult::Error => Err(format!("failed to parse {}: {:?}", name, input)), |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 207 | } |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 208 | } |
| 209 | } |