chore(tazjin/rlox): Implement From<ScannerError> for bytecode errors
Change-Id: I446c6e38cf239a132882d37df156884d319ca111 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2553 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in>
This commit is contained in:
parent
2974d4b4b6
commit
ebc987f4aa
2 changed files with 22 additions and 3 deletions
|
|
@ -1,15 +1,18 @@
|
|||
use crate::scanner::ScannerError;
|
||||
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ErrorKind {
|
||||
// CompileError,
|
||||
// RuntimeError,
|
||||
UnexpectedChar(char),
|
||||
UnterminatedString,
|
||||
InternalError(&'static str),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Error {
|
||||
pub kind: ErrorKind,
|
||||
pub line: usize,
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
|
|
@ -18,4 +21,20 @@ impl fmt::Display for Error {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<ScannerError> for Error {
|
||||
fn from(err: ScannerError) -> Self {
|
||||
match err {
|
||||
ScannerError::UnexpectedChar { line, unexpected } => Error {
|
||||
line,
|
||||
kind: ErrorKind::UnexpectedChar(unexpected),
|
||||
},
|
||||
|
||||
ScannerError::UnterminatedString { line } => Error {
|
||||
line,
|
||||
kind: ErrorKind::UnterminatedString,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub type LoxResult<T> = Result<T, Error>;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue