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 | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 19 | mod generics; |
| 20 | pub use generics::{ |
| 21 | Generics, |
| 22 | Lifetime, |
| 23 | LifetimeDef, |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 24 | TraitBoundModifier, |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 25 | TyParam, |
| 26 | TyParamBound, |
| 27 | WhereBoundPredicate, |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 28 | WhereClause, |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 29 | WherePredicate, |
| 30 | WhereRegionPredicate, |
| 31 | }; |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 32 | |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 33 | mod ident; |
| 34 | pub use ident::{ |
| 35 | Ident, |
| 36 | }; |
| 37 | |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 38 | mod item; |
| 39 | pub use item::{ |
| 40 | Body, |
| 41 | Field, |
| 42 | Item, |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 43 | Variant, |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 44 | VariantData, |
| 45 | Visibility, |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 46 | }; |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 47 | |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 48 | mod ty; |
| 49 | pub use ty::{ |
| 50 | AngleBracketedParameterData, |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 51 | BareFnTy, |
David Tolnay | 66daf74 | 2016-09-07 08:21:49 -0700 | [diff] [blame] | 52 | FnArg, |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 53 | FnDecl, |
| 54 | FunctionRetTy, |
| 55 | MutTy, |
| 56 | Mutability, |
| 57 | ParenthesizedParameterData, |
| 58 | Path, |
| 59 | PathParameters, |
| 60 | PathSegment, |
| 61 | PolyTraitRef, |
| 62 | QSelf, |
| 63 | Ty, |
| 64 | TypeBinding, |
| 65 | }; |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 66 | |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 67 | #[cfg(feature = "aster")] |
| 68 | pub mod aster; |
David Tolnay | 7ebb9fb | 2016-09-03 12:07:47 -0700 | [diff] [blame] | 69 | |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 70 | #[cfg(feature = "visit")] |
| 71 | pub mod visit; |
| 72 | |
| 73 | #[cfg(feature = "parsing")] |
| 74 | pub use parsing::*; |
| 75 | |
| 76 | #[cfg(feature = "parsing")] |
| 77 | mod parsing { |
| 78 | use super::*; |
| 79 | use {generics, item, ty}; |
| 80 | use nom; |
| 81 | |
| 82 | pub fn parse_item(input: &str) -> Result<Item, String> { |
David Tolnay | b5a7b14 | 2016-09-13 22:46:39 -0700 | [diff] [blame^] | 83 | unwrap("item", item::parsing::item, input) |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 84 | } |
| 85 | |
David Tolnay | 32a112e | 2016-09-11 17:46:15 -0700 | [diff] [blame] | 86 | pub fn parse_type(input: &str) -> Result<Ty, String> { |
David Tolnay | b5a7b14 | 2016-09-13 22:46:39 -0700 | [diff] [blame^] | 87 | unwrap("type", ty::parsing::ty, input) |
David Tolnay | 32a112e | 2016-09-11 17:46:15 -0700 | [diff] [blame] | 88 | } |
| 89 | |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 90 | pub fn parse_path(input: &str) -> Result<Path, String> { |
David Tolnay | b5a7b14 | 2016-09-13 22:46:39 -0700 | [diff] [blame^] | 91 | unwrap("path", ty::parsing::path, input) |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | pub fn parse_where_clause(input: &str) -> Result<WhereClause, String> { |
David Tolnay | b5a7b14 | 2016-09-13 22:46:39 -0700 | [diff] [blame^] | 95 | unwrap("where clause", generics::parsing::where_clause, input) |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 96 | } |
| 97 | |
David Tolnay | b5a7b14 | 2016-09-13 22:46:39 -0700 | [diff] [blame^] | 98 | fn unwrap<T>(name: &'static str, f: fn(&str) -> nom::IResult<&str, T>, input: &str) -> Result<T, String> { |
| 99 | match f(input) { |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 100 | nom::IResult::Done(rest, t) => { |
| 101 | if rest.is_empty() { |
| 102 | Ok(t) |
| 103 | } else { |
| 104 | Err(format!("remaining tokens after {}: {:?}", name, rest)) |
David Tolnay | c94c38a | 2016-09-05 17:02:03 -0700 | [diff] [blame] | 105 | } |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 106 | } |
David Tolnay | b5a7b14 | 2016-09-13 22:46:39 -0700 | [diff] [blame^] | 107 | nom::IResult::Error => Err(format!("failed to parse {}: {:?}", name, input)), |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 108 | } |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 109 | } |
| 110 | } |