arrow_parser/
error.rs

1use super::source::SourceRange;
2use super::token::TokenType;
3
4#[derive(Copy, Clone, Eq, PartialEq, Debug)]
5pub enum SyntaxErrorType {
6  BindingToNonImpl,
7  ExpectedNotFound,
8  ExpectedSyntax(&'static str),
9  InvalidAssigmentTarget,
10  LoopCannotResult,
11  MalformedLiteral,
12  RedeclaredVar,
13  RequiredTokenNotFound(TokenType),
14  UnexpectedEnd,
15}
16
17#[derive(Clone, Debug)]
18pub struct SyntaxError {
19  pub source: SourceRange,
20  pub typ: SyntaxErrorType,
21  pub actual_token: Option<TokenType>,
22}
23
24impl SyntaxError {
25  pub fn new(
26    typ: SyntaxErrorType,
27    source: SourceRange,
28    actual_token: Option<TokenType>,
29  ) -> SyntaxError {
30    SyntaxError {
31      typ,
32      source,
33      actual_token,
34    }
35  }
36
37  pub fn from_loc(
38    loc: SourceRange,
39    typ: SyntaxErrorType,
40    actual_token: Option<TokenType>,
41  ) -> SyntaxError {
42    SyntaxError {
43      source: loc,
44      typ,
45      actual_token,
46    }
47  }
48}
49
50pub type SyntaxResult<T> = Result<T, SyntaxError>;