Improve pbrt errors
This commit is contained in:
parent
d799bb51bc
commit
9065bfd7b4
2 changed files with 10 additions and 46 deletions
|
|
@ -48,48 +48,9 @@ enum Statement {
|
|||
}
|
||||
|
||||
fn parse_look_at(iter: &mut Tokenizer) -> Result<Statement> {
|
||||
let eye = Pos3::new(
|
||||
iter.next()
|
||||
.ok_or(miette!("missing argument"))??
|
||||
.parse()
|
||||
.into_diagnostic()?,
|
||||
iter.next()
|
||||
.ok_or(miette!("missing argument"))??
|
||||
.parse()
|
||||
.into_diagnostic()?,
|
||||
iter.next()
|
||||
.ok_or(miette!("missing argument"))??
|
||||
.parse()
|
||||
.into_diagnostic()?,
|
||||
);
|
||||
let look_at = Pos3::new(
|
||||
iter.next()
|
||||
.ok_or(miette!("missing argument"))??
|
||||
.parse()
|
||||
.into_diagnostic()?,
|
||||
iter.next()
|
||||
.ok_or(miette!("missing argument"))??
|
||||
.parse()
|
||||
.into_diagnostic()?,
|
||||
iter.next()
|
||||
.ok_or(miette!("missing argument"))??
|
||||
.parse()
|
||||
.into_diagnostic()?,
|
||||
);
|
||||
let up = Dir3::new(
|
||||
iter.next()
|
||||
.ok_or(miette!("missing argument"))??
|
||||
.parse()
|
||||
.into_diagnostic()?,
|
||||
iter.next()
|
||||
.ok_or(miette!("missing argument"))??
|
||||
.parse()
|
||||
.into_diagnostic()?,
|
||||
iter.next()
|
||||
.ok_or(miette!("missing argument"))??
|
||||
.parse()
|
||||
.into_diagnostic()?,
|
||||
);
|
||||
let eye = Pos3::new(iter.parse_next()?, iter.parse_next()?, iter.parse_next()?);
|
||||
let look_at = Pos3::new(iter.parse_next()?, iter.parse_next()?, iter.parse_next()?);
|
||||
let up = Dir3::new(iter.parse_next()?, iter.parse_next()?, iter.parse_next()?);
|
||||
|
||||
Ok(Statement::ConcatTransform(
|
||||
AffineTransform::look_at(eye, look_at, up)
|
||||
|
|
@ -470,7 +431,7 @@ impl<I: Iterator<Item = Result<u8, std::io::Error>>> Iterator for BytesToChar<I>
|
|||
Ok(a) => {
|
||||
self.count += 1;
|
||||
if a & 0x80 == 0 {
|
||||
Some(Ok((self.count, char::from(a))))
|
||||
Some(Ok((self.count - 1, char::from(a))))
|
||||
} else {
|
||||
todo!()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use miette::{Diagnostic, IntoDiagnostic, Result, SourceSpan, bail, miette};
|
||||
use miette::{Diagnostic, Error, IntoDiagnostic, Report, Result, SourceSpan, bail, miette};
|
||||
use std::{
|
||||
fs::File,
|
||||
io::{BufReader, Bytes, Read},
|
||||
|
|
@ -155,12 +155,13 @@ impl Tokenizer {
|
|||
{
|
||||
let s = self.next().ok_or_else(|| miette!("Value expected"))??;
|
||||
|
||||
s.parse::<T>().map_err(|_e| {
|
||||
s.parse::<T>().into_diagnostic().map_err(|e| {
|
||||
ParsingError {
|
||||
src: SourceFile {
|
||||
path: self.path.clone(),
|
||||
},
|
||||
bad_bit: self.last_span,
|
||||
error: Some(e),
|
||||
}
|
||||
.into()
|
||||
})
|
||||
|
|
@ -181,7 +182,6 @@ impl Tokenizer {
|
|||
match p.as_str() {
|
||||
"[" => {
|
||||
let d = self.parse_next()?;
|
||||
|
||||
if !self
|
||||
.next()
|
||||
.is_none_or(|p| p.is_ok_and(|p| p.as_str() == "]"))
|
||||
|
|
@ -325,6 +325,9 @@ struct ParsingError {
|
|||
|
||||
#[label("Here")]
|
||||
bad_bit: SourceSpan,
|
||||
|
||||
#[related]
|
||||
error: Option<Report>,
|
||||
}
|
||||
|
||||
#[derive(Error, Debug, Diagnostic)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue