luau_lexer/
error.rs

1//! The [`ParseError`] struct.
2
3use smol_str::SmolStr;
4
5use crate::position::Position;
6
7/// An error that can be met during parsing.
8#[derive(Clone, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
9#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
10pub struct ParseError {
11    /// The starting location of the error.
12    start: Position,
13
14    /// The error message.
15    message: SmolStr,
16
17    /// The ending location of the error.
18    end: Option<Position>,
19}
20
21impl ParseError {
22    /// Create a new [`ParseError`].
23    #[inline]
24    pub fn new(start: Position, message: impl Into<SmolStr>, end: Option<Position>) -> Self {
25        Self {
26            start,
27            message: message.into(),
28            end,
29        }
30    }
31
32    /// Get the start of the error.
33    #[inline]
34    pub fn start(&self) -> Position {
35        self.start
36    }
37
38    /// Get the error message.
39    #[inline]
40    pub fn message(&self) -> &str {
41        &self.message
42    }
43
44    /// Get the end of the error.
45    #[inline]
46    pub fn end(&self) -> Option<Position> {
47        self.end
48    }
49}