From 681c201c3c6156e723abcf6735b0ec278d6381f9 Mon Sep 17 00:00:00 2001 From: Evan Shaw Date: Sun, 11 Sep 2022 21:01:31 +1200 Subject: [PATCH] Add support for block statements --- trunk_parser/src/ast.rs | 3 +++ trunk_parser/src/parser/mod.rs | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/trunk_parser/src/ast.rs b/trunk_parser/src/ast.rs index cdb8b13..82ce978 100644 --- a/trunk_parser/src/ast.rs +++ b/trunk_parser/src/ast.rs @@ -271,6 +271,9 @@ pub enum Statement { name: Identifier, value: Option, }, + Block { + body: Block, + }, Noop, } diff --git a/trunk_parser/src/parser/mod.rs b/trunk_parser/src/parser/mod.rs index 9712862..aac2b80 100644 --- a/trunk_parser/src/parser/mod.rs +++ b/trunk_parser/src/parser/mod.rs @@ -893,6 +893,12 @@ impl Parser { finally, } } + TokenKind::LeftBrace => { + self.next(); + let body = self.block(&TokenKind::RightBrace)?; + self.rbrace()?; + Statement::Block { body } + } _ => { let expr = self.expression(0)?; @@ -2957,6 +2963,19 @@ mod tests { ); } + #[test] + fn block() { + assert_ast("