The unpac monorepo manager self-hosting as a monorepo using unpac

refactor: remove pretty printer hackery (#549)

the conversion to dyn is good enough

authored by

Rudi Grinberg and committed by
GitHub
73e4c4e7 e8e8ecb0

+11 -35
+11 -35
lib/automata.ml
··· 224 224 225 225 and to_dyn sem { id = _; def } = dyn_of_def sem def 226 226 227 - let with_sem prev next fmt pp () = 228 - let open Fmt in 229 - let wrapped fmt () = sexp fmt (Format.asprintf "%a" Sem.pp next) pp () in 230 - match prev with 231 - | None -> wrapped fmt () 232 - | Some prev -> if Sem.equal prev next then pp fmt () else wrapped fmt () 233 - ;; 234 - 235 227 let rec pp_with_sem sem ch e = 236 228 let open Fmt in 237 229 match e.def with 238 230 | Cst l -> sexp ch "cst" Cset.pp l 239 231 | Alt l -> sexp ch "alt" (list (pp_with_sem sem)) l 240 232 | Seq (k, e, e') -> 241 - let pp ch () = 242 - let sem = Some k in 243 - sexp ch "seq" (pair (pp_with_sem sem) (pp_with_sem sem)) (e, e') 244 - in 245 - with_sem sem k ch pp () 233 + sexp ch "seq" (triple Sem.pp (pp_with_sem sem) (pp_with_sem sem)) (k, e, e') 246 234 | Eps -> str ch "eps" 247 235 | Rep (_rk, k, e) -> sexp ch "rep" (pair Sem.pp (pp_with_sem (Some k))) (k, e) 248 236 | Mark i -> sexp ch "mark" Mark.pp i ··· 495 483 | TExp (marks, _) | TMatch marks -> f marks) 496 484 ;; 497 485 498 - let rec print_state_rec sem ch e (y : Expr.t) = 486 + let rec print_state_rec ch e (y : Expr.t) = 499 487 match e with 500 488 | TMatch marks -> Format.fprintf ch "@[<2>(TMatch@ %a)@]" Marks.pp marks 501 - | TSeq (sem', l', x) -> 502 - let pp ch () = 503 - let sem = Some sem' in 504 - Format.fprintf ch "@[<2>(TSeq@ "; 505 - print_state_lst sem ch l' x; 506 - Format.fprintf ch "@ %a)@]" (Expr.pp_with_sem sem) x 507 - in 508 - with_sem sem sem' ch pp () 489 + | TSeq (sem, l', x) -> 490 + Format.fprintf ch "@[<2>(TSeq@ %a@ " Sem.pp sem; 491 + print_state_lst ch l' x; 492 + Format.fprintf ch "@ %a)@]" Expr.pp x 509 493 | TExp (marks, { def = Eps; _ }) -> 510 494 Format.fprintf ch "@[<2>(TExp@ %a@ (%a)@ (eps))@]" Id.pp y.id Marks.pp marks 511 495 | TExp (marks, x) -> 512 - Format.fprintf 513 - ch 514 - "@[<2>(TExp@ %a@ (%a)@ %a)@]" 515 - Id.pp 516 - x.id 517 - Marks.pp 518 - marks 519 - (Expr.pp_with_sem sem) 520 - x 496 + Format.fprintf ch "@[<2>(TExp@ %a@ (%a)@ %a)@]" Id.pp x.id Marks.pp marks Expr.pp x 521 497 522 - and print_state_lst sem ch l y = 498 + and print_state_lst ch l y = 523 499 match l with 524 500 | [] -> Format.fprintf ch "()" 525 501 | e :: rem -> 526 - print_state_rec sem ch e y; 502 + print_state_rec ch e y; 527 503 List.iter rem ~f:(fun e -> 528 504 Format.fprintf ch "@ | "; 529 - print_state_rec sem ch e y) 505 + print_state_rec ch e y) 530 506 ;; 531 507 532 - let pp ch t = print_state_lst None ch [ t ] { id = Id.zero; def = Eps } 508 + let pp ch t = print_state_lst ch [ t ] { id = Id.zero; def = Eps } 533 509 534 510 let rec first_match = function 535 511 | [] -> None