1use std::fmt;
6
7#[derive(Clone,Copy,PartialEq)]
11pub struct ErrorPos {
12 #[allow(missing_docs)]
13 pub row: usize,
14 #[allow(missing_docs)]
15 pub col: usize,
16}
17
18impl ErrorPos {
19 pub fn new(row: usize, col: usize) -> ErrorPos {
21 ErrorPos {
22 row: row,
23 col: col,
24 }
25 }
26}
27
28impl fmt::Debug for ErrorPos {
29 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
30 write!(f, "{}:{}", &self.row, &self.col)
31 }
32}
33
34#[derive(Clone,Copy,PartialEq)]
36pub enum Error {
37 UnexpectedEndOfStream(ErrorPos),
41 InvalidAdvance {
43 expected: isize,
45 total: usize,
47 pos: ErrorPos,
49 },
50 UnsupportedToken(ErrorPos),
52 UnknownToken(ErrorPos),
54}
55
56impl fmt::Debug for Error {
57
58 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
59 match *self {
60 Error::UnexpectedEndOfStream(ref pos) =>
61 write!(f, "Unexpected end of stream at {:?}", pos),
62 Error::InvalidAdvance{ref expected, ref total, ref pos} =>
63 write!(f, "Attempt to advance to the pos {} from {:?}, but total len is {}",
64 expected, pos, total),
65 Error::UnsupportedToken(ref pos) =>
66 write!(f, "Unsupported token at {:?}", pos),
67 Error::UnknownToken(ref pos) =>
68 write!(f, "Unknown token at {:?}", pos),
69 }
70 }
71}