Module syn::token [−][src]
Tokens representing Rust punctuation, keywords, and delimiters.
The type names in this module can be difficult to keep straight, so we
prefer to use the Token! macro instead. This is a type-macro that
expands to the token type of the given token.
Example
The ItemStatic syntax tree node is defined like this.
pub struct ItemStatic { pub attrs: Vec<Attribute>, pub vis: Visibility, pub static_token: Token![static], pub mutability: Option<Token![mut]>, pub ident: Ident, pub colon_token: Token![:], pub ty: Box<Type>, pub eq_token: Token![=], pub expr: Box<Expr>, pub semi_token: Token![;], }
Parsing
These tokens can be parsed using the Synom trait and the parser
combinator macros punct!, keyword!, parens!, braces!, and
brackets!.
#[macro_use] extern crate syn; use syn::synom::Synom; use syn::{Attribute, Visibility, Ident, Type, Expr}; // Parse the ItemStatic struct shown above. impl Synom for ItemStatic { named!(parse -> Self, do_parse!( attrs: many0!(Attribute::parse_outer) >> vis: syn!(Visibility) >> static_token: keyword!(static) >> mutability: option!(keyword!(mut)) >> ident: syn!(Ident) >> colon_token: punct!(:) >> ty: syn!(Type) >> eq_token: punct!(=) >> expr: syn!(Expr) >> semi_token: punct!(;) >> (ItemStatic { attrs, vis, static_token, mutability, ident, colon_token, ty: Box::new(ty), eq_token, expr: Box::new(expr), semi_token, }) )); }
Structs
| Add |
|
| AddEq |
|
| And |
|
| AndAnd |
|
| AndEq |
|
| Apostrophe |
|
| As |
|
| Async |
|
| At |
|
| Auto |
|
| Bang |
|
| Box |
|
| Brace |
|
| Bracket |
|
| Break |
|
| CapSelf |
|
| Caret |
|
| CaretEq |
|
| Catch |
|
| Colon |
|
| Colon2 |
|
| Comma |
|
| Const |
|
| Continue |
|
| Crate |
|
| Default |
|
| Div |
|
| DivEq |
|
| Do |
|
| Dollar |
|
| Dot |
|
| Dot2 |
|
| Dot3 |
|
| DotDotEq |
|
| Dyn |
|
| Else |
|
| Enum |
|
| Eq |
|
| EqEq |
|
| Extern |
|
| FatArrow |
|
| Fn |
|
| For |
|
| Ge |
|
| Group |
None-delimited group |
| Gt |
|
| If |
|
| Impl |
|
| In |
|
| LArrow |
|
| Le |
|
| Let |
|
| Loop |
|
| Lt |
|
| Macro |
|
| Match |
|
| Mod |
|
| Move |
|
| MulEq |
|
| Mut |
|
| Ne |
|
| Or |
|
| OrEq |
|
| OrOr |
|
| Paren |
|
| Pound |
|
| Pub |
|
| Question |
|
| RArrow |
|
| Ref |
|
| Rem |
|
| RemEq |
|
| Return |
|
| Self_ |
|
| Semi |
|
| Shl |
|
| ShlEq |
|
| Shr |
|
| ShrEq |
|
| Star |
|
| Static |
|
| Struct |
|
| Sub |
|
| SubEq |
|
| Super |
|
| Trait |
|
| Type |
|
| Underscore |
|
| Union |
|
| Unsafe |
|
| Use |
|
| Where |
|
| While |
|
| Yield |
|