From 9c7445d90450f0dbd7114f1e0fa38d74522b48e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Mon, 2 Jan 2023 18:56:26 +0100 Subject: [PATCH] AST - Added function to extract all block statements --- src/ast.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/ast.rs b/src/ast.rs index a410f82..39b0cd9 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -45,6 +45,17 @@ pub enum StmtNode { }, } +impl StmtNode { + /// Extract the list of statements from a block. Panic if the statement + /// is not a block. + pub fn extract_block_statements(self) -> Vec { + match self { + Self::Block(stmts) => stmts, + _ => panic!("Statement is not a block"), + } + } +} + /// An AST node that represents an expression. #[derive(Debug, Clone)] pub enum ExprNode {