@@ -559,6 +559,8 @@ end = struct (* {{{ *)
559559 error ~loc (" duplicate attribute " ^ s) in
560560 let illegal_err a =
561561 error ~loc (" illegal attribute " ^ show_raw_attribute a) in
562+ let illegal_replace s =
563+ error ~loc (" replacing clause for " ^ s ^ " cannot have a name attribute" ) in
562564 let rec aux r = function
563565 | [] -> r
564566 | Name s :: rest ->
@@ -570,13 +572,21 @@ end = struct (* {{{ *)
570572 | Before s :: rest ->
571573 if r.insertion <> None then duplicate_err " insertion" ;
572574 aux { r with insertion = Some (Before s) } rest
575+ | Replace s :: rest ->
576+ if r.insertion <> None then duplicate_err " insertion" ;
577+ aux { r with insertion = Some (Replace s) } rest
573578 | If s :: rest ->
574579 if r.ifexpr <> None then duplicate_err " if" ;
575580 aux { r with ifexpr = Some s } rest
576581 | (External | Index _ ) as a :: _ -> illegal_err a
577582 in
578- { c with Clause. attributes =
579- aux { insertion = None ; id = None ; ifexpr = None } attributes }
583+ let attributes = aux { insertion = None ; id = None ; ifexpr = None } attributes in
584+ begin
585+ match attributes.insertion, attributes.id with
586+ | Some (Replace x ), Some _ -> illegal_replace x
587+ | _ -> ()
588+ end ;
589+ { c with Clause. attributes }
580590
581591 let structure_chr_attributes ({ Chr. attributes; loc } as c ) =
582592 let duplicate_err s =
@@ -590,7 +600,7 @@ end = struct (* {{{ *)
590600 | If s :: rest ->
591601 if r.cifexpr <> None then duplicate_err " if" ;
592602 aux { r with cifexpr = Some s } rest
593- | (Before _ | After _ | External | Index _ ) as a :: _ -> illegal_err a
603+ | (Before _ | After _ | Replace _ | External | Index _ ) as a :: _ -> illegal_err a
594604 in
595605 let cid = Loc. show loc in
596606 { c with Chr. attributes = aux { cid; cifexpr = None } attributes }
@@ -614,7 +624,7 @@ end = struct (* {{{ *)
614624 | Some (Structured. Index _ ) -> duplicate_err " index"
615625 | Some _ -> error ~loc " external predicates cannot be indexed"
616626 end
617- | (Before _ | After _ | Name _ | If _ ) as a :: _ -> illegal_err a
627+ | (Before _ | After _ | Replace _ | Name _ | If _ ) as a :: _ -> illegal_err a
618628 in
619629 let attributes = aux None attributes in
620630 let attributes =
@@ -1910,8 +1920,12 @@ end = struct (* {{{ *)
19101920 match l, loc_name with
19111921 | [] ,_ -> error ~loc: c.Ast.Clause. loc (" unable to graft this clause: no clause named " ^
19121922 match loc_name with
1923+ | Ast.Structured. Replace x -> x
19131924 | Ast.Structured. After x -> x
19141925 | Ast.Structured. Before x -> x)
1926+ | { Ast.Clause. attributes = { Assembled. id = Some n }} :: xs,
1927+ Ast.Structured. Replace name when n = name ->
1928+ c :: xs
19151929 | { Ast.Clause. attributes = { Assembled. id = Some n }} as x :: xs,
19161930 Ast.Structured. After name when n = name ->
19171931 c :: x :: xs
0 commit comments