fix(parser): make ; be part of the statement

Signed-off-by: Charlotte Meyer <dev@buffet.sh>
This commit is contained in:
buffet 2022-11-07 13:41:28 +00:00
parent a990418704
commit cfd15122ab
4 changed files with 54 additions and 6 deletions

View file

@ -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),

View file

@ -685,3 +685,17 @@ fn quoted_command_substitution() {
"#]],
);
}
#[test]
fn empty_pipeline() {
check(
";",
expect![[r#"
Ok(
Code(
[],
),
)
"#]],
);
}

View file

@ -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,
},
],
}
"#]],
);
}

View file

@ -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,
),
]
"#]],
);
}