From cfd15122ab86cd74a975bfc00168dcab3b55cf94 Mon Sep 17 00:00:00 2001 From: Charlotte Meyer Date: Mon, 7 Nov 2022 13:41:28 +0000 Subject: [PATCH] fix(parser): make ; be part of the statement Signed-off-by: Charlotte Meyer --- crates/oyster_parser/src/parser.rs | 3 ++- crates/oyster_parser/tests/it/ast.rs | 14 +++++++++++++ crates/oyster_parser/tests/it/cst.rs | 26 +++++++++++++++++++++---- crates/oyster_parser/tests/it/parser.rs | 17 +++++++++++++++- 4 files changed, 54 insertions(+), 6 deletions(-) diff --git a/crates/oyster_parser/src/parser.rs b/crates/oyster_parser/src/parser.rs index 50e6a5a..1abeaef 100644 --- a/crates/oyster_parser/src/parser.rs +++ b/crates/oyster_parser/src/parser.rs @@ -179,7 +179,8 @@ impl Iterator for Parser<'_> { Comment => leaf!(Comment), Pipe => chain!(leaf!(Pipe), call!(PipelineCont)), PlainText | DoubleQuote | OpeningParenthesis | EscapedChar => call!(Command), - Newlines | Semicolon | ClosingParenthesis | Eof => ret!(), + Semicolon => chain_buf!(leaf!(Semicolon), ret!()), + Newlines | ClosingParenthesis | Eof => ret!(), }, NodeKind::PipelineCont => match self.lookahead.kind { Whitespace => leaf!(Whitespace), diff --git a/crates/oyster_parser/tests/it/ast.rs b/crates/oyster_parser/tests/it/ast.rs index 8095558..7d2b4fb 100644 --- a/crates/oyster_parser/tests/it/ast.rs +++ b/crates/oyster_parser/tests/it/ast.rs @@ -685,3 +685,17 @@ fn quoted_command_substitution() { "#]], ); } + +#[test] +fn empty_pipeline() { + check( + ";", + expect![[r#" + Ok( + Code( + [], + ), + ) + "#]], + ); +} diff --git a/crates/oyster_parser/tests/it/cst.rs b/crates/oyster_parser/tests/it/cst.rs index 359d2b4..ddd0993 100644 --- a/crates/oyster_parser/tests/it/cst.rs +++ b/crates/oyster_parser/tests/it/cst.rs @@ -197,12 +197,12 @@ fn semicolon() { }, ], }, + Leaf { + kind: Semicolon, + len: 1, + }, ], }, - Leaf { - kind: Semicolon, - len: 1, - }, Leaf { kind: Whitespace, len: 1, @@ -1085,3 +1085,21 @@ fn quoted_command_substitution() { "#]], ); } + +#[test] +fn empty_pipeline() { + check( + ";", + expect![[r#" + Tree { + kind: Program, + children: [ + Leaf { + kind: Semicolon, + len: 1, + }, + ], + } + "#]], + ); +} diff --git a/crates/oyster_parser/tests/it/parser.rs b/crates/oyster_parser/tests/it/parser.rs index 1b28e10..7ca39b0 100644 --- a/crates/oyster_parser/tests/it/parser.rs +++ b/crates/oyster_parser/tests/it/parser.rs @@ -165,11 +165,11 @@ fn semicolon() { ), EndNode, EndNode, - EndNode, NewLeaf( Semicolon, 1, ), + EndNode, NewLeaf( Whitespace, 1, @@ -935,3 +935,18 @@ fn quoted_command_substitution() { "#]], ); } + +#[test] +fn empty_pipeline() { + check( + ";", + expect![[r#" + [ + NewLeaf( + Semicolon, + 1, + ), + ] + "#]], + ); +}