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