Skip to content

Commit cdeecc2

Browse files
[aslspec] remove angle brackets before performing text substitutions for prose
1 parent 7265830 commit cdeecc2

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

asllib/aslspec/render.ml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ module Make (S : SPEC_VALUE) = struct
684684
missing prose templates. *)
685685
let prose_or_empty_message ~name prose =
686686
if Utils.string_is_empty prose then
687-
Format.asprintf "<empty prose for %s>"
687+
Format.asprintf "``empty prose for %s''"
688688
(Latex.spec_var_to_latex_var ~font_type:TextTT name)
689689
else prose
690690

@@ -699,6 +699,15 @@ module Make (S : SPEC_VALUE) = struct
699699
*)
700700
let var_to_prose id = spec_var_to_latex_var ~font_type:TextTT id
701701

702+
(** Removes angle brackets from the template and substitutes the
703+
placeholders with the provided substitutions. *)
704+
let preprocess_template_and_substitute template substitutions =
705+
(* Replace text inside angle brackets with the text itself. *)
706+
let template =
707+
Str.global_replace (Str.regexp "<\\([^>]*\\)>") "\\1" template
708+
in
709+
substitute template substitutions
710+
702711
(** [expr_to_prose expr] converts an expression [expr] to its prose
703712
representation. *)
704713
let rec expr_to_prose expr =
@@ -759,7 +768,7 @@ module Make (S : SPEC_VALUE) = struct
759768
| Some name -> Some (name, prose))
760769
formal_opt_prose_pairs
761770
in
762-
substitute expr_prose formal_prose_pairs
771+
preprocess_template_and_substitute expr_prose formal_prose_pairs
763772
| Record { label_opt; fields } ->
764773
let variant = Spec.record_variant_for_expr S.spec expr in
765774
let name =
@@ -800,7 +809,9 @@ module Make (S : SPEC_VALUE) = struct
800809
(fun (field, field_expr) -> (field, expr_to_prose field_expr))
801810
(fields @ unspecified_defaults)
802811
in
803-
let result = substitute expr_prose field_to_prose in
812+
let result =
813+
preprocess_template_and_substitute expr_prose field_to_prose
814+
in
804815
result
805816
| RecordUpdate { record_expr; updates } ->
806817
let record_prose = expr_to_prose record_expr in
@@ -870,7 +881,7 @@ module Make (S : SPEC_VALUE) = struct
870881
msg)
871882
in
872883
let formal_prose_pair = [ (formal_arg_name, args_prose) ] in
873-
substitute expr_prose formal_prose_pair
884+
preprocess_template_and_substitute expr_prose formal_prose_pair
874885
else
875886
let formal_arg_pairs = List.combine formal_args args in
876887
let formal_prose_pairs =
@@ -879,7 +890,7 @@ module Make (S : SPEC_VALUE) = struct
879890
named_args_for_opt_named_term opt_named_term arg)
880891
formal_arg_pairs
881892
in
882-
substitute expr_prose formal_prose_pairs
893+
preprocess_template_and_substitute expr_prose formal_prose_pairs
883894

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

0 commit comments

Comments
 (0)