1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use thiserror::Error;

// =============================================================================
// Parse
// =============================================================================

// Traits

pub trait Parse<'t>
where
    Self: Sized,
{
    fn parse(raw: &'t str, global: usize) -> (usize, Self);
}

#[allow(clippy::module_name_repetitions)]
pub trait TryParse<'t>
where
    Self: Sized,
{
    fn try_parse(raw: &'t str, base: usize) -> Result<(usize, Self), ParseError>;
}

// -----------------------------------------------------------------------------

// Errors

#[allow(clippy::module_name_repetitions)]
#[derive(Debug, Error)]
pub enum ParseError {
    #[error("{message} at position: {position}. expected: {expected}.")]
    UnexpectedInput {
        position: usize,
        message: String,
        expected: String,
    },
}