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> {
|
fn parse_look_at(iter: &mut Tokenizer) -> Result<Statement> {
|
||||||
let eye = Pos3::new(
|
let eye = Pos3::new(iter.parse_next()?, iter.parse_next()?, iter.parse_next()?);
|
||||||
iter.next()
|
let look_at = Pos3::new(iter.parse_next()?, iter.parse_next()?, iter.parse_next()?);
|
||||||
.ok_or(miette!("missing argument"))??
|
let up = Dir3::new(iter.parse_next()?, iter.parse_next()?, iter.parse_next()?);
|
||||||
.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()?,
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok(Statement::ConcatTransform(
|
Ok(Statement::ConcatTransform(
|
||||||
AffineTransform::look_at(eye, look_at, up)
|
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) => {
|
Ok(a) => {
|
||||||
self.count += 1;
|
self.count += 1;
|
||||||
if a & 0x80 == 0 {
|
if a & 0x80 == 0 {
|
||||||
Some(Ok((self.count, char::from(a))))
|
Some(Ok((self.count - 1, char::from(a))))
|
||||||
} else {
|
} else {
|
||||||
todo!()
|
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::{
|
use std::{
|
||||||
fs::File,
|
fs::File,
|
||||||
io::{BufReader, Bytes, Read},
|
io::{BufReader, Bytes, Read},
|
||||||
|
|
@ -155,12 +155,13 @@ impl Tokenizer {
|
||||||
{
|
{
|
||||||
let s = self.next().ok_or_else(|| miette!("Value expected"))??;
|
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 {
|
ParsingError {
|
||||||
src: SourceFile {
|
src: SourceFile {
|
||||||
path: self.path.clone(),
|
path: self.path.clone(),
|
||||||
},
|
},
|
||||||
bad_bit: self.last_span,
|
bad_bit: self.last_span,
|
||||||
|
error: Some(e),
|
||||||
}
|
}
|
||||||
.into()
|
.into()
|
||||||
})
|
})
|
||||||
|
|
@ -181,7 +182,6 @@ impl Tokenizer {
|
||||||
match p.as_str() {
|
match p.as_str() {
|
||||||
"[" => {
|
"[" => {
|
||||||
let d = self.parse_next()?;
|
let d = self.parse_next()?;
|
||||||
|
|
||||||
if !self
|
if !self
|
||||||
.next()
|
.next()
|
||||||
.is_none_or(|p| p.is_ok_and(|p| p.as_str() == "]"))
|
.is_none_or(|p| p.is_ok_and(|p| p.as_str() == "]"))
|
||||||
|
|
@ -325,6 +325,9 @@ struct ParsingError {
|
||||||
|
|
||||||
#[label("Here")]
|
#[label("Here")]
|
||||||
bad_bit: SourceSpan,
|
bad_bit: SourceSpan,
|
||||||
|
|
||||||
|
#[related]
|
||||||
|
error: Option<Report>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Error, Debug, Diagnostic)]
|
#[derive(Error, Debug, Diagnostic)]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue