Make.Parser_state
include Support.State.STATE
run a init
runs a
with initial state init
, returning (final, v)
where final
is the final state and v
is the output.
val traverse_list : ('a -> 'b t) -> 'a Support.List.t -> 'b Support.List.t t
val traverse_list1 : ('a -> 'b t) -> 'a Support.List1.t -> 'b Support.List1.t t
val traverse_list2 : ('a -> 'b t) -> 'a Support.List2.t -> 'b Support.List2.t t
val traverse_list_void : ('a -> _ t) -> 'a Support.List.t -> Stdlib.Unit.t t
val traverse_list1_void : ('a -> _ t) -> 'a Support.List1.t -> Stdlib.Unit.t t
val traverse_list2_void : ('a -> _ t) -> 'a Support.List2.t -> Stdlib.Unit.t t
val traverse_reverse_list :
('a -> 'b t) ->
'a Support.List.t ->
'b Support.List.t t
val traverse_reverse_list1 :
('a -> 'b t) ->
'a Support.List1.t ->
'b Support.List1.t t
val traverse_reverse_list2 :
('a -> 'b t) ->
'a Support.List2.t ->
'b Support.List2.t t
val traverse_reverse_list_void :
('a -> _ t) ->
'a Support.List.t ->
Stdlib.Unit.t t
val traverse_reverse_list1_void :
('a -> _ t) ->
'a Support.List1.t ->
Stdlib.Unit.t t
val traverse_reverse_list2_void :
('a -> _ t) ->
'a Support.List2.t ->
Stdlib.Unit.t t
val traverse_option :
('a -> 'b t) ->
'a Support.Option.t ->
'b Support.Option.t t
val traverse_option_void :
('a -> _ t) ->
'a Support.Option.t ->
Stdlib.Unit.t t
val seq_list : 'a t Support.List.t -> 'a Support.List.t t
val seq_list1 : 'a t Support.List1.t -> 'a Support.List1.t t
seq_list_void [x1; x2; ...; xn]
performs x1
, x2
, ..., xn
in order.
include Support.Monad.MONAD with type 'a t := 'a t
val return : 'a -> 'a t
return a
injects a
into the monadic type.
bind f a
is the sequential composition of two actions, passing any value produced by a
as argument to f
.
compose g f
is the Kleisli composition of f
and g
, passing the input to f
, then binding the output to g
.
( let* ) ma f
is bind f ma
. This is a binding operator, and it is used as let* a = ma in f a
.
include Support.Functor.FUNCTOR with type 'a t := 'a t
map f
is the function that maps values of t
by f
. The order of arguments is for use in function pipelines as fb = fa |> map (fun a -> (* ... *))
.
( let+ ) ma f
is map f a
. This is a binding operator, and is used as let+ a = ma in f a
include Support.Apply.APPLY with type 'a t := 'a t
ap fa fab
applies argument fa
to fab
under the abstract datatype t
.
ap_first second first
combines actions first
and second
but keeps only first
. That is, ap_first second first = first
. The order of arguments is for use in function pipelines as first = first |> ap_first second
.
ap_second second first
combines actions first
and second
but keeps only second
. That is, ap_second second first = second
. The order of arguments is for use in function pipelines as second = first |> ap_second second
.
seq2 fa1 fa2
sequentially executes actions fa1
and fa2
, and keeps their outputs under the abstract datatype t
.
seq3 fa1 fa2 fa3
sequentially executes actions fa1
, fa2
and fa3
, and keeps their outputs under the abstract datatype t
.
seq4 fa1 fa2 fa3 fa4
sequentially executes actions fa1
, fa2
, fa3
and fa4
, and keeps their outputs under the abstract datatype t
.
seq5 fa1 fa2 fa3 fa4 fa5
sequentially executes actions fa1
, fa2
, fa3
, fa4
and fa5
, and keeps their outputs under the abstract datatype t
.
lift2 f ma1 ma2
sequentially executes actions ma1
, ma2
and passes their outputs to f
.
lift3 f ma1 ma2 ma3
sequentially executes actions ma1
, ma2
, ma3
and passes their outputs to f
.
lift4 f ma1 ma2 ma3 ma4
sequentially executes actions ma1
, ma2
, ma3
, ma4
and passes their outputs to f
.
type token = Located_token.t
The type of token in the finite stream being parsed.
peek state
is (state', token_opt)
where token_opt
is the next unconsumed token in state
. If token_opt = Option.None
, then the end of the input stream was reached. Otherwise, token_opt = Option.Some token
. The token is not consumed, meaning that state'
is not advanced to the next token in the stream.
val accept : unit t
accept state
is (state', ())
where state'
is derived from state
by consuming the next token in the input stream. This effectively observes and discards the next token in state
.
insert token state
is (state', ())
where state'
is derived from state
by inserting token
at the beginning of the input stream. That is, token
is the next token in state'
.
type location = Beluga_syntax.Location.t
The type of locations with which input tokens are annotated.
next_location state
is (state', next_location_opt)
where next_location_opt
is the location of the next token in state
. This does not advance the input stream. next_location_opt = Option.None
at the end of the input stream.
previous_location state
is (state', previous_location_opt)
where previous_location_opt
is the location of the last token in state
to have been consumed. previous_location_opt = Option.None
at the beginning of the input stream.
val enable_backtracking : unit t
enable_backtracking state
is (state', ())
where state'
has backtracking enabled.
val disable_backtracking : unit t
enable_backtracking state
is (state', ())
where state'
has backtracking disabled.
val can_backtrack : bool t
can_backtrack state
is (state', flag)
where flag = true
indicates that state
and state'
allow backtracking out of an erroneous result, and flag = false
otherwise.
allow_backtracking_on_error m
is m'
such that m' state
is (state', x)
with backtracking enabled in state'
if x = Result.Error cause
. That is, this combinator enables backtracking if m'
produces an error. Backtracking then needs to be manually disabled afterwards.
val with_checkpoint :
('a, 'e) Stdlib.result t ->
('a, [> `Backtracked of 'e | `Did_not_backtrack of 'e ]) Stdlib.result t
with_checkpoint m
is m'
such that m' state
marks the current state, performs m
, then either
m state = (state', Result.Ok x)
,m state = (state', Result.Error cause)
.The output error from m
is additionally annotated with whether backtracking occurred.
In the case of a parser m
, backtracking can occur if backtracking is enabled with allow_backtracking_on_error
, or if m
did not consume any input.