package opam-format

  1. Overview
  2. Docs

doc/opam-format/OpamFilter/index.html

Module OpamFilterSource

Formulas on variables, as used in opam files build scripts

Filters are a small language of formulas over strings and booleans used for conditions and text replacements. It has relational operators over strings (using version-number comparison), And, Or and Not boolean operations, dynamic casting (using strings "true" and "false"), and string interpolation. Variables are resolved using a user function returning an option, undefined values are propagated.

String interpolation uses the syntax %{identifier}%

Identifiers have the form

[package:]var[?str_if_true:str_if_false_or_undef]

The last optional part specifies a conversion from boolean to static strings.

The syntax pkg1+pkg2+pkgn:var is allowed as a shortcut to pkg1:var & pkg2:var & pkgn:var.

The special variable pkg:enable is allowed as a shortcut for pkg:installed?enable:disable

Sourceval to_string : ?custom: (context:[> `And | `Defined | `Not | `Or | `Relop ] -> paren:(?cond:bool -> string -> string) -> OpamTypes.filter -> string option) -> OpamTypes.filter -> string

Pretty-print custom ?context ?paren filter is a function that permit to customise part of filter pretty-printing.

Sourceval fold_down_left : ('a -> OpamTypes.filter -> 'a) -> 'a -> OpamTypes.filter -> 'a

Folds on the tree of a filter

Maps on all nodes of a filter, bottom-up

Sourceval string_interp_regex : Re.re

Regex matching string interpolation syntax ("%%", "%{xxx}%", or "%{xxx" if unclosed)

Sourceval extract_variables_from_string : string -> string list

Returns all the variables appearing in a filter (including the ones within string interpolations

Type of filter environment.

Sourcetype fident = OpamTypes.name option list * OpamTypes.variable * (string * string) option

The type of filter idents with (optionally multiple) qualifying package names and optional string converter. Package name None encodes the self-reference _

Maps on all variables appearing in a filter. The case where package variables are renamed differently and appear in a filter ident of the form %{pkg1+pkg2:var}% is not supported and raises Invalid_argument.

Sourceval map_variables_in_string : (OpamTypes.full_variable -> OpamTypes.full_variable) -> string -> string

Same limitation as map_variables

Sourceval map_variables_in_fident : (OpamTypes.full_variable -> OpamTypes.full_variable) -> fident -> fident

Does not handle rewriting the variables to different names (which can't be expressed with a fident anymore), and raises Invalid_argument

Sourceval distribute_negations : ?neg:bool -> OpamTypes.filter -> OpamTypes.filter

Distributes the negations to apply only to atoms

Sourceval expand_string : ?partial:bool -> ?default:(string -> string) -> env -> string -> string

Rewrites string interpolations within a string. default is applied to the fident string (e.g. what's between %{ and }%) when the expansion is undefined. If unspecified, this raises Failure.

With partial, default defaults to the identity, and is otherwise expected to return a fident. In this case, the returned string is supposed to be expanded again (expansion results are escaped, escapes are otherwise kept). This makes the function idempotent

Sourceval unclosed_expansions : string -> ((int * int) * string) list

Returns the (beginning, end) offsets and substrings of any unclosed %{ expansions

Computes the value of a filter. May raise Failure if default isn't provided

Sourceval eval_to_bool : ?default:bool -> env -> OpamTypes.filter -> bool

Like eval but casts the result to a bool. Raises Invalid_argument if not a valid bool and no default supplied.

Sourceval opt_eval_to_bool : env -> OpamTypes.filter option -> bool

Same as eval_to_bool, but takes an option as filter and returns always true on None, false when the filter is Undefined. This is the most common behaviour for using "filters" for filtering

Sourceval eval_to_string : ?default:string -> env -> OpamTypes.filter -> string

Like eval but casts the result to a string

Reduces what can be, keeps the rest unchanged

Wraps a full_variable into a fident accessor

Sourceval ident_of_string : string -> fident

A fident accessor directly referring a variable with the given name

Resolves a filter ident. Like eval, may raise Failure if no default is provided

Sourceval ident_string : ?default:string -> env -> fident -> string

Like ident_value, but casts the result to a string

Sourceval ident_bool : ?default:bool -> env -> fident -> bool

Like ident_value, but casts the result to a bool

Sourceval expand_interpolations_in_file_full : env -> src:OpamTypes.filename -> dst:OpamTypes.filename -> unit

Same as expand_interpolations_in_file but allows to set the source src and destination dst files independently instead of implying src = dst.in

Sourceval expand_interpolations_in_file : env -> OpamTypes.basename -> unit

Rewrites basename.in to basename, expanding interpolations. If the first line begins "opam-version:", assumes that expansion of variables within strings should be properly escaped. In particular, this means that Windows paths should expand correctly when generating .config files.

Sourceval commands : env -> OpamTypes.command list -> string list list

Processes filters evaluation in a command list: parameter expansion and conditional filtering

Sourceval single_command : env -> OpamTypes.arg list -> string list

Process a simpler command, without filters

Sourceval simple_arg_variables : OpamTypes.simple_arg -> OpamTypes.full_variable list

Extracts the list of variables from an argument

Sourceval commands_variables : OpamTypes.command list -> OpamTypes.full_variable list

Extracts variables appearing in a list of commands

Converts a generic formula to a filter, given a converter for atoms

Sourceval filter_formula : ?default_version:OpamTypes.version -> ?default:bool -> env -> OpamTypes.filtered_formula -> OpamTypes.formula

Resolves the filter in a filtered formula, reducing to a pure formula.

default is the assumed result for undefined filters. If a version filter doesn't resolve to a valid version, the constraint is dropped unless default_version is specified.

May raise, as other filter functions, if default is not provided and filters don't resolve.

Reduces according to what is defined in env, and returns the simplified formula

Sourceval gen_filter_formula : ('a -> [< `True | `False | `Formula of 'b OpamTypes.generic_formula ]) -> ('c * 'a) OpamFormula.formula -> ('c * 'b OpamTypes.generic_formula) OpamFormula.formula

A more generic formula reduction function, that takes a "partial resolver" as argument

Sourceval string_of_filtered_formula : OpamTypes.filtered_formula -> string
Sourceval variables_of_filtered_formula : OpamTypes.filtered_formula -> OpamTypes.full_variable list
Sourceval filter_deps : build:bool -> post:bool -> ?test:bool -> ?doc:bool -> ?dev_setup:bool -> ?dev:bool -> ?default_version:OpamTypes.version -> ?default:bool -> OpamTypes.filtered_formula -> OpamTypes.formula

Resolves the build, post, test, doc, dev flags in a filtered formula (which is supposed to have been pre-processed to remove switch and global variables). default determines the behaviour on undefined filters, and the function may raise if it is undefined. If a constraint resolves to an invalid version, it is dropped, or replaced with default_version if specified. If test, doc or dev are unspecified, they are assumed to be filtered out already and encountering them will raise an assert.

Sourceval deps_var_env : build:bool -> post:bool -> ?test:bool -> ?doc:bool -> ?dev_setup:bool -> ?dev:bool -> env

The environment used in resolving the dependency filters, as per filter_deps.

Sourceval simplify_extended_version_formula : OpamTypes.condition -> OpamTypes.condition option

Like OpamFormula.simplify_version_formula, but on filtered formulas (filters are kept unchanged, but put in front)

OCaml

Innovation. Community. Security.