blob: 0841f17ef8f22efe16088ffe8836618582a6ff06 [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 Tolnayb79ee962016-09-04 09:39:20 -07008#[macro_use]
David Tolnayb5a7b142016-09-13 22:46:39 -07009mod nom;
David Tolnay6b7aaf02016-09-04 10:39:25 -070010
11#[macro_use]
David Tolnayb79ee962016-09-04 09:39:20 -070012mod helper;
David Tolnay35161ff2016-09-03 11:33:15 -070013
David Tolnay886d8ea2016-09-13 08:34:07 -070014mod escape;
15
David Tolnayb79ee962016-09-04 09:39:20 -070016mod attr;
17pub use attr::{
18 Attribute,
19 MetaItem,
20};
David Tolnay35161ff2016-09-03 11:33:15 -070021
David Tolnayf38cdf62016-09-23 19:07:09 -070022mod data;
23pub use data::{
24 Discriminant,
25 Field,
26 Variant,
27 VariantData,
28 Visibility,
29};
30
David Tolnayf4bbbd92016-09-23 14:41:55 -070031#[cfg(feature = "full")]
32mod expr;
33#[cfg(feature = "full")]
34pub use expr::{
35 Arm,
36 BinOp,
37 BindingMode,
38 Block,
39 BlockCheckMode,
40 CaptureBy,
41 Expr,
42 FieldPat,
43 Local,
44 MacStmtStyle,
45 Pat,
46 RangeLimits,
47 Stmt,
48 UnOp,
49};
50
David Tolnayb79ee962016-09-04 09:39:20 -070051mod generics;
52pub use generics::{
53 Generics,
54 Lifetime,
55 LifetimeDef,
David Tolnay55337722016-09-11 12:58:56 -070056 TraitBoundModifier,
David Tolnayb79ee962016-09-04 09:39:20 -070057 TyParam,
58 TyParamBound,
59 WhereBoundPredicate,
David Tolnay55337722016-09-11 12:58:56 -070060 WhereClause,
David Tolnayb79ee962016-09-04 09:39:20 -070061 WherePredicate,
62 WhereRegionPredicate,
63};
David Tolnay35161ff2016-09-03 11:33:15 -070064
David Tolnay55337722016-09-11 12:58:56 -070065mod ident;
66pub use ident::{
67 Ident,
68};
69
David Tolnayf38cdf62016-09-23 19:07:09 -070070#[cfg(feature = "full")]
David Tolnayb79ee962016-09-04 09:39:20 -070071mod item;
David Tolnayf38cdf62016-09-23 19:07:09 -070072#[cfg(feature = "full")]
David Tolnayb79ee962016-09-04 09:39:20 -070073pub use item::{
David Tolnayf38cdf62016-09-23 19:07:09 -070074 Abi,
75 Constness,
76 Defaultness,
77 ForeignItemKind,
78 ForeignItem,
79 ForeignMod,
80 ImplItem,
81 ImplItemKind,
82 ImplPolarity,
David Tolnayb79ee962016-09-04 09:39:20 -070083 Item,
David Tolnayf38cdf62016-09-23 19:07:09 -070084 ItemKind,
85 MethodSig,
86 PathListItem,
87 TraitItem,
88 TraitItemKind,
89 Unsafety,
90 ViewPath,
David Tolnayb79ee962016-09-04 09:39:20 -070091};
David Tolnay35161ff2016-09-03 11:33:15 -070092
David Tolnayf4bbbd92016-09-23 14:41:55 -070093mod lit;
94pub use lit::{
95 FloatTy,
96 IntTy,
97 Lit,
98 StrStyle,
99};
100
101#[cfg(feature = "full")]
102mod mac;
103#[cfg(feature = "full")]
104pub use mac::{
105 BinOpToken,
106 DelimToken,
107 Delimited,
108 Mac,
109 SequenceRepetition,
110 Token,
111 TokenTree,
112};
113
David Tolnayf38cdf62016-09-23 19:07:09 -0700114mod macro_input;
115pub use macro_input::{
116 Body,
117 MacroInput,
118};
119
David Tolnayb79ee962016-09-04 09:39:20 -0700120mod ty;
121pub use ty::{
122 AngleBracketedParameterData,
David Tolnayb79ee962016-09-04 09:39:20 -0700123 BareFnTy,
David Tolnay66daf742016-09-07 08:21:49 -0700124 FnArg,
David Tolnayb79ee962016-09-04 09:39:20 -0700125 FnDecl,
126 FunctionRetTy,
127 MutTy,
128 Mutability,
129 ParenthesizedParameterData,
130 Path,
131 PathParameters,
132 PathSegment,
133 PolyTraitRef,
134 QSelf,
135 Ty,
136 TypeBinding,
137};
David Tolnay35161ff2016-09-03 11:33:15 -0700138
David Tolnay55337722016-09-11 12:58:56 -0700139#[cfg(feature = "aster")]
140pub mod aster;
David Tolnay7ebb9fb2016-09-03 12:07:47 -0700141
David Tolnay55337722016-09-11 12:58:56 -0700142#[cfg(feature = "visit")]
143pub mod visit;
144
145#[cfg(feature = "parsing")]
146pub use parsing::*;
147
148#[cfg(feature = "parsing")]
149mod parsing {
150 use super::*;
David Tolnayf38cdf62016-09-23 19:07:09 -0700151 use {generics, macro_input, ty};
David Tolnay55337722016-09-11 12:58:56 -0700152 use nom;
153
David Tolnayedf2b992016-09-23 20:43:45 -0700154 #[cfg(feature = "full")]
David Tolnayb9c8e322016-09-23 20:48:37 -0700155 use {expr, item};
David Tolnayedf2b992016-09-23 20:43:45 -0700156
David Tolnayf38cdf62016-09-23 19:07:09 -0700157 pub fn parse_macro_input(input: &str) -> Result<MacroInput, String> {
158 unwrap("macro input", macro_input::parsing::macro_input, input)
David Tolnay55337722016-09-11 12:58:56 -0700159 }
160
David Tolnayedf2b992016-09-23 20:43:45 -0700161 #[cfg(feature = "full")]
162 pub fn parse_item(input: &str) -> Result<Item, String> {
163 unwrap("item", item::parsing::item, input)
164 }
165
David Tolnayb9c8e322016-09-23 20:48:37 -0700166 #[cfg(feature = "full")]
167 pub fn parse_expr(input: &str) -> Result<Expr, String> {
168 unwrap("expression", expr::parsing::expr, input)
169 }
170
David Tolnay32a112e2016-09-11 17:46:15 -0700171 pub fn parse_type(input: &str) -> Result<Ty, String> {
David Tolnayb5a7b142016-09-13 22:46:39 -0700172 unwrap("type", ty::parsing::ty, input)
David Tolnay32a112e2016-09-11 17:46:15 -0700173 }
174
David Tolnay55337722016-09-11 12:58:56 -0700175 pub fn parse_path(input: &str) -> Result<Path, String> {
David Tolnayb5a7b142016-09-13 22:46:39 -0700176 unwrap("path", ty::parsing::path, input)
David Tolnay55337722016-09-11 12:58:56 -0700177 }
178
179 pub fn parse_where_clause(input: &str) -> Result<WhereClause, String> {
David Tolnayb5a7b142016-09-13 22:46:39 -0700180 unwrap("where clause", generics::parsing::where_clause, input)
David Tolnay55337722016-09-11 12:58:56 -0700181 }
182
David Tolnayb5a7b142016-09-13 22:46:39 -0700183 fn unwrap<T>(name: &'static str, f: fn(&str) -> nom::IResult<&str, T>, input: &str) -> Result<T, String> {
184 match f(input) {
David Tolnay55337722016-09-11 12:58:56 -0700185 nom::IResult::Done(rest, t) => {
186 if rest.is_empty() {
187 Ok(t)
188 } else {
189 Err(format!("remaining tokens after {}: {:?}", name, rest))
David Tolnayc94c38a2016-09-05 17:02:03 -0700190 }
David Tolnay55337722016-09-11 12:58:56 -0700191 }
David Tolnayb5a7b142016-09-13 22:46:39 -0700192 nom::IResult::Error => Err(format!("failed to parse {}: {:?}", name, input)),
David Tolnay35161ff2016-09-03 11:33:15 -0700193 }
David Tolnay35161ff2016-09-03 11:33:15 -0700194 }
195}