Skip to content

Commit d3adc75

Browse files
[aslspec] remove angle brackets before performing text substitutions for prose
1 parent 37166b6 commit d3adc75

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

asllib/aslspec/render.ml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ module Make (S : SPEC_VALUE) = struct
674674
missing prose templates. *)
675675
let prose_or_empty_message ~name prose =
676676
if Utils.string_is_empty prose then
677-
Format.asprintf "<empty prose for %s>"
677+
Format.asprintf "``empty prose for %s''"
678678
(Latex.spec_var_to_latex_var ~font_type:TextTT name)
679679
else prose
680680

@@ -689,6 +689,15 @@ module Make (S : SPEC_VALUE) = struct
689689
*)
690690
let var_to_prose id = spec_var_to_latex_var ~font_type:TextTT id
691691

692+
(** Removes angle brackets from the template and substitutes the
693+
placeholders with the provided substitutions. *)
694+
let preprocess_template_and_substitute template substitutions =
695+
(* Replace text inside angle brackets with the text itself. *)
696+
let template =
697+
Str.global_replace (Str.regexp "<\\([^>]*\\)>") "\\1" template
698+
in
699+
substitute template substitutions
700+
692701
(** [expr_to_prose expr] converts an expression [expr] to its prose
693702
representation. *)
694703
let rec expr_to_prose expr =
@@ -749,7 +758,7 @@ module Make (S : SPEC_VALUE) = struct
749758
| Some name -> Some (name, prose))
750759
formal_opt_prose_pairs
751760
in
752-
substitute expr_prose formal_prose_pairs
761+
preprocess_template_and_substitute expr_prose formal_prose_pairs
753762
| Record { label_opt; fields } ->
754763
let variant = Spec.record_variant_for_expr S.spec expr in
755764
let name =
@@ -790,8 +799,7 @@ module Make (S : SPEC_VALUE) = struct
790799
(fun (field, field_expr) -> (field, expr_to_prose field_expr))
791800
(fields @ unspecified_defaults)
792801
in
793-
let result = substitute expr_prose field_to_prose in
794-
result
802+
preprocess_template_and_substitute expr_prose field_to_prose
795803
| RecordUpdate { record_expr; updates } ->
796804
let record_prose = expr_to_prose record_expr in
797805
let updates_prose =
@@ -859,7 +867,7 @@ module Make (S : SPEC_VALUE) = struct
859867
relation.name
860868
in
861869
let formal_prose_pair = [ (formal_arg_name, args_prose) ] in
862-
substitute expr_prose formal_prose_pair
870+
preprocess_template_and_substitute expr_prose formal_prose_pair
863871
else
864872
let formal_arg_pairs = List.combine formal_args args in
865873
let formal_prose_pairs =
@@ -868,7 +876,7 @@ module Make (S : SPEC_VALUE) = struct
868876
named_args_for_opt_named_term opt_named_term arg)
869877
formal_arg_pairs
870878
in
871-
substitute expr_prose formal_prose_pairs
879+
preprocess_template_and_substitute expr_prose formal_prose_pairs
872880

873881
(** [short_circuit_to_prose relation_name short_circuit] returns the prose
874882
for the short-circuit expressions added as superscripts. *)

0 commit comments

Comments
 (0)