mlang_rs/lang/parser/
error.rs

1/// Error returns by `parser` mod
2#[derive(Debug, thiserror::Error, PartialEq, PartialOrd, Clone)]
3pub enum ParseError {
4    #[error("")]
5    End,
6
7    #[error("Invalid ident.")]
8    Ident,
9
10    #[error("semantic analyze error.")]
11    Semantic,
12
13    #[error(transparent)]
14    Parserc(#[from] parserc::Kind),
15
16    #[error("io error: {0}")]
17    Io(String),
18
19    #[error("Expect stat.")]
20    Unparsed,
21    #[error("Syntax error of literal number, {0}")]
22    Uint(UnitKind),
23    #[error("Syntax error of property, {0}")]
24    Prop(PropKind),
25
26    #[error("Syntax error of call exp, {0}")]
27    Call(CallKind),
28
29    #[error("Syntax error of type declaration, {0}")]
30    Type(TypeKind),
31
32    #[error("Syntax error of enum, {0}")]
33    Enum(EnumKind),
34
35    #[error("Syntax error of fields, {0}")]
36    Fields(FieldsKind),
37
38    #[error("Syntax error of name field, {0}")]
39    NamedField(NamedFieldKind),
40
41    #[error("Syntax error of unamed field, expect field type declaration.")]
42    UnnamedField,
43
44    #[error("Syntax error of node, {0}")]
45    Node(NodeKind),
46
47    #[error("Syntax error of group, {0}")]
48    Group(GroupKind),
49
50    #[error("Syntax error of tuple, {0}")]
51    Tuple(TupleKind),
52
53    #[error("Syntax error of apply ... to ..., {0}")]
54    ApplyTo(ApplyToKind),
55
56    #[error("Syntax error of children ... of ..., {0}")]
57    ChildrenOf(ChildrenOfKind),
58}
59
60impl parserc::ParseError for ParseError {}
61
62/// Error kind of parsing tuple `(ident,...)` stat.
63#[derive(Debug, thiserror::Error, PartialEq, PartialOrd, Clone)]
64pub enum TupleKind {
65    #[error("expect `(`.")]
66    BodyStart,
67    #[error("expect `)`.")]
68    BodyEnd,
69}
70
71/// Error kind of parsing children .. of ... stat.
72#[derive(Debug, thiserror::Error, PartialEq, PartialOrd, Clone)]
73pub enum ChildrenOfKind {
74    #[error("expect keyword `of`.")]
75    Of,
76    #[error(
77        "expect an `ident` or a group of idents `(ident,...)` following by `children` keyword."
78    )]
79    From,
80    #[error("expect an `ident` or a group of idents `(ident,...)` following by `of` keyword.")]
81    To,
82    #[error("expect `;`.")]
83    End,
84}
85
86/// Error kind of parsing apply .. to ... stat.
87#[derive(Debug, thiserror::Error, PartialEq, PartialOrd, Clone)]
88pub enum ApplyToKind {
89    #[error("expect keyword `to`.")]
90    To,
91    #[error("expect an `ident` or a group of idents `(ident,...)` following by `to` keyword.")]
92    Target,
93    #[error("expect `;`.")]
94    End,
95}
96
97/// Error kind of node parsing.
98#[derive(Debug, thiserror::Error, PartialEq, PartialOrd, Clone)]
99pub enum GroupKind {
100    #[error("expect `:=`.")]
101    Assign,
102
103    #[error("expect `;`.")]
104    End,
105}
106
107/// Error kind of node parsing.
108#[derive(Debug, thiserror::Error, PartialEq, PartialOrd, Clone)]
109pub enum NodeKind {
110    #[error("epxect mixin `ident`.")]
111    MixinIdent,
112
113    #[error("epxect fields.")]
114    Fields,
115
116    #[error("expect `;`")]
117    End,
118}
119
120/// Error kind of enum parsing.
121#[derive(Debug, thiserror::Error, PartialEq, PartialOrd, Clone)]
122pub enum NamedFieldKind {
123    #[error("expect value/type split char `:`")]
124    SemiColons,
125
126    #[error("expect field type declaration.")]
127    Type,
128}
129
130/// Error kind of enum parsing.
131#[derive(Debug, thiserror::Error, PartialEq, PartialOrd, Clone)]
132pub enum FieldsKind {
133    #[error("expect end tag `{0}`")]
134    EndTag(char),
135}
136
137/// Error kind of enum parsing.
138#[derive(Debug, thiserror::Error, PartialEq, PartialOrd, Clone)]
139pub enum EnumKind {
140    #[error("invalid enum ident.")]
141    Ident,
142
143    #[error("expect `{{`")]
144    BodyStart,
145
146    #[error("expect `}}`")]
147    BodyEnd,
148}
149
150/// Error kind of unit parsing.
151#[derive(Debug, thiserror::Error, PartialEq, PartialOrd, Clone)]
152pub enum TypeKind {
153    #[error("unrecognized array length.")]
154    Uint,
155
156    #[error("miss `;` for array declaration.")]
157    Semicolons,
158
159    #[error("miss array/list start tag `[`")]
160    SquareBracketStart,
161
162    #[error("miss array/list end tag `]`")]
163    SquareBracketEnd,
164
165    #[error("miss data name.")]
166    Data,
167}
168
169/// Error kind of unit parsing.
170#[derive(Debug, thiserror::Error, PartialEq, PartialOrd, Clone)]
171pub enum CallKind {
172    #[error("expect call expr parameter list end tag `)`")]
173    ParamEnd,
174}
175
176/// Error kind of unit parsing.
177#[derive(Debug, thiserror::Error, PartialEq, PartialOrd, Clone)]
178pub enum PropKind {
179    #[error("expect property end tag `]`")]
180    MissEnd,
181}
182
183/// Error kind of unit parsing.
184#[derive(Debug, thiserror::Error, PartialEq, PartialOrd, Clone)]
185pub enum UnitKind {
186    #[error("miss hexadecimal prefix: 0x..")]
187    Prefix,
188    #[error("miss hexadecimal body.")]
189    MissBody,
190}