|
| 1 | +//! Errors that may occur while lexing. |
| 2 | +// I Language lexer errors. |
| 3 | +// Version: 1.0.0 |
| 4 | + |
| 5 | +// Copyright (c) 2023-present I Language Development. |
| 6 | + |
| 7 | +// Permission is hereby granted, free of charge, to any person obtaining a |
| 8 | +// copy of this software and associated documentation files (the 'Software'), |
| 9 | +// to deal in the Software without restriction, including without limitation |
| 10 | +// the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 | +// and/or sell copies of the Software, and to permit persons to whom the |
| 12 | +// Software is furnished to do so, subject to the following conditions: |
| 13 | + |
| 14 | +// The above copyright notice and this permission notice shall be included in |
| 15 | +// all copies or substantial portions of the Software. |
| 16 | + |
| 17 | +// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 18 | +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 22 | +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 23 | +// DEALINGS IN THE SOFTWARE. |
| 24 | + |
| 25 | +///////////// |
| 26 | +// IMPORTS // |
| 27 | +///////////// |
| 28 | + |
| 29 | +use crate::tokens::token::Location; |
| 30 | + |
| 31 | +use thiserror::Error; |
| 32 | + |
| 33 | + |
| 34 | +//////////// |
| 35 | +// ERRORS // |
| 36 | +//////////// |
| 37 | + |
| 38 | +/// The different kinds of errors the lexer can raise. |
| 39 | +/// All of these errors implement [`std::error::Error`]. |
| 40 | +#[allow(clippy::module_name_repetitions)] |
| 41 | +#[derive(Clone, Debug, Eq, Error, Hash, Ord, PartialEq, PartialOrd)] |
| 42 | +pub enum LexerError { |
| 43 | + /// An error which will be returned if a mark was invalid for some reason. |
| 44 | + /// This can occur when the starting character of a mark is valid, but the character after it is not. |
| 45 | + #[error("invalid mark at {location}")] |
| 46 | + InvalidMark { location: Location }, |
| 47 | + |
| 48 | + /// An error which will be returned if an unexpected character is encountered. |
| 49 | + /// this is most likely to occur when using unicode characters as they are not supported. |
| 50 | + #[error("unexpected character `{character}` at {location}")] |
| 51 | + UnexpectedCharacter { character: char, location: Location }, |
| 52 | + |
| 53 | + /// An error which will be returned if a comment is not terminated by a closing `*/`. |
| 54 | + #[error("unterminated comment at {location}")] |
| 55 | + UnterminatedComment { location: Location }, |
| 56 | + |
| 57 | + /// An error which will be returned if a string is not terminated by a closing quote or the quote is escaped. |
| 58 | + #[error("unterminated string at {location}")] |
| 59 | + UnterminatedString { location: Location }, |
| 60 | +} |
0 commit comments