include header in fatal parse errors

This commit is contained in:
Folkert 2021-03-23 16:14:20 +01:00
parent e3b65b1ce0
commit 4418a99c89
3 changed files with 14 additions and 7 deletions

View file

@ -17,6 +17,6 @@ isEmpty : Dict * * -> Bool
## See for example #Result.map, #List.map, and #Set.map.
map :
Dict beforeKey beforeValue,
({ key: beforeKey, value: beforeValue } ->
(\{ key: beforeKey, value: beforeValue } ->
{ key: afterKey, value: afterValue }
) -> Dict afterKey afterValue

View file

@ -2293,7 +2293,7 @@ fn load_pkg_config<'a>(
Ok(Msg::Many(vec![effects_module_msg, pkg_config_module_msg]))
}
Err(fail) => Err(LoadingProblem::ParsingFailed(
SyntaxError::Header(fail).into_parse_problem(filename, bytes),
SyntaxError::Header(fail).into_parse_problem(filename, "", bytes),
)),
}
}
@ -2565,7 +2565,7 @@ fn parse_header<'a>(
module_timing,
)),
Err(fail) => Err(LoadingProblem::ParsingFailed(
SyntaxError::Header(fail).into_parse_problem(filename, src_bytes),
SyntaxError::Header(fail).into_parse_problem(filename, "", src_bytes),
)),
}
}
@ -3614,9 +3614,11 @@ fn parse<'a>(arena: &'a Bump, header: ModuleHeader<'a>) -> Result<Msg<'a>, Loadi
let parsed_defs = match module_defs().parse(&arena, parse_state) {
Ok((_, success, _state)) => success,
Err((_, fail, _)) => {
return Err(LoadingProblem::ParsingFailed(
fail.into_parse_problem(header.module_path, source),
));
return Err(LoadingProblem::ParsingFailed(fail.into_parse_problem(
header.module_path,
header.header_src,
source,
)));
}
};
@ -4196,7 +4198,8 @@ fn to_parse_problem_report<'a>(
// TODO this is not in fact safe
let src = unsafe { from_utf8_unchecked(problem.bytes) };
let src_lines: Vec<&str> = src.split('\n').collect();
let mut src_lines: Vec<&str> = problem.prefix.lines().collect();
src_lines.extend(src.lines().skip(1));
let module_id = module_ids.get_or_insert(&"find module name somehow?".into());

View file

@ -360,6 +360,7 @@ impl<'a> SyntaxError<'a> {
pub fn into_parse_problem(
self,
filename: std::path::PathBuf,
prefix: &'a str,
bytes: &'a [u8],
) -> ParseProblem<'a, SyntaxError<'a>> {
ParseProblem {
@ -368,6 +369,7 @@ impl<'a> SyntaxError<'a> {
problem: self,
filename,
bytes,
prefix,
}
}
}
@ -679,6 +681,8 @@ pub struct ParseProblem<'a, T> {
pub problem: T,
pub filename: std::path::PathBuf,
pub bytes: &'a [u8],
/// prefix is usually the header (for parse problems in the body), or empty
pub prefix: &'a str,
}
pub trait Parser<'a, Output, Error> {