forked from AbleScript/ablescript
Error comments + renaming
This commit is contained in:
parent
63af15cc94
commit
f2d3561508
|
@ -9,14 +9,32 @@ pub struct Error {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ErrorKind {
|
pub enum ErrorKind {
|
||||||
|
/// Parser expected token, but none was available
|
||||||
UnexpectedEoi,
|
UnexpectedEoi,
|
||||||
|
|
||||||
|
/// Parser expected certain token, but other one appeared
|
||||||
UnexpectedToken(Token),
|
UnexpectedToken(Token),
|
||||||
|
|
||||||
|
/// Attempted to assign to undefined variable
|
||||||
UnknownVariable(String),
|
UnknownVariable(String),
|
||||||
|
|
||||||
|
/// Attempted to access banned variable
|
||||||
MeloVariable(String),
|
MeloVariable(String),
|
||||||
TopLevelEnough,
|
|
||||||
|
/// Breaking / re-starting loop outside loop
|
||||||
|
LoopOpOutsideLoop,
|
||||||
|
|
||||||
|
/// Rlyeh was executed but host interface's exit
|
||||||
|
/// doesn't exit the program
|
||||||
NonExitingRlyeh(i32),
|
NonExitingRlyeh(i32),
|
||||||
|
|
||||||
|
/// Missing left-hand side expression in binary expression
|
||||||
MissingLhs,
|
MissingLhs,
|
||||||
|
|
||||||
|
/// Error when executing BF code
|
||||||
Brian(InterpretError),
|
Brian(InterpretError),
|
||||||
|
|
||||||
|
/// IO Error
|
||||||
Io(io::Error),
|
Io(io::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +69,10 @@ impl Display for ErrorKind {
|
||||||
ErrorKind::UnexpectedToken(token) => write!(f, "unexpected token {:?}", token),
|
ErrorKind::UnexpectedToken(token) => write!(f, "unexpected token {:?}", token),
|
||||||
ErrorKind::UnknownVariable(name) => write!(f, "unknown identifier \"{}\"", name),
|
ErrorKind::UnknownVariable(name) => write!(f, "unknown identifier \"{}\"", name),
|
||||||
ErrorKind::MeloVariable(name) => write!(f, "banned variable \"{}\"", name),
|
ErrorKind::MeloVariable(name) => write!(f, "banned variable \"{}\"", name),
|
||||||
ErrorKind::TopLevelEnough => write!(f, "can only `enough` out of a loop"),
|
ErrorKind::LoopOpOutsideLoop => write!(
|
||||||
|
f,
|
||||||
|
"unable to perform loop operation (enough or and enough) outside a loop"
|
||||||
|
),
|
||||||
&ErrorKind::NonExitingRlyeh(code) => write!(f, "program exited with code {code}"),
|
&ErrorKind::NonExitingRlyeh(code) => write!(f, "program exited with code {code}"),
|
||||||
ErrorKind::Brian(err) => write!(f, "brainfuck error: {}", err),
|
ErrorKind::Brian(err) => write!(f, "brainfuck error: {}", err),
|
||||||
// TODO: give concrete numbers here.
|
// TODO: give concrete numbers here.
|
||||||
|
|
|
@ -124,7 +124,7 @@ impl<H: HostInterface> ExecEnv<H> {
|
||||||
HaltStatus::Enough(span) | HaltStatus::AndAgain(span) => Err(Error {
|
HaltStatus::Enough(span) | HaltStatus::AndAgain(span) => Err(Error {
|
||||||
// It's an error to issue a `enough` outside of a
|
// It's an error to issue a `enough` outside of a
|
||||||
// `loop` statement.
|
// `loop` statement.
|
||||||
kind: ErrorKind::TopLevelEnough,
|
kind: ErrorKind::LoopOpOutsideLoop,
|
||||||
span,
|
span,
|
||||||
}),
|
}),
|
||||||
}?;
|
}?;
|
||||||
|
|
Loading…
Reference in a new issue