module Bitstring_persistent:sig..end
typepatt =Camlp4.PreCast.Syntax.Ast.patt
typeexpr =Camlp4.PreCast.Syntax.Ast.expr
typeloc_t =Camlp4.PreCast.Syntax.Ast.Loc.t
type 'a field
typepattern =patt field list
bitmatch operator), is just a
list of pattern fields.typeconstructor =expr field list
BITSTRING operator), is just a
list of constructor fields.typenamed =string * alt
type alt =
| |
Pattern of |
(* |
Pattern
| *) |
| |
Constructor of |
(* |
Constructor
| *) |
The name is used when binding a pattern from a file, but
is otherwise ignored.
val string_of_pattern : pattern -> string
val string_of_constructor : constructor -> string
val string_of_pattern_field : patt field -> string
val string_of_constructor_field : expr field -> string
The strings look similar to the syntax used by bitmatch, but
some things cannot be printed fully, eg. length expressions.
val named_to_channel : Pervasives.out_channel -> named -> unitval named_to_string : named -> stringval named_to_buffer : string -> int -> int -> named -> intval named_from_channel : Pervasives.in_channel -> named
Note: This is not type safe. The pattern/constructor must
have been written out under the same version of OCaml and
the same version of bitstring.
val named_from_string : string -> int -> named
Note: This is not type safe. The pattern/constructor must
have been written out under the same version of OCaml and
the same version of bitstring.
val create_pattern_field : loc_t ->
patt field
The pattern is unbound, the type is set to int, bit length to 32,
endianness to BigEndian, signedness to unsigned (false),
source code location to the _loc parameter, and no offset expression.
To create a complete field you need to call the set_*
functions. For example, to create { len : 8 : int }
you would do:
let field = create_pattern_field _loc in
let field = set_lident_patt field "len" in
let field = set_length_int field 8 inval set_lident_patt : patt field ->
string -> patt field
The effect is that the field { len : 8 : int } could
be created by calling set_lident_patt field "len".
val set_int_patt : patt field ->
int -> patt field
The effect is that the field { 2 : 8 : int } could
be created by calling set_int_patt field 2.
val set_string_patt : patt field ->
string -> patt field
The effect is that the field { "MAGIC" : 8*5 : string } could
be created by calling set_int_patt field "MAGIC".
val set_unbound_patt : patt field ->
patt field_).
The effect is that the field { _ : 8 : int } could
be created by calling set_unbound_patt field.
val set_patt : patt field ->
patt ->
patt fieldval set_length_int : 'a field -> int -> 'a field
The effect is that the field { len : 8 : string } could
be created by calling set_length field 8.
val set_length : 'a field ->
expr -> 'a field
The effect is that the field { len : 2*i : string } could
be created by calling set_length field <:expr< 2*i >>.
val set_endian : 'a field ->
Bitstring.endian -> 'a field
The effect is that the field { _ : 16 : bigendian } could
be created by calling set_endian field Bitstring.BigEndian.
val set_endian_expr : 'a field ->
expr -> 'a field
The effect is that the field { _ : 16 : endian(e) } could
be created by calling set_endian_expr field e.
val set_signed : 'a field -> bool -> 'a field
The effect is that the field { _ : 16 : signed } could
be created by calling set_signed field true.
val set_type_int : 'a field -> 'a fieldint.
The effect is that the field { _ : 16 : int } could
be created by calling set_type_int field.
val set_type_string : 'a field -> 'a fieldstring.
The effect is that the field { str : 16 : string } could
be created by calling set_type_string field.
val set_type_bitstring : 'a field -> 'a fieldbitstring.
The effect is that the field { _ : 768 : bitstring } could
be created by calling set_type_bitstring field.
val set_location : 'a field ->
loc_t -> 'a fieldval set_offset_int : 'a field -> int -> 'a field
The effect is that the field { _ : 8 : offset(160) } could
be created by calling set_offset_int field 160.
val set_offset : 'a field ->
expr -> 'a field
The effect is that the field { _ : 8 : offset(160) } could
be created by calling set_offset_int field <:expr< 160 >>.
val set_no_offset : 'a field -> 'a fieldval set_check : 'a field ->
expr -> 'a fieldval set_no_check : 'a field -> 'a fieldval set_bind : 'a field ->
expr -> 'a fieldval set_no_bind : 'a field -> 'a fieldval set_save_offset_to : 'a field ->
patt -> 'a fieldval set_save_offset_to_lident : 'a field -> string -> 'a fieldval set_no_save_offset_to : 'a field -> 'a fieldval create_constructor_field : loc_t ->
expr field
The defaults are the same as for Bitstring_persistent.create_pattern_field
except that the expression is initialized to 0.
val set_lident_expr : expr field ->
string -> expr field
The effect is that the field { len : 8 : int } could
be created by calling set_lident_expr field "len".
val set_int_expr : expr field ->
int -> expr field
The effect is that the field { 2 : 8 : int } could
be created by calling set_int_expr field 2.
val set_string_expr : expr field ->
string -> expr field
The effect is that the field { "MAGIC" : 8*5 : string } could
be created by calling set_int_expr field "MAGIC".
val set_expr : expr field ->
expr ->
expr fieldval get_patt : patt field ->
pattval get_expr : expr field ->
exprval get_length : 'a field -> exprtype endian_expr =
| |
ConstantEndian of |
| |
EndianExpr of |
val get_endian : 'a field -> endian_exprBitstring_persistent.endian_expr which
could be a constant or an OCaml expression.val get_signed : 'a field -> booltype field_type =
| |
Int |
| |
String |
| |
Bitstring |
val get_type : 'a field -> field_typeInt, String or Bitstring.val get_location : 'a field -> loc_tval get_offset : 'a field -> expr optionNone if there is none.val get_check : 'a field -> expr optionNone if there is none.val get_bind : 'a field -> expr optionNone if there is none.val get_save_offset_to : 'a field -> patt optionNone if there is none.