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
use std::string;
use std::io;
use std::num;
error_chain! {
errors {
Parse(t: ParseError, s: String) {
description("parse error")
display("parse error: '{}'", s)
}
}
foreign_links {
Io(io::Error) #[doc = "IO error"];
FromUtf8(string::FromUtf8Error) #[doc = "Utf8 error"];
Float(num::ParseFloatError) #[doc = "Float error"];
Int(num::ParseIntError) #[doc = "Int error"];
}
}
#[derive(Debug)]
pub struct ParseError {
msg: String,
line: usize,
col: usize,
}
pub fn parse_error<T>(line: usize, col: usize, msg: String) -> Result<T> {
let pe = ParseError {
msg: msg,
line: line,
col: col,
};
let s = format!("Parse Error: {}:{} {}", line, col, pe.msg);
Err(ErrorKind::Parse(pe, s).into())
}