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

Add command line option to print comment table #560

Merged
merged 2 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Debug a file:
# write code in test.res
dune exec -- rescript test.res # test printer
dune exec -- rescript -print ast test.res # print ast
dune exec -- rescript -print comments test.res # print comment table
dune exec -- rescript -print ml test.res # show ocaml code
dune exec -- rescript -print res -width 80 test.res # test printer and change default print width
```
Expand Down
5 changes: 3 additions & 2 deletions cli/res_cli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ end = struct
let spec = [
("-recover", Arg.Unit (fun () -> recover := true), "Emit partial ast");
("-parse", Arg.String (fun txt -> origin := txt), "Parse reasonBinary, ml or res. Default: res");
("-print", Arg.String (fun txt -> print := txt), "Print either binary, ml, ast, sexp or res. Default: res");
("-print", Arg.String (fun txt -> print := txt), "Print either binary, ml, ast, sexp, comments or res. Default: res");
("-width", Arg.Int (fun w -> width := w), "Specify the line length for the printer (formatter)");
("-interface", Arg.Unit (fun () -> interface := true), "Parse as interface");
("-ppx", Arg.String (fun txt -> ppx := txt), "Apply a specific built-in ppx before parsing, none or jsx. Default: none");
Expand Down Expand Up @@ -229,9 +229,10 @@ module CliArgProcessor = struct
| "ml" -> Res_driver_ml_parser.printEngine
| "ast" -> Res_ast_debugger.printEngine
| "sexp" -> Res_ast_debugger.sexpPrintEngine
| "comments" -> Res_ast_debugger.commentsPrintEngine
| "res" -> Res_driver.printEngine
| target ->
print_endline ("-print needs to be either binary, ml, ast, sexp or res. You provided " ^ target);
print_endline ("-print needs to be either binary, ml, ast, sexp, comments or res. You provided " ^ target);
exit 1
in

Expand Down
15 changes: 15 additions & 0 deletions src/res_ast_debugger.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module Doc = Res_doc
module CommentTable = Res_comments_table

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

let sexpPrintEngine = SexpAst.printEngine

let commentsPrintEngine =
{
Res_driver.printImplementation =
(fun ~width:_ ~filename:_ ~comments s ->
let cmtTbl = CommentTable.make () in
CommentTable.walkStructure s cmtTbl comments;
CommentTable.log cmtTbl);
printInterface =
(fun ~width:_ ~filename:_ ~comments s ->
let cmtTbl = CommentTable.make () in
CommentTable.walkSignature s cmtTbl comments;
CommentTable.log cmtTbl);
}
7 changes: 1 addition & 6 deletions src/res_ast_debugger.mli
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@



val printEngine : Res_driver.printEngine


val sexpPrintEngine : Res_driver.printEngine

val commentsPrintEngine : Res_driver.printEngine
1 change: 0 additions & 1 deletion src/res_comments_table.ml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ let log t =
Doc.line;
])
|> Doc.toString ~width:80 |> print_endline
[@@live]

let attach tbl loc comments =
match comments with
Expand Down