Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 71e62b4

Browse files
authored
Add command line option to print comment table (#560)
* Add command line option to print comment table * Remove @@LiVe annotation from Res_comments_table.log
1 parent 7ab668b commit 71e62b4

File tree

5 files changed

+20
-9
lines changed

5 files changed

+20
-9
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ Debug a file:
6565
# write code in test.res
6666
dune exec -- rescript test.res # test printer
6767
dune exec -- rescript -print ast test.res # print ast
68+
dune exec -- rescript -print comments test.res # print comment table
6869
dune exec -- rescript -print ml test.res # show ocaml code
6970
dune exec -- rescript -print res -width 80 test.res # test printer and change default print width
7071
```

cli/res_cli.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ end = struct
190190
let spec = [
191191
("-recover", Arg.Unit (fun () -> recover := true), "Emit partial ast");
192192
("-parse", Arg.String (fun txt -> origin := txt), "Parse reasonBinary, ml or res. Default: res");
193-
("-print", Arg.String (fun txt -> print := txt), "Print either binary, ml, ast, sexp or res. Default: res");
193+
("-print", Arg.String (fun txt -> print := txt), "Print either binary, ml, ast, sexp, comments or res. Default: res");
194194
("-width", Arg.Int (fun w -> width := w), "Specify the line length for the printer (formatter)");
195195
("-interface", Arg.Unit (fun () -> interface := true), "Parse as interface");
196196
("-ppx", Arg.String (fun txt -> ppx := txt), "Apply a specific built-in ppx before parsing, none or jsx. Default: none");
@@ -229,9 +229,10 @@ module CliArgProcessor = struct
229229
| "ml" -> Res_driver_ml_parser.printEngine
230230
| "ast" -> Res_ast_debugger.printEngine
231231
| "sexp" -> Res_ast_debugger.sexpPrintEngine
232+
| "comments" -> Res_ast_debugger.commentsPrintEngine
232233
| "res" -> Res_driver.printEngine
233234
| target ->
234-
print_endline ("-print needs to be either binary, ml, ast, sexp or res. You provided " ^ target);
235+
print_endline ("-print needs to be either binary, ml, ast, sexp, comments or res. You provided " ^ target);
235236
exit 1
236237
in
237238

src/res_ast_debugger.ml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module Doc = Res_doc
2+
module CommentTable = Res_comments_table
23

34
let printEngine = Res_driver.{
45
printImplementation = begin fun ~width:_ ~filename:_ ~comments:_ structure ->
@@ -1236,3 +1237,17 @@ module SexpAst = struct
12361237
end
12371238

12381239
let sexpPrintEngine = SexpAst.printEngine
1240+
1241+
let commentsPrintEngine =
1242+
{
1243+
Res_driver.printImplementation =
1244+
(fun ~width:_ ~filename:_ ~comments s ->
1245+
let cmtTbl = CommentTable.make () in
1246+
CommentTable.walkStructure s cmtTbl comments;
1247+
CommentTable.log cmtTbl);
1248+
printInterface =
1249+
(fun ~width:_ ~filename:_ ~comments s ->
1250+
let cmtTbl = CommentTable.make () in
1251+
CommentTable.walkSignature s cmtTbl comments;
1252+
CommentTable.log cmtTbl);
1253+
}

src/res_ast_debugger.mli

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
2-
3-
41
val printEngine : Res_driver.printEngine
5-
6-
72
val sexpPrintEngine : Res_driver.printEngine
8-
3+
val commentsPrintEngine : Res_driver.printEngine

src/res_comments_table.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ let log t =
7979
Doc.line;
8080
])
8181
|> Doc.toString ~width:80 |> print_endline
82-
[@@live]
8382

8483
let attach tbl loc comments =
8584
match comments with

0 commit comments

Comments
 (0)