@@ -25,6 +25,7 @@ type to_js_conf = {
2525 output_path : string option ;
2626 sort_choices : bool ;
2727 sort_rules : bool ;
28+ strip : bool ;
2829}
2930
3031type cmd_conf =
@@ -66,6 +67,7 @@ let to_js (conf : to_js_conf) =
6667 To_JS. run
6768 ~sort_choices: conf.sort_choices
6869 ~sort_rules: conf.sort_rules
70+ ~strip: conf.strip
6971 conf.input_path conf.output_path
7072
7173let run conf =
@@ -179,6 +181,23 @@ let to_js_cmd =
179181 in
180182 Arg. value (Arg. flag info) in
181183
184+ let strip_term : bool Term.t =
185+ let info = Arg. info [" strip" ]
186+ ~doc: " Remove elements that don't affect the generated OCaml types \
187+ such as precedences."
188+ in
189+ Arg. value (Arg. flag info) in
190+
191+ let normalize_term : bool Term.t =
192+ let info = Arg. info [" normalize" ]
193+ ~doc: " Shorthand for all the options that rearrange the grammar \
194+ so as to make them easier to compare while ignoring the parts \
195+ that don't affect the generated types in file 'CST.ml'. \
196+ It currently combines --sort-choices, --sort-rules, \
197+ and --strip."
198+ in
199+ Arg. value (Arg. flag info) in
200+
182201 let doc =
183202 " recover a tree-sitter grammar.js from grammar.json" in
184203
@@ -191,15 +210,22 @@ let to_js_cmd =
191210 https://github.com/returntocorp/ocaml-tree-sitter/issues." ;
192211 ] in
193212 let info = Term. info ~doc ~man " to-js" in
194- let config input_path output_path sort_choices sort_rules =
195- To_JS { input_path; output_path; sort_choices; sort_rules }
213+ let config input_path output_path sort_choices sort_rules strip normalize =
214+ let sort_choices, sort_rules, strip =
215+ normalize || sort_choices,
216+ normalize || sort_rules,
217+ normalize || strip
218+ in
219+ To_JS { input_path; output_path; sort_choices; sort_rules; strip }
196220 in
197221 let cmdline_term = Term. (
198222 const config
199223 $ input_path_term
200224 $ output_path_term
201225 $ sort_choices_term
202- $ sort_rules_term) in
226+ $ sort_rules_term
227+ $ strip_term
228+ $ normalize_term) in
203229 (cmdline_term, info)
204230
205231let gen_cmd =
0 commit comments