package encore
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Module Encore.LavoisierSource
Type of lavoisier's state.
The common way to use it is to fill a Buffer.t when we get the Partial case:
let rec go = function
| Partial { buffer; off; len; continue } ->
let str = Bigstringaf.substring buffer ~off ~len in
Buffer.add_string buf str ;
go (continue ~committed:len)
| Done -> Buffer.contents buf
| Fail -> failwith "serialization" in
go (emit v d)A serializer for values of type 'a.
emit_string ?chunk v t runs t with v. The serializer allocates an internal buffer of chunk byte(s) (default to 4096 bytes) and enlarge it if it's needed.
string str accepts only a string which is equal to str and emits it. Otherwise, it fails.
pure ~compare v accepts only a value 'a equal (see compare) to v and emits it. Otherwise, it fails.
choose p q runs p and emits it if succeeds. If p fails, then the output is reset and q will be run instead.
put_while0 p accepts a string which respects the predicate p and emits it.
Same as put_while1 but the given string must be not empty.
put p n accepts a string which respects the predicate p and must have n bytes. Then, it emits it otherwise it fails. For example, this ABNF:
DIGIT := '0' .. '9' NUMBER := 2DIGIT
can be translated to:
let number = put (function '0' .. '9' -> true | _ -> false) 2 at_least_put p n accepts a string which respects the predicate p and must have, at least, n bytes. Then, it emits it otherwise it fails. For example, this ABNF:
DIGIT := '0' .. '9' NUMBER := 1*DIGIT
can be translated to:
let number = at_least_put (function '0' .. '9' -> true | _ -> false) 1