From 146eda102a5d0241c96a808a847f3b855340765e Mon Sep 17 00:00:00 2001 From: Laurenz Date: Thu, 11 Feb 2021 19:26:47 +0100 Subject: =?UTF-8?q?Move=20span=20directly=20into=20diagnostics=20?= =?UTF-8?q?=F0=9F=9A=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/parse/mod.rs | 2 +- src/parse/parser.rs | 27 ++++++++------------------- 2 files changed, 9 insertions(+), 20 deletions(-) (limited to 'src/parse') diff --git a/src/parse/mod.rs b/src/parse/mod.rs index e7e25a1d..8780efaf 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -22,7 +22,7 @@ use collection::{args, parenthesized}; /// Parse a string of source code. pub fn parse(src: &str) -> Pass { let mut p = Parser::new(src); - Pass::new(tree(&mut p), p.finish()) + Pass::new(tree(&mut p), p.diags) } /// Parse a syntax tree. diff --git a/src/parse/parser.rs b/src/parse/parser.rs index a64e39dd..7c660182 100644 --- a/src/parse/parser.rs +++ b/src/parse/parser.rs @@ -1,12 +1,13 @@ use std::fmt::{self, Debug, Formatter}; use super::{Scanner, TokenMode, Tokens}; -use crate::diag::Diag; -use crate::diag::{Deco, Feedback}; -use crate::syntax::{Pos, Span, Spanned, Token}; +use crate::diag::{Diag, DiagSet}; +use crate::syntax::{Pos, Span, Token}; /// A convenient token-based parser. pub struct Parser<'s> { + /// Parsing diagnostics. + pub diags: DiagSet, /// An iterator over the source tokens. tokens: Tokens<'s>, /// The next token. @@ -20,8 +21,6 @@ pub struct Parser<'s> { last_end: Pos, /// The stack of open groups. groups: Vec, - /// Accumulated feedback. - feedback: Feedback, } /// A logical group of tokens, e.g. `[...]`. @@ -67,18 +66,13 @@ impl<'s> Parser<'s> { next_start: Pos::ZERO, last_end: Pos::ZERO, groups: vec![], - feedback: Feedback::new(), + diags: DiagSet::new(), } } - /// Finish parsing and return the accumulated feedback. - pub fn finish(self) -> Feedback { - self.feedback - } - - /// Add a diagnostic to the feedback. - pub fn diag(&mut self, diag: Spanned) { - self.feedback.diags.push(diag); + /// Add a diagnostic. + pub fn diag(&mut self, diag: Diag) { + self.diags.insert(diag); } /// Eat the next token and add a diagnostic that it is not the expected @@ -112,11 +106,6 @@ impl<'s> Parser<'s> { } } - /// Add a decoration to the feedback. - pub fn deco(&mut self, deco: Spanned) { - self.feedback.decos.push(deco); - } - /// Continue parsing in a group. /// /// When the end delimiter of the group is reached, all subsequent calls to -- cgit v1.2.3