use super::types::{ParseError, ParseErrorKind, Position, Span};
#[derive(Debug)]
pub(crate) struct ErrorBuilder {
kind: ParseErrorKind,
span: Option<Span>,
context: Option<String>,
suggestion: Option<String>,
}
impl ErrorBuilder {
pub fn new(kind: ParseErrorKind) -> Self {
Self {
kind,
span: None,
context: None,
suggestion: None,
}
}
pub fn at_span(mut self, span: Span) -> Self {
self.span = Some(span);
self
}
pub fn at_position(mut self, position: Position) -> Self {
self.span = Some(Span::at(position));
self
}
pub fn with_context<S: Into<String>>(mut self, context: S) -> Self {
self.context = Some(context.into());
self
}
pub fn with_suggestion<S: Into<String>>(mut self, suggestion: S) -> Self {
self.suggestion = Some(suggestion.into());
self
}
pub fn build(self) -> ParseError {
ParseError {
kind: self.kind,
span: self.span,
context: self.context,
suggestion: self.suggestion,
}
}
}