grammers_tl_parser/errors.rs
1// Copyright 2020 - developers of the `grammers` project.
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
6// option. This file may not be copied, modified, or distributed
7// except according to those terms.
8
9//! Errors that can occur during the parsing of [Type Language] definitions.
10//!
11//! [Type Language]: https://core.telegram.org/mtproto/TL
12
13use std::num::ParseIntError;
14
15/// The error type for the parsing operation of [`Definition`]s.
16///
17/// [`Definition`]: crate::Definition
18#[derive(Debug, PartialEq)]
19pub enum ParseError {
20 /// The definition is empty.
21 Empty,
22
23 /// The identifier from this definition is invalid.
24 InvalidId(ParseIntError),
25
26 /// One of the parameters from this definition was invalid.
27 InvalidParam(ParamParseError),
28
29 /// The name information is missing from the definition.
30 MissingName,
31
32 /// The type information is missing from the definition.
33 MissingType,
34
35 /// The parser does not know how to parse the definition.
36 NotImplemented,
37
38 /// The file contained an unknown separator (such as `---foo---`)
39 UnknownSeparator,
40}
41
42/// The error type for the parsing operation of [`Parameter`]s.
43///
44/// [`Parameter`]: crate::tl::Parameter
45#[derive(Debug, PartialEq)]
46pub enum ParamParseError {
47 /// The parameter was empty.
48 Empty,
49
50 /// The flag specification was invalid.
51 InvalidFlag,
52
53 /// The generic argument was invalid.
54 InvalidGeneric,
55
56 /// The parameter is actually a generic type definition for later
57 /// use, such as `{X:Type}`, but it is not a parameter in itself.
58 TypeDef { name: String },
59
60 /// The parameter refers to some unknown definition.
61 MissingDef,
62
63 /// The parser does not know how to parse the parameter.
64 NotImplemented,
65}