forked from FuelLabs/sway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lex_error.rs
73 lines (69 loc) · 2.3 KB
/
lex_error.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use sway_ast::token::Delimiter;
use sway_types::{Ident, Span, Spanned};
use thiserror::Error;
#[derive(Error, Debug, Clone, PartialEq, Eq, PartialOrd, Hash)]
#[error("{}", kind)]
pub struct LexError {
pub span: Span,
pub kind: LexErrorKind,
}
#[derive(Error, Debug, Clone, PartialEq, Eq, PartialOrd, Hash)]
pub enum LexErrorKind {
#[error("unclosed multiline comment")]
UnclosedMultilineComment { unclosed_indices: Vec<usize> },
#[error("unexpected close delimiter")]
UnexpectedCloseDelimiter {
position: usize,
close_delimiter: Delimiter,
},
#[error("mismatched delimiters")]
MismatchedDelimiters {
open_position: usize,
close_position: usize,
open_delimiter: Delimiter,
close_delimiter: Delimiter,
},
#[error("unclosed delimiter")]
UnclosedDelimiter {
open_position: usize,
open_delimiter: Delimiter,
},
#[error("unclosed string literal")]
UnclosedStringLiteral { position: usize },
#[error("unclosed char literal")]
UnclosedCharLiteral { position: usize },
#[error("expected close quote")]
ExpectedCloseQuote { position: usize },
#[error("incomplete hex int literal")]
IncompleteHexIntLiteral { position: usize },
#[error("incomplete binary int literal")]
IncompleteBinaryIntLiteral { position: usize },
#[error("incomplete octal int literal")]
IncompleteOctalIntLiteral { position: usize },
#[error("invalid int suffix: {}", suffix)]
InvalidIntSuffix { suffix: Ident },
#[error("invalid character")]
InvalidCharacter { position: usize, character: char },
#[error("invalid hex escape")]
InvalidHexEscape,
#[error("unicode escape missing brace")]
UnicodeEscapeMissingBrace { position: usize },
#[error("invalid unicode escape digit")]
InvalidUnicodeEscapeDigit { position: usize },
#[error("unicode escape out of range")]
UnicodeEscapeOutOfRange { position: usize },
#[error("unicode escape represents an invalid char value")]
UnicodeEscapeInvalidCharValue { span: Span },
#[error("invalid escape code")]
InvalidEscapeCode { position: usize },
}
impl Spanned for LexError {
fn span(&self) -> Span {
self.span.clone()
}
}
impl LexError {
pub fn span_ref(&self) -> &Span {
&self.span
}
}