Skip to content

Commit

Permalink
Upgrade to parsing-utils.0.0.10
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarbin committed Aug 22, 2024
1 parent 9551961 commit 9324289
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 23 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.0.10 (2024-08-22)

### Changed

- Upgrade `parsing-utils` to `0.0.7` (breaking change).

## 0.0.9 (2024-08-19)

### Changed
Expand Down
2 changes: 1 addition & 1 deletion auto-format.opam
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ depends: [
"fpath" {>= "0.7.3"}
"fpath-base" {>= "0.0.9"}
"loc" {>= "0.0.2"}
"parsing-utils" {>= "0.0.2"}
"parsing-utils" {>= "0.0.7"}
"pp" {>= "1.2.0"}
"pp-extended" {>= "0.0.2"}
"ppx_compare" {>= "v0.17" & < "v0.18"}
Expand Down
2 changes: 1 addition & 1 deletion dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
(loc
(>= 0.0.2))
(parsing-utils
(>= 0.0.2))
(>= 0.0.7))
(pp
(>= 1.2.0))
(pp-extended
Expand Down
56 changes: 35 additions & 21 deletions src/auto_format.ml
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,32 @@ struct
}
end

module Parsing_result = struct
type 'a t = 'a Parsing_utils.Parsing_result.t

let with_dot m = if String.is_suffix m ~suffix:"." then m else m ^ "."

let or_error (t : _ t) =
match t with
| Ok t -> Ok t
| Error { loc; exn } ->
let extra =
match exn with
| Failure m -> "\nError: " ^ with_dot m
| Eio.Io _ as exn -> "\nError: " ^ with_dot (Exn.to_string exn)
| _ -> " syntax error."
in
Or_error.errorf "%s%s" (Loc.to_string loc) extra
;;
end

let rec find_fix_point ~path ~num_steps ~contents =
let%bind (program : T.t) =
Parsing_utils.parse_lexbuf
(module T_syntax)
~path
~lexbuf:(Lexing.from_string contents)
|> Parsing_result.or_error
in
let pretty_printed_contents = Pp_extended.to_string (T_pp.pp program) in
let ts_are_equal =
Expand All @@ -64,14 +84,15 @@ struct
(module T_syntax)
~path
~lexbuf:(Lexing.from_string pretty_printed_contents)
|> Parsing_result.or_error
in
Ref.set_temporarily Loc.equal_ignores_positions true ~f:(fun () ->
T.equal program program_2)
in
let ts_are_equal =
match ts_are_equal with
| Ok false -> if force allow_changes then Ok true else ts_are_equal
| t -> t
| (Ok true | Error _) as t -> t
in
match ts_are_equal with
| Ok false ->
Expand Down Expand Up @@ -271,26 +292,19 @@ into this issue.
and debug_comments =
Arg.flag [ "debug-comments" ] ~doc:"dump comments state messages"
in
match
Eio_main.run
@@ fun env ->
let cwd = Eio.Stdenv.fs env in
let path = Eio.Path.(cwd / Fpath.to_string path) in
let%bind (program : T.t) =
Ref.set_temporarily
Parsing_utils.Comments_state.debug
debug_comments
~f:(fun () -> Parsing_utils.parse (module T_syntax) ~path)
in
Ref.set_temporarily Loc.include_sexp_of_positions with_positions ~f:(fun () ->
Eio_writer.with_flow (Eio.Stdenv.stdout env) (fun stdout ->
Eio_writer.write_sexp stdout [%sexp (program : T.t)]));
return ()
with
| Ok () -> ()
| Error err ->
Stdlib.prerr_endline (Error.to_string_hum err);
Stdlib.exit 1)
Eio_main.run
@@ fun env ->
let cwd = Eio.Stdenv.fs env in
let path = Eio.Path.(cwd / Fpath.to_string path) in
let (program : T.t) =
Ref.set_temporarily
Parsing_utils.Comments_state.debug
debug_comments
~f:(fun () -> Parsing_utils.parse_exn (module T_syntax) ~path)
in
Ref.set_temporarily Loc.include_sexp_of_positions with_positions ~f:(fun () ->
Eio_writer.with_flow (Eio.Stdenv.stdout env) (fun stdout ->
Eio_writer.write_sexp stdout [%sexp (program : T.t)])))
;;

let fmt_cmd =
Expand Down

0 comments on commit 9324289

Please sign in to comment.