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
use std::io;
use std::prelude::v1::Result as Either;

use super::lexical::Token;
use super::position::Position;

/// Errors raised during the tokenization stage
#[derive(Debug)]
pub enum Lexical {
    /// A byte outside the expected range
    UnknownByte(Position, u8),
    /// Operator not (currently) recognised
    UnknownOperator(Position),
    /// Runaway multi-line comment
    UnclosedComment(Position),
    /// Non-printable character inside a quoted string
    NonPrintable(Position, u8),
    /// Invalid escape character inside a quoted string
    BadEscape(Position, u8),
    /// Runaway quoted string
    UnclosedQuote(Position),
    /// End of iterator mid-token
    UnexpectedEnd,
}

/// Errors raised during the parsing stage
#[derive(Debug)]
pub enum Syntactic {
    /// An as-yet unknown TPTP role
    UnknownRole(Position, String),
    /// An as-yet unknown TPTP defined operation
    UnknownDefined(Position, String),
    /// Syntax error
    UnexpectedToken(Position, Token),
    /// Syntax error: end of iterator mid-statement
    UnexpectedEnd,
}

/// Errors raised while processing includes
#[derive(Debug)]
pub enum Include {
    /// A circular inclusion occurred
    Circular(Position, String),
}

/// Any error that might be encountered
#[derive(Debug)]
pub enum Reported {
    /// IO error on the underlying streams
    IO(io::Error),
    /// Lexical error
    Lexical(Lexical),
    /// Syntactic error
    Syntactic(Syntactic),
    /// Include error
    Include(Include),
}

pub(crate) type Result<T> = Either<T, Reported>;

/// A reported error plus some context.
#[derive(Debug)]
pub struct Error {
    /// The error that was encountered
    pub reported: Reported,
    /// Chain of `include`s leading up to the error
    pub includes: Vec<String>,
}