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 | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame^] | 19 | #[cfg(feature = "full")] |
| 20 | mod expr; |
| 21 | #[cfg(feature = "full")] |
| 22 | pub use expr::{ |
| 23 | Arm, |
| 24 | BinOp, |
| 25 | BindingMode, |
| 26 | Block, |
| 27 | BlockCheckMode, |
| 28 | CaptureBy, |
| 29 | Expr, |
| 30 | FieldPat, |
| 31 | Local, |
| 32 | MacStmtStyle, |
| 33 | Pat, |
| 34 | RangeLimits, |
| 35 | Stmt, |
| 36 | UnOp, |
| 37 | }; |
| 38 | |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 39 | mod generics; |
| 40 | pub use generics::{ |
| 41 | Generics, |
| 42 | Lifetime, |
| 43 | LifetimeDef, |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 44 | TraitBoundModifier, |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 45 | TyParam, |
| 46 | TyParamBound, |
| 47 | WhereBoundPredicate, |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 48 | WhereClause, |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 49 | WherePredicate, |
| 50 | WhereRegionPredicate, |
| 51 | }; |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 52 | |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 53 | mod ident; |
| 54 | pub use ident::{ |
| 55 | Ident, |
| 56 | }; |
| 57 | |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 58 | mod item; |
| 59 | pub use item::{ |
| 60 | Body, |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame^] | 61 | Discriminant, |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 62 | Field, |
| 63 | Item, |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 64 | Variant, |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 65 | VariantData, |
| 66 | Visibility, |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 67 | }; |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 68 | |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame^] | 69 | mod lit; |
| 70 | pub use lit::{ |
| 71 | FloatTy, |
| 72 | IntTy, |
| 73 | Lit, |
| 74 | StrStyle, |
| 75 | }; |
| 76 | |
| 77 | #[cfg(feature = "full")] |
| 78 | mod mac; |
| 79 | #[cfg(feature = "full")] |
| 80 | pub use mac::{ |
| 81 | BinOpToken, |
| 82 | DelimToken, |
| 83 | Delimited, |
| 84 | Mac, |
| 85 | SequenceRepetition, |
| 86 | Token, |
| 87 | TokenTree, |
| 88 | }; |
| 89 | |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 90 | mod ty; |
| 91 | pub use ty::{ |
| 92 | AngleBracketedParameterData, |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 93 | BareFnTy, |
David Tolnay | 66daf74 | 2016-09-07 08:21:49 -0700 | [diff] [blame] | 94 | FnArg, |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 95 | FnDecl, |
| 96 | FunctionRetTy, |
| 97 | MutTy, |
| 98 | Mutability, |
| 99 | ParenthesizedParameterData, |
| 100 | Path, |
| 101 | PathParameters, |
| 102 | PathSegment, |
| 103 | PolyTraitRef, |
| 104 | QSelf, |
| 105 | Ty, |
| 106 | TypeBinding, |
| 107 | }; |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 108 | |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 109 | #[cfg(feature = "aster")] |
| 110 | pub mod aster; |
David Tolnay | 7ebb9fb | 2016-09-03 12:07:47 -0700 | [diff] [blame] | 111 | |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 112 | #[cfg(feature = "visit")] |
| 113 | pub mod visit; |
| 114 | |
| 115 | #[cfg(feature = "parsing")] |
| 116 | pub use parsing::*; |
| 117 | |
| 118 | #[cfg(feature = "parsing")] |
| 119 | mod parsing { |
| 120 | use super::*; |
| 121 | use {generics, item, ty}; |
| 122 | use nom; |
| 123 | |
| 124 | pub fn parse_item(input: &str) -> Result<Item, String> { |
David Tolnay | b5a7b14 | 2016-09-13 22:46:39 -0700 | [diff] [blame] | 125 | unwrap("item", item::parsing::item, input) |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 126 | } |
| 127 | |
David Tolnay | 32a112e | 2016-09-11 17:46:15 -0700 | [diff] [blame] | 128 | pub fn parse_type(input: &str) -> Result<Ty, String> { |
David Tolnay | b5a7b14 | 2016-09-13 22:46:39 -0700 | [diff] [blame] | 129 | unwrap("type", ty::parsing::ty, input) |
David Tolnay | 32a112e | 2016-09-11 17:46:15 -0700 | [diff] [blame] | 130 | } |
| 131 | |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 132 | pub fn parse_path(input: &str) -> Result<Path, String> { |
David Tolnay | b5a7b14 | 2016-09-13 22:46:39 -0700 | [diff] [blame] | 133 | unwrap("path", ty::parsing::path, input) |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | pub fn parse_where_clause(input: &str) -> Result<WhereClause, String> { |
David Tolnay | b5a7b14 | 2016-09-13 22:46:39 -0700 | [diff] [blame] | 137 | unwrap("where clause", generics::parsing::where_clause, input) |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 138 | } |
| 139 | |
David Tolnay | b5a7b14 | 2016-09-13 22:46:39 -0700 | [diff] [blame] | 140 | fn unwrap<T>(name: &'static str, f: fn(&str) -> nom::IResult<&str, T>, input: &str) -> Result<T, String> { |
| 141 | match f(input) { |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 142 | nom::IResult::Done(rest, t) => { |
| 143 | if rest.is_empty() { |
| 144 | Ok(t) |
| 145 | } else { |
| 146 | Err(format!("remaining tokens after {}: {:?}", name, rest)) |
David Tolnay | c94c38a | 2016-09-05 17:02:03 -0700 | [diff] [blame] | 147 | } |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 148 | } |
David Tolnay | b5a7b14 | 2016-09-13 22:46:39 -0700 | [diff] [blame] | 149 | nom::IResult::Error => Err(format!("failed to parse {}: {:?}", name, input)), |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 150 | } |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 151 | } |
| 152 | } |