Start fixing error outputs
Signed-off-by: Marcel Müller <neikos@neikos.email>
This commit is contained in:
parent
d6ac7af36b
commit
7f7bf5c98d
16 changed files with 319 additions and 21 deletions
|
|
@ -104,13 +104,14 @@ impl FromRecoverableError<Input<'_>, AstError> for AstError {
|
|||
.filter(|t| t.kind() != TokenKind::Whitespace);
|
||||
let last = tokens.next();
|
||||
let first = tokens.last();
|
||||
|
||||
match (last, first) {
|
||||
(None, None) => None,
|
||||
(None, Some(single)) | (Some(single), None) => Some(SourceSpan {
|
||||
range: single.source().get_range(),
|
||||
}),
|
||||
(Some(last), Some(first)) => {
|
||||
let start = first.source().get_range().start;
|
||||
let start = first.source().get_range().end;
|
||||
let end = last.source().get_range().end;
|
||||
|
||||
Some(SourceSpan { range: start..end })
|
||||
|
|
@ -212,7 +213,7 @@ pub enum TemplateAstExpr<'input> {
|
|||
ElseConditional {
|
||||
expression: Option<Box<TemplateAstExpr<'input>>>,
|
||||
},
|
||||
#[expect(unused)]
|
||||
#[allow(unused)]
|
||||
Invalid(&'input [TemplateToken]),
|
||||
MathOperation {
|
||||
op: TokenOperator,
|
||||
|
|
@ -311,7 +312,7 @@ fn parse_action<'input>(input: &mut Input<'input>) -> Result<TemplateAstExpr<'in
|
|||
(parse_block(
|
||||
cut_err(not(repeat_till(
|
||||
0..,
|
||||
any,
|
||||
parse_expression,
|
||||
peek((ws, TokenKind::RightDelim)),
|
||||
)
|
||||
.map(|((), _)| ())))
|
||||
|
|
@ -342,7 +343,7 @@ fn parse_for_chain<'input>(input: &mut Input<'input>) -> Result<TemplateAstExpr<
|
|||
|
||||
let (content, taken) = resume_after_cut(
|
||||
repeat_till(0.., parse_ast, loop_end),
|
||||
repeat_till(0.., any, parse_end).map(|((), _)| ()),
|
||||
repeat_till(0.., parse_ast, parse_end).map(|((), _)| ()),
|
||||
)
|
||||
.with_taken()
|
||||
.parse_next(input)?;
|
||||
|
|
@ -372,9 +373,11 @@ fn parse_for_loop<'input>(input: &mut Input<'input>) -> Result<TemplateAstExpr<'
|
|||
ws,
|
||||
TokenKind::For,
|
||||
ws,
|
||||
TokenKind::Ident,
|
||||
cut_err(TokenKind::Ident.context(AstError::ctx().msg("Expected identifier here"))),
|
||||
ws,
|
||||
TokenKind::In,
|
||||
cut_err(
|
||||
TokenKind::In.context(AstError::ctx().msg("Missing `in` in `for _ in <expr>`")),
|
||||
),
|
||||
ws,
|
||||
parse_expression.map(Box::new),
|
||||
)
|
||||
|
|
@ -601,11 +604,34 @@ where
|
|||
fn parse_operand<'input>(input: &mut Input<'input>) -> Result<TemplateAstExpr<'input>, AstError> {
|
||||
trace(
|
||||
"operand",
|
||||
alt((parse_function, parse_variable_access, parse_literal)),
|
||||
alt((
|
||||
parse_keywords_fail,
|
||||
parse_function,
|
||||
parse_variable_access,
|
||||
parse_literal,
|
||||
)),
|
||||
)
|
||||
.parse_next(input)
|
||||
}
|
||||
|
||||
fn parse_keywords_fail<'input>(
|
||||
input: &mut Input<'input>,
|
||||
) -> Result<TemplateAstExpr<'input>, AstError> {
|
||||
let value = alt((
|
||||
TokenKind::ConditionalIf,
|
||||
TokenKind::For,
|
||||
TokenKind::End,
|
||||
TokenKind::In,
|
||||
))
|
||||
.take()
|
||||
.map(TemplateAstExpr::Invalid)
|
||||
.parse_next(input)?;
|
||||
|
||||
cut_err(fail::<_, (), _>.context(AstError::ctx().msg("Found literal, expected expression")))
|
||||
.value(value)
|
||||
.parse_next(input)
|
||||
}
|
||||
|
||||
fn parse_literal<'input>(input: &mut Input<'input>) -> Result<TemplateAstExpr<'input>, AstError> {
|
||||
trace(
|
||||
"literal",
|
||||
|
|
@ -895,7 +921,7 @@ mod tests {
|
|||
help: None,
|
||||
span: Some(
|
||||
SourceSpan {
|
||||
range: 0..6,
|
||||
range: 2..6,
|
||||
},
|
||||
),
|
||||
is_fatal: false,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue