blob: 50a754c83414475fb1744994b67853b944fad5c2 [file] [log] [blame]
David Tolnayaed77b02016-09-23 20:50:31 -07001#![cfg_attr(feature = "clippy", feature(plugin))]
2#![cfg_attr(feature = "clippy", plugin(clippy))]
3
David Tolnay87d0b442016-09-04 11:52:12 -07004#[cfg(feature = "printing")]
5extern crate quote;
6
David Tolnayb5a7b142016-09-13 22:46:39 -07007#[cfg(feature = "parsing")]
David Tolnay10413f02016-09-30 09:12:02 -07008extern crate unicode_xid;
9
10#[cfg(feature = "parsing")]
David Tolnayb79ee962016-09-04 09:39:20 -070011#[macro_use]
David Tolnayb5a7b142016-09-13 22:46:39 -070012mod nom;
David Tolnay6b7aaf02016-09-04 10:39:25 -070013
14#[macro_use]
David Tolnayb79ee962016-09-04 09:39:20 -070015mod helper;
David Tolnay35161ff2016-09-03 11:33:15 -070016
David Tolnay886d8ea2016-09-13 08:34:07 -070017mod escape;
18
David Tolnayb79ee962016-09-04 09:39:20 -070019mod attr;
20pub use attr::{
21 Attribute,
David Tolnay4a51dc72016-10-01 00:40:31 -070022 AttrStyle,
David Tolnayb79ee962016-09-04 09:39:20 -070023 MetaItem,
24};
David Tolnay35161ff2016-09-03 11:33:15 -070025
David Tolnayf38cdf62016-09-23 19:07:09 -070026mod data;
27pub use data::{
28 Discriminant,
29 Field,
30 Variant,
31 VariantData,
32 Visibility,
33};
34
David Tolnayf4bbbd92016-09-23 14:41:55 -070035#[cfg(feature = "full")]
36mod expr;
37#[cfg(feature = "full")]
38pub 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 Tolnayb79ee962016-09-04 09:39:20 -070055mod generics;
56pub use generics::{
57 Generics,
58 Lifetime,
59 LifetimeDef,
David Tolnay55337722016-09-11 12:58:56 -070060 TraitBoundModifier,
David Tolnayb79ee962016-09-04 09:39:20 -070061 TyParam,
62 TyParamBound,
63 WhereBoundPredicate,
David Tolnay55337722016-09-11 12:58:56 -070064 WhereClause,
David Tolnayb79ee962016-09-04 09:39:20 -070065 WherePredicate,
66 WhereRegionPredicate,
67};
David Tolnay35161ff2016-09-03 11:33:15 -070068
David Tolnay4a51dc72016-10-01 00:40:31 -070069#[cfg(feature = "full")]
70mod krate;
71#[cfg(feature = "full")]
72pub use krate::Crate;
73
David Tolnay55337722016-09-11 12:58:56 -070074mod ident;
75pub use ident::{
76 Ident,
77};
78
David Tolnayf38cdf62016-09-23 19:07:09 -070079#[cfg(feature = "full")]
David Tolnayb79ee962016-09-04 09:39:20 -070080mod item;
David Tolnayf38cdf62016-09-23 19:07:09 -070081#[cfg(feature = "full")]
David Tolnayb79ee962016-09-04 09:39:20 -070082pub use item::{
David Tolnayf38cdf62016-09-23 19:07:09 -070083 Abi,
84 Constness,
85 Defaultness,
86 ForeignItemKind,
87 ForeignItem,
88 ForeignMod,
89 ImplItem,
90 ImplItemKind,
91 ImplPolarity,
David Tolnayb79ee962016-09-04 09:39:20 -070092 Item,
David Tolnayf38cdf62016-09-23 19:07:09 -070093 ItemKind,
94 MethodSig,
95 PathListItem,
96 TraitItem,
97 TraitItemKind,
98 Unsafety,
99 ViewPath,
David Tolnayb79ee962016-09-04 09:39:20 -0700100};
David Tolnay35161ff2016-09-03 11:33:15 -0700101
David Tolnayf4bbbd92016-09-23 14:41:55 -0700102mod lit;
103pub use lit::{
104 FloatTy,
105 IntTy,
106 Lit,
107 StrStyle,
108};
109
110#[cfg(feature = "full")]
111mod mac;
112#[cfg(feature = "full")]
113pub use mac::{
114 BinOpToken,
115 DelimToken,
116 Delimited,
117 Mac,
118 SequenceRepetition,
119 Token,
120 TokenTree,
121};
122
David Tolnayf38cdf62016-09-23 19:07:09 -0700123mod macro_input;
124pub use macro_input::{
125 Body,
126 MacroInput,
127};
128
David Tolnayb79ee962016-09-04 09:39:20 -0700129mod ty;
130pub use ty::{
131 AngleBracketedParameterData,
David Tolnayb79ee962016-09-04 09:39:20 -0700132 BareFnTy,
David Tolnay66daf742016-09-07 08:21:49 -0700133 FnArg,
David Tolnayb79ee962016-09-04 09:39:20 -0700134 FnDecl,
135 FunctionRetTy,
136 MutTy,
137 Mutability,
138 ParenthesizedParameterData,
139 Path,
140 PathParameters,
141 PathSegment,
142 PolyTraitRef,
143 QSelf,
144 Ty,
145 TypeBinding,
146};
David Tolnay35161ff2016-09-03 11:33:15 -0700147
David Tolnay55337722016-09-11 12:58:56 -0700148#[cfg(feature = "aster")]
149pub mod aster;
David Tolnay7ebb9fb2016-09-03 12:07:47 -0700150
David Tolnay55337722016-09-11 12:58:56 -0700151#[cfg(feature = "visit")]
152pub mod visit;
153
154#[cfg(feature = "parsing")]
155pub use parsing::*;
156
157#[cfg(feature = "parsing")]
158mod parsing {
159 use super::*;
David Tolnayf38cdf62016-09-23 19:07:09 -0700160 use {generics, macro_input, ty};
David Tolnay55337722016-09-11 12:58:56 -0700161 use nom;
162
David Tolnayedf2b992016-09-23 20:43:45 -0700163 #[cfg(feature = "full")]
David Tolnay4a51dc72016-10-01 00:40:31 -0700164 use {expr, item, krate};
David Tolnayedf2b992016-09-23 20:43:45 -0700165
David Tolnayf38cdf62016-09-23 19:07:09 -0700166 pub fn parse_macro_input(input: &str) -> Result<MacroInput, String> {
167 unwrap("macro input", macro_input::parsing::macro_input, input)
David Tolnay55337722016-09-11 12:58:56 -0700168 }
169
David Tolnayedf2b992016-09-23 20:43:45 -0700170 #[cfg(feature = "full")]
David Tolnay4a51dc72016-10-01 00:40:31 -0700171 pub fn parse_crate(input: &str) -> Result<Crate, String> {
172 unwrap("crate", krate::parsing::krate, input)
173 }
174
175 #[cfg(feature = "full")]
David Tolnayedf2b992016-09-23 20:43:45 -0700176 pub fn parse_item(input: &str) -> Result<Item, String> {
177 unwrap("item", item::parsing::item, input)
178 }
179
David Tolnayb9c8e322016-09-23 20:48:37 -0700180 #[cfg(feature = "full")]
181 pub fn parse_expr(input: &str) -> Result<Expr, String> {
182 unwrap("expression", expr::parsing::expr, input)
183 }
184
David Tolnay32a112e2016-09-11 17:46:15 -0700185 pub fn parse_type(input: &str) -> Result<Ty, String> {
David Tolnayb5a7b142016-09-13 22:46:39 -0700186 unwrap("type", ty::parsing::ty, input)
David Tolnay32a112e2016-09-11 17:46:15 -0700187 }
188
David Tolnay55337722016-09-11 12:58:56 -0700189 pub fn parse_path(input: &str) -> Result<Path, String> {
David Tolnayb5a7b142016-09-13 22:46:39 -0700190 unwrap("path", ty::parsing::path, input)
David Tolnay55337722016-09-11 12:58:56 -0700191 }
192
193 pub fn parse_where_clause(input: &str) -> Result<WhereClause, String> {
David Tolnayb5a7b142016-09-13 22:46:39 -0700194 unwrap("where clause", generics::parsing::where_clause, input)
David Tolnay55337722016-09-11 12:58:56 -0700195 }
196
David Tolnayb5a7b142016-09-13 22:46:39 -0700197 fn unwrap<T>(name: &'static str, f: fn(&str) -> nom::IResult<&str, T>, input: &str) -> Result<T, String> {
198 match f(input) {
David Tolnay55337722016-09-11 12:58:56 -0700199 nom::IResult::Done(rest, t) => {
200 if rest.is_empty() {
201 Ok(t)
202 } else {
203 Err(format!("remaining tokens after {}: {:?}", name, rest))
David Tolnayc94c38a2016-09-05 17:02:03 -0700204 }
David Tolnay55337722016-09-11 12:58:56 -0700205 }
David Tolnayb5a7b142016-09-13 22:46:39 -0700206 nom::IResult::Error => Err(format!("failed to parse {}: {:?}", name, input)),
David Tolnay35161ff2016-09-03 11:33:15 -0700207 }
David Tolnay35161ff2016-09-03 11:33:15 -0700208 }
209}