Theory Recover_Tests
theory Recover_Tests
imports TIGER_Grammar_Tests.Diag_Tests TIGER_Grammar_Tests.Parser_Check
begin
section ‹Recovery from rejected words›
text ‹Tokens with their offsets, as a lexer gives them: the span of an error token
is computed from them.›
definition tr :: ‹nat ⇒ nat ⇒ 'tok ⇒ ('tok, unit) token› where
‹tr l c x = ⦇tok = x, span = span.make l c (100 * l + c) 1 []⦈›
fun toks :: ‹nat ⇒ 'tok list ⇒ ('tok, unit) token list› where
‹toks i [] = []›
| ‹toks i (x # xs) = tr 0 i x # toks (Suc (Suc i)) xs›
definition rtoks :: ‹('n, 't, unit, unit) perr list × ('t, unit) token list ⇒
nat list × ('t × nat × nat) list› where
‹rtoks r = (map pe_index (fst r), map (λx. (tok x, s_col (span x), s_len (span x))) (snd r))›
subsection ‹Layout-free: the simple driver›