Skip to content

Commit

Permalink
Give better warnings if lexer/grammar can't be read at build time.
Browse files Browse the repository at this point in the history
If the user gave an incorrect path, they got an internal `unwrap`, or
similarly unhelpful message, from lrlex and lrpar. This commit tells
them what file was attempting to be read, which makes working out what's
actually gone wrong much easier.
  • Loading branch information
ltratt committed Jun 4, 2024
1 parent 05e40d1 commit 1409b63
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lrlex/src/lib/ctbuilder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,8 @@ where
lk.insert(outp.clone());
}

let lex_src = read_to_string(lexerp)?;
let lex_src = read_to_string(lexerp)
.map_err(|e| format!("When reading '{}': {e}", lexerp.display()))?;
let line_cache = NewlineCache::from_str(&lex_src).unwrap();
let mut lexerdef: Box<dyn LexerDef<LexerTypesT>> = match self.lexerkind {
LexerKind::LRNonStreamingLexer => Box::new(
Expand Down
3 changes: 2 additions & 1 deletion lrpar/src/lib/ctbuilder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,8 @@ where
lk.insert(outp.clone());
}

let inc = read_to_string(grmp).unwrap();
let inc =
read_to_string(grmp).map_err(|e| format!("When reading '{}': {e}", grmp.display()))?;
let ast_validation = ASTWithValidityInfo::new(yk, &inc);
let warnings = ast_validation.ast().warnings();
let spanned_fmt = |x: &dyn Spanned, inc: &str, line_cache: &NewlineCache| {
Expand Down

0 comments on commit 1409b63

Please sign in to comment.