package xtmpl

  1. Overview
  2. Docs

Base types and functor to create XML documents.

Locations

type pos = Lexing.position

A position in a source (file, string, ...).

val pos : ?fname:string -> line:int -> bol:int -> char:int -> unit -> Lexing.position
type loc = pos * pos

A location is a range defined by two positions.

type 'a with_loc = 'a * loc
type 'a with_loc_option = 'a * loc option
val loc : 'a -> 'b -> 'a * 'b

loc loc_start loc_stop creates a loc structure with the given positions.

val loc_of_pos : Lexing.position -> int -> Lexing.position * Lexing.position

loc_of_pos p len creates a loc structure with starting at position p and ending at position p + len. We aware that only the pos_cnum field is modified in the ending position.

val string_of_loc : (Lexing.position * Lexing.position) -> string
val string_of_loc_option : (Lexing.position * Lexing.position) option -> string
val pp_loc_option : Format.formatter -> (Lexing.position * Lexing.position) option -> unit
val loc_sprintf : (Lexing.position * Lexing.position) option -> ('a, unit, string) format -> 'a

Errors

type error = ..
exception Error of error
val error : error -> 'a
val register_string_of_error : (error -> string option) -> unit
val string_of_error : error -> string

Documents

type cdata = {
  1. loc : loc option;
  2. text : string;
  3. quoted : bool;
}
type comment = {
  1. loc : loc option;
  2. comment : string;
}
val compare_cdata : cdata -> cdata -> int
val compare_comment : comment -> comment -> int
module type P = sig ... end
module type S = sig ... end
module Make (P : P) : S with type name = P.Attributes.key and type attr_value = P.attr_value and type attributes = P.attr_value P.Attributes.t and type data = P.data
val merge_cdata : cdata -> cdata -> cdata

merge_cdata c1 c2 returns a new cdata by merging text of the ones provided. If both have a location, the returned cdata has a location, ranging from the start position of the first to the end position of the second. If any of the cdatas has its quoted flag set to true, then the new cdata has this flag set to true.

Mapping trees

type ('n1, 'av1, 'a1, 'd1, 'n2, 'av2, 'a2, 'd2) map_param = {
  1. map_name : 'n1 -> 'n2;
    (*

    mapping names

    *)
  2. map_attr_value : 'av1 -> 'av2;
    (*

    mapping attribute values

    *)
  3. map_attributes : ('a1 -> 'a2) option;
    (*

    mapping attributes; if provided attributes will be mapped by this function; else map_name and map_attr_value will be used for mapping each pair (name, value) of attributes.

    *)
  4. map_data : 'd1 -> 'd2;
    (*

    mapping data

    *)
}

Description of how to map various types in trees

type ('a1, 'x1, 'd1, 'p1, 'a2, 'x2, 'd2, 'p2) mapper = {
  1. map_atts : 'a1 -> 'a2;
    (*

    map attributes

    *)
  2. map_xml : 'x1 -> 'x2;
    (*

    map a single tree

    *)
  3. map_xmls : 'x1 list -> 'x2 list;
    (*

    map a list of trees

    *)
  4. map_doc : 'd1 -> 'd2;
    (*

    map a whole document

    *)
  5. map_prolog : 'p1 -> 'p2;
    (*

    map prolog of a document

    *)
}

The functions to map trees and documents, obtained with Make_map.mapper.

module Make_map (X1 : S) (X2 : S) : sig ... end

This functor creates a module with a Make_map.mapper function from trees and documents of the first module to the second one.

OCaml

Innovation. Community. Security.