somni_parser/
lib.rs

1pub mod ast;
2pub mod lexer;
3pub mod parser;
4
5#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
6pub struct Location {
7    pub start: usize,
8    pub end: usize,
9}
10
11impl Location {
12    pub const fn dummy() -> Self {
13        Location { start: 0, end: 0 }
14    }
15}
16
17impl Location {
18    pub fn extract(self, source: &str) -> &str {
19        &source[self.start..self.end]
20    }
21}
22
23#[derive(Debug, Clone, PartialEq)]
24pub struct Error {
25    pub location: Location,
26    pub error: Box<str>,
27}
28
29impl std::fmt::Display for Error {
30    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31        f.write_str(&self.error)
32    }
33}