Skip to content

Commit 3e4e28e

Browse files
committed
synx syntax
1 parent d519570 commit 3e4e28e

File tree

5 files changed

+92
-49
lines changed

5 files changed

+92
-49
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#### :rocket: New Feature
1616

17+
- Fix pretty printer where it would print doc comments on the same line as other attributes https://github.com/rescript-lang/syntax/pull/642
1718
- Propagte `"jsx"` configuration to dependencies https://github.com/rescript-lang/rescript-compiler/pull/5661
1819
- Add support for empty record literal `{}` for records where all fields are optional https://github.com/rescript-lang/rescript-compiler/pull/5658
1920
- Add support for empty record type (e.g. `type empty = {}`) https://github.com/rescript-lang/rescript-compiler/pull/5658

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47250,6 +47250,9 @@ val customLayout : t list -> t
4725047250
val breakParent : t
4725147251
val join : sep:t -> t list -> t
4725247252

47253+
(* [(doc1, sep1); (doc2,sep2)] joins as doc1 sep1 doc2 *)
47254+
val joinWithSep : (t * t) list -> t
47255+
4725347256
val space : t
4725447257
val comma : t
4725547258
val dot : t
@@ -47430,6 +47433,15 @@ let join ~sep docs =
4743047433
in
4743147434
concat (loop [] sep docs)
4743247435

