templater: merge ParseIntError into generic Expression error

It was only needed to attach the source error object, which is now handled
by the outer error type.
This commit is contained in:
Yuya Nishihara 2024-03-29 23:00:07 +09:00
parent 76f3b80e8a
commit 339b199ee3

View file

@ -75,8 +75,6 @@ pub struct TemplateParseError {
pub enum TemplateParseErrorKind { pub enum TemplateParseErrorKind {
#[error("Syntax error")] #[error("Syntax error")]
SyntaxError, SyntaxError,
#[error("Invalid integer literal")]
ParseIntError,
#[error(r#"Keyword "{name}" doesn't exist"#)] #[error(r#"Keyword "{name}" doesn't exist"#)]
NoSuchKeyword { NoSuchKeyword {
name: String, name: String,
@ -405,8 +403,7 @@ fn parse_term_node(pair: Pair<Rule>) -> TemplateParseResult<ExpressionNode> {
} }
Rule::integer_literal => { Rule::integer_literal => {
let value = expr.as_str().parse().map_err(|err| { let value = expr.as_str().parse().map_err(|err| {
TemplateParseError::with_span(TemplateParseErrorKind::ParseIntError, span) TemplateParseError::expression("Invalid integer literal", span).with_source(err)
.with_source(err)
})?; })?;
ExpressionNode::new(ExpressionKind::Integer(value), span) ExpressionNode::new(ExpressionKind::Integer(value), span)
} }
@ -1229,7 +1226,7 @@ mod tests {
); );
assert_matches!( assert_matches!(
parse_into_kind(&format!("{}", (i64::MAX as u64) + 1)), parse_into_kind(&format!("{}", (i64::MAX as u64) + 1)),
Err(TemplateParseErrorKind::ParseIntError) Err(TemplateParseErrorKind::Expression(_))
); );
} }