Expand description
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
&=- As
as- At
@- Auto
auto- Bang
!- Box
box- Brace
{...}- Bracket
[...]- Break
break- CapSelf
Self- Caret
^- CaretEq
^=- Catch
catch- Colon
:- Colon2
::- Comma
,- Const
const- Continue
continue- Crate
crate- Default
default- Div
/- DivEq
/=- Do
do- Dot
.- Dot2
..- Dot3
...- DotDot
Eq ..=- Dyn
dyn- Else
else- Enum
enum- Eq
=- EqEq
==- Extern
extern- Fn
fn- For
for- Ge
>=- Group
- None-delimited group
- Gt
>- If
if- Impl
impl- In
in- LArrow
<-- Le
<=- Let
let- Loop
loop- Lt
<- Macro
macro- Match
match- Mod
mod- Move
move- MulEq
*=- Mut
mut- Ne
!=- Or
|- OrEq
|=- OrOr
||- Paren
(...)- Pound
#- Pub
pub- Question
?- RArrow
->- Ref
ref- Rem
%- RemEq
%=- Return
return- Rocket
=>- Self_
self- Semi
;- Shl
<<- ShlEq
<<=- Shr
>>- ShrEq
>>=- Star
*- Static
static- Struct
struct- Sub
-- SubEq
-=- Super
super- Trait
trait- Type
type- Underscore
_- Union
union- Unsafe
unsafe- Use
use- Where
where- While
while- Yield
yield