jingo_lib/error.rs
1//! Various enums and implementations of errors for downstream use
2//!
3//! Most error enums include an `Unknown` field, this is used for when there was
4//! a fatal unknown error whilst doing something in the jurastiction of that error
5//! enum, for example if there was an unknown error lexing then a
6//! [ScanningError::Unknown] would show
7//!
8//! ## Error Hierarchy
9//!
10//! Here is a chart of what errors are also an instance of other errors (e.g.
11//! the x error enum is inside of y error enum as `X(x)`):
12//!
13//! ```none
14//! JingoError
15//! ScanningError
16//! ParsingError
17//! ```
18
19/// Main error enum for all of jingo-lib, containing mostly module-level error
20/// enums
21///
22/// The goal of this enum is to provide a single overall representation for all
23/// errors in this compiler to make much easier downstream compatibility whilst
24/// still having seperate logical groups (like lexing with [ScanningError]) seperated
25#[derive(Debug, Clone, PartialEq, PartialOrd)]
26pub enum JingoError {
27 /// Downstream error when scanning, see [ScanningError] for more infomation.
28 ScanningError(ScanningError),
29
30 /// Downstream error when parsing, see [ParsingError] for more infomation.
31 ParsingError(ParsingError),
32
33 /// A part of the compiler is unfinished that the user tried to access with
34 /// some extra info in the form of an optional [String] appended onto the end
35 /// in brackets.
36 ///
37 /// **This shouldn't ever happen in public releases without docs saying it
38 /// will happen!**
39 Unimplemented(Option<String>),
40
41 /// See [crate::error] documentation for more on this.
42 Unknown,
43}
44
45/// Errors for the [crate::frontend::lexer] module.
46#[derive(Debug, Clone, PartialEq, PartialOrd)]
47pub enum ScanningError {
48 /// When a string was started but jingo reached the end of the file without
49 /// it being closed.
50 ///
51 /// # Examples
52 ///
53 /// ```jingo
54 /// fn awesome(input) {
55 /// return input * 2;
56 /// }
57 ///
58 /// var x = "following string never closes
59 ///
60 /// fn broken_func(fix_string) {
61 /// print fix_string;
62 /// }
63 /// ```
64 UnterminatedString(usize),
65
66 /// A number was given that was not valid, possibly looking like `0-2-30`.
67 InvalidNumber(usize),
68
69 /// A float was given that was not valid, possibly looking like `0...3221.`.
70 InvalidFloat(usize),
71
72 /// An unknown token was given, user error (`usize` is line num, `char` is
73 /// bad token).
74 UnknownToken(usize, char),
75
76 /// Unknown escape sequence (e.g. `\9` isn't an escape sequence like `\n`).
77 UnknownEscape(usize, char),
78
79 /// See [crate::error] documentation for more on this.
80 Unknown,
81}
82
83/// Errors regarding the parsing flow inside of [crate::frontend::parser] (also
84/// linked to [crate::frontend::ast]).
85#[derive(Debug, Clone, PartialEq, PartialOrd)]
86pub enum ParsingError {
87 /// See [crate::error] documentation for more on this.
88 Unknown,
89}