-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ways to configure whether attributes are shown by Pp_ast
Signed-off-by: Nathan Rebours <nathan.p.rebours@gmail.com>
- Loading branch information
Showing
5 changed files
with
225 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,27 @@ | ||
open! Import | ||
|
||
val structure : Format.formatter -> structure -> unit | ||
val signature : Format.formatter -> signature -> unit | ||
val expression : Format.formatter -> expression -> unit | ||
val pattern : Format.formatter -> pattern -> unit | ||
val core_type : Format.formatter -> core_type -> unit | ||
module Config : sig | ||
type t | ||
(** Type for AST pretty-printing config *) | ||
|
||
val make : ?show_attrs:bool -> unit -> t | ||
(** Create a custom pretty-printing config. | ||
Default values are the ones that are used when no configuration is passed | ||
to the pretty-printers defined below. | ||
@param show_attrs | ||
controls whether attributes are shown or hidden. It defaults to [false]. | ||
When set to [true], records such as [expression] that have a [desc] | ||
field will only be printed if the list of attributes is non-empty, | ||
otherwise their [_desc] field will be printed directly instead, as it is | ||
the case when [show_attrs] is [false]. *) | ||
end | ||
|
||
type 'node pp = ?config:Config.t -> Format.formatter -> 'node -> unit | ||
|
||
val structure : structure pp | ||
val signature : signature pp | ||
val expression : expression pp | ||
val pattern : pattern pp | ||
val core_type : core_type pp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(cram | ||
(deps | ||
(package ppxlib))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
ppxlib-pp-ast as a --show-attrs flag that controls whether attributes are shown | ||
|
||
Consider the following .ml file: | ||
|
||
$ cat > test.ml << EOF | ||
> let x = 2 + (2[@foo 1]) | ||
> [@@bar: int * string] | ||
> EOF | ||
|
||
And how it's printed without the flag: | ||
|
||
$ ppxlib-pp-ast test.ml | ||
[ Pstr_value | ||
( Nonrecursive | ||
, [ { pvb_pat = Ppat_var "x" | ||
; pvb_expr = | ||
Pexp_apply | ||
( Pexp_ident (Lident "+") | ||
, [ ( Nolabel, Pexp_constant (Pconst_integer ( "2", None))) | ||
; ( Nolabel, Pexp_constant (Pconst_integer ( "2", None))) | ||
] | ||
) | ||
; pvb_attributes = __attrs | ||
; pvb_loc = __loc | ||
} | ||
] | ||
) | ||
] | ||
|
||
And with the flag: | ||
|
||
$ ppxlib-pp-ast --show-attrs test.ml | ||
[ Pstr_value | ||
( Nonrecursive | ||
, [ { pvb_pat = Ppat_var "x" | ||
; pvb_expr = | ||
Pexp_apply | ||
( Pexp_ident (Lident "+") | ||
, [ ( Nolabel, Pexp_constant (Pconst_integer ( "2", None))) | ||
; ( Nolabel | ||
, { pexp_desc = Pexp_constant (Pconst_integer ( "2", None)) | ||
; pexp_loc = __loc | ||
; pexp_loc_stack = __lstack | ||
; pexp_attributes = | ||
[ { attr_name = "foo" | ||
; attr_payload = | ||
PStr | ||
[ Pstr_eval | ||
( Pexp_constant | ||
(Pconst_integer ( "1", None)) | ||
, [] | ||
) | ||
] | ||
; attr_loc = __loc | ||
} | ||
] | ||
} | ||
) | ||
] | ||
) | ||
; pvb_attributes = | ||
[ { attr_name = "bar" | ||
; attr_payload = | ||
PTyp | ||
(Ptyp_tuple | ||
[ Ptyp_constr ( Lident "int", []) | ||
; Ptyp_constr ( Lident "string", []) | ||
]) | ||
; attr_loc = __loc | ||
} | ||
] | ||
; pvb_loc = __loc | ||
} | ||
] | ||
) | ||
] |