package dunolint
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=1b064927c9e1ef5352a1886ae34a206fef0ce6a913c19a77b0162acc108e0e50
sha512=6cbc08ba318bef6584d15a4491e3dde1bf436109ce0f8b7c400a9f91bbcee64c5785bc924df11eafe98243ec2f188a7f92c58c5062729f3e2af1e9977f1a5e67
doc/dunolint.dunolinter/Dunolinter/Sexp_handler/index.html
Module Dunolinter.Sexp_handler
Source
A handler for fields found in a dune stanza (in files "dune", "dune-project", etc.)
Such field is typically identified by its name, and then it is immediately followed by a variable number of arguments.
For example:
(name dunolint)
(libraries base sexps-rewriter)
A field starts with an atom (the field name), and the arguments are in a list of sexps.
By that definition, a stanza is a field itself, and its subfields just as well.
A util to create a handler for an atom field, that is one that expects exactly one required argument that is an Sexp.Atom
.
A util to create a generic field handler that doesn't try to parse its arguments.
A util to create a handler from a single sexpable type. The handler will expect exactly one value, which will be parsed and written (or replaced) according to the sexp serializer provided.
module Make_sexpable_list
(_ : sig ... end)
(M : Base.Sexpable.S) :
S with type t = M.t Base.list
A util to create a handler for multiple args with the same sexpable type. The handler will expect a list of arguments, which will each be parsed and written (or replaced) according to the sexp serializer provided.
module Make_sexpable_ordered_set
(_ : sig ... end)
(M : Base.Sexpable.S) :
S with type t = M.t Ordered_set.t
A util to create a handler for an ordered set where individual elements have the same sexpable type. The handler will expect a list of arguments, will support and parse the ordered set constructors of dune, and parse the elements according to the sexp serializer provided.
Utils
val replace_field :
sexps_rewriter:Sexps_rewriter.t ->
field:Base.Sexp.t ->
new_field:Base.Sexp.t ->
Base.unit
Replace a field in a sexps_rewriter if the new field is different from the old one.
val find :
(module S with type t = 'a) ->
sexps_rewriter:Sexps_rewriter.t ->
fields:Base.Sexp.t Base.list ->
'a Base.option
A convenient wrapper for read
that finds the field to read from a list of fields embedded within a containing list of fields. The first field with the expected name is chosen and then we call read
on it.
val get_args :
field_name:Base.string ->
sexps_rewriter:Sexps_rewriter.t ->
field:Base.Sexp.t ->
Base.Sexp.t Base.list
Destruct the given field and verify it has the correct field name. Return the args then. If the field doesn't have the right shape, and error is raised, using a location found via sexps_rewriter
.
val insert_new_fields :
sexps_rewriter:Sexps_rewriter.t ->
indicative_field_ordering:Base.string Base.list ->
fields:Base.Sexp.t Base.list ->
new_fields:Base.Sexp.t Base.list ->
Base.unit
During a dunolint lint, insert all fields found in new_fields
that are not present in the existing fields
. For those that are already present, it will be necessary to merge them with the expected value, see the rewrite
functions of the module that corresponds to that particular field. For example: Dune_linter.Library.rewrite
.
val read :
(module S with type t = 'a) ->
sexps_rewriter:Sexps_rewriter.t ->
field:Base.Sexp.t ->
('a, Pplumbing_err.Err.t) Base.Result.t
Wrap M.read
with an exception handler that improves the error message and add location when able.
Shared utils to map a Parsexp range to a Loc.t.