amarok_syntax/diagnostic.rs
1use crate::Span;
2
3/// A message attached to a (optional) source span.
4///
5/// Shared by parser and interpreter error types so that error rendering
6/// (line/column lookup, caret pointing) can be implemented once.
7#[derive(Debug, Clone)]
8pub struct Diagnostic {
9 pub message: String,
10 pub span: Option<Span>,
11}
12
13impl Diagnostic {
14 pub fn new(message: impl Into<String>) -> Self {
15 Self {
16 message: message.into(),
17 span: None,
18 }
19 }
20
21 #[must_use]
22 pub fn with_span(mut self, span: Span) -> Self {
23 self.span = Some(span);
24 self
25 }
26}