blob: c3c90ea5eb32f094ddd8116ea616b94c0c7d5a04 [file] [log] [blame]
use super::*;
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Expr {
/// A `box x` expression.
Box(Box<Expr>),
/// An array (`[a, b, c, d]`)
Vec(Vec<Expr>),
/// A function call
///
/// The first field resolves to the function itself,
/// and the second field is the list of arguments
Call(Box<Expr>, Vec<Expr>),
/// A method call (`x.foo::<Bar, Baz>(a, b, c, d)`)
///
/// The `Ident` is the identifier for the method name.
/// The vector of `Ty`s are the ascripted type parameters for the method
/// (within the angle brackets).
///
/// The first element of the vector of `Expr`s is the expression that evaluates
/// to the object on which the method is being called on (the receiver),
/// and the remaining elements are the rest of the arguments.
///
/// Thus, `x.foo::<Bar, Baz>(a, b, c, d)` is represented as
/// `ExprKind::MethodCall(foo, [Bar, Baz], [x, a, b, c, d])`.
MethodCall(Ident, Vec<Ty>, Vec<Expr>),
/// A tuple (`(a, b, c, d)`)
Tup(Vec<Expr>),
/// A binary operation (For example: `a + b`, `a * b`)
Binary(BinOp, Box<Expr>, Box<Expr>),
/// A unary operation (For example: `!x`, `*x`)
Unary(UnOp, Box<Expr>),
/// A literal (For example: `1`, `"foo"`)
Lit(Lit),
/// A cast (`foo as f64`)
Cast(Box<Expr>, Box<Ty>),
/// Type ascription (`foo: f64`)
Type(Box<Expr>, Box<Ty>),
/// An `if` block, with an optional else block
///
/// `if expr { block } else { expr }`
If(Box<Expr>, Box<Block>, Option<Box<Expr>>),
/// An `if let` expression with an optional else block
///
/// `if let pat = expr { block } else { expr }`
///
/// This is desugared to a `match` expression.
IfLet(Box<Pat>, Box<Expr>, Box<Block>, Option<Box<Expr>>),
/// A while loop, with an optional label
///
/// `'label: while expr { block }`
While(Box<Expr>, Box<Block>, Option<Ident>),
/// A while-let loop, with an optional label
///
/// `'label: while let pat = expr { block }`
///
/// This is desugared to a combination of `loop` and `match` expressions.
WhileLet(Box<Pat>, Box<Expr>, Box<Block>, Option<Ident>),
/// A for loop, with an optional label
///
/// `'label: for pat in expr { block }`
///
/// This is desugared to a combination of `loop` and `match` expressions.
ForLoop(Box<Pat>, Box<Expr>, Box<Block>, Option<Ident>),
/// Conditionless loop (can be exited with break, continue, or return)
///
/// `'label: loop { block }`
Loop(Box<Block>, Option<Ident>),
/// A `match` block.
Match(Box<Expr>, Vec<Arm>),
/// A closure (for example, `move |a, b, c| {a + b + c}`)
Closure(CaptureBy, Box<FnDecl>, Box<Block>),
/// A block (`{ ... }`)
Block(Box<Block>),
/// An assignment (`a = foo()`)
Assign(Box<Expr>, Box<Expr>),
/// An assignment with an operator
///
/// For example, `a += 1`.
AssignOp(BinOp, Box<Expr>, Box<Expr>),
/// Access of a named struct field (`obj.foo`)
Field(Box<Expr>, Ident),
/// Access of an unnamed field of a struct or tuple-struct
///
/// For example, `foo.0`.
TupField(Box<Expr>, usize),
/// An indexing operation (`foo[2]`)
Index(Box<Expr>, Box<Expr>),
/// A range (`1..2`, `1..`, `..2`, `1...2`, `1...`, `...2`)
Range(Option<Box<Expr>>, Option<Box<Expr>>, RangeLimits),
/// Variable reference, possibly containing `::` and/or type
/// parameters, e.g. foo::bar::<baz>.
///
/// Optionally "qualified",
/// E.g. `<Vec<T> as SomeTrait>::SomeType`.
Path(Option<QSelf>, Path),
/// A referencing operation (`&a` or `&mut a`)
AddrOf(Mutability, Box<Expr>),
/// A `break`, with an optional label to break
Break(Option<Ident>),
/// A `continue`, with an optional label
Continue(Option<Ident>),
/// A `return`, with an optional value to be returned
Ret(Option<Box<Expr>>),
/// A macro invocation; pre-expansion
Mac(Mac),
/// A struct literal expression.
///
/// For example, `Foo {x: 1, y: 2}`, or
/// `Foo {x: 1, .. base}`, where `base` is the `Option<Expr>`.
Struct(Path, Vec<Field>, Option<Box<Expr>>),
/// An array literal constructed from one repeated element.
///
/// For example, `[1; 5]`. The first expression is the element
/// to be repeated; the second is the number of times to repeat it.
Repeat(Box<Expr>, Box<Expr>),
/// No-op: used solely so we can pretty-print faithfully
Paren(Box<Expr>),
/// `expr?`
Try(Box<Expr>),
}
/// A Block (`{ .. }`).
///
/// E.g. `{ .. }` as in `fn foo() { .. }`
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Block {
/// Statements in a block
pub stmts: Vec<Stmt>,
/// Distinguishes between `unsafe { ... }` and `{ ... }`
pub rules: BlockCheckMode,
}
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum BlockCheckMode {
Default,
Unsafe,
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Stmt {
/// A local (let) binding.
Local(Box<Local>),
/// An item definition.
Item(Box<Item>),
/// Expr without trailing semi-colon.
Expr(Box<Expr>),
Semi(Box<Expr>),
Mac(Box<(Mac, MacStmtStyle, Vec<Attribute>)>),
}
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum MacStmtStyle {
/// The macro statement had a trailing semicolon, e.g. `foo! { ... };`
/// `foo!(...);`, `foo![...];`
Semicolon,
/// The macro statement had braces; e.g. foo! { ... }
Braces,
/// The macro statement had parentheses or brackets and no semicolon; e.g.
/// `foo!(...)`. All of these will end up being converted into macro
/// expressions.
NoBraces,
}
/// Local represents a `let` statement, e.g., `let <pat>:<ty> = <expr>;`
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Local {
pub pat: Box<Pat>,
pub ty: Option<Box<Ty>>,
/// Initializer expression to set the value, if any
pub init: Option<Box<Expr>>,
pub attrs: Vec<Attribute>,
}
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum BinOp {
/// The `+` operator (addition)
Add,
/// The `-` operator (subtraction)
Sub,
/// The `*` operator (multiplication)
Mul,
/// The `/` operator (division)
Div,
/// The `%` operator (modulus)
Rem,
/// The `&&` operator (logical and)
And,
/// The `||` operator (logical or)
Or,
/// The `^` operator (bitwise xor)
BitXor,
/// The `&` operator (bitwise and)
BitAnd,
/// The `|` operator (bitwise or)
BitOr,
/// The `<<` operator (shift left)
Shl,
/// The `>>` operator (shift right)
Shr,
/// The `==` operator (equality)
Eq,
/// The `<` operator (less than)
Lt,
/// The `<=` operator (less than or equal to)
Le,
/// The `!=` operator (not equal to)
Ne,
/// The `>=` operator (greater than or equal to)
Ge,
/// The `>` operator (greater than)
Gt,
}
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum UnOp {
/// The `*` operator for dereferencing
Deref,
/// The `!` operator for logical inversion
Not,
/// The `-` operator for negation
Neg,
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Pat {
/// Represents a wildcard pattern (`_`)
Wild,
/// A `Pat::Ident` may either be a new bound variable (`ref mut binding @ OPT_SUBPATTERN`),
/// or a unit struct/variant pattern, or a const pattern (in the last two cases the third
/// field must be `None`). Disambiguation cannot be done with parser alone, so it happens
/// during name resolution.
Ident(BindingMode, Ident, Option<Box<Pat>>),
/// A struct or struct variant pattern, e.g. `Variant {x, y, ..}`.
/// The `bool` is `true` in the presence of a `..`.
Struct(Path, Vec<FieldPat>, bool),
/// A tuple struct/variant pattern `Variant(x, y, .., z)`.
/// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.
/// 0 <= position <= subpats.len()
TupleStruct(Path, Vec<Pat>, Option<usize>),
/// A possibly qualified path pattern.
/// Unquailfied path patterns `A::B::C` can legally refer to variants, structs, constants
/// or associated constants. Quailfied path patterns `<A>::B::C`/`<A as Trait>::B::C` can
/// only legally refer to associated constants.
Path(Option<QSelf>, Path),
/// A tuple pattern `(a, b)`.
/// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.
/// 0 <= position <= subpats.len()
Tuple(Vec<Pat>, Option<usize>),
/// A `box` pattern
Box(Box<Pat>),
/// A reference pattern, e.g. `&mut (a, b)`
Ref(Box<Pat>, Mutability),
/// A literal
Lit(Box<Expr>),
/// A range pattern, e.g. `1...2`
Range(Box<Expr>, Box<Expr>),
/// `[a, b, ..i, y, z]` is represented as:
/// `Pat::Vec(box [a, b], Some(i), box [y, z])`
Vec(Vec<Pat>, Option<Box<Pat>>, Vec<Pat>),
/// A macro pattern; pre-expansion
Mac(Mac),
}
/// An arm of a 'match'.
///
/// E.g. `0...10 => { println!("match!") }` as in
///
/// ```rust,ignore
/// match n {
/// 0...10 => { println!("match!") },
/// // ..
/// }
/// ```
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Arm {
pub attrs: Vec<Attribute>,
pub pats: Vec<Pat>,
pub guard: Option<Box<Expr>>,
pub body: Box<Expr>,
}
/// A capture clause
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum CaptureBy {
Value,
Ref,
}
/// Limit types of a range (inclusive or exclusive)
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum RangeLimits {
/// Inclusive at the beginning, exclusive at the end
HalfOpen,
/// Inclusive at the beginning and end
Closed,
}
/// A single field in a struct pattern
///
/// Patterns like the fields of Foo `{ x, ref y, ref mut z }`
/// are treated the same as `x: x, y: ref y, z: ref mut z`,
/// except `is_shorthand` is true
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct FieldPat {
/// The identifier for the field
pub ident: Ident,
/// The pattern the field is destructured to
pub pat: Box<Pat>,
pub is_shorthand: bool,
}
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum BindingMode {
ByRef(Mutability),
ByValue(Mutability),
}
#[cfg(feature = "parsing")]
pub mod parsing {
use super::*;
use {Ident, Lifetime, Ty};
use attr::parsing::outer_attr;
use generics::parsing::lifetime;
use ident::parsing::ident;
use lit::parsing::lit;
use ty::parsing::{mutability, ty};
named!(pub expr -> Expr, do_parse!(
mut e: alt!(
expr_box
|
expr_vec
|
expr_tup
|
expr_unary
|
expr_lit
|
expr_if
// TODO: IfLet
|
expr_while
// TODO: WhileLet
// TODO: ForLoop
// TODO: Loop
// TODO: ForLoop
|
expr_loop
|
expr_match
// TODO: Closure
|
expr_block
// TODO: Path
// TODO: AddrOf
|
expr_break
|
expr_continue
|
expr_ret
// TODO: Mac
// TODO: Struct
// TODO: Repeat
// TODO: Pparen
) >>
many0!(alt!(
tap!(args: and_call => {
e = Expr::Call(Box::new(e), args);
})
|
tap!(more: and_method_call => {
let (method, ascript, mut args) = more;
args.insert(0, e);
e = Expr::MethodCall(method, ascript, args);
})
|
tap!(more: and_binary => {
let (op, other) = more;
e = Expr::Binary(op, Box::new(e), Box::new(other));
})
|
tap!(ty: and_cast => {
e = Expr::Cast(Box::new(e), Box::new(ty));
})
|
tap!(ty: and_ascription => {
e = Expr::Type(Box::new(e), Box::new(ty));
})
// TODO: Assign
// TODO: AssignOp
// TODO: Field
// TODO: TupField
// TODO: Index
// TODO: Range
// TODO: Try
)) >>
(e)
));
named!(expr_box -> Expr, do_parse!(
keyword!("box") >>
inner: expr >>
(Expr::Box(Box::new(inner)))
));
named!(expr_vec -> Expr, do_parse!(
punct!("[") >>
elems: separated_list!(punct!(","), expr) >>
punct!("]") >>
(Expr::Vec(elems))
));
named!(and_call -> Vec<Expr>, do_parse!(
punct!("(") >>
args: separated_list!(punct!(","), expr) >>
punct!(")") >>
(args)
));
named!(and_method_call -> (Ident, Vec<Ty>, Vec<Expr>), do_parse!(
punct!(".") >>
method: ident >>
ascript: opt_vec!(delimited!(
punct!("<"),
separated_list!(punct!(","), ty),
punct!(">")
)) >>
punct!("(") >>
args: separated_list!(punct!(","), expr) >>
punct!(")") >>
(method, ascript, args)
));
named!(expr_tup -> Expr, do_parse!(
punct!("(") >>
elems: separated_list!(punct!(","), expr) >>
punct!(")") >>
(Expr::Tup(elems))
));
named!(and_binary -> (BinOp, Expr), tuple!(
alt!(
punct!("&&") => { |_| BinOp::And }
|
punct!("||") => { |_| BinOp::Or }
|
punct!("<<") => { |_| BinOp::Shl }
|
punct!(">>") => { |_| BinOp::Shr }
|
punct!("==") => { |_| BinOp::Eq }
|
punct!("<=") => { |_| BinOp::Le }
|
punct!("!=") => { |_| BinOp::Ne }
|
punct!(">=") => { |_| BinOp::Ge }
|
punct!("+") => { |_| BinOp::Add }
|
punct!("-") => { |_| BinOp::Sub }
|
punct!("*") => { |_| BinOp::Mul }
|
punct!("/") => { |_| BinOp::Div }
|
punct!("%") => { |_| BinOp::Rem }
|
punct!("^") => { |_| BinOp::BitXor }
|
punct!("&") => { |_| BinOp::BitAnd }
|
punct!("|") => { |_| BinOp::BitOr }
|
punct!("<") => { |_| BinOp::Lt }
|
punct!(">") => { |_| BinOp::Gt }
),
expr
));
named!(expr_unary -> Expr, do_parse!(
operator: alt!(
punct!("*") => { |_| UnOp::Deref }
|
punct!("!") => { |_| UnOp::Not }
|
punct!("-") => { |_| UnOp::Neg }
) >>
operand: expr >>
(Expr::Unary(operator, Box::new(operand)))
));
named!(expr_lit -> Expr, map!(lit, Expr::Lit));
named!(and_cast -> Ty, do_parse!(
keyword!("as") >>
ty: ty >>
(ty)
));
named!(and_ascription -> Ty, preceded!(punct!(":"), ty));
named!(expr_if -> Expr, do_parse!(
keyword!("if") >>
cond: expr >>
punct!("{") >>
then_block: within_block >>
punct!("}") >>
else_block: option!(preceded!(
keyword!("else"),
alt!(
expr_if
|
do_parse!(
punct!("{") >>
else_block: within_block >>
punct!("}") >>
(Expr::Block(Box::new(Block {
stmts: else_block,
rules: BlockCheckMode::Default,
})))
)
)
)) >>
(Expr::If(
Box::new(cond),
Box::new(Block {
stmts: then_block,
rules: BlockCheckMode::Default,
}),
else_block.map(Box::new),
))
));
named!(expr_loop -> Expr, do_parse!(
lbl: option!(terminated!(label, punct!(":"))) >>
keyword!("loop") >>
loop_block: block >>
(Expr::Loop(
Box::new(loop_block),
lbl,
))
));
named!(expr_match -> Expr, do_parse!(
keyword!("match") >>
obj: expr >>
punct!("{") >>
arms: many0!(do_parse!(
attrs: many0!(outer_attr) >>
pats: separated_nonempty_list!(punct!("|"), pat) >>
guard: option!(preceded!(keyword!("if"), expr)) >>
punct!("=>") >>
body: alt!(
terminated!(expr, punct!(","))
|
map!(block, |blk| Expr::Block(Box::new(blk)))
) >>
(Arm {
attrs: attrs,
pats: pats,
guard: guard.map(Box::new),
body: Box::new(body),
})
)) >>
punct!("}") >>
(Expr::Match(Box::new(obj), arms))
));
named!(expr_while -> Expr, do_parse!(
lbl: option!(terminated!(label, punct!(":"))) >>
keyword!("while") >>
cond: expr >>
while_block: block >>
(Expr::While(
Box::new(cond),
Box::new(while_block),
lbl,
))
));
named!(expr_continue -> Expr, do_parse!(
keyword!("continue") >>
lbl: option!(label) >>
(Expr::Continue(
lbl,
))
));
named!(expr_break -> Expr, do_parse!(
keyword!("break") >>
lbl: option!(label) >>
(Expr::Break(
lbl,
))
));
named!(expr_ret -> Expr, do_parse!(
keyword!("return") >>
ret_value: option!(expr) >>
(Expr::Ret(
ret_value.map(Box::new),
))
));
named!(expr_block -> Expr, do_parse!(
rules: block_check_mode >>
b: block >>
(Expr::Block(Box::new(Block {
stmts: b.stmts,
rules: rules,
})))
));
named!(pub block -> Block, do_parse!(
punct!("{") >>
stmts: within_block >>
punct!("}") >>
(Block {
stmts: stmts,
rules: BlockCheckMode::Default,
})
));
named!(block_check_mode -> BlockCheckMode, alt!(
keyword!("unsafe") => { |_| BlockCheckMode::Unsafe }
|
epsilon!() => { |_| BlockCheckMode::Default }
));
named!(within_block -> Vec<Stmt>, do_parse!(
mut most: many0!(standalone_stmt) >>
last: option!(expr) >>
(match last {
None => most,
Some(last) => {
most.push(Stmt::Expr(Box::new(last)));
most
}
})
));
named!(standalone_stmt -> Stmt, alt!(
// TODO: local
// TODO: item
// TODO: expr
stmt_semi
// TODO: mac
));
named!(stmt_semi -> Stmt, do_parse!(
e: expr >>
punct!(";") >>
(Stmt::Semi(Box::new(e)))
));
named!(pub pat -> Pat, alt!(
pat_wild
|
pat_ident
// TODO: Struct
// TODO: TupleStruct
// TODO: Path
// TODO: Tuple
// TODO: Box
// TODO: Ref
// TODO: Lit
// TODO: Range
// TODO: Vec
// TODO: Mac
));
named!(pat_wild -> Pat, map!(keyword!("_"), |_| Pat::Wild));
named!(pat_ident -> Pat, do_parse!(
mode: option!(keyword!("ref")) >>
mutability: mutability >>
name: ident >>
subpat: option!(preceded!(punct!("@"), pat)) >>
(Pat::Ident(
if mode.is_some() {
BindingMode::ByRef(mutability)
} else {
BindingMode::ByValue(mutability)
},
name,
subpat.map(Box::new),
))
));
named!(label -> Ident, map!(lifetime, |lt: Lifetime| lt.ident));
}
#[cfg(feature = "printing")]
mod printing {
use super::*;
use Mutability;
use quote::{Tokens, ToTokens};
impl ToTokens for Expr {
fn to_tokens(&self, tokens: &mut Tokens) {
match *self {
Expr::Box(ref _inner) => unimplemented!(),
Expr::Vec(ref _inner) => unimplemented!(),
Expr::Call(ref _func, ref _args) => unimplemented!(),
Expr::MethodCall(ref _ident, ref _ascript, ref _args) => unimplemented!(),
Expr::Tup(ref fields) => {
tokens.append("(");
tokens.append_separated(fields, ",");
if fields.len() == 1 {
tokens.append(",");
}
tokens.append(")");
}
Expr::Binary(_op, ref _left, ref _right) => unimplemented!(),
Expr::Unary(_op, ref _expr) => unimplemented!(),
Expr::Lit(ref lit) => lit.to_tokens(tokens),
Expr::Cast(ref _expr, ref _ty) => unimplemented!(),
Expr::Type(ref _expr, ref _ty) => unimplemented!(),
Expr::If(ref _cond, ref _then_block, ref _else_block) => unimplemented!(),
Expr::IfLet(ref _pat, ref _expr, ref _then_block, ref _else_block) => unimplemented!(),
Expr::While(ref _cond, ref _body, ref _label) => unimplemented!(),
Expr::WhileLet(ref _pat, ref _expr, ref _body, ref _label) => unimplemented!(),
Expr::ForLoop(ref _pat, ref _expr, ref _body, ref _label) => unimplemented!(),
Expr::Loop(ref _body, ref _label) => unimplemented!(),
Expr::Match(ref expr, ref arms) => {
tokens.append("match");
expr.to_tokens(tokens);
tokens.append("{");
tokens.append_separated(arms, ",");
tokens.append("}");
}
Expr::Closure(_capture, ref _decl, ref _body) => unimplemented!(),
Expr::Block(ref _block) => unimplemented!(),
Expr::Assign(ref _var, ref _expr) => unimplemented!(),
Expr::AssignOp(_op, ref _var, ref _expr) => unimplemented!(),
Expr::Field(ref _expr, ref _field) => unimplemented!(),
Expr::TupField(ref _expr, _field) => unimplemented!(),
Expr::Index(ref _expr, ref _index) => unimplemented!(),
Expr::Range(ref _from, ref _to, _limits) => unimplemented!(),
Expr::Path(ref _qself, ref _path) => unimplemented!(),
Expr::AddrOf(_mutability, ref _expr) => unimplemented!(),
Expr::Break(ref _label) => unimplemented!(),
Expr::Continue(ref _label) => unimplemented!(),
Expr::Ret(ref opt_expr) => {
tokens.append("return");
opt_expr.to_tokens(tokens);
}
Expr::Mac(ref _mac) => unimplemented!(),
Expr::Struct(ref _path, ref _fields, ref _base) => unimplemented!(),
Expr::Repeat(ref _expr, ref _times) => unimplemented!(),
Expr::Paren(ref _inner) => unimplemented!(),
Expr::Try(ref _expr) => unimplemented!(),
}
}
}
impl ToTokens for Arm {
fn to_tokens(&self, tokens: &mut Tokens) {
for attr in &self.attrs {
attr.to_tokens(tokens);
}
tokens.append_separated(&self.pats, "|");
if let Some(ref guard) = self.guard {
tokens.append("if");
guard.to_tokens(tokens);
}
tokens.append("=>");
self.body.to_tokens(tokens);
match *self.body {
Expr::Block(_) => { /* no comma */ }
_ => tokens.append(","),
}
}
}
impl ToTokens for Pat {
fn to_tokens(&self, tokens: &mut Tokens) {
match *self {
Pat::Wild => tokens.append("_"),
Pat::Ident(mode, ref ident, ref subpat) => {
mode.to_tokens(tokens);
ident.to_tokens(tokens);
if let Some(ref subpat) = *subpat {
tokens.append("@");
subpat.to_tokens(tokens);
}
}
Pat::Struct(ref _path, ref _fields, _dots) => unimplemented!(),
Pat::TupleStruct(ref _path, ref _pats, _dotpos) => unimplemented!(),
Pat::Path(ref _qself, ref _path) => unimplemented!(),
Pat::Tuple(ref _pats, _dotpos) => unimplemented!(),
Pat::Box(ref _inner) => unimplemented!(),
Pat::Ref(ref _target, _mutability) => unimplemented!(),
Pat::Lit(ref _expr) => unimplemented!(),
Pat::Range(ref _lower, ref _upper) => unimplemented!(),
Pat::Vec(ref _before, ref _dots, ref _after) => unimplemented!(),
Pat::Mac(ref _mac) => unimplemented!(),
}
}
}
impl ToTokens for BindingMode {
fn to_tokens(&self, tokens: &mut Tokens) {
match *self {
BindingMode::ByRef(Mutability::Immutable) => {
tokens.append("ref");
}
BindingMode::ByRef(Mutability::Mutable) => {
tokens.append("ref");
tokens.append("mut");
}
BindingMode::ByValue(Mutability::Immutable) => {}
BindingMode::ByValue(Mutability::Mutable) => {
tokens.append("mut");
}
}
}
}
impl ToTokens for Block {
fn to_tokens(&self, tokens: &mut Tokens) {
self.rules.to_tokens(tokens);
tokens.append("{");
for stmt in &self.stmts {
stmt.to_tokens(tokens);
}
tokens.append("}");
}
}
impl ToTokens for BlockCheckMode {
fn to_tokens(&self, tokens: &mut Tokens) {
match *self {
BlockCheckMode::Default => { /* nothing */ },
BlockCheckMode::Unsafe => tokens.append("unsafe"),
}
}
}
impl ToTokens for Stmt {
fn to_tokens(&self, tokens: &mut Tokens) {
match *self {
Stmt::Local(ref _local) => unimplemented!(),
Stmt::Item(ref item) => item.to_tokens(tokens),
Stmt::Expr(ref expr) => expr.to_tokens(tokens),
Stmt::Semi(ref expr) => {
expr.to_tokens(tokens);
tokens.append(";");
}
Stmt::Mac(ref _mac) => unimplemented!(),
}
}
}
}