package b0

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

Module B0_text.TdecSource

Text decoder.

A text decoder inputs UTF-8 data and checks its validity. It updates locations according to advances in the input and has a token buffer used for lexing.

Decoder

Sourcetype t

The type for UTF-8 text decoders.

Sourceval create : ?file:Tloc.fpath -> string -> t

create ~file input decodes input using file (defaults to Tloc.no_file) for text location.

Locations

Sourceval file : t -> Tloc.fpath

file d is the input file.

Sourceval pos : t -> Tloc.pos

pos d is the current decoding byte position.

Sourceval line : t -> Tloc.line_pos

line d is the current line position. Lines increment as described here.

Sourceval loc : t -> sbyte:Tloc.pos -> ebyte:Tloc.pos -> sline:Tloc.line_pos -> eline:Tloc.line_pos -> Tloc.t

loc d ~sbyte ~ebyte ~sline ~eline is a location with the correponding position ranges and file according to file.

Sourceval loc_to_here : t -> sbyte:Tloc.pos -> sline:Tloc.line_pos -> Tloc.t

loc_to_here d ~sbyte ~sline is a location that starts at ~sbyte and ~sline and ends at the current decoding position.

Sourceval loc_here : t -> Tloc.t

loc_here d is like loc_to_here with the start position at the current decoding position.

Errors

Sourceexception Err of Tloc.t * string

The exception for errors. A location and an error message

Sourceval err : Tloc.t -> string -> 'b

err loc msg raises Err (loc, msg) with no trace.

Sourceval err_to_here : t -> sbyte:Tloc.pos -> sline:Tloc.line_pos -> ('a, Format.formatter, unit, 'b) format4 -> 'a

err_to_here d ~sbyte ~sline fmt ... is err d (loc_to_here d ~sbyte ~sline) fmt ...

Sourceval err_here : t -> ('a, Format.formatter, unit, 'b) format4 -> 'a

err_here d is err d (loc_here d) fmt ....

Error message helpers

Sourceval err_suggest : ?dist:int -> string list -> string -> string list

err_suggest ~dist candidates s are the elements of candidates whose edit distance is the smallest to s and at most at a distance of dist of s (defaults to 2). If multiple results are returned the order of candidates is preserved.

Sourcetype 'a fmt = Format.formatter -> 'a -> unit

The type for formatters.

Sourceval pp_and_enum : ?empty:unit fmt -> 'a fmt -> 'a list fmt

and_enum ~empty pp_v ppf l formats l according to its length.

  • 0, formats empty (defaults to nop).
  • 1, formats the element with pp_v.
  • 2, formats "%a and %a" with the list elements
  • n, formats "%a, ... and %a" with the list elements
Sourceval pp_or_enum : ?empty:unit fmt -> 'a fmt -> 'a list fmt

or_enum is like pp_and_enum but uses "or" instead of "and".

Sourceval pp_did_you_mean : 'a fmt -> 'a list fmt

did_you_mean pp_v formats "Did you mean %a ?" with pp_or_enum if the list is non-empty and nop otherwise.

Sourceval pp_must_be : 'a fmt -> 'a list fmt

must_be pp_v formats "Must be %a." with pp_or_enum if the list is non-empty and nop otherwise.

Sourceval pp_unknown : kind:unit fmt -> 'a fmt -> 'a fmt

pp_unknown ~kind pp_v formats "Unknown %a %a." kind () pp_v.

Sourceval pp_unknown' : kind:unit fmt -> 'a fmt -> hint:('a fmt -> 'a list fmt) -> ('a * 'a list) fmt

pp_unknown' ~kind pp_v ~hint (v, hints) formats pp_unknown followed by a space and hint pp_v hints if hints is non-empty.

Decoding

Sourceval eoi : t -> bool

eoi d is true iff the decoder is at the end of input.

Sourceval byte : t -> int

byte d is the byte at current position or 0xFFFF if eoi d is true.

Sourceval accept_uchar : t -> unit

accept_uchar d accepts an UTF-8 encoded character starting at the current position and moves to the byte after it. Raises Err in case of UTF-8 decoding error.

Sourceval accept_byte : t -> unit

accept_byte d accepts the byte at the current position and moves to the next byte. Warning. Faster than accept_uchar but the client needs to make sure it's not accepting invalid UTF-8 data, i.e. that byte d is an US-ASCII encoded character (i.e. <= 0x7F).

Token buffer

Sourceval tok_reset : t -> unit

tok_reset d resets the token.

Sourceval tok_pop : t -> string

tok_pop d returns the token and tok_resets it.

Sourceval tok_accept_uchar : t -> unit

tok_accept_uchar d is like accept_uchar but also adds the UTF-8 byte sequence to the token.

Sourceval tok_accept_byte : t -> unit

tok_accept_byte d is like accept_byte but also adds the byte to the token. Warning. accept_byte's warning applies.

Sourceval tok_add_byte : t -> int -> unit

tok_add_byte d b adds byte b to the token.

Sourceval tok_add_bytes : t -> string -> unit

tok_add_byte d s adds bytes s to the token.

Sourceval tok_add_char : t -> char -> unit

tok_add_char d c adds character c to the token.

Sourceval tok_add_uchar : t -> Uchar.t -> unit

tok_add_uchar t u adds the UTF-8 encoding of character u to the token.