47436+
let joinWithSep docsWithSep =
47437+
let rec loop acc docs =
47438+
match docs with
47439+
| [] -> List.rev acc
47440+
| [(x, _sep)] -> List.rev (x :: acc)
47441+
| (x, sep) :: xs -> loop (sep :: x :: acc) xs
47442+
in
47443+
concat (loop [] docsWithSep)
47444+
4743347445
let fits w stack =
4743447446
let width = ref w in
4743547447
let result = ref None in
@@ -51816,7 +51828,7 @@ and printStructureItem ~customLayout (si : Parsetree.structure_item) cmtTbl =
5181651828
in
5181751829
Doc.concat [printAttributes ~customLayout attrs cmtTbl; exprDoc]
5181851830
| Pstr_attribute attr ->
51819-
printAttribute ~customLayout ~standalone:true attr cmtTbl
51831+
fst (printAttribute ~customLayout ~standalone:true attr cmtTbl)
5182051832
| Pstr_extension (extension, attrs) ->
5182151833
Doc.concat
5182251834
[
@@ -52187,7 +52199,7 @@ and printSignatureItem ~customLayout (si : Parsetree.signature_item) cmtTbl =
5218752199
| Psig_include includeDescription ->
5218852200
printIncludeDescription ~customLayout includeDescription cmtTbl
5218952201
| Psig_attribute attr ->
52190-
printAttribute ~customLayout ~standalone:true attr cmtTbl
52202+
fst (printAttribute ~customLayout ~standalone:true attr cmtTbl)
5219152203
| Psig_extension (extension, attrs) ->
5219252204
Doc.concat
5219352205
[
@@ -56280,7 +56292,7 @@ and printAttributes ?loc ?(inline = false) ~customLayout
5628056292
Doc.concat
5628156293
[
5628256294
Doc.group
56283-
(Doc.join ~sep:Doc.line
56295+
(Doc.joinWithSep
5628456296
(List.map
5628556297
(fun attr -> printAttribute ~customLayout attr cmtTbl)
5628656298
attrs));
@@ -56381,20 +56393,22 @@ and printAttribute ?(standalone = false) ~customLayout
5638156393
Pstr_eval ({pexp_desc = Pexp_constant (Pconst_string (txt, _))}, _);
5638256394
};
5638356395
] ) ->
56384-
Doc.concat
56385-
[
56386-
Doc.text (if standalone then "/***" else "/**");
56387-
Doc.text txt;
56388-
Doc.text "*/";
56389-
]
56396+
( Doc.concat
56397+
[
56398+
Doc.text (if standalone then "/***" else "/**");
56399+
Doc.text txt;
56400+
Doc.text "*/";
56401+
],
56402+
Doc.hardLine )
5639056403
| _ ->
56391-
Doc.group
56392-
(Doc.concat
56393-
[
56394-
Doc.text (if standalone then "@@" else "@");
56395-
Doc.text (convertBsExternalAttribute id.txt);
56396-
printPayload ~customLayout payload cmtTbl;
56397-
])
56404+
( Doc.group
56405+
(Doc.concat
56406+
[
56407+
Doc.text (if standalone then "@@" else "@");
56408+
Doc.text (convertBsExternalAttribute id.txt);
56409+
printPayload ~customLayout payload cmtTbl;
56410+
]),
56411+
Doc.line )
5639856412

5639956413
and printModExpr ~customLayout modExpr cmtTbl =
5640056414
let doc =

lib/4.06.1/unstable/js_playground_compiler.ml

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47250,6 +47250,9 @@ val customLayout : t list -> t
4725047250
val breakParent : t
4725147251
val join : sep:t -> t list -> t
4725247252

47253+
(* [(doc1, sep1); (doc2,sep2)] joins as doc1 sep1 doc2 *)
47254+
val joinWithSep : (t * t) list -> t
47255+
4725347256
val space : t
4725447257
val comma : t
4725547258
val dot : t
@@ -47430,6 +47433,15 @@ let join ~sep docs =
4743047433
in
4743147434
concat (loop [] sep docs)
4743247435

47436+
let joinWithSep docsWithSep =
47437+
let rec loop acc docs =
47438+
match docs with
47439+
| [] -> List.rev acc
47440+
| [(x, _sep)] -> List.rev (x :: acc)
47441+
| (x, sep) :: xs -> loop (sep :: x :: acc) xs
47442+
in
47443+
concat (loop [] docsWithSep)
47444+
4743347445
let fits w stack =
4743447446
let width = ref w in
4743547447
let result = ref None in
@@ -51816,7 +51828,7 @@ and printStructureItem ~customLayout (si : Parsetree.structure_item) cmtTbl =
5181651828
in
5181751829
Doc.concat [printAttributes ~customLayout attrs cmtTbl; exprDoc]
5181851830
| Pstr_attribute attr ->
51819-
printAttribute ~customLayout ~standalone:true attr cmtTbl
51831+
fst (printAttribute ~customLayout ~standalone:true attr cmtTbl)
5182051832
| Pstr_extension (extension, attrs) ->
5182151833
Doc.concat
5182251834
[
@@ -52187,7 +52199,7 @@ and printSignatureItem ~customLayout (si : Parsetree.signature_item) cmtTbl =
5218752199
| Psig_include includeDescription ->
5218852200
printIncludeDescription ~customLayout includeDescription cmtTbl
5218952201
| Psig_attribute attr ->
52190-
printAttribute ~customLayout ~standalone:true attr cmtTbl
52202+
fst (printAttribute ~customLayout ~standalone:true attr cmtTbl)
5219152203
| Psig_extension (extension, attrs) ->
5219252204
Doc.concat
5219352205
[
@@ -56280,7 +56292,7 @@ and printAttributes ?loc ?(inline = false) ~customLayout
5628056292
Doc.concat
5628156293
[
5628256294
Doc.group
56283-
(Doc.join ~sep:Doc.line
56295+
(Doc.joinWithSep
5628456296
(List.map
5628556297
(fun attr -> printAttribute ~customLayout attr cmtTbl)
5628656298
attrs));
@@ -56381,20 +56393,22 @@ and printAttribute ?(standalone = false) ~customLayout
5638156393
Pstr_eval ({pexp_desc = Pexp_constant (Pconst_string (txt, _))}, _);
5638256394
};
5638356395
] ) ->
56384-
Doc.concat
56385-
[
56386-
Doc.text (if standalone then "/***" else "/**");
56387-
Doc.text txt;
56388-
Doc.text "*/";
56389-
]
56396+
( Doc.concat
56397+
[
56398+
Doc.text (if standalone then "/***" else "/**");
56399+
Doc.text txt;
56400+
Doc.text "*/";
56401+
],
56402+
Doc.hardLine )
5639056403
| _ ->
56391-
Doc.group
56392-
(Doc.concat
56393-
[
56394-
Doc.text (if standalone then "@@" else "@");
56395-
Doc.text (convertBsExternalAttribute id.txt);
56396-
printPayload ~customLayout payload cmtTbl;
56397-
])
56404+
( Doc.group
56405+
(Doc.concat
56406+
[
56407+
Doc.text (if standalone then "@@" else "@");
56408+
Doc.text (convertBsExternalAttribute id.txt);
56409+
printPayload ~customLayout payload cmtTbl;
56410+
]),
56411+
Doc.line )
5639856412

5639956413
and printModExpr ~customLayout modExpr cmtTbl =
5640056414
let doc =

lib/4.06.1/whole_compiler.ml

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -223437,6 +223437,9 @@ val customLayout : t list -> t
223437223437
val breakParent : t
223438223438
val join : sep:t -> t list -> t
223439223439

223440+
(* [(doc1, sep1); (doc2,sep2)] joins as doc1 sep1 doc2 *)
223441+
val joinWithSep : (t * t) list -> t
223442+
223440223443
val space : t
223441223444
val comma : t
223442223445
val dot : t
@@ -223617,6 +223620,15 @@ let join ~sep docs =
223617223620
in
223618223621
concat (loop [] sep docs)
223619223622

223623+
let joinWithSep docsWithSep =
223624+
let rec loop acc docs =
223625+
match docs with
223626+
| [] -> List.rev acc
223627+
| [(x, _sep)] -> List.rev (x :: acc)
223628+
| (x, sep) :: xs -> loop (sep :: x :: acc) xs
223629+
in
223630+
concat (loop [] docsWithSep)
223631+
223620223632
let fits w stack =
223621223633
let width = ref w in
223622223634
let result = ref None in
@@ -228003,7 +228015,7 @@ and printStructureItem ~customLayout (si : Parsetree.structure_item) cmtTbl =
228003228015
in
228004228016
Doc.concat [printAttributes ~customLayout attrs cmtTbl; exprDoc]
228005228017
| Pstr_attribute attr ->
228006-
printAttribute ~customLayout ~standalone:true attr cmtTbl
228018+
fst (printAttribute ~customLayout ~standalone:true attr cmtTbl)
228007228019
| Pstr_extension (extension, attrs) ->
228008228020
Doc.concat
228009228021
[
@@ -228374,7 +228386,7 @@ and printSignatureItem ~customLayout (si : Parsetree.signature_item) cmtTbl =
228374228386
| Psig_include includeDescription ->
228375228387
printIncludeDescription ~customLayout includeDescription cmtTbl
228376228388
| Psig_attribute attr ->
228377-
printAttribute ~customLayout ~standalone:true attr cmtTbl
228389+
fst (printAttribute ~customLayout ~standalone:true attr cmtTbl)
228378228390
| Psig_extension (extension, attrs) ->
228379228391
Doc.concat
228380228392
[
@@ -232467,7 +232479,7 @@ and printAttributes ?loc ?(inline = false) ~customLayout
232467232479
Doc.concat
232468232480
[
232469232481
Doc.group
232470-
(Doc.join ~sep:Doc.line
232482+
(Doc.joinWithSep
232471232483
(List.map
232472232484
(fun attr -> printAttribute ~customLayout attr cmtTbl)
232473232485
attrs));
@@ -232568,20 +232580,22 @@ and printAttribute ?(standalone = false) ~customLayout
232568232580
Pstr_eval ({pexp_desc = Pexp_constant (Pconst_string (txt, _))}, _);
232569232581
};
232570232582
] ) ->
232571-
Doc.concat
232572-
[
232573-
Doc.text (if standalone then "/***" else "/**");
232574-
Doc.text txt;
232575-
Doc.text "*/";
232576-
]
232583+
( Doc.concat
232584+
[
232585+
Doc.text (if standalone then "/***" else "/**");
232586+
Doc.text txt;
232587+
Doc.text "*/";
232588+
],
232589+
Doc.hardLine )
232577232590
| _ ->
232578-
Doc.group
232579-
(Doc.concat
232580-
[
232581-
Doc.text (if standalone then "@@" else "@");
232582-
Doc.text (convertBsExternalAttribute id.txt);
232583-
printPayload ~customLayout payload cmtTbl;
232584-
])
232591+
( Doc.group
232592+
(Doc.concat
232593+
[
232594+
Doc.text (if standalone then "@@" else "@");
232595+
Doc.text (convertBsExternalAttribute id.txt);
232596+
printPayload ~customLayout payload cmtTbl;
232597+
]),
232598+
Doc.line )
232585232599

232586232600
and printModExpr ~customLayout modExpr cmtTbl =
232587232601
let doc =

0 commit comments

Comments
 (0)