blob: a9c8e4bfd7aea074261a81a5b6f0ebf99254d745 [file] [log] [blame]
David Tolnay87d0b442016-09-04 11:52:12 -07001#[cfg(feature = "printing")]
2extern crate quote;
3
David Tolnayb5a7b142016-09-13 22:46:39 -07004#[cfg(feature = "parsing")]
David Tolnayb79ee962016-09-04 09:39:20 -07005#[macro_use]
David Tolnayb5a7b142016-09-13 22:46:39 -07006mod nom;
David Tolnay6b7aaf02016-09-04 10:39:25 -07007
8#[macro_use]
David Tolnayb79ee962016-09-04 09:39:20 -07009mod helper;
David Tolnay35161ff2016-09-03 11:33:15 -070010
David Tolnay886d8ea2016-09-13 08:34:07 -070011mod escape;
12
David Tolnayb79ee962016-09-04 09:39:20 -070013mod attr;
14pub use attr::{
15 Attribute,
16 MetaItem,
17};
David Tolnay35161ff2016-09-03 11:33:15 -070018
David Tolnayf38cdf62016-09-23 19:07:09 -070019mod data;
20pub use data::{
21 Discriminant,
22 Field,
23 Variant,
24 VariantData,
25 Visibility,
26};
27
David Tolnayf4bbbd92016-09-23 14:41:55 -070028#[cfg(feature = "full")]
29mod expr;
30#[cfg(feature = "full")]
31pub 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 Tolnayb79ee962016-09-04 09:39:20 -070048mod generics;
49pub use generics::{
50 Generics,
51 Lifetime,
52 LifetimeDef,
David Tolnay55337722016-09-11 12:58:56 -070053 TraitBoundModifier,
David Tolnayb79ee962016-09-04 09:39:20 -070054 TyParam,
55 TyParamBound,
56 WhereBoundPredicate,
David Tolnay55337722016-09-11 12:58:56 -070057 WhereClause,
David Tolnayb79ee962016-09-04 09:39:20 -070058 WherePredicate,
59 WhereRegionPredicate,
60};
David Tolnay35161ff2016-09-03 11:33:15 -070061
David Tolnay55337722016-09-11 12:58:56 -070062mod ident;
63pub use ident::{
64 Ident,
65};
66
David Tolnayf38cdf62016-09-23 19:07:09 -070067#[cfg(feature = "full")]
David Tolnayb79ee962016-09-04 09:39:20 -070068mod item;
David Tolnayf38cdf62016-09-23 19:07:09 -070069#[cfg(feature = "full")]
David Tolnayb79ee962016-09-04 09:39:20 -070070pub use item::{
David Tolnayf38cdf62016-09-23 19:07:09 -070071 Abi,
72 Constness,
73 Defaultness,
74 ForeignItemKind,
75 ForeignItem,
76 ForeignMod,
77 ImplItem,
78 ImplItemKind,
79 ImplPolarity,
David Tolnayb79ee962016-09-04 09:39:20 -070080 Item,
David Tolnayf38cdf62016-09-23 19:07:09 -070081 ItemKind,
82 MethodSig,
83 PathListItem,
84 TraitItem,
85 TraitItemKind,
86 Unsafety,
87 ViewPath,
David Tolnayb79ee962016-09-04 09:39:20 -070088};
David Tolnay35161ff2016-09-03 11:33:15 -070089
David Tolnayf4bbbd92016-09-23 14:41:55 -070090mod lit;
91pub use lit::{
92 FloatTy,
93 IntTy,
94 Lit,
95 StrStyle,
96};
97
98#[cfg(feature = "full")]
99mod mac;
100#[cfg(feature = "full")]
101pub use mac::{
102 BinOpToken,
103 DelimToken,
104 Delimited,
105 Mac,
106 SequenceRepetition,
107 Token,
108 TokenTree,
109};
110
David Tolnayf38cdf62016-09-23 19:07:09 -0700111mod macro_input;
112pub use macro_input::{
113 Body,
114 MacroInput,
115};
116
David Tolnayb79ee962016-09-04 09:39:20 -0700117mod ty;
118pub use ty::{
119 AngleBracketedParameterData,
David Tolnayb79ee962016-09-04 09:39:20 -0700120 BareFnTy,
David Tolnay66daf742016-09-07 08:21:49 -0700121 FnArg,
David Tolnayb79ee962016-09-04 09:39:20 -0700122 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 Tolnay35161ff2016-09-03 11:33:15 -0700135
David Tolnay55337722016-09-11 12:58:56 -0700136#[cfg(feature = "aster")]
137pub mod aster;
David Tolnay7ebb9fb2016-09-03 12:07:47 -0700138
David Tolnay55337722016-09-11 12:58:56 -0700139#[cfg(feature = "visit")]
140pub mod visit;
141
142#[cfg(feature = "parsing")]
143pub use parsing::*;
144
145#[cfg(feature = "parsing")]
146mod parsing {
147 use super::*;
David Tolnayf38cdf62016-09-23 19:07:09 -0700148 use {generics, macro_input, ty};
David Tolnay55337722016-09-11 12:58:56 -0700149 use nom;
150
David Tolnayedf2b992016-09-23 20:43:45 -0700151 #[cfg(feature = "full")]
152 use item;
153
David Tolnayf38cdf62016-09-23 19:07:09 -0700154 pub fn parse_macro_input(input: &str) -> Result<MacroInput, String> {
155 unwrap("macro input", macro_input::parsing::macro_input, input)
David Tolnay55337722016-09-11 12:58:56 -0700156 }
157
David Tolnayedf2b992016-09-23 20:43:45 -0700158 #[cfg(feature = "full")]
159 pub fn parse_item(input: &str) -> Result<Item, String> {
160 unwrap("item", item::parsing::item, input)
161 }
162
David Tolnay32a112e2016-09-11 17:46:15 -0700163 pub fn parse_type(input: &str) -> Result<Ty, String> {
David Tolnayb5a7b142016-09-13 22:46:39 -0700164 unwrap("type", ty::parsing::ty, input)
David Tolnay32a112e2016-09-11 17:46:15 -0700165 }
166
David Tolnay55337722016-09-11 12:58:56 -0700167 pub fn parse_path(input: &str) -> Result<Path, String> {
David Tolnayb5a7b142016-09-13 22:46:39 -0700168 unwrap("path", ty::parsing::path, input)
David Tolnay55337722016-09-11 12:58:56 -0700169 }
170
171 pub fn parse_where_clause(input: &str) -> Result<WhereClause, String> {
David Tolnayb5a7b142016-09-13 22:46:39 -0700172 unwrap("where clause", generics::parsing::where_clause, input)
David Tolnay55337722016-09-11 12:58:56 -0700173 }
174
David Tolnayb5a7b142016-09-13 22:46:39 -0700175 fn unwrap<T>(name: &'static str, f: fn(&str) -> nom::IResult<&str, T>, input: &str) -> Result<T, String> {
176 match f(input) {
David Tolnay55337722016-09-11 12:58:56 -0700177 nom::IResult::Done(rest, t) => {
178 if rest.is_empty() {
179 Ok(t)
180 } else {
181 Err(format!("remaining tokens after {}: {:?}", name, rest))
David Tolnayc94c38a2016-09-05 17:02:03 -0700182 }
David Tolnay55337722016-09-11 12:58:56 -0700183 }
David Tolnayb5a7b142016-09-13 22:46:39 -0700184 nom::IResult::Error => Err(format!("failed to parse {}: {:?}", name, input)),
David Tolnay35161ff2016-09-03 11:33:15 -0700185 }
David Tolnay35161ff2016-09-03 11:33:15 -0700186 }
187}