microcad_lang/parse/
parse_error.rs1use crate::{parse::*, ty::*};
7use thiserror::Error;
8
9#[derive(Debug, Error)]
11pub enum ParseError {
12 #[error("Expected identifier")]
14 ExpectedIdentifier,
15
16 #[error("Error parsing floating point literal: {0}")]
18 ParseFloatError(#[from] std::num::ParseFloatError),
19
20 #[error("Error parsing integer literal: {0}")]
22 ParseIntError(#[from] std::num::ParseIntError),
23
24 #[error("Cannot parse rule: {0:?}")]
26 RuleError(Box<crate::parser::Rule>),
27
28 #[error("IO Error: {0}")]
30 IoError(#[from] std::io::Error),
31
32 #[error("Parser error: {0}")]
34 Parser(#[from] Box<pest::error::Error<crate::parser::Rule>>),
35
36 #[error("Error parsing color: {0}")]
38 ParseColorError(#[from] microcad_core::ParseColorError),
39
40 #[error("Unknown color: {0}")]
42 UnknownColorName(String),
43
44 #[error("Unknown unit: {0}")]
46 UnknownUnit(String),
47
48 #[error("Unexpected token")]
50 UnexpectedToken,
51
52 #[error("Tuple expression contains both named and positional arguments")]
54 MixedTupleArguments,
55
56 #[error("Duplicate named argument: {0}")]
58 DuplicateNamedArgument(Identifier),
59
60 #[error("Positional argument after named argument")]
62 PositionalArgumentAfterNamed,
63
64 #[error("Empty tuple expression")]
66 EmptyTupleExpression,
67
68 #[error("Missing type or value for definition parameter: {0}")]
70 ParameterMissingTypeOrValue(Identifier),
71
72 #[error("Duplicate parameter: {0}")]
74 DuplicateParameter(Identifier),
75
76 #[error("Duplicate argument: {0}")]
78 DuplicateArgument(Identifier),
79
80 #[error("Invalid map key type: {0}")]
82 InvalidMapKeyType(String),
83
84 #[error("Duplicated type name in map: {0}")]
86 DuplicatedMapType(Identifier),
87
88 #[error("Duplicate identifier: {0}")]
90 DuplicateIdentifier(Identifier),
91
92 #[error("Duplicate identifier in tuple: {0}")]
94 DuplicateTupleIdentifier(Identifier),
95
96 #[error("Duplicate unnamed type in tuple: {0}")]
98 DuplicateTupleType(Type),
99
100 #[error("Missing format expression")]
102 MissingFormatExpression,
103
104 #[error("Statement between two init statements")]
106 StatementBetweenInit,
107
108 #[error("Loading of source file {0:?} failed")]
110 LoadSource(std::path::PathBuf),
111
112 #[error("Grammar rule error {0}")]
114 GrammarRuleError(String),
115
116 #[error("Invalid qualified name '{0}'")]
118 InvalidQualifiedName(String),
119
120 #[error("Invalid identifier '{0}'")]
122 InvalidIdentifier(String),
123
124 #[error("Qualified name {0} cannot be converted into an Id")]
126 QualifiedNameIsNoId(QualifiedName),
127
128 #[error("Statement not allowed within workbenches ({0})")]
130 IllegalWorkbenchStatement(SrcRef),
131
132 #[error("Code between initializers is not allowed ({0})")]
134 CodeBetweenInitializers(SrcRef),
135
136 #[error("Statement not allowed prior initializers ({0})")]
138 StatementNotAllowedPriorInitializers(SrcRef),
139
140 #[error("Element is not available")]
142 NotAvailable,
143
144 #[error("Unknown type: {0}")]
146 UnknownType(String),
147}
148
149pub type ParseResult<T> = Result<T, ParseError>;