opql/error/
mod.rs

1use super::*;
2
3pub type Loc = usize;
4pub type LocInfo = (Loc, Loc);
5pub type PQLResult<T> = Result<T, PQLError>;
6
7type Given = PQLType;
8type Expected = Given;
9type GivenN = usize;
10type ExpectedN = GivenN;
11type Lhs = PQLType;
12type Rhs = PQLType;
13
14#[derive(Debug, Clone, PartialEq, Eq)]
15pub struct PQLError {
16    pub loc: LocInfo,
17    pub kind: PQLErrorKind,
18}
19
20impl<E> From<(SourceLocation, E)> for PQLError
21where
22    PQLErrorKind: From<E>,
23{
24    fn from((loc, kind): (SourceLocation, E)) -> Self {
25        Self {
26            loc,
27            kind: PQLErrorKind::from(kind),
28        }
29    }
30}
31
32type NumPlayers = usize;
33
34#[derive(Debug, Clone, PartialEq, Eq, derive_more::From)]
35pub enum PQLErrorKind {
36    SyntaxError(SyntaxError),
37    ParseError(ParseError),
38    RangeError(RangeError),
39    Internal(InternalError),
40    Runtime(RuntimeError),
41    UnrecognizedFunction,
42    UnrecognizedIdentifier,
43    ExceededMaximumPlayers(NumPlayers),
44    InvalidPlayer,
45    InvalidDeadcards,
46    InvalidCardCount,
47    TypeError(Given, Expected),
48    WrongNumberOfArguments(GivenN, ExpectedN),
49    SamplingFailed,
50    #[from(skip)]
51    ArithmeticOperationUnsupported(Lhs, Rhs),
52    #[from(skip)]
53    ComparisonOperationUnsupported(Lhs, Rhs),
54    VmErr(VmError),
55}
56
57#[derive(Debug, Clone, PartialEq, Eq)]
58pub enum InternalError {
59    StackUnderflow,
60    NonNumericStackValue,
61    UnexpectedTypeCast,
62    UnexpectedComparison,
63}
64
65#[derive(Debug, Clone, PartialEq, Eq)]
66pub enum RuntimeError {
67    AddOverflow,
68    SubOverflow,
69    MulOverflow,
70    InvalidHand,
71    RequiresFiveCards,
72    IntegerRequired,
73    ValueRetrievalFailed(PQLType),
74}
75
76// used for flow control
77#[derive(Debug, Clone, PartialEq, Eq)]
78pub enum VmError {
79    SamplingFailed,
80}