refactor(parser): small improvements

Acked-by: ElKowar
Signed-off-by: Charlotte Meyer <dev@buffet.sh>
This commit is contained in:
buffet 2022-11-06 22:41:06 +00:00
parent f215335627
commit c6a972c76b

View file

@ -144,15 +144,13 @@ impl Iterator for Parser<'_> {
};
}
use TokenKind::*;
if let Some(ev) = self.buffer.take() {
return Some(ev);
}
match self.stack.last() {
None => None,
Some(nt) => match nt {
use TokenKind::*;
match self.stack.last()? {
// XXX: unify Program and CommandSubstitution to avoid duplication
NodeKind::Program => match self.lookahead.kind {
Whitespace => leaf!(Whitespace),
@ -211,8 +209,9 @@ impl Iterator for Parser<'_> {
OpeningParenthesis => {
chain_buf!(call!(CommandSubstitution), leaf!(OpeningParenthesis))
}
Comment | Whitespace | Newlines | Semicolon | Pipe | ClosingParenthesis
| Eof => ret!(),
Comment | Whitespace | Newlines | Semicolon | Pipe | ClosingParenthesis | Eof => {
ret!()
}
},
NodeKind::DQuotedString => match self.lookahead.kind {
PlainText => leaf!(PlainText, String),
@ -227,7 +226,6 @@ impl Iterator for Parser<'_> {
_ => unreachable!(),
},
_ => unreachable!(),
},
}
}
}