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