diff options
Diffstat (limited to 'src/parse')
| -rw-r--r-- | src/parse/mod.rs | 2 | ||||
| -rw-r--r-- | src/parse/parser.rs | 27 |
2 files changed, 9 insertions, 20 deletions
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<Tree> { 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<GroupEntry>, - /// 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<Diag>) { - 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<Deco>) { - self.feedback.decos.push(deco); - } - /// Continue parsing in a group. /// /// When the end delimiter of the group is reached, all subsequent calls to |
