package xtmpl

  1. Overview
  2. Docs

Module Xtmpl.TypesSource

Base types and functor to create XML documents.

Locations

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

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

A location is a range defined by two positions.

Sourcetype 'a with_loc = 'a * loc
Sourcetype 'a with_loc_option = 'a * loc option
Sourceval loc : 'a -> 'b -> 'a * 'b

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

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.

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

Errors

Sourcetype error = ..
Sourceexception Error of error
Sourceval error : error -> 'a
Sourceval register_string_of_error : (error -> string option) -> unit
Sourceval string_of_error : error -> string

Documents

Sourcetype cdata = {
  1. loc : loc option;
  2. text : string;
  3. quoted : bool;
}
Sourcetype comment = {
  1. loc : loc option;
  2. comment : string;
}
Sourceval compare_cdata : cdata -> cdata -> int
Sourceval compare_comment : comment -> comment -> int
Sourcemodule type P = sig ... end
Sourcemodule type S = sig ... end
Sourcemodule 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
Sourceval 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

Sourcetype ('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

Sourcetype ('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.

Sourcemodule 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.