1
1
(*
2
2
This CLI isn't used apart for this repo's testing purposes. The syntax
3
- itself is used by BS programmatically through various other apis.
3
+ itself is used by ReScript's compiler programmatically through various other apis.
4
4
*)
5
5
6
6
(*
21
21
But when used by this cli file, that coloring logic doesn't render properly
22
22
because we're compiling against vanilla OCaml 4.06 instead of ReScript's
23
23
OCaml fork. For example, the vanilla compiler doesn't support the `dim`
24
- color (grey). So we emulate the right coloring logic by copy pasting how BS'
25
- OCaml does it.
24
+ color (grey). So we emulate the right coloring logic by copy pasting how our
25
+ forked OCaml compiler does it.
26
26
*)
27
27
module Color = struct
28
28
(* use ANSI color codes, see https://en.wikipedia.org/wiki/ANSI_escape_code *)
@@ -164,7 +164,6 @@ module ResClflags: sig
164
164
val origin : string ref
165
165
val files : string list ref
166
166
val interface : bool ref
167
- val report : string ref
168
167
val ppx : string ref
169
168
170
169
val parse : unit -> unit
@@ -175,27 +174,26 @@ end = struct
175
174
let files = ref []
176
175
let addFilename filename = files := filename::(! files)
177
176
178
- let print = ref " "
179
- let origin = ref " "
177
+ let print = ref " res "
178
+ let origin = ref " res "
180
179
let interface = ref false
181
- let report = ref " pretty"
182
180
let ppx = ref " "
183
181
184
- let usage = " Usage:\n rescript <options> <file>\n\n " ^
182
+ let usage = " \n **This command line is for the repo developer's testing purpose only. DO NOT use it in production**!\n\n " ^
183
+ " Usage:\n rescript <options> <file>\n\n " ^
185
184
" Examples:\n " ^
186
185
" rescript myFile.res\n " ^
187
- " rescript -parse ml -print ns myFile.ml\n " ^
188
- " rescript -parse ns -print binary -interface myFile.resi\n\n " ^
186
+ " rescript -parse ml -print res myFile.ml\n " ^
187
+ " rescript -parse res -print binary -interface myFile.resi\n\n " ^
189
188
" Options are:"
190
189
191
190
let spec = [
192
191
(" -recover" , Arg. Unit (fun () -> recover := true ), " Emit partial ast" );
193
- (" -parse" , Arg. String (fun txt -> origin := txt), " Parse reasonBinary, ml or ns . Default: ns " );
194
- (" -print" , Arg. String (fun txt -> print := txt), " Print either binary or ns . Default: ns " );
192
+ (" -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 " );
195
194
(" -width" , Arg. Int (fun w -> width := w), " Specify the line length for the printer (formatter)" );
196
195
(" -interface" , Arg. Unit (fun () -> interface := true ), " Parse as interface" );
197
196
(" -ppx" , Arg. String (fun txt -> ppx := txt), " Apply a specific built-in ppx before parsing, none or jsx. Default: none" );
198
- (* ("-report", Arg.String (fun txt -> report := txt), "Stylize errors and messages using color and context. Accepts `Pretty` and `Plain`. Default `Plain`") *)
199
197
]
200
198
201
199
let parse () = Arg. parse spec addFilename usage
@@ -204,29 +202,35 @@ end
204
202
module CliArgProcessor = struct
205
203
type backend = Parser : ('diagnostics ) Res_driver .parsingEngine -> backend [@@ unboxed]
206
204
207
- let processFile ~isInterface ~width ~recover ~origin ~target ~report : _ ~ ppx filename =
205
+ let processFile ~isInterface ~width ~recover ~origin ~target ~ppx filename =
208
206
try
209
207
let len = String. length filename in
210
208
let processInterface =
211
209
isInterface || len > 0 && (String. get [@ doesNotRaise]) filename (len - 1 ) = 'i'
212
210
in
213
211
let parsingEngine =
214
- match origin with
215
- | "reasonBinary" -> Parser Res_driver_reason_binary. parsingEngine
216
- | "ml" | "ocaml" -> Parser Res_driver_ml_parser. parsingEngine
217
- | _ -> Parser Res_driver. parsingEngine
212
+ match origin with
213
+ | "reasonBinary" -> Parser Res_driver_reason_binary. parsingEngine
214
+ | "ml" -> Parser Res_driver_ml_parser. parsingEngine
215
+ | "res" -> Parser Res_driver. parsingEngine
216
+ | origin ->
217
+ print_endline (" -parse needs to be either reasonBinary, ml or res. You provided " ^ origin);
218
+ exit 1
218
219
in
219
220
let printEngine =
220
221
match target with
221
- | "ml" | "ocaml" -> Res_driver_ml_parser. printEngine
222
+ | "binary" -> Res_driver_binary. printEngine
223
+ | "ml" -> Res_driver_ml_parser. printEngine
222
224
| "ast" -> Res_ast_debugger. printEngine
223
225
| "sexp" -> Res_ast_debugger. sexpPrintEngine
224
- | "binary" -> Res_driver_binary. printEngine
225
- | _ -> Res_driver. printEngine
226
+ | "res" -> Res_driver. printEngine
227
+ | target ->
228
+ print_endline (" -print needs to be either binary, ml, ast, sexp or res. You provided " ^ target);
229
+ exit 1
226
230
in
227
231
228
232
let forPrinter = match target with
229
- | "res" | "rescript" | " sexp" -> true
233
+ | "res" | "sexp" -> true
230
234
| _ -> false
231
235
in
232
236
@@ -239,7 +243,7 @@ module CliArgProcessor = struct
239
243
backend.stringOfDiagnostics
240
244
~source: parseResult.source
241
245
~filename: parseResult.filename
242
- parseResult.diagnostics;
246
+ parseResult.diagnostics;
243
247
if recover then
244
248
printEngine.printInterface
245
249
~width ~filename ~comments: parseResult.comments parseResult.parsetree
@@ -292,7 +296,6 @@ let [@raises Invalid_argument, exit] () =
292
296
~recover: ! ResClflags. recover
293
297
~target: ! ResClflags. print
294
298
~origin: ! ResClflags. origin
295
- ~report: ! ResClflags. report
296
299
~ppx: ! ResClflags. ppx
297
300
" "
298
301
| files ->
@@ -303,7 +306,6 @@ let [@raises Invalid_argument, exit] () =
303
306
~recover: ! ResClflags. recover
304
307
~target: ! ResClflags. print
305
308
~origin: ! ResClflags. origin
306
- ~report: ! ResClflags. report
307
309
~ppx: ! ResClflags. ppx
308
310
filename
309
311
) files
0 commit comments