This commit is contained in:
nora 2022-07-08 22:33:32 +02:00
parent f229dd7fdc
commit 92292c756c
8 changed files with 60 additions and 2 deletions

View file

@ -12,6 +12,8 @@ mod pre;
mod pretty;
mod token;
pub use parser::Parser;
pub type Spanned<T> = (T, Span);
#[derive(PartialEq, Eq, Clone, Copy, Default)]

View file

@ -45,7 +45,7 @@ impl DebugPls for ParserError {
type Result<T, E = ParserError> = std::result::Result<T, E>;
struct Parser<'src, I>
pub struct Parser<'src, I>
where
I: Iterator<Item = (Tok<'src>, Span)>,
{
@ -549,6 +549,22 @@ where
}
}
impl<'src, I> Iterator for Parser<'src, I>
where
I: Iterator<Item = (Tok<'src>, Span)>,
{
type Item = Result<Spanned<ExternalDecl>>;
fn next(&mut self) -> Option<Self::Item> {
if self.peek_t().is_ok() {
let decl = self.external_declaration();
Some(decl)
} else {
None
}
}
}
pub fn parse_declarations<'src>(
src: impl Iterator<Item = (Tok<'src>, Span)>,
) -> Result<Vec<Spanned<ExternalDecl>>> {