mirror of
https://github.com/uutils/awk.git
synced 2026-06-10 16:15:04 -07:00
parser: tighten error reporting
This commit is contained in:
@@ -149,7 +149,7 @@ pub fn report_error<'a>(
|
||||
name: &'a str,
|
||||
source: &'a [u8],
|
||||
) -> super::AriadneErr<'a> {
|
||||
let span = error.span().unwrap();
|
||||
let span = error.span().unwrap_or(source.len()..source.len());
|
||||
let source = str::from_utf8(source).unwrap();
|
||||
let mut report = Report::build(ReportKind::Error, (name, span.clone()))
|
||||
.with_message("Syntax error")
|
||||
|
||||
+2
-2
@@ -53,7 +53,7 @@ impl<'a> Lexer<'a> {
|
||||
Some(Ok(tok)) if expected == &tok => Ok(tok),
|
||||
Some(Ok(_)) => Err(err(self.span())),
|
||||
Some(err @ Err(_)) => err.map_err(Into::into),
|
||||
None => todo!(),
|
||||
None => Err(ParsingError::LexingError(LexingError::UnexpectedEof)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ impl<'a> Lexer<'a> {
|
||||
Some(Ok(tok)) if expected(&tok) => Ok(tok),
|
||||
Some(Ok(_)) => Err(ParsingError::UnexpectedToken(self.span(), msg)),
|
||||
Some(err @ Err(_)) => err.map_err(Into::into),
|
||||
None => todo!(),
|
||||
None => Err(ParsingError::LexingError(LexingError::UnexpectedEof)),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
-2
@@ -157,7 +157,12 @@ impl<'a> Parser<'a> {
|
||||
));
|
||||
}
|
||||
Token::Newline | Token::Semicolon => {}
|
||||
x => unimplemented!("{x:?}"),
|
||||
_ => {
|
||||
return Err(ParsingError::UnexpectedToken(
|
||||
lex.span(),
|
||||
"invalid rule beginning.".into(),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -362,7 +367,12 @@ impl<'a> Parser<'a> {
|
||||
.then(|| self.parse_expression(lex))
|
||||
.transpose()?,
|
||||
),
|
||||
a => todo!("{a:?}"),
|
||||
_ => {
|
||||
return Err(ParsingError::UnexpectedToken(
|
||||
lex.span(),
|
||||
"invalid statement start.".into(),
|
||||
));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+4
-1
@@ -163,7 +163,10 @@ impl<'a, 'b> Pratt<'a, 'b> {
|
||||
self.parser
|
||||
.parse_function_call(lex, name.qualify(self.parser.namespace), lex.span())
|
||||
} else {
|
||||
Ok(Expr::leaf(self.parser.parse_atom(lex, next)?))
|
||||
match self.parser.parse_atom(lex, next) {
|
||||
Ok(atom) => Ok(Expr::leaf(atom)),
|
||||
Err(_) => Err(ParsingError::InvalidExpression(lex.span())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user