daisy/src/parser/parsererror.rs

41 lines
849 B
Rust
Raw Normal View History

2023-06-11 13:53:45 -07:00
/// Specifies the location of a token in an input string.
#[derive(Debug)]
#[derive(Copy, Clone)]
pub struct LineLocation {
pub pos: usize,
pub len: usize
}
/// Types of parser errors.
/// If we cannot parse a string, one of these is returned.
#[derive(Debug)]
pub enum ParserError {
//MissingCloseParen,
ExtraCloseParen,
EmptyGroup,
Syntax,
BadNumber
}
impl ToString for ParserError {
fn to_string(&self) -> String {
match self {
//ParserError::MissingCloseParen => {
// String::from("This group is never closed")
//},
ParserError::ExtraCloseParen => {
String::from("Extra close parenthesis")
},
ParserError::EmptyGroup => {
String::from("Groups can't be empty")
},
ParserError::Syntax => {
String::from("Syntax")
},
ParserError::BadNumber => {
String::from("Invalid number")
}
}
}
}