svlog: add last span tracking to parser
Add a `last_span` field to the parser that keeps track of the position
the last token that was bumped had in the file. This will allow for some
more clean parsing code when we start caring about the location of AST
nodes.
@@ -31,6 +31,7 @@ struct Parser<'a> {
input: Lexer<'a>,
queue: VecDeque<TokenAndSpan>,
diagnostics: Vec<DiagBuilder2>,
+ last_span: Span,
}
impl<'a> Parser<'a> {
@@ -39,6 +40,7 @@ impl<'a> Parser<'a> {
input: input,
queue: VecDeque::new(),
diagnostics: Vec::new(),
+ last_span: INVALID_SPAN,
}
}
@@ -68,7 +70,13 @@ impl<'a> Parser<'a> {
if self.queue.is_empty() {
self.ensure_queue_filled(1);
}
- self.queue.pop_front();
+ if let Some((_,sp)) = self.queue.pop_front() {
+ self.last_span = sp;
+ }
+ }
+
+ fn last_span(&self) -> Span {
+ self.last_span
}
fn add_diag(&mut self, diag: DiagBuilder2) {
