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, |
David Tolnay | 62f374c | 2016-10-02 13:37:00 -0700 | [diff] [blame^] | 86 | FnArg, |
| 87 | FnDecl, |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame] | 88 | ForeignItemKind, |
| 89 | ForeignItem, |
| 90 | ForeignMod, |
| 91 | ImplItem, |
| 92 | ImplItemKind, |
| 93 | ImplPolarity, |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 94 | Item, |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame] | 95 | ItemKind, |
| 96 | MethodSig, |
| 97 | PathListItem, |
| 98 | TraitItem, |
| 99 | TraitItemKind, |
| 100 | Unsafety, |
| 101 | ViewPath, |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 102 | }; |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 103 | |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 104 | mod lit; |
| 105 | pub use lit::{ |
| 106 | FloatTy, |
| 107 | IntTy, |
| 108 | Lit, |
| 109 | StrStyle, |
| 110 | }; |
| 111 | |
| 112 | #[cfg(feature = "full")] |
| 113 | mod mac; |
| 114 | #[cfg(feature = "full")] |
| 115 | pub use mac::{ |
| 116 | BinOpToken, |
| 117 | DelimToken, |
| 118 | Delimited, |
| 119 | Mac, |
| 120 | SequenceRepetition, |
| 121 | Token, |
| 122 | TokenTree, |
| 123 | }; |
| 124 | |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame] | 125 | mod macro_input; |
| 126 | pub use macro_input::{ |
| 127 | Body, |
| 128 | MacroInput, |
| 129 | }; |
| 130 | |
David Tolnay | 14cbdeb | 2016-10-01 12:13:59 -0700 | [diff] [blame] | 131 | mod space; |
| 132 | |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 133 | mod ty; |
| 134 | pub use ty::{ |
| 135 | AngleBracketedParameterData, |
David Tolnay | 62f374c | 2016-10-02 13:37:00 -0700 | [diff] [blame^] | 136 | BareFnArg, |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 137 | BareFnTy, |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 138 | FunctionRetTy, |
| 139 | MutTy, |
| 140 | Mutability, |
| 141 | ParenthesizedParameterData, |
| 142 | Path, |
| 143 | PathParameters, |
| 144 | PathSegment, |
| 145 | PolyTraitRef, |
| 146 | QSelf, |
| 147 | Ty, |
| 148 | TypeBinding, |
| 149 | }; |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 150 | |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 151 | #[cfg(feature = "aster")] |
| 152 | pub mod aster; |
David Tolnay | 7ebb9fb | 2016-09-03 12:07:47 -0700 | [diff] [blame] | 153 | |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 154 | #[cfg(feature = "visit")] |
| 155 | pub mod visit; |
| 156 | |
| 157 | #[cfg(feature = "parsing")] |
| 158 | pub use parsing::*; |
| 159 | |
| 160 | #[cfg(feature = "parsing")] |
| 161 | mod parsing { |
| 162 | use super::*; |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame] | 163 | use {generics, macro_input, ty}; |
David Tolnay | 14cbdeb | 2016-10-01 12:13:59 -0700 | [diff] [blame] | 164 | use nom::IResult; |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 165 | |
David Tolnay | edf2b99 | 2016-09-23 20:43:45 -0700 | [diff] [blame] | 166 | #[cfg(feature = "full")] |
David Tolnay | 4a51dc7 | 2016-10-01 00:40:31 -0700 | [diff] [blame] | 167 | use {expr, item, krate}; |
David Tolnay | edf2b99 | 2016-09-23 20:43:45 -0700 | [diff] [blame] | 168 | |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame] | 169 | pub fn parse_macro_input(input: &str) -> Result<MacroInput, String> { |
| 170 | unwrap("macro input", macro_input::parsing::macro_input, input) |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 171 | } |
| 172 | |
David Tolnay | edf2b99 | 2016-09-23 20:43:45 -0700 | [diff] [blame] | 173 | #[cfg(feature = "full")] |
David Tolnay | 4a51dc7 | 2016-10-01 00:40:31 -0700 | [diff] [blame] | 174 | pub fn parse_crate(input: &str) -> Result<Crate, String> { |
| 175 | unwrap("crate", krate::parsing::krate, input) |
| 176 | } |
| 177 | |
| 178 | #[cfg(feature = "full")] |
David Tolnay | edf2b99 | 2016-09-23 20:43:45 -0700 | [diff] [blame] | 179 | pub fn parse_item(input: &str) -> Result<Item, String> { |
| 180 | unwrap("item", item::parsing::item, input) |
| 181 | } |
| 182 | |
David Tolnay | b9c8e32 | 2016-09-23 20:48:37 -0700 | [diff] [blame] | 183 | #[cfg(feature = "full")] |
| 184 | pub fn parse_expr(input: &str) -> Result<Expr, String> { |
| 185 | unwrap("expression", expr::parsing::expr, input) |
| 186 | } |
| 187 | |
David Tolnay | 32a112e | 2016-09-11 17:46:15 -0700 | [diff] [blame] | 188 | pub fn parse_type(input: &str) -> Result<Ty, String> { |
David Tolnay | b5a7b14 | 2016-09-13 22:46:39 -0700 | [diff] [blame] | 189 | unwrap("type", ty::parsing::ty, input) |
David Tolnay | 32a112e | 2016-09-11 17:46:15 -0700 | [diff] [blame] | 190 | } |
| 191 | |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 192 | pub fn parse_path(input: &str) -> Result<Path, String> { |
David Tolnay | b5a7b14 | 2016-09-13 22:46:39 -0700 | [diff] [blame] | 193 | unwrap("path", ty::parsing::path, input) |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | pub fn parse_where_clause(input: &str) -> Result<WhereClause, String> { |
David Tolnay | b5a7b14 | 2016-09-13 22:46:39 -0700 | [diff] [blame] | 197 | unwrap("where clause", generics::parsing::where_clause, input) |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 198 | } |
| 199 | |
David Tolnay | 14cbdeb | 2016-10-01 12:13:59 -0700 | [diff] [blame] | 200 | 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] | 201 | match f(input) { |
David Tolnay | 14cbdeb | 2016-10-01 12:13:59 -0700 | [diff] [blame] | 202 | IResult::Done(rest, t) => { |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 203 | if rest.is_empty() { |
| 204 | Ok(t) |
| 205 | } else { |
| 206 | Err(format!("remaining tokens after {}: {:?}", name, rest)) |
David Tolnay | c94c38a | 2016-09-05 17:02:03 -0700 | [diff] [blame] | 207 | } |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 208 | } |
David Tolnay | 14cbdeb | 2016-10-01 12:13:59 -0700 | [diff] [blame] | 209 | IResult::Error => Err(format!("failed to parse {}: {:?}", name, input)), |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 210 | } |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 211 | } |
| 212 | } |