Directly using tadpole_frontend
Currently, the Frontend interface only offers a basic string for frontend parsing errors. This will likely be improved eventually, but as of this time it can be advantageous to directly call the internal functions of the tadpole_frontend parser to gain access to the much richer error types. This can be done as follows:
let directives = TadpoleParser::parse(&spec);
let engine = match directives {
Ok(dirs) => Ok(SoundChanger::new(dirs)),
Err(e) => {
// print or forward error with rich error data
}
}The error type returned here is Vec<ValidationError>. Each ValidationError consists of a main error with a code span as well as optional hints, each of which may or may not have an associated span. Types provided by the Chumsky parser library are used for the spans. Below is an example of a simplified way to print the error content. The tadpole CLI uses Ariadne to format errors.
println!("error at {}: {}", e.span(), e.reason());
for (hint, hint_span) in e.hints() {
if let Some(span) = hint_span {
println!(" at {span}: {hint}");
} else {
println!(" hint: {hint}");
}
}