package fmlib_parse
Module Parse_with_lexer.Make
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 = charType of syntax expectations:
type expect = string * Indent.expectation optionParameters
module Lex : Interfaces.LEXER with type final = Position.range * Token.tmodule 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.tSignature
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
Feeding Tokens
type item = tokenIn order to conform to the interface Fmlib_std.Interfaces.SINK.
val needs_more : t -> boolneeds_more p Does the parser p need more tokens?
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.
Success
type final = Final.tType of the final result.
val has_succeeded : t -> boolhas_succeeded p Has the parser p succeeded?
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 optionType of expectations.
val has_failed_syntax : t -> boolhas_failed_syntax p Has the parser p failed with a syntax error?
failed_expectations p The failed expectations due to a syntax error.
Precondition: has_failed_syntax p
Semantic Errors
type semantic = Semantic.tType of semantic errors.
val has_failed_semantic : t -> boolHas the parser failed because of a semantic error?
The semantic error encountered.
Precondition: A semantic error has occurred.
State
type state = State.tType of the state of the parser (in many cases unit)
Lexer and Parser
Position
val position : t -> Position.tThe current position in the input.