@@ -398,11 +398,6 @@ let classifyIdentContent ?(allowUident = false) ?(allowHyphen = false) txt =
398
398
in
399
399
loop 0
400
400
401
- let printIdentLike ?allowUident ?allowHyphen txt =
402
- match classifyIdentContent ?allowUident ?allowHyphen txt with
403
- | ExoticIdent -> Doc. concat [Doc. text " \\\" " ; Doc. text txt; Doc. text " \" " ]
404
- | NormalIdent -> Doc. text txt
405
-
406
401
let rec unsafe_for_all_range s ~start ~finish p =
407
402
start > finish
408
403
|| p (String. unsafe_get s start)
@@ -433,7 +428,7 @@ let printPolyVarIdent txt =
433
428
if isValidNumericPolyvarNumber txt then Doc. text txt
434
429
else
435
430
match classifyIdentContent ~allow Uident:true txt with
436
- | ExoticIdent -> Doc. concat [Doc. text " \" " ; Doc. text txt; Doc. text " \" " ]
431
+ | ExoticIdent -> Doc. concat [Doc. text " \" " ; Doc. text ( Ext_ident. unwrap_exotic txt) ; Doc. text " \" " ]
437
432
| NormalIdent -> (
438
433
match txt with
439
434
| "" -> Doc. concat [Doc. text " \" " ; Doc. text txt; Doc. text " \" " ]
@@ -453,7 +448,7 @@ let printLident l =
453
448
flat [] lid
454
449
in
455
450
match l with
456
- | Longident. Lident txt -> printIdentLike txt
451
+ | Longident. Lident txt -> Doc. text txt
457
452
| Longident. Ldot (path , txt ) ->
458
453
let doc =
459
454
match flatLidOpt path with
@@ -462,7 +457,7 @@ let printLident l =
462
457
[
463
458
Doc. join ~sep: Doc. dot (List. map Doc. text txts);
464
459
Doc. dot;
465
- printIdentLike txt;
460
+ Doc. text txt;
466
461
]
467
462
| None -> Doc. text " printLident: Longident.Lapply is not supported"
468
463
in
@@ -484,7 +479,7 @@ let printIdentPath path cmtTbl =
484
479
printComments doc cmtTbl path.loc
485
480
486
481
let printStringLoc sloc cmtTbl =
487
- let doc = printIdentLike sloc.Location. txt in
482
+ let doc = Doc. text sloc.Location. txt in
488
483
printComments doc cmtTbl sloc.loc
489
484
490
485
let printStringContents txt =
@@ -1060,7 +1055,7 @@ and printValueDescription ~state valueDescription cmtTbl =
1060
1055
attrs;
1061
1056
Doc. text header;
1062
1057
printComments
1063
- (printIdentLike valueDescription.pval_name.txt)
1058
+ (Doc. text valueDescription.pval_name.txt)
1064
1059
cmtTbl valueDescription.pval_name.loc;
1065
1060
Doc. text " : " ;
1066
1061
printTypExpr ~state valueDescription.pval_type cmtTbl;
@@ -1197,7 +1192,7 @@ and printTypeDeclaration ~state ~name ~equalSign ~recFlag i
1197
1192
and printTypeDeclaration2 ~state ~recFlag (td : Parsetree.type_declaration )
1198
1193
cmtTbl i =
1199
1194
let name =
1200
- let doc = printIdentLike td.Parsetree. ptype_name.txt in
1195
+ let doc = Doc. text td.Parsetree. ptype_name.txt in
1201
1196
printComments doc cmtTbl td.ptype_name.loc
1202
1197
in
1203
1198
let equalSign = " =" in
@@ -1502,7 +1497,7 @@ and printLabelDeclaration ~state (ld : Parsetree.label_declaration) cmtTbl =
1502
1497
let name, isDot =
1503
1498
let doc, isDot =
1504
1499
if ld.pld_name.txt = " ..." then (Doc. text ld.pld_name.txt, true )
1505
- else (printIdentLike ld.pld_name.txt, false )
1500
+ else (Doc. text ld.pld_name.txt, false )
1506
1501
in
1507
1502
(printComments doc cmtTbl ld.pld_name.loc, isDot)
1508
1503
in
@@ -1603,7 +1598,7 @@ and printTypExpr ~(state : State.t) (typExpr : Parsetree.core_type) cmtTbl =
1603
1598
match typExpr.ptyp_desc with
1604
1599
| Ptyp_any -> Doc. text " _"
1605
1600
| Ptyp_var var ->
1606
- Doc. concat [Doc. text " '" ; printIdentLike ~allow Uident: true var]
1601
+ Doc. concat [Doc. text " '" ; Doc. text var]
1607
1602
| Ptyp_extension extension ->
1608
1603
printExtension ~state ~at ModuleLvl:false extension cmtTbl
1609
1604
| Ptyp_alias (typ , alias ) ->
@@ -1622,7 +1617,7 @@ and printTypExpr ~(state : State.t) (typExpr : Parsetree.core_type) cmtTbl =
1622
1617
if needsParens then Doc. concat [Doc. lparen; doc; Doc. rparen] else doc
1623
1618
in
1624
1619
Doc. concat
1625
- [typ; Doc. text " as " ; Doc. concat [Doc. text " '" ; printIdentLike alias]]
1620
+ [typ; Doc. text " as " ; Doc. concat [Doc. text " '" ; Doc. text alias]]
1626
1621
(* object printings *)
1627
1622
| Ptyp_object (fields , openFlag ) ->
1628
1623
printObject ~state ~inline: false fields openFlag cmtTbl
@@ -1879,9 +1874,9 @@ and printTypeParameter ~state (attrs, lbl, typ) cmtTbl =
1879
1874
match lbl with
1880
1875
| Asttypes. Nolabel -> Doc. nil
1881
1876
| Labelled lbl ->
1882
- Doc. concat [Doc. text " ~" ; printIdentLike lbl; Doc. text " : " ]
1877
+ Doc. concat [Doc. text " ~" ; Doc. text lbl; Doc. text " : " ]
1883
1878
| Optional lbl ->
1884
- Doc. concat [Doc. text " ~" ; printIdentLike lbl; Doc. text " : " ]
1879
+ Doc. concat [Doc. text " ~" ; Doc. text lbl; Doc. text " : " ]
1885
1880
in
1886
1881
let optionalIndicator =
1887
1882
match lbl with
@@ -2118,7 +2113,7 @@ and printExtension ~state ~atModuleLvl (stringLoc, payload) cmtTbl =
2118
2113
[
2119
2114
Doc. text " %" ;
2120
2115
(if atModuleLvl then Doc. text " %" else Doc. nil);
2121
- Doc. text txt;
2116
+ Doc. text ( Ext_ident. unwrap_exotic txt) ;
2122
2117
]
2123
2118
in
2124
2119
printComments doc cmtTbl stringLoc.Location. loc
@@ -2129,7 +2124,7 @@ and printPattern ~state (p : Parsetree.pattern) cmtTbl =
2129
2124
let patternWithoutAttributes =
2130
2125
match p.ppat_desc with
2131
2126
| Ppat_any -> Doc. text " _"
2132
- | Ppat_var var -> printIdentLike var.txt
2127
+ | Ppat_var var -> Doc. text var.txt
2133
2128
| Ppat_constant c ->
2134
2129
let templateLiteral =
2135
2130
ParsetreeViewer. hasTemplateLiteralAttr p.ppat_attributes
@@ -4377,9 +4372,9 @@ and printJsxProp ~state arg cmtTbl =
4377
4372
when lblTxt = ident (* jsx punning *) -> (
4378
4373
match lbl with
4379
4374
| Nolabel -> Doc. nil
4380
- | Labelled _lbl -> printComments (printIdentLike ident) cmtTbl argLoc
4375
+ | Labelled _lbl -> printComments (Doc. text ident) cmtTbl argLoc
4381
4376
| Optional _lbl ->
4382
- let doc = Doc. concat [Doc. question; printIdentLike ident] in
4377
+ let doc = Doc. concat [Doc. question; Doc. text ident] in
4383
4378
printComments doc cmtTbl argLoc)
4384
4379
| ( ((Asttypes. Labelled lblTxt | Optional lblTxt) as lbl),
4385
4380
{
@@ -4389,8 +4384,8 @@ and printJsxProp ~state arg cmtTbl =
4389
4384
when lblTxt = ident (* jsx punning when printing from Reason *) -> (
4390
4385
match lbl with
4391
4386
| Nolabel -> Doc. nil
4392
- | Labelled _lbl -> printIdentLike ident
4393
- | Optional _lbl -> Doc. concat [Doc. question; printIdentLike ident])
4387
+ | Labelled _lbl -> Doc. text ident
4388
+ | Optional _lbl -> Doc. concat [Doc. question; Doc. text ident])
4394
4389
| Asttypes. Labelled "_spreadProps" , expr ->
4395
4390
let doc = printExpressionWithComments ~state expr cmtTbl in
4396
4391
Doc. concat [Doc. lbrace; Doc. dotdotdot; doc; Doc. rbrace]
@@ -4404,10 +4399,10 @@ and printJsxProp ~state arg cmtTbl =
4404
4399
let lblDoc =
4405
4400
match lbl with
4406
4401
| Asttypes. Labelled lbl ->
4407
- let lbl = printComments (printIdentLike lbl) cmtTbl argLoc in
4402
+ let lbl = printComments (Doc. text lbl) cmtTbl argLoc in
4408
4403
Doc. concat [lbl; Doc. equal]
4409
4404
| Asttypes. Optional lbl ->
4410
- let lbl = printComments (printIdentLike lbl) cmtTbl argLoc in
4405
+ let lbl = printComments (Doc. text lbl) cmtTbl argLoc in
4411
4406
Doc. concat [lbl; Doc. equal; Doc. question]
4412
4407
| Nolabel -> Doc. nil
4413
4408
in
@@ -4431,7 +4426,7 @@ and printJsxProp ~state arg cmtTbl =
4431
4426
* Navabar.createElement -> Navbar
4432
4427
* Staff.Users.createElement -> Staff.Users *)
4433
4428
and printJsxName {txt = lident } =
4434
- let printIdent = printIdentLike ~allow Uident: true ~allow Hyphen: true in
4429
+ let printIdent = Doc. text in
4435
4430
let rec flatten acc lident =
4436
4431
match lident with
4437
4432
| Longident. Lident txt -> printIdent txt :: acc
@@ -4458,9 +4453,9 @@ and printArgumentsWithCallbackInFirstPosition ~dotted ~state args cmtTbl =
4458
4453
match lbl with
4459
4454
| Asttypes. Nolabel -> Doc. nil
4460
4455
| Asttypes. Labelled txt ->
4461
- Doc. concat [Doc. tilde; printIdentLike txt; Doc. equal]
4456
+ Doc. concat [Doc. tilde; Doc. text txt; Doc. equal]
4462
4457
| Asttypes. Optional txt ->
4463
- Doc. concat [Doc. tilde; printIdentLike txt; Doc. equal; Doc. question]
4458
+ Doc. concat [Doc. tilde; Doc. text txt; Doc. equal; Doc. question]
4464
4459
in
4465
4460
let callback =
4466
4461
Doc. concat
@@ -4538,9 +4533,9 @@ and printArgumentsWithCallbackInLastPosition ~state ~dotted args cmtTbl =
4538
4533
match lbl with
4539
4534
| Asttypes. Nolabel -> Doc. nil
4540
4535
| Asttypes. Labelled txt ->
4541
- Doc. concat [Doc. tilde; printIdentLike txt; Doc. equal]
4536
+ Doc. concat [Doc. tilde; Doc. text txt; Doc. equal]
4542
4537
| Asttypes. Optional txt ->
4543
- Doc. concat [Doc. tilde; printIdentLike txt; Doc. equal; Doc. question]
4538
+ Doc. concat [Doc. tilde; Doc. text txt; Doc. equal; Doc. question]
4544
4539
in
4545
4540
let callbackFitsOnOneLine =
4546
4541
lazy
@@ -4702,7 +4697,7 @@ and printArgument ~state (argLbl, arg) cmtTbl =
4702
4697
| ({Location. txt = "res.namedArgLoc" ; loc} , _ ) :: _ -> loc
4703
4698
| _ -> arg.pexp_loc
4704
4699
in
4705
- let doc = Doc. concat [Doc. tilde; printIdentLike lbl] in
4700
+ let doc = Doc. concat [Doc. tilde; Doc. text lbl] in
4706
4701
printComments doc cmtTbl loc
4707
4702
(* ~a: int (punned)*)
4708
4703
| ( Labelled lbl,
@@ -4726,7 +4721,7 @@ and printArgument ~state (argLbl, arg) cmtTbl =
4726
4721
Doc. concat
4727
4722
[
4728
4723
Doc. tilde;
4729
- printIdentLike lbl;
4724
+ Doc. text lbl;
4730
4725
Doc. text " : " ;
4731
4726
printTypExpr ~state typ cmtTbl;
4732
4727
]
@@ -4744,7 +4739,7 @@ and printArgument ~state (argLbl, arg) cmtTbl =
4744
4739
| ({Location. txt = "res.namedArgLoc" ; loc} , _ ) :: _ -> loc
4745
4740
| _ -> arg.pexp_loc
4746
4741
in
4747
- let doc = Doc. concat [Doc. tilde; printIdentLike lbl; Doc. question] in
4742
+ let doc = Doc. concat [Doc. tilde; Doc. text lbl; Doc. question] in
4748
4743
printComments doc cmtTbl loc
4749
4744
| _lbl , expr ->
4750
4745
let argLoc, expr =
@@ -4760,11 +4755,11 @@ and printArgument ~state (argLbl, arg) cmtTbl =
4760
4755
let doc = Doc. text " ..." in
4761
4756
(printComments doc cmtTbl argLoc, true )
4762
4757
| Labelled lbl ->
4763
- let doc = Doc. concat [Doc. tilde; printIdentLike lbl; Doc. equal] in
4758
+ let doc = Doc. concat [Doc. tilde; Doc. text lbl; Doc. equal] in
4764
4759
(printComments doc cmtTbl argLoc, false )
4765
4760
| Optional lbl ->
4766
4761
let doc =
4767
- Doc. concat [Doc. tilde; printIdentLike lbl; Doc. equal; Doc. question]
4762
+ Doc. concat [Doc. tilde; Doc. text lbl; Doc. equal; Doc. question]
4768
4763
in
4769
4764
(printComments doc cmtTbl argLoc, false )
4770
4765
in
@@ -4898,7 +4893,7 @@ and printExprFunParameters ~state ~inCallback ~async ~uncurried ~hasConstraint
4898
4893
]
4899
4894
when not dotted ->
4900
4895
let txtDoc =
4901
- let var = printIdentLike stringLoc.txt in
4896
+ let var = Doc. text stringLoc.txt in
4902
4897
let var =
4903
4898
match attrs with
4904
4899
| [] -> if hasConstraint then addParens var else var
@@ -4973,7 +4968,7 @@ and printExpFunParameter ~state parameter cmtTbl =
4973
4968
(List. map
4974
4969
(fun lbl ->
4975
4970
printComments
4976
- (printIdentLike lbl.Asttypes. txt)
4971
+ (Doc. text lbl.Asttypes. txt)
4977
4972
cmtTbl lbl.Asttypes. loc)
4978
4973
lbls);
4979
4974
])
@@ -5002,7 +4997,7 @@ and printExpFunParameter ~state parameter cmtTbl =
5002
4997
[
5003
4998
printAttributes ~state ppat_attributes cmtTbl;
5004
4999
Doc. text " ~" ;
5005
- printIdentLike lbl;
5000
+ Doc. text lbl;
5006
5001
]
5007
5002
| ( (Asttypes. Labelled lbl | Optional lbl),
5008
5003
{
@@ -5015,7 +5010,7 @@ and printExpFunParameter ~state parameter cmtTbl =
5015
5010
[
5016
5011
printAttributes ~state ppat_attributes cmtTbl;
5017
5012
Doc. text " ~" ;
5018
- printIdentLike lbl;
5013
+ Doc. text lbl;
5019
5014
Doc. text " : " ;
5020
5015
printTypExpr ~state typ cmtTbl;
5021
5016
]
@@ -5024,7 +5019,7 @@ and printExpFunParameter ~state parameter cmtTbl =
5024
5019
Doc. concat
5025
5020
[
5026
5021
Doc. text " ~" ;
5027
- printIdentLike lbl;
5022
+ Doc. text lbl;
5028
5023
Doc. text " as " ;
5029
5024
printPattern ~state pattern cmtTbl;
5030
5025
]
@@ -5433,7 +5428,7 @@ and printAttribute ?(standalone = false) ~state
5433
5428
(Doc. concat
5434
5429
[
5435
5430
Doc. text (if standalone then " @@" else " @" );
5436
- Doc. text id.txt;
5431
+ Doc. text ( Ext_ident. unwrap_exotic id.txt) ;
5437
5432
printPayload ~state payload cmtTbl;
5438
5433
]),
5439
5434
Doc. line )
0 commit comments