Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve: remove utility functions from Fmt_ast #1059

Merged
merged 8 commits into from
Oct 9, 2019
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 CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### (master)

+ Improve: remove utility functions from Fmt_ast (#1059) (Guillaume Petiot)
+ Fix newlines and indentation in toplevel extension points (#1054) (Guillaume Petiot)
+ Fix placement of doc comments around extensions (#1052) (Jules Aguillon)
+ Improve: inline extensions that do not break (#1050) (Guillaume Petiot)
Expand Down
38 changes: 37 additions & 1 deletion src/Conf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2078,4 +2078,40 @@ and debug = !debug

and check = !check

let parse_line_in_attribute = parse_line ~from:`Attribute
open Migrate_ast.Parsetree

let update ?(quiet = false) c {attr_name= {txt; loc}; attr_payload; _} =
let result =
match txt with
| "ocamlformat" -> (
match attr_payload with
| PStr
[ { pstr_desc=
Pstr_eval
( { pexp_desc= Pexp_constant (Pconst_string (str, None))
; pexp_attributes= []
; _ }
, [] )
; _ } ] ->
parse_line ~from:`Attribute c str
| _ -> Error (`Malformed "string expected") )
| _ when String.is_prefix ~prefix:"ocamlformat." txt ->
Error
(`Malformed
(Format.sprintf "unknown suffix %S"
(String.chop_prefix_exn ~prefix:"ocamlformat." txt)))
| _ -> Ok c
in
match result with
| Ok conf -> conf
| Error error ->
let reason = function
| `Malformed line -> Format.sprintf "Invalid format %S" line
| `Misplaced (name, _) -> Format.sprintf "%s not allowed here" name
| `Unknown (name, _) -> Format.sprintf "Unknown option %s" name
| `Bad_value (name, value) ->
Format.sprintf "Invalid value for %s: %S" name value
in
let w = Warnings.Attribute_payload (txt, reason error) in
if (not c.quiet) && not quiet then Compat.print_warning loc w ;
c
12 changes: 3 additions & 9 deletions src/Conf.mli
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,6 @@ val debug : bool
val check : bool
(** Check whether the input files already are formatted. *)

val parse_line_in_attribute :
t
-> string
-> ( t
, [ `Unknown of string * string
| `Bad_value of string * string
| `Malformed of string
| `Misplaced of string * string ] )
Result.t
val update : ?quiet:bool -> t -> Migrate_ast.Parsetree.attribute -> t
(** [update ?quiet c a] updates configuration [c] after reading attribute
[a]. [quiet] is false by default. *)
Loading