Error returning
This commit is contained in:
+11
-4
@@ -14,13 +14,18 @@ pub enum ParseError<'a> {
|
|||||||
PreAst(pest::error::Error<Rule>),
|
PreAst(pest::error::Error<Rule>),
|
||||||
Ast {
|
Ast {
|
||||||
span: pest::Span<'a>,
|
span: pest::Span<'a>,
|
||||||
error_code: i32,
|
error_code: ErrorCode,
|
||||||
error_message: String,
|
error_message: String,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
type ParseResult<'a, T> = Result<T, ParseError<'a>>;
|
type ParseResult<'a, T> = Result<T, ParseError<'a>>;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum ErrorCode {
|
||||||
|
InvalidStatement = 200,
|
||||||
|
}
|
||||||
|
|
||||||
pub fn parse<'a>(source: &'a str) -> ParseResult<'a, Vec<TopLevel>> {
|
pub fn parse<'a>(source: &'a str) -> ParseResult<'a, Vec<TopLevel>> {
|
||||||
let mut pairs = MistParser::parse(Rule::program, source)?;
|
let mut pairs = MistParser::parse(Rule::program, source)?;
|
||||||
|
|
||||||
@@ -611,9 +616,11 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Statement {
|
|||||||
),
|
),
|
||||||
|
|
||||||
Rule::unexpected_statement => {
|
Rule::unexpected_statement => {
|
||||||
let pos = pair.as_span().start_pos().line_col();
|
return Err(ParseError::Ast {
|
||||||
|
span: pair.as_span(),
|
||||||
panic!("({}:{}) Invalid Statement: {}", pos.0, pos.1, pair.as_str())
|
error_code: ErrorCode::InvalidStatement,
|
||||||
|
error_message: "Invalid Statement".to_string(),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => unimplemented!("{rule:#?}"),
|
_ => unimplemented!("{rule:#?}"),
|
||||||
|
|||||||
Reference in New Issue
Block a user