package fmlib_parse

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Generate the parser with a lexer and a token parser.

The generated parser parses a stream of characters. The lexer is used to convert the stream of characters into a stream of tokens of type Position.range * Token.t which are fed into the token parser.

The type of tokens is char.

type token = char

Type of syntax expectations:

type expect = string * Indent.expectation option

Parameters

module State : ANY
module Token : ANY
module Final : ANY
module Semantic : ANY
module Parse : Interfaces.FULL_PARSER with type state = State.t and type token = Position.range * Token.t and type expect = string * Indent.expectation option and type final = Final.t and type semantic = Semantic.t

Signature

include Interfaces.NORMAL_PARSER with type token = char and type final = Final.t and type expect = string * Indent.expectation option and type semantic = Semantic.t and type state = State.t
type t

Type of the parser.

Feeding Tokens

type token = char

Type of the tokens.

type item = token

In order to conform to the interface Fmlib_std.Interfaces.SINK.

val needs_more : t -> bool

needs_more p Does the parser p need more tokens?

val put : token -> t -> t

put tok p Push token tok into the parser p.

Even if the parser has ended, more tokens can be pushed into the parser. The parser stores the token as lookahead token.

If the parser has already received the end of the token stream via put_end, then all subsequent tokens are ignored.

val put_end : t -> t

put_end p Push and end token into the parser p.

Success

type final = Final.t

Type of the final result.

val has_succeeded : t -> bool

has_succeeded p Has the parser p succeeded?

val final : t -> final

final p The final object constructed by the parser p in case of success.

Precondition: has_succeeded p

Syntax Errors

type expect = string * Indent.expectation option

Type of expectations.

val has_failed_syntax : t -> bool

has_failed_syntax p Has the parser p failed with a syntax error?

val failed_expectations : t -> expect list

failed_expectations p The failed expectations due to a syntax error.

Precondition: has_failed_syntax p

Semantic Errors

type semantic = Semantic.t

Type of semantic errors.

val has_failed_semantic : t -> bool

Has the parser failed because of a semantic error?

val failed_semantic : t -> semantic

The semantic error encountered.

Precondition: A semantic error has occurred.

State

type state = State.t

Type of the state of the parser (in many cases unit)

val state : t -> state

The state of the parser.

Lexer and Parser

val make : Lex.t -> Parse.t -> t

make lex parse Make the parser from a lexer and a parser.

val lex : t -> Lex.t

The lexer part of the parser.

val parse : t -> Parse.t

The parser part of the parser.

Position

val position : t -> Position.t

The current position in the input.

Run on a String

val run_on_string : string -> t -> t

run_on_string str p Run the parser p on the string str.

OCaml

Innovation. Community. Security.