luau_lexer/
error.rs

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