From 61c04bb61655c8ed27a8617d6a551f6ab6b01b88 Mon Sep 17 00:00:00 2001 From: Ryan Chandler Date: Tue, 13 Sep 2022 11:41:02 +0100 Subject: [PATCH 1/2] fix: support empty array items --- trunk_parser/src/ast.rs | 1 + trunk_parser/src/parser/mod.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/trunk_parser/src/ast.rs b/trunk_parser/src/ast.rs index 7d0b67b..bcb6b9a 100644 --- a/trunk_parser/src/ast.rs +++ b/trunk_parser/src/ast.rs @@ -388,6 +388,7 @@ pub struct Use { #[derive(Debug, PartialEq, Clone)] pub enum Expression { Static, + Empty, ErrorSuppress { expr: Box, }, diff --git a/trunk_parser/src/parser/mod.rs b/trunk_parser/src/parser/mod.rs index 9fcbe0e..67b77a8 100644 --- a/trunk_parser/src/parser/mod.rs +++ b/trunk_parser/src/parser/mod.rs @@ -1505,6 +1505,12 @@ impl Parser { self.skip_comments(); while self.current.kind != TokenKind::RightBracket { + if self.current.kind == TokenKind::Comma { + items.push(ArrayItem { key: None, value: Expression::Empty }); + self.next(); + continue; + } + let mut key = None; let mut value = self.expression(0)?; @@ -3421,6 +3427,30 @@ mod tests { ); } + #[test] + fn array_empty_items() { + assert_ast(" Date: Tue, 13 Sep 2022 11:41:53 +0100 Subject: [PATCH 2/2] chore: format --- trunk_parser/src/parser/mod.rs | 48 +++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/trunk_parser/src/parser/mod.rs b/trunk_parser/src/parser/mod.rs index 67b77a8..f6de6bd 100644 --- a/trunk_parser/src/parser/mod.rs +++ b/trunk_parser/src/parser/mod.rs @@ -1506,7 +1506,10 @@ impl Parser { while self.current.kind != TokenKind::RightBracket { if self.current.kind == TokenKind::Comma { - items.push(ArrayItem { key: None, value: Expression::Empty }); + items.push(ArrayItem { + key: None, + value: Expression::Empty, + }); self.next(); continue; } @@ -3429,26 +3432,29 @@ mod tests { #[test] fn array_empty_items() { - assert_ast("