Skip to content

Commit

Permalink
Fix a grammar panic (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
tirix authored Mar 6, 2022
1 parent 0d57450 commit 0dbd297
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/diag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ pub enum Diagnostic {
NotAProvableStatement,
OldAltNotDiscouraged,
ParenOrderError(Span, Span),
ParsedStatementTooShort(Token),
ParsedStatementTooShort(Option<Token>),
ParsedStatementNoTypeCode,
ParsedStatementWrongTypeCode(Token),
ProofDvViolation,
Expand Down Expand Up @@ -831,9 +831,12 @@ impl Diagnostic {
later,
)])
}
ParsedStatementTooShort(ref tok) => ("Parsed statement too short".into(), vec![(
ParsedStatementTooShort(ref opt_tok) => ("Parsed statement too short".into(), vec![(
AnnotationType::Error,
format!("Statement is too short, expecting for example {expected}", expected = t(tok)).into(),
match opt_tok {
Some(tok) => format!("Statement is too short, expecting for example {expected}", expected = t(tok)).into(),
None => "Statement is too short, and does not correspond to any valid prefix".into(),
},
stmt,
stmt.span(),
)]),
Expand Down
8 changes: 5 additions & 3 deletions src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,11 @@ impl Grammar {
}

fn too_short(map: &HashMap<(SymbolType, Atom), NextNode>, nset: &Nameset) -> Diagnostic {
let expected_symbol = map.keys().find(|k| k.0 == SymbolType::Constant).unwrap().1;
let expected_token = nset.atom_name(expected_symbol).into();
Diagnostic::ParsedStatementTooShort(expected_token)
Diagnostic::ParsedStatementTooShort(
map.keys()
.find(|k| k.0 == SymbolType::Constant)
.map(|(_, expected_symbol)| nset.atom_name(*expected_symbol).into()),
)
}

/// Gets the map of a branch
Expand Down

0 comments on commit 0dbd297

Please sign in to comment.