Module Impl.State
include Parsexp__.Parsexp_intf.Parser_state
val create : ?pos:Parsexp.Positions.pos -> unit -> t
Create a new parser state.
pos
is the initial position, it defaults to{line=1;col=0;offset=0}
.
val reset : ?pos:Parsexp.Positions.pos -> t -> unit
Reset the given parsing state. The following always succeed:
reset t ?pos; assert (t = create ?pos ())
val offset : t -> int
Number of characters fed to the parser
val line : t -> int
Position in the text
val column : t -> int
val position : t -> Parsexp.Positions.pos
val stop : t -> unit
Prevent the state from receiving any more characters. Trying to feed more characters will result in an exception, unless the state is reset.
module Read_only : sig ... end
val create : ?pos:Parsexp.Positions.pos -> ?no_sexp_is_error:bool -> (Read_only.t -> parsed_value -> unit) -> t
create ~f
create a new eager parser state.f
will be called on each s-expression found. Iff
raises, then the parser is made unusable (stop t
is invoked).no_sexp_is_error
controls the behavior of the parse when the end of input is reached and no s-expression has been found. Whenno_sexp_is_error
isfalse
(the default)feed_eoi
just returns()
, when it isfalse
feed_eoi
raises. In any case, if the end of input is reached while parsing an incomplete s-expression such as(abc
, error is raised.f
must not save the read-only parser state it receives to access it after returning. It is unspecified what values it will read if it does so.