1use std::fmt::{ Display, Formatter };
2use std::fmt::Error as FormatError;
3use read_token::{ ParseNumberError, ParseStringError };
4use std::sync::Arc;
5
6use DebugId;
7
8#[derive(Debug, PartialEq)]
10pub enum ParseError {
11 ExpectedWhitespace(DebugId),
13 ExpectedNewLine(DebugId),
15 ExpectedSomething(DebugId),
17 ExpectedNumber(DebugId),
19 ParseNumberError(ParseNumberError, DebugId),
21 ExpectedText(DebugId),
23 EmptyTextNotAllowed(DebugId),
25 ParseStringError(ParseStringError, DebugId),
27 ExpectedTag(Arc<String>, DebugId),
29 DidNotExpectTag(Arc<String>, DebugId),
31 InvalidRule(&'static str, DebugId),
33 NoRules,
35 ExpectedEnd,
37 Conversion(String),
39}
40
41impl Display for ParseError {
42 fn fmt(&self, fmt: &mut Formatter) -> Result<(), FormatError> {
43 match self {
44 &ParseError::ExpectedWhitespace(debug_id) =>
45 write!(fmt, "#{}, Expected whitespace", debug_id)?,
46 &ParseError::ExpectedNewLine(debug_id) =>
47 write!(fmt, "#{}, Expected new line", debug_id)?,
48 &ParseError::ExpectedSomething(debug_id) =>
49 write!(fmt, "#{}, Expected something", debug_id)?,
50 &ParseError::ExpectedNumber(debug_id) =>
51 write!(fmt, "#{}, Expected number", debug_id)?,
52 &ParseError::ParseNumberError(ref err, debug_id) =>
53 write!(fmt, "#{}, Invalid number format: {}", debug_id, err)?,
54 &ParseError::ExpectedTag(ref token, debug_id) =>
55 write!(fmt, "#{}, Expected: `{}`", debug_id, token)?,
56 &ParseError::DidNotExpectTag(ref token, debug_id) =>
57 write!(fmt, "#{}, Did not expect: `{}`", debug_id, token)?,
58 &ParseError::ExpectedText(debug_id) =>
59 write!(fmt, "#{}, Expected text", debug_id)?,
60 &ParseError::EmptyTextNotAllowed(debug_id) =>
61 write!(fmt, "#{}, Empty text not allowed", debug_id)?,
62 &ParseError::ParseStringError(err, debug_id) =>
63 write!(fmt, "#{}, Invalid string format: {}", debug_id, err)?,
64 &ParseError::InvalidRule(msg, debug_id) =>
65 write!(fmt, "#{}, Invalid rule: {}", debug_id, msg)?,
66 &ParseError::NoRules =>
67 write!(fmt, "No rules are specified")?,
68 &ParseError::ExpectedEnd =>
69 write!(fmt, "Expected end")?,
70 &ParseError::Conversion(ref msg) =>
71 write!(fmt, "Conversion, {}", msg)?,
72 }
73 Ok(())
74 }
75}