blob: 7c7bd13855ee757edb7691e7b4b4a606c282b941 [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 Tolnay14cbdeb2016-10-01 12:13:59 -0700129mod space;
130
David Tolnayb79ee962016-09-04 09:39:20 -0700131mod ty;
132pub use ty::{
133 AngleBracketedParameterData,
David Tolnayb79ee962016-09-04 09:39:20 -0700134 BareFnTy,
David Tolnay66daf742016-09-07 08:21:49 -0700135 FnArg,
David Tolnayb79ee962016-09-04 09:39:20 -0700136 FnDecl,
137 FunctionRetTy,
138 MutTy,
139 Mutability,
140 ParenthesizedParameterData,
141 Path,
142 PathParameters,
143 PathSegment,
144 PolyTraitRef,
145 QSelf,
146 Ty,
147 TypeBinding,
148};
David Tolnay35161ff2016-09-03 11:33:15 -0700149
David Tolnay55337722016-09-11 12:58:56 -0700150#[cfg(feature = "aster")]
151pub mod aster;
David Tolnay7ebb9fb2016-09-03 12:07:47 -0700152
David Tolnay55337722016-09-11 12:58:56 -0700153#[cfg(feature = "visit")]
154pub mod visit;
155
156#[cfg(feature = "parsing")]
157pub use parsing::*;
158
159#[cfg(feature = "parsing")]
160mod parsing {
161 use super::*;
David Tolnayf38cdf62016-09-23 19:07:09 -0700162 use {generics, macro_input, ty};
David Tolnay14cbdeb2016-10-01 12:13:59 -0700163 use nom::IResult;
David Tolnay55337722016-09-11 12:58:56 -0700164
David Tolnayedf2b992016-09-23 20:43:45 -0700165 #[cfg(feature = "full")]
David Tolnay4a51dc72016-10-01 00:40:31 -0700166 use {expr, item, krate};
David Tolnayedf2b992016-09-23 20:43:45 -0700167
David Tolnayf38cdf62016-09-23 19:07:09 -0700168 pub fn parse_macro_input(input: &str) -> Result<MacroInput, String> {
169 unwrap("macro input", macro_input::parsing::macro_input, input)
David Tolnay55337722016-09-11 12:58:56 -0700170 }
171
David Tolnayedf2b992016-09-23 20:43:45 -0700172 #[cfg(feature = "full")]
David Tolnay4a51dc72016-10-01 00:40:31 -0700173 pub fn parse_crate(input: &str) -> Result<Crate, String> {
174 unwrap("crate", krate::parsing::krate, input)
175 }
176
177 #[cfg(feature = "full")]
David Tolnayedf2b992016-09-23 20:43:45 -0700178 pub fn parse_item(input: &str) -> Result<Item, String> {
179 unwrap("item", item::parsing::item, input)
180 }
181
David Tolnayb9c8e322016-09-23 20:48:37 -0700182 #[cfg(feature = "full")]
183 pub fn parse_expr(input: &str) -> Result<Expr, String> {
184 unwrap("expression", expr::parsing::expr, input)
185 }
186
David Tolnay32a112e2016-09-11 17:46:15 -0700187 pub fn parse_type(input: &str) -> Result<Ty, String> {
David Tolnayb5a7b142016-09-13 22:46:39 -0700188 unwrap("type", ty::parsing::ty, input)
David Tolnay32a112e2016-09-11 17:46:15 -0700189 }
190
David Tolnay55337722016-09-11 12:58:56 -0700191 pub fn parse_path(input: &str) -> Result<Path, String> {
David Tolnayb5a7b142016-09-13 22:46:39 -0700192 unwrap("path", ty::parsing::path, input)
David Tolnay55337722016-09-11 12:58:56 -0700193 }
194
195 pub fn parse_where_clause(input: &str) -> Result<WhereClause, String> {
David Tolnayb5a7b142016-09-13 22:46:39 -0700196 unwrap("where clause", generics::parsing::where_clause, input)
David Tolnay55337722016-09-11 12:58:56 -0700197 }
198
David Tolnay14cbdeb2016-10-01 12:13:59 -0700199 fn unwrap<T>(name: &'static str, f: fn(&str) -> IResult<&str, T>, input: &str) -> Result<T, String> {
David Tolnayb5a7b142016-09-13 22:46:39 -0700200 match f(input) {
David Tolnay14cbdeb2016-10-01 12:13:59 -0700201 IResult::Done(rest, t) => {
David Tolnay55337722016-09-11 12:58:56 -0700202 if rest.is_empty() {
203 Ok(t)
204 } else {
205 Err(format!("remaining tokens after {}: {:?}", name, rest))
David Tolnayc94c38a2016-09-05 17:02:03 -0700206 }
David Tolnay55337722016-09-11 12:58:56 -0700207 }
David Tolnay14cbdeb2016-10-01 12:13:59 -0700208 IResult::Error => Err(format!("failed to parse {}: {:?}", name, input)),
David Tolnay35161ff2016-09-03 11:33:15 -0700209 }
David Tolnay35161ff2016-09-03 11:33:15 -0700210 }
211}