blob: 6814c983166ac6f58459d0a2b399af59fea74bf3 [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,
David Tolnay62f374c2016-10-02 13:37:00 -070086 FnArg,
87 FnDecl,
David Tolnayf38cdf62016-09-23 19:07:09 -070088 ForeignItemKind,
89 ForeignItem,
90 ForeignMod,
91 ImplItem,
92 ImplItemKind,
93 ImplPolarity,
David Tolnayb79ee962016-09-04 09:39:20 -070094 Item,
David Tolnayf38cdf62016-09-23 19:07:09 -070095 ItemKind,
96 MethodSig,
97 PathListItem,
98 TraitItem,
99 TraitItemKind,
100 Unsafety,
101 ViewPath,
David Tolnayb79ee962016-09-04 09:39:20 -0700102};
David Tolnay35161ff2016-09-03 11:33:15 -0700103
David Tolnayf4bbbd92016-09-23 14:41:55 -0700104mod lit;
105pub use lit::{
106 FloatTy,
107 IntTy,
108 Lit,
109 StrStyle,
110};
111
112#[cfg(feature = "full")]
113mod mac;
114#[cfg(feature = "full")]
115pub use mac::{
116 BinOpToken,
117 DelimToken,
118 Delimited,
119 Mac,
120 SequenceRepetition,
121 Token,
122 TokenTree,
123};
124
David Tolnayf38cdf62016-09-23 19:07:09 -0700125mod macro_input;
126pub use macro_input::{
127 Body,
128 MacroInput,
129};
130
David Tolnay14cbdeb2016-10-01 12:13:59 -0700131mod space;
132
David Tolnayb79ee962016-09-04 09:39:20 -0700133mod ty;
134pub use ty::{
135 AngleBracketedParameterData,
David Tolnay62f374c2016-10-02 13:37:00 -0700136 BareFnArg,
David Tolnayb79ee962016-09-04 09:39:20 -0700137 BareFnTy,
David Tolnayb79ee962016-09-04 09:39:20 -0700138 FunctionRetTy,
139 MutTy,
140 Mutability,
141 ParenthesizedParameterData,
142 Path,
143 PathParameters,
144 PathSegment,
145 PolyTraitRef,
146 QSelf,
147 Ty,
148 TypeBinding,
149};
David Tolnay35161ff2016-09-03 11:33:15 -0700150
David Tolnay55337722016-09-11 12:58:56 -0700151#[cfg(feature = "aster")]
152pub mod aster;
David Tolnay7ebb9fb2016-09-03 12:07:47 -0700153
David Tolnay55337722016-09-11 12:58:56 -0700154#[cfg(feature = "visit")]
155pub mod visit;
156
157#[cfg(feature = "parsing")]
158pub use parsing::*;
159
160#[cfg(feature = "parsing")]
161mod parsing {
162 use super::*;
David Tolnayf38cdf62016-09-23 19:07:09 -0700163 use {generics, macro_input, ty};
David Tolnay14cbdeb2016-10-01 12:13:59 -0700164 use nom::IResult;
David Tolnay55337722016-09-11 12:58:56 -0700165
David Tolnayedf2b992016-09-23 20:43:45 -0700166 #[cfg(feature = "full")]
David Tolnay4a51dc72016-10-01 00:40:31 -0700167 use {expr, item, krate};
David Tolnayedf2b992016-09-23 20:43:45 -0700168
David Tolnayf38cdf62016-09-23 19:07:09 -0700169 pub fn parse_macro_input(input: &str) -> Result<MacroInput, String> {
170 unwrap("macro input", macro_input::parsing::macro_input, input)
David Tolnay55337722016-09-11 12:58:56 -0700171 }
172
David Tolnayedf2b992016-09-23 20:43:45 -0700173 #[cfg(feature = "full")]
David Tolnay4a51dc72016-10-01 00:40:31 -0700174 pub fn parse_crate(input: &str) -> Result<Crate, String> {
175 unwrap("crate", krate::parsing::krate, input)
176 }
177
178 #[cfg(feature = "full")]
David Tolnayedf2b992016-09-23 20:43:45 -0700179 pub fn parse_item(input: &str) -> Result<Item, String> {
180 unwrap("item", item::parsing::item, input)
181 }
182
David Tolnayb9c8e322016-09-23 20:48:37 -0700183 #[cfg(feature = "full")]
184 pub fn parse_expr(input: &str) -> Result<Expr, String> {
185 unwrap("expression", expr::parsing::expr, input)
186 }
187
David Tolnay32a112e2016-09-11 17:46:15 -0700188 pub fn parse_type(input: &str) -> Result<Ty, String> {
David Tolnayb5a7b142016-09-13 22:46:39 -0700189 unwrap("type", ty::parsing::ty, input)
David Tolnay32a112e2016-09-11 17:46:15 -0700190 }
191
David Tolnay55337722016-09-11 12:58:56 -0700192 pub fn parse_path(input: &str) -> Result<Path, String> {
David Tolnayb5a7b142016-09-13 22:46:39 -0700193 unwrap("path", ty::parsing::path, input)
David Tolnay55337722016-09-11 12:58:56 -0700194 }
195
196 pub fn parse_where_clause(input: &str) -> Result<WhereClause, String> {
David Tolnayb5a7b142016-09-13 22:46:39 -0700197 unwrap("where clause", generics::parsing::where_clause, input)
David Tolnay55337722016-09-11 12:58:56 -0700198 }
199
David Tolnay14cbdeb2016-10-01 12:13:59 -0700200 fn unwrap<T>(name: &'static str, f: fn(&str) -> IResult<&str, T>, input: &str) -> Result<T, String> {
David Tolnayb5a7b142016-09-13 22:46:39 -0700201 match f(input) {
David Tolnay14cbdeb2016-10-01 12:13:59 -0700202 IResult::Done(rest, t) => {
David Tolnay55337722016-09-11 12:58:56 -0700203 if rest.is_empty() {
204 Ok(t)
205 } else {
206 Err(format!("remaining tokens after {}: {:?}", name, rest))
David Tolnayc94c38a2016-09-05 17:02:03 -0700207 }
David Tolnay55337722016-09-11 12:58:56 -0700208 }
David Tolnay14cbdeb2016-10-01 12:13:59 -0700209 IResult::Error => Err(format!("failed to parse {}: {:?}", name, input)),
David Tolnay35161ff2016-09-03 11:33:15 -0700210 }
David Tolnay35161ff2016-09-03 11:33:15 -0700211 }
212}