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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// This file is part of ICU4X. For terms of use, please see the file
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

//! An error enum for representing `ixdtf` parsing errors.

use displaydoc::Display;

#[non_exhaustive]
#[derive(PartialEq, Display, Clone, Copy, Debug)]
/// The error returned by `ixdtf`'s parsers.
pub enum ParseError {
    #[displaydoc("Implementation error: this error must not throw.")]
    ImplAssert,
    #[displaydoc("Invalid float while parsing fraction part.")]
    ParseFloat,
    #[displaydoc("Parsing ended abruptly while parsing {location}")]
    AbruptEnd { location: &'static str },
    #[displaydoc("Unexpected character found after parsing was completed.")]
    InvalidEnd,

    // Date related errors
    #[displaydoc("Parsed month value not in a valid range.")]
    InvalidMonthRange,
    #[displaydoc("Parsed day value not in a valid range.")]
    InvalidDayRange,
    #[displaydoc("Invalid chracter while parsing year value.")]
    DateYear,
    #[displaydoc("Invalid character while parsing extended year value.")]
    DateExtendedYear,
    #[displaydoc("Invalid caracter while parsing month value.")]
    DateMonth,
    #[displaydoc("Invalid character while parsing day value.")]
    DateDay,
    #[displaydoc("Unexpected end while parsing a date value.")]
    DateUnexpectedEnd,

    // Time Related errors
    #[displaydoc("Time is required.")]
    TimeRequired,
    #[displaydoc("Invalid character while parsing hour value.")]
    TimeHour,
    #[displaydoc("Invalid character while parsing minute value.")]
    TimeMinute,
    #[displaydoc("Invalid character while parsing second value.")]
    TimeSecond,
    #[displaydoc("Invalid character while parsing fraction part value.")]
    FractionPart,
    #[displaydoc("Invalid character while parsing date separator.")]
    DateSeparator,
    #[displaydoc("Invalid character while parsing time separator.")]
    TimeSeparator,
    #[displaydoc("Invalid character while parsing decimal separator.")]
    DecimalSeparator,

    // Annotation Related Errors
    #[displaydoc("Invalid annotation.")]
    InvalidAnnotation,
    #[displaydoc("Invalid annotation open character.")]
    AnnotationOpen,
    #[displaydoc("Invalid annotation close character.")]
    AnnotationClose,
    #[displaydoc("Invalid annotation character.")]
    AnnotationChar,
    #[displaydoc("Invalid annotation key-value separator character.")]
    AnnotationKeyValueSeparator,
    #[displaydoc("Invalid annotation key leading character.")]
    AnnotationKeyLeadingChar,
    #[displaydoc("Invalid annotation key character.")]
    AnnotationKeyChar,
    #[displaydoc("Expected annotation value character must exist after hyphen.")]
    AnnotationValueCharPostHyphen,
    #[displaydoc("Invalid annotation value character.")]
    AnnotationValueChar,

    // Duplicate calendar with critical.
    #[displaydoc("Duplicate calendars cannot be provided when one is critical.")]
    CriticalDuplicateCalendar,
    #[displaydoc("Unrecognized annoation is marked as critical.")]
    UnrecognizedCritical,

    // Time Zone Errors
    #[displaydoc("Invalid time zone leading character.")]
    TzLeadingChar,
    #[displaydoc("Expected time zone character after '/'.")]
    IanaCharPostSeparator,
    #[displaydoc("Invalid IANA time zone character after '/'.")]
    IanaChar,
    #[displaydoc("Invalid time zone character after '/'.")]
    UtcTimeSeparator,

    // MonthDay Errors
    #[displaydoc("MonthDay must begin with a month or '--'")]
    MonthDayHyphen,

    // Duration Errors
    #[displaydoc("Invalid duration designator.")]
    DurationDisgnator,
    #[displaydoc("Provided Duration field value exceeds supported range.")]
    DurationValueExceededRange,
    #[displaydoc("Invalid date duration part order.")]
    DateDurationPartOrder,
    #[displaydoc("Invalid time duration part order.")]
    TimeDurationPartOrder,
    #[displaydoc("Invalid time duration designator.")]
    TimeDurationDesignator,
}

impl ParseError {
    pub(crate) fn abrupt_end(location: &'static str) -> Self {
        ParseError::AbruptEnd { location }
    }
}