Skip to content

Commit

Permalink
refactor: move [Rep ..] delta to own function (#521)
Browse files Browse the repository at this point in the history
  • Loading branch information
rgrinberg authored Oct 5, 2024
1 parent 4db72ce commit e69f5f7
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions lib/automata.ml
Original file line number Diff line number Diff line change
Expand Up @@ -599,16 +599,7 @@ let rec delta_expr ({ c; _ } as ctx) marks (x : Expr.t) rem =
| Seq (kind, y, z) ->
let y = delta_expr ctx marks y Desc.empty in
delta_seq ctx kind y z rem
| Rep (rep_kind, kind, y) ->
let y, marks' =
let y = delta_expr ctx marks y Desc.empty in
match Desc.first_match y with
| None -> y, marks
| Some marks -> Desc.remove_matches y, marks
in
(match rep_kind with
| `Greedy -> Desc.tseq kind y x (Desc.add_match rem marks')
| `Non_greedy -> Desc.add_match (Desc.tseq kind y x rem) marks)
| Rep (rep_kind, kind, y) -> delta_rep ctx marks x rep_kind kind y rem
| Eps -> Desc.add_match rem marks
| Mark i -> Desc.add_match rem (Marks.set_mark marks i)
| Pmark i -> Desc.add_match rem (Marks.set_pmark marks i)
Expand All @@ -618,6 +609,17 @@ let rec delta_expr ({ c; _ } as ctx) marks (x : Expr.t) rem =
| After cat ->
if Category.intersect ctx.prev_cat cat then Desc.add_match rem marks else rem

and delta_rep ctx marks x rep_kind kind y rem =
let y, marks' =
let y = delta_expr ctx marks y Desc.empty in
match Desc.first_match y with
| None -> y, marks
| Some marks -> Desc.remove_matches y, marks
in
match rep_kind with
| `Greedy -> Desc.tseq kind y x (Desc.add_match rem marks')
| `Non_greedy -> Desc.add_match (Desc.tseq kind y x rem) marks

and delta_alt ctx marks l rem =
match l with
| [] -> rem
Expand Down

0 comments on commit e69f5f7

Please sign in to comment.