Library
Module
Module type
Parameter
Class
Class type
val state : 'a option -> int -> int -> string -> 'a state
Create a new parser state
val state_value : 'a state -> 'a option
Get the parsed value
val state_offset : 'a state -> int
Get the current position of the parser inside the string
val state_line : 'a state -> int
Get the current line position of the parser inside the string
val state_rest : 'a state -> string
Get the remaining characters of the string beeing parsed
val report : error -> unit
Report an error
val pure : 'a -> 'a parser
Pure parser consuming no character and returning a value of type 'a
.
val check : (char -> bool) -> char parser
Test a predicate on the first character of the input. Resolve to this character if the predicate is verified
Binding operator using the let*
operator. This syntax is similar to Haskel's "do notation" :
let tuple_parser =
let* f1 = floatingpoint in
let* _ = char ',' in
let* f2 = floatingpoint in
pure (f1, f2)
Even if this operator can be usefull in extreme cases, users are encouraged to use the (<*>)
operator instead :
let tuple_parser =
(fun x y -> (x, y)) <$> floatingpoint <*> char ',' *> floatingpoint
The following operators are usefull to parse patterns which are left recursive by nature. The typical exemple is arithmetic expressions.
Eliminate left recursion in "left associative" chains. chainl op term
is a parser recognizing chains of terms term
bound by the operator op
. The operator is considered left associative.
Eliminate left recursion in "right associative" chains. chainr term op
is a parser recognizing chains of terms term
bound by the operator op
. The operator is considered right associative.
Feed a parser with a string (from left to right) This is verry different from do_parse
! No verifications are made on the remaining chars.
Feed a parser with a string (from right to left) p <-- input
is input --> p
. This function is just for convenience.