b2285ce0e0
Just's first parser performed both parsing, i.e the transformation of a token stream according to the language grammar, and a number of consistency checks and analysis passes. This made parsing and analysis quite complex, so this diff introduces a new, much cleaner `Parser`, and moves existing analysis into a dedicated `Analyzer`.
24 lines
507 B
Rust
24 lines
507 B
Rust
use crate::common::*;
|
|
|
|
pub(crate) trait CompilationResultExt {
|
|
fn expected(self, kinds: &[TokenKind]) -> Self;
|
|
}
|
|
|
|
impl<'src, T> CompilationResultExt for CompilationResult<'src, T> {
|
|
fn expected(mut self, kinds: &[TokenKind]) -> Self {
|
|
if let Err(CompilationError {
|
|
kind: CompilationErrorKind::UnexpectedToken {
|
|
ref mut expected, ..
|
|
},
|
|
..
|
|
}) = &mut self
|
|
{
|
|
expected.extend_from_slice(kinds);
|
|
expected.sort();
|
|
expected.dedup();
|
|
}
|
|
|
|
self
|
|
}
|
|
}
|