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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use thiserror::Error;

/// Error type for *Phonet*
#[derive(Error, Debug)]
pub enum Error {
    #[error("Error while parsing: {0}, at line {1}")]
    Parse(ParseError, usize),

    #[error("Missing 'any' class. Use `$_ = ___` to define it")]
    MissingAnyClass,
}

#[derive(Error, Debug)]
pub enum ParseError {
    #[error("Mode already defined")]
    ModeAlreadyDefined,

    #[error("Invalid mode specifier, at line")]
    InvalidModeSpecifier,

    #[error("No class name given, at line")]
    NoClassName,

    #[error("Invalid class name '{0}'")]
    InvalidClassName(String),

    #[error("Class already exists named '{0}'")]
    ClassAlreadyExists(String),

    #[error("No pattern was given for class named '{0}'")]
    NoClassPattern(String),

    #[error("Missing or invalid test intent identifier")]
    InvalidTestIntent,

    #[error("Note cannot be empty")]
    EmptyNote,

    #[error("Unknown statement operator '{0}'")]
    UnknownStatementOperator(char),

    #[error("Unexpected class name opening bracket in regex pattern")]
    UnexpectedClassNameOpen,

    #[error("Unexpected class name closing bracket in regex pattern")]
    UnexpectedClassNameClose,

    #[error("Class not found named '{0}'")]
    ClassNotFound(String),

    #[error("Unexpected end of regex pattern for class name")]
    UnexpectedPatternEnd,

    #[error("Failed to parse rule pattern as regex - {0}")]
    RegexParseFail(fancy_regex::Error),
}