Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Block Expressions

This section is a work-in-progress experiment about making the book executable.

Syntax
BlockExpression: {
        inner_attrs=InnerAttribute*
        statements=Statement*
        tail=ExpressionWithoutBlock?
    }
    => BlockExpression { label: None, inner_attrs, statements, tail: tail.map(Box::new) }
BlockExpressionNoInnerAttributes: {
        statements=Statement*
        tail=ExpressionWithoutBlock?
    }
    => BlockExpression { label: None, inner_attrs: vec![], statements, tail: tail.map(Box::new) }
LabelBlockExpression: label=BlockLabel? block=BlockExpression
    => block.with_label(label)
BlockLabel: label=LIFETIME : => label

pub struct BlockExpression {
    pub label: Option<String>,
    pub inner_attrs: Vec<InnerAttribute>,
    pub statements: Vec<Statement>,
    pub tail: Option<Box<Expression>>,
}

impl BlockExpression {
    pub fn with_label(mut self, label: Option<String>) -> Self {
        self.label = label;
        self
    }
}

impl From<BlockExpression> for Expression {
    fn from(block: BlockExpression) -> Self {
        Expression::new(ExpressionKind::Block(block))
    }
}