clojure_reader/
error.rs

1use core::error;
2use core::fmt::{self, Debug};
3
4pub type Result<T> = core::result::Result<T, Error>;
5
6pub struct Error {
7  /// Error code. This is `non_exhaustive`.
8  pub code: Code,
9  /// Line number, counting from 1.
10  pub line: Option<usize>,
11  /// Column number, counting from 1. The count is utf-8 chars.
12  pub column: Option<usize>,
13  /// This is a pointer offset of the str trying to be parsed, not a utf-8 char offset
14  pub ptr: Option<usize>,
15}
16
17#[derive(Debug, Eq, PartialEq)]
18#[non_exhaustive]
19pub enum Code {
20  /// Parse errors
21  HashMapDuplicateKey,
22  SetDuplicateKey,
23  InvalidChar,
24  InvalidEscape,
25  InvalidKeyword,
26  InvalidNumber,
27  InvalidRadix(Option<u8>),
28  UnexpectedEOF,
29  UnmatchedDelimiter(char),
30
31  /// Feature errors
32  NoFloatFeature,
33
34  /// Serde
35  #[cfg(feature = "serde")]
36  Serde(alloc::string::String),
37}
38
39impl error::Error for Error {}
40
41impl Debug for Error {
42  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43    write!(
44      f,
45      "EdnError {{ code: {:?}, line: {:?}, column: {:?}, ptr: {:?} }}",
46      self.code, self.line, self.column, self.ptr
47    )
48  }
49}
50
51impl alloc::fmt::Display for Error {
52  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
53    write!(f, "{self:?}")
54  }
55}