package opam-lib

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Manage filters

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 '%dentifier%'

Identifiers have the form

[package:]var[?str_if_true:str_if_false_or_undef]v}.
    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]
val to_string : OpamTypes.filter -> string

Pretty-print

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

Folds on the tree of a filter

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

Type of filter environment.

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

The type of filter idents with (optionally multiple) qualifying package names and optional string converter

val expand_string : env -> string -> string

Rewrites string interpolations within a string

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

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

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

val 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

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

Like to_value but casts the result to a string

val ident_of_var : OpamTypes.full_variable -> fident

Wraps a full_variable into a fident accessor

val 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

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

Like ident_value, but casts the result to a string

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

Like ident_value, but casts the result to a bool

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

Rewrites basename.in to basename, expanding interpolations

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

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

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

Process a simpler command, without filters

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

Extracts variables appearing in a list of commands

OCaml

Innovation. Community. Security.