blob: df62d75983c89dec8487fc5afaa583e163387729 [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,
22 MetaItem,
23};
David Tolnay35161ff2016-09-03 11:33:15 -070024
David Tolnayf38cdf62016-09-23 19:07:09 -070025mod data;
26pub use data::{
27 Discriminant,
28 Field,
29 Variant,
30 VariantData,
31 Visibility,
32};
33
David Tolnayf4bbbd92016-09-23 14:41:55 -070034#[cfg(feature = "full")]
35mod expr;
36#[cfg(feature = "full")]
37pub use expr::{
38 Arm,
39 BinOp,
40 BindingMode,
41 Block,
42 BlockCheckMode,
43 CaptureBy,
44 Expr,
45 FieldPat,
46 Local,
47 MacStmtStyle,
48 Pat,
49 RangeLimits,
50 Stmt,
51 UnOp,
52};
53
David Tolnayb79ee962016-09-04 09:39:20 -070054mod generics;
55pub use generics::{
56 Generics,
57 Lifetime,
58 LifetimeDef,
David Tolnay55337722016-09-11 12:58:56 -070059 TraitBoundModifier,
David Tolnayb79ee962016-09-04 09:39:20 -070060 TyParam,
61 TyParamBound,
62 WhereBoundPredicate,
David Tolnay55337722016-09-11 12:58:56 -070063 WhereClause,
David Tolnayb79ee962016-09-04 09:39:20 -070064 WherePredicate,
65 WhereRegionPredicate,
66};
David Tolnay35161ff2016-09-03 11:33:15 -070067
David Tolnay55337722016-09-11 12:58:56 -070068mod ident;
69pub use ident::{
70 Ident,
71};
72
David Tolnayf38cdf62016-09-23 19:07:09 -070073#[cfg(feature = "full")]
David Tolnayb79ee962016-09-04 09:39:20 -070074mod item;
David Tolnayf38cdf62016-09-23 19:07:09 -070075#[cfg(feature = "full")]
David Tolnayb79ee962016-09-04 09:39:20 -070076pub use item::{
David Tolnayf38cdf62016-09-23 19:07:09 -070077 Abi,
78 Constness,
79 Defaultness,
80 ForeignItemKind,
81 ForeignItem,
82 ForeignMod,
83 ImplItem,
84 ImplItemKind,
85 ImplPolarity,
David Tolnayb79ee962016-09-04 09:39:20 -070086 Item,
David Tolnayf38cdf62016-09-23 19:07:09 -070087 ItemKind,
88 MethodSig,
89 PathListItem,
90 TraitItem,
91 TraitItemKind,
92 Unsafety,
93 ViewPath,
David Tolnayb79ee962016-09-04 09:39:20 -070094};
David Tolnay35161ff2016-09-03 11:33:15 -070095
David Tolnayf4bbbd92016-09-23 14:41:55 -070096mod lit;
97pub use lit::{
98 FloatTy,
99 IntTy,
100 Lit,
101 StrStyle,
102};
103
104#[cfg(feature = "full")]
105mod mac;
106#[cfg(feature = "full")]
107pub use mac::{
108 BinOpToken,
109 DelimToken,
110 Delimited,
111 Mac,
112 SequenceRepetition,
113 Token,
114 TokenTree,
115};
116
David Tolnayf38cdf62016-09-23 19:07:09 -0700117mod macro_input;
118pub use macro_input::{
119 Body,
120 MacroInput,
121};
122
David Tolnayb79ee962016-09-04 09:39:20 -0700123mod ty;
124pub use ty::{
125 AngleBracketedParameterData,
David Tolnayb79ee962016-09-04 09:39:20 -0700126 BareFnTy,
David Tolnay66daf742016-09-07 08:21:49 -0700127 FnArg,
David Tolnayb79ee962016-09-04 09:39:20 -0700128 FnDecl,
129 FunctionRetTy,
130 MutTy,
131 Mutability,
132 ParenthesizedParameterData,
133 Path,
134 PathParameters,
135 PathSegment,
136 PolyTraitRef,
137 QSelf,
138 Ty,
139 TypeBinding,
140};
David Tolnay35161ff2016-09-03 11:33:15 -0700141
David Tolnay55337722016-09-11 12:58:56 -0700142#[cfg(feature = "aster")]
143pub mod aster;
David Tolnay7ebb9fb2016-09-03 12:07:47 -0700144
David Tolnay55337722016-09-11 12:58:56 -0700145#[cfg(feature = "visit")]
146pub mod visit;
147
148#[cfg(feature = "parsing")]
149pub use parsing::*;
150
151#[cfg(feature = "parsing")]
152mod parsing {
153 use super::*;
David Tolnayf38cdf62016-09-23 19:07:09 -0700154 use {generics, macro_input, ty};
David Tolnay55337722016-09-11 12:58:56 -0700155 use nom;
156
David Tolnayedf2b992016-09-23 20:43:45 -0700157 #[cfg(feature = "full")]
David Tolnayb9c8e322016-09-23 20:48:37 -0700158 use {expr, item};
David Tolnayedf2b992016-09-23 20:43:45 -0700159
David Tolnayf38cdf62016-09-23 19:07:09 -0700160 pub fn parse_macro_input(input: &str) -> Result<MacroInput, String> {
161 unwrap("macro input", macro_input::parsing::macro_input, input)
David Tolnay55337722016-09-11 12:58:56 -0700162 }
163
David Tolnayedf2b992016-09-23 20:43:45 -0700164 #[cfg(feature = "full")]
165 pub fn parse_item(input: &str) -> Result<Item, String> {
166 unwrap("item", item::parsing::item, input)
167 }
168
David Tolnayb9c8e322016-09-23 20:48:37 -0700169 #[cfg(feature = "full")]
170 pub fn parse_expr(input: &str) -> Result<Expr, String> {
171 unwrap("expression", expr::parsing::expr, input)
172 }
173
David Tolnay32a112e2016-09-11 17:46:15 -0700174 pub fn parse_type(input: &str) -> Result<Ty, String> {
David Tolnayb5a7b142016-09-13 22:46:39 -0700175 unwrap("type", ty::parsing::ty, input)
David Tolnay32a112e2016-09-11 17:46:15 -0700176 }
177
David Tolnay55337722016-09-11 12:58:56 -0700178 pub fn parse_path(input: &str) -> Result<Path, String> {
David Tolnayb5a7b142016-09-13 22:46:39 -0700179 unwrap("path", ty::parsing::path, input)
David Tolnay55337722016-09-11 12:58:56 -0700180 }
181
182 pub fn parse_where_clause(input: &str) -> Result<WhereClause, String> {
David Tolnayb5a7b142016-09-13 22:46:39 -0700183 unwrap("where clause", generics::parsing::where_clause, input)
David Tolnay55337722016-09-11 12:58:56 -0700184 }
185
David Tolnayb5a7b142016-09-13 22:46:39 -0700186 fn unwrap<T>(name: &'static str, f: fn(&str) -> nom::IResult<&str, T>, input: &str) -> Result<T, String> {
187 match f(input) {
David Tolnay55337722016-09-11 12:58:56 -0700188 nom::IResult::Done(rest, t) => {
189 if rest.is_empty() {
190 Ok(t)
191 } else {
192 Err(format!("remaining tokens after {}: {:?}", name, rest))
David Tolnayc94c38a2016-09-05 17:02:03 -0700193 }
David Tolnay55337722016-09-11 12:58:56 -0700194 }
David Tolnayb5a7b142016-09-13 22:46:39 -0700195 nom::IResult::Error => Err(format!("failed to parse {}: {:?}", name, input)),
David Tolnay35161ff2016-09-03 11:33:15 -0700196 }
David Tolnay35161ff2016-09-03 11:33:15 -0700197 }
198}