package alba

  1. Overview
  2. Docs

Advanced Parser.

  • State: User state.
  • Final: Final result type of the parser.
  • Expect_msg: Error message, if something syntactically expected is not there.
  • Semantic: Semantic error message (triggered by fail message)
  • Context_msg: Each new context is opened with a value of type Context_msg.

Parameters

Signature

Modules and Types

module Context : CONTEXT with type msg = Context_msg.t
type final = Final.t
type token = char option

Combinators

include COMBINATORS with type expect = Expect_msg.t and type semantic = Semantic.t and type state = State.t and type context = Context_msg.t

Basic Combinators

type expect = Expect_msg.t
include Generic_parser.COMBINATORS with type semantic = Semantic.t
type 'a t
type semantic = Semantic.t
val return : 'a -> 'a t
val succeed : 'a -> 'a t
val fail : semantic -> 'a t
val consumer : 'a t -> 'a t
val map : ('a -> 'b) -> 'a t -> 'b t
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
val (<|>) : 'a t -> 'a t -> 'a t
val optional : 'a t -> 'a option t
val one_of : 'a t list -> 'a t
val zero_or_more : 'a t -> 'a list t
val one_or_more : 'a t -> 'a list t
val one_or_more_separated : 'a t -> _ t -> 'a list t
val zero_or_more_separated : 'a t -> _ t -> 'a list t
val skip_zero_or_more : 'a t -> int t
val skip_one_or_more : 'a t -> int t
val (|=) : ('a -> 'b) t -> 'a t -> 'b t
val (|.) : 'a t -> _ t -> 'a t
val (|==) : ('a -> 'b) t -> (unit -> 'a t) -> 'b t
val (|..) : 'a t -> (unit -> _ t) -> 'a t
val unexpected : expect -> 'a t
val backtrackable : 'a t -> expect -> 'a t
val followed_by : 'a t -> expect -> unit t
val not_followed_by : 'a t -> expect -> unit t
val (<?>) : 'a t -> expect -> 'a t

Position and State Combinators

val get_position : Position.t t
val located : 'a t -> 'a Located.t t
val get_state : State.t t
val put_state : State.t -> unit t
val update : (State.t -> State.t) -> unit t

Indentation Combinators

val absolute : 'a t -> 'a t
val absolute_at : int -> 'a t -> 'a t
val indented : 'a t -> 'a t
val maybe_indented : 'a t -> 'a t
val detached : 'a t -> 'a t
val get_bounds : (int * int option) t
val one_or_more_aligned : 'a t -> 'a list t
val zero_or_more_aligned : 'a t -> 'a list t
val skip_one_or_more_aligned : 'a t -> int t
val skip_zero_or_more_aligned : 'a t -> int t

Context Combinator

type context = Context_msg.t
val in_context : context -> 'a t -> 'a t

Character Combinators

val expect : (char -> bool) -> Expect_msg.t -> char t
val expect_end : Expect_msg.t -> unit t
val one_of_chars : string -> Expect_msg.t -> char t
val string : string -> (int -> Expect_msg.t) -> unit t
val char : char -> Expect_msg.t -> unit t
val space : Expect_msg.t -> unit t
val letter : Expect_msg.t -> char t
val digit : Expect_msg.t -> char t
val word : (char -> bool) -> (char -> bool) -> Expect_msg.t -> string t

Parser

During Parsing

include PARSER with type state = State.t
type state = State.t

State type

type parser

Parser Type

val needs_more : parser -> bool

Does the parser need more tokens (i.e. either put_character or put_end)?

val has_ended : parser -> bool

Has the parser terminated (opposite of needs_more p)?

val has_succeeded : parser -> bool

Has the parser succeeded

val has_failed : parser -> bool

Has the parser failed

val position : parser -> Position.t

The current position.

val line : parser -> int

The current line.

val column : parser -> int

The current column.

val state : parser -> state

The state of the parser.

val error_tabs : parser -> int list
val put_character : parser -> char -> parser

put_character p c feeds the parser p with the character token c. Only possible if needs_more p is valid.

val put_end : parser -> parser

put_end p signals to the parser p the end of stream. Only possible if needs_more p is valid.

Terminated Parser

val result : parser -> final option

The result the parser has produced which is either a final value or a list of dead ends. Only valid if the parser has terminated.

val error : parser -> Error.t
val lookahead : parser -> token list

The list of tokens (i.e. optional characters) which the parser has not processed at the point of termination.

Create and Run the Parser

val make : final t -> State.t -> parser

make pc st makes a parser from a parser combinator pc and the initial state st.

val run : final t -> State.t -> string -> parser

run pc st str makes a parser from the combinator pc and the initial state st and runs the parser on the string str.

OCaml

Innovation. Community. Security.