fn stmt(&mut self) -> Result<StmtLine> {
        if let Some(tok) = self.lexer.next() {
            let line = self.lexer.line();
            let stmt = match tok? {
                Token::Semi => Stmt::Empty,
                tok @ Token::Keyword(Keyword::Const) | tok @ Token::Keyword(Keyword::Int) => {
                    self.lexer.put_back(tok);
                    self.stmt_after_type()?
                }
                Token::Ident(ident) => {
                    if let Some(tok) = self.lexer.next() {
                        match tok? {
                            Token::Assign => {
                                let expr = self.expr()?;
                                self.expect(Token::Semi)?;
                                Stmt::Assign(ident, expr)
                            }
                            Token::AddAssign => {
                                let expr = self.expr()?;
                                self.expect(Token::Semi)?;
                                Stmt::CompoundAssign(ident, BinOp::Add, expr)
                            }
                            Token::SubAssign => {
                                let expr = self.expr()?;
                                self.expect(Token::Semi)?;
                                Stmt::CompoundAssign(ident, BinOp::Sub, expr)
                            }
                            tok => {
                                self.lexer.put_back(tok);
                                self.expect(Token::Semi)?;
                                Stmt::Expr(self.expr()?)
                            }
                        }
                    } else {
                        return Err(eparse!(self, "expected expression or assignment"));
                    }
                }
                Token::LBrace => {
                    let block = self.block()?;
                    self.expect(Token::RBrace)?;
                    Stmt::Block(block)
                }
                tok => {
                    self.lexer.put_back(tok);
                    let res = Stmt::Expr(self.expr()?);
                    self.expect(Token::Semi)?;
                    res
                }
            };
            Ok(stmt.with_line(line))
        } else {
            Err(eparse!(self, "unexpected end of program"))
        }
    }
/// Parses a statement.
///
/// The semicolon at the end of the line will be parsed as a part of this node (or a helper function, like `stmt_after_type`), if relevant.
Parses a statement.
The semicolon at the end of the line will be parsed as a part of this node (or a helper function, like `stmt_after_type`), if relevant.
Parses a statement . The semicolon at the end of the line will be parsed as a part of this node ( or a helper function like ` stmt_after_type ` ) if relevant .
fn stmt(&mut self) -> Result<StmtLine> {
        if let Some(tok) = self.lexer.next() {
            let line = self.lexer.line();
            let stmt = match tok? {
                Token::Semi => Stmt::Empty,
                tok @ Token::Keyword(Keyword::Const) | tok @ Token::Keyword(Keyword::Int) => {
                    self.lexer.put_back(tok);
                    self.stmt_after_type()?
                }
                Token::Ident(ident) => {
                    if let Some(tok) = self.lexer.next() {
                        match tok? {
                            Token::Assign => {
                                let expr = self.expr()?;
                                self.expect(Token::Semi)?;
                                Stmt::Assign(ident, expr)
                            }
                            Token::AddAssign => {
                                let expr = self.expr()?;
                                self.expect(Token::Semi)?;
                                Stmt::CompoundAssign(ident, BinOp::Add, expr)
                            }
                            Token::SubAssign => {
                                let expr = self.expr()?;
                                self.expect(Token::Semi)?;
                                Stmt::CompoundAssign(ident, BinOp::Sub, expr)
                            }
                            tok => {
                                self.lexer.put_back(tok);
                                self.expect(Token::Semi)?;
                                Stmt::Expr(self.expr()?)
                            }
                        }
                    } else {
                        return Err(eparse!(self, "expected expression or assignment"));
                    }
                }
                Token::LBrace => {
                    let block = self.block()?;
                    self.expect(Token::RBrace)?;
                    Stmt::Block(block)
                }
                tok => {
                    self.lexer.put_back(tok);
                    let res = Stmt::Expr(self.expr()?);
                    self.expect(Token::Semi)?;
                    res
                }
            };
            Ok(stmt.with_line(line))
        } else {
            Err(eparse!(self, "unexpected end of program"))
        }
    }
fn stmt ( & mut self ) -> Result < StmtLine > { if let Some ( tok ) = self . lexer . next ( ) { let line = self . lexer . line ( ) ; let stmt = match tok ? { Token :: Semi => Stmt :: Empty , tok @ Token :: Keyword ( Keyword :: Const ) | tok @ Token :: Keyword ( Keyword :: Int ) => { self . lexer . put_back ( tok ) ; self . stmt_after_type ( ) ? } Token :: Ident ( ident ) => { if let Some ( tok ) = self . lexer . next ( ) { match tok ? { Token :: Assign => { let expr = self . expr ( ) ? ; self . expect ( Token :: Semi ) ? ; Stmt :: Assign ( ident , expr ) } Token :: AddAssign => { let expr = self . expr ( ) ? ; self . expect ( Token :: Semi ) ? ; Stmt :: CompoundAssign ( ident , BinOp :: Add , expr ) } Token :: SubAssign => { let expr = self . expr ( ) ? ; self . expect ( Token :: Semi ) ? ; Stmt :: CompoundAssign ( ident , BinOp :: Sub , expr ) } tok => { self . lexer . put_back ( tok ) ; self . expect ( Token :: Semi ) ? ; Stmt :: Expr ( self . expr ( ) ? ) } } } else { return Err ( eparse ! ( self " " ) ) ; } } Token :: LBrace => { let block = self . block ( ) ? ; self . expect ( Token :: RBrace ) ? ; Stmt :: Block ( block ) } tok => { self . lexer . put_back ( tok ) ; let res = Stmt :: Expr ( self . expr ( ) ? ) ; self . expect ( Token :: Semi ) ? ; res } } ; Ok ( stmt . with_line ( line ) ) } else { Err ( eparse ! ( self " " ) ) } }
Parses a statement.
Parses a statement .
&mut self
&mut self