Theory TIGER_Pattern

(* Author: Basil Fürer *)

theory TIGER_Pattern
  imports TIGER_Lexer.TIGER_Codepoints
  keywords "pattern" :: diag
begin

section ‹Patterns›

text ‹A pattern is the text of a cartouche in a regex syntax after flex and ocamllex
  cite‹‹Sect.~6› in "paxson2026-flex-manual"› cite‹‹Sect.~17.2.4› in "leroy2026-ocaml-manual"›. It elaborates to a codepoint class
  (typ‹nat cls›) or a regex over classes (typ‹nat cls rexp›). A class in
  brackets is a literal interval list in sorted normal form, and the class operators
  become const‹cp_disj›, const‹cp_conj› and const‹cp_neg›. A class used as
  a regex is wrapped in const‹Pred›.

  The elaborator infers the kind of every pattern (there is one namespace for classes
  and regexes, as in ocamllex cite‹‹Sect.~17.2.2› in "leroy2026-ocaml-manual"›). Union, difference ‹#› and complement ‹[^…]› of classes
  are classes, everything else is a regex. A character is a codepoint: an ASCII or
  UTF-8 symbol, or a named symbol such as ‹α› read through the ‹code› column of
  Isabelle's symbol table.

  The command @{command pattern} prints the elaboration of a pattern, optionally in an
  environment of definitions after ‹where›. A term ‹PAT‹…›› is the elaboration of
  a pattern whose names are constants of these types.›

ML_file ‹pattern.ML›

syntax "_lexer_pattern" :: ‹cartouche_position ⇒ 'a›  (‹PAT_›)

parse_translation ‹[(syntax_const‹_lexer_pattern›, Pattern.pattern_tr)]›

end