(* Author: Peter Lammich *) section ‹Parser Combinators› theory Parser_Combinator imports "HOL-Library.Monad_Syntax" "HOL-Library.Char_ord" "HOL-Library.Code_Target_Nat" "Certification_Monads.Error_Monad" Munta_Error_Monad_Add "Show.Show" "HOL-Library.Rewrite" begin (** Parser Combinators, based on Sternagel et Thiemann's Parser_Monad, with the following additional features/differences: * Setup for the function package, to handle recursion parser uses fuel to ensure termination. * Uses (unit ⇒ shows) for error messages instead of String (lazy computation of messages, more comfortable due to shows) * Everything defined over generic token type * Some fancy combinators a ∥ b choice, type a = type b --[f] sequential composition, combine results with f -- = --[Pair] --* seq, ignore right result *-- seq, ignore left result TODO/FIXME * Currently, the bind and repeat operation dynamically check whether input is consumed and then fail. At least for bind (no input is generated), we could try to encode this information into the parser's type. However, interplay with function package is not clear at this point :( Possible solution: Fixed-point based recursion combinator and partial_function. We could then do totality proof afterwards. *) subsection ‹Type Definitions›