@@ -389,7 +389,14 @@ module Printing = struct
389389 open Fmt
390390
391391 let trailing_space (t : 'a Fmt.t ) : 'a Fmt.t = fun ppf -> pf ppf " %a@ " t
392- let pp_identifier ppf = string ppf
392+
393+ let pp_identifier ppf s =
394+ if Common.Unicode. is_ascii s then string ppf s
395+ else
396+ (* so called "Universal character names" - not required on newer compilers
397+ but hopefully more backward-compatible *)
398+ let f _ c = Fmt. pf ppf " \\ u%04X" (Uchar. to_scalar c) in
399+ Common.Unicode. iter_uchars s f
393400
394401 let rec pp_type_ ppf t =
395402 match t with
@@ -473,8 +480,8 @@ module Printing = struct
473480 pf ppf " <@,%a>" (list ~sep: comma pp_type_) types in
474481 match e with
475482 | Literal s -> pf ppf " %s" s
476- | Var id -> string ppf id
477- | VarRef id -> pf ppf " &%s " id
483+ | Var id -> pp_identifier ppf id
484+ | VarRef id -> pf ppf " &%a " pp_identifier id
478485 | Parens e -> pf ppf " (%a)" pp_expr e
479486 | Cast (t , e ) -> pf ppf " @[(%a)@ %a@]" pp_type_ t pp_expr e
480487 | Constructor (t , es ) ->
@@ -491,7 +498,7 @@ module Printing = struct
491498 | StreamInsertion (e , es ) ->
492499 pf ppf " %a <<@[@ %a@]" pp_expr e (list ~sep: comma pp_expr) es
493500 | FunCall (fn , tys , es ) ->
494- pf ppf " @[<hov 2>%s %a(@,%a@])" fn maybe_templates tys
501+ pf ppf " @[<hov 2>%a %a(@,%a@])" pp_identifier fn maybe_templates tys
495502 (list ~sep: comma pp_expr) es
496503 | MethodCall (e , fn , tys , es ) ->
497504 pf ppf " @[<hov 2>%a.%s%a(%a)@]" pp_expr e fn maybe_templates tys
@@ -519,8 +526,8 @@ module Printing = struct
519526 pf ppf " {@[<hov>%a@]}" (list ~sep: comma pp_expr) es in
520527 let static = if static then " static " else " " in
521528 let constexpr = if constexpr then " constexpr " else " " in
522- pf ppf " @[<hov 2>%s%s%a@ %s %a@]" static constexpr pp_type_ type_ name
523- pp_init init
529+ pf ppf " @[<hov 2>%s%s%a@ %a %a@]" static constexpr pp_type_ type_
530+ pp_identifier name pp_init init
524531
525532 let rec pp_stmt ppf s =
526533 match s with
0 commit comments