lisette_syntax/parse/
error.rs1use crate::ast::Span;
2
3#[derive(Debug, Clone)]
4pub struct ParseError {
5 pub message: String,
6 pub labels: Vec<(Span, String)>,
7 pub help: Option<String>,
8 pub code: String,
9}
10
11impl ParseError {
12 pub(crate) fn new(message: impl Into<String>, span: Span, label: impl Into<String>) -> Self {
13 Self {
14 message: message.into(),
15 labels: vec![(span, label.into())],
16 help: None,
17 code: String::new(),
18 }
19 }
20
21 pub(crate) fn with_span_label(mut self, span: Span, label: impl Into<String>) -> Self {
22 self.labels.push((span, label.into()));
23 self
24 }
25
26 pub(crate) fn with_help(mut self, help: impl Into<String>) -> Self {
27 self.help = Some(help.into());
28 self
29 }
30
31 pub(crate) fn with_lex_code(mut self, code: &str) -> Self {
32 self.code = format!("lex.{}", code);
33 self
34 }
35
36 pub(crate) fn with_parse_code(mut self, code: &str) -> Self {
37 self.code = format!("parse.{}", code);
38 self
39 }
40}