Add more interesting compilation error messages
This commit is contained in:
parent
267d3aabf0
commit
0f45350bec
@ -1,2 +1 @@
|
|||||||
let otus = "gotus";
|
let otus = "dotus";
|
||||||
let dotus = otus;
|
|
@ -75,3 +75,24 @@ impl CompilerError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl Display for CompilerError {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
let text = match self {
|
||||||
|
CompilerError::Fatal => "Fatal error".to_string(),
|
||||||
|
CompilerError::VariableExists(pos, name) => {
|
||||||
|
format!("Variable '{}' already exists, re-assign at {}", pos, name)
|
||||||
|
}
|
||||||
|
CompilerError::VariableNotExists(pos, name) => {
|
||||||
|
format!("Variable '{}' does not exist, at {}", pos, name)
|
||||||
|
}
|
||||||
|
CompilerError::InvalidScopeExit(pos) => {
|
||||||
|
format!("Attempted to escape a scope invalidly at {}", pos)
|
||||||
|
}
|
||||||
|
CompilerError::LetFailed(pos, error) => {
|
||||||
|
format!("Let statement failed at {}:\n {}", pos, error)
|
||||||
|
}
|
||||||
|
CompilerError::CanNotAssignVoidType => format!("Can not assign void type to variable"),
|
||||||
|
};
|
||||||
|
write!(f, "{}", text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -20,7 +20,7 @@ fn main() {
|
|||||||
dbg!(&parsed);
|
dbg!(&parsed);
|
||||||
let compiled = Compiler::from(parsed).compile();
|
let compiled = Compiler::from(parsed).compile();
|
||||||
if let Err(error) = compiled {
|
if let Err(error) = compiled {
|
||||||
eprintln!("Compilation error: {:#?}", error);
|
eprintln!("Compilation error: {}", error);
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
dbg!(compiled);
|
dbg!(compiled);
|
||||||
|
Loading…
Reference in New Issue
Block a user