@@ -378,7 +378,7 @@ let print_longident = function
378
378
| Longident. Lident txt -> Doc. text txt
379
379
| lid -> Doc. join ~sep: Doc. dot (print_longident_aux [] lid)
380
380
381
- type identifier_style = ExoticIdent | NormalIdent
381
+ type identifier_style = UppercaseExoticIdent | ExoticIdent | NormalIdent
382
382
383
383
let classify_ident_content ?(allow_uident = false ) ?(allow_hyphen = false ) txt =
384
384
if Token. is_keyword_txt txt then ExoticIdent
@@ -388,9 +388,9 @@ let classify_ident_content ?(allow_uident = false) ?(allow_hyphen = false) txt =
388
388
if i == len then NormalIdent
389
389
else if i == 0 then
390
390
match String. unsafe_get txt i with
391
+ | '\\' -> UppercaseExoticIdent
391
392
| 'A' .. 'Z' when allow_uident -> loop (i + 1 )
392
393
| 'a' .. 'z' | '_' -> loop (i + 1 )
393
- | '-' when allow_hyphen -> loop (i + 1 )
394
394
| _ -> ExoticIdent
395
395
else
396
396
match String. unsafe_get txt i with
@@ -401,10 +401,9 @@ let classify_ident_content ?(allow_uident = false) ?(allow_hyphen = false) txt =
401
401
loop 0
402
402
403
403
let print_ident_like ?allow_uident ?allow_hyphen txt =
404
- let txt = Ext_ident. unwrap_uppercase_exotic txt in
405
404
match classify_ident_content ?allow_uident ?allow_hyphen txt with
406
405
| ExoticIdent -> Doc. concat [Doc. text " \\\" " ; Doc. text txt; Doc. text " \" " ]
407
- | NormalIdent -> Doc. text txt
406
+ | UppercaseExoticIdent | NormalIdent -> Doc. text txt
408
407
409
408
let rec unsafe_for_all_range s ~start ~finish p =
410
409
start > finish
@@ -435,8 +434,12 @@ let print_poly_var_ident txt =
435
434
(* numeric poly-vars don't need quotes: #644 *)
436
435
if is_valid_numeric_polyvar_number txt then Doc. text txt
437
436
else
438
- let txt = Ext_ident. unwrap_uppercase_exotic txt in
439
437
match classify_ident_content ~allow_uident: true txt with
438
+ | UppercaseExoticIdent ->
439
+ let len = String. length txt in
440
+ (* UppercaseExoticIdent follows the \"..." format,
441
+ so removing the leading backslash is enough to transform it into polyvar style *)
442
+ Doc. text ((String. sub [@ doesNotRaise]) txt 1 (len - 1 ))
440
443
| ExoticIdent -> Doc. concat [Doc. text " \" " ; Doc. text txt; Doc. text " \" " ]
441
444
| NormalIdent -> (
442
445
match txt with
0 commit comments