package mparser

  1. Overview
  2. Docs

Predefined token parsers.

This module provides parsers for tokens that are commonly used in parsing computer languages. All parsers in this module skip the spaces (as defined by the MParser.spaces parser) that occur after a token. Where they are applied to a user-defined parser p, however, they do not skip the spaces occurring after the characters parsed by p. For example, parens p is equivalent to char '(' >> spaces >> p << char ')' << spaces.

val symbol : string -> (string, 's) t

symbol sym parses the literal string sym and returns it.

val skip_symbol : string -> (unit, 's) t

skip_symbol sym is equivalent to skip (symbol sym).

val parens : ('a, 's) t -> ('a, 's) t

parens p parses p between parentheses '(' and ')'.

val braces : ('a, 's) t -> ('a, 's) t

braces p parses p between curly braces '{' and '}'.

val brackets : ('a, 's) t -> ('a, 's) t

brackets p parses p between angle brackets '<' and '>'.

val squares : ('a, 's) t -> ('a, 's) t

squares p parses p between square brackets '[' and ']'.

val semi : (char, 's) t

Parses a semicolon ';'.

val comma : (char, 's) t

Parses a comma ','.

val colon : (char, 's) t

Parses a colon ':'.

val dot : (char, 's) t

Parses a dot '.'.

val semi_sep : ('a, 's) t -> ('a list, 's) t

semi_sep p parses zero or more occurrences of p, separated by ';'. It returns a list of the results returned by p.

val semi_sep1 : ('a, 's) t -> ('a list, 's) t

semi_sep1 p parses one or more occurrences of p, separated by ';'. It returns a list of the results returned by p.

val semi_sep_end : ('a, 's) t -> ('a list, 's) t

semi_sep_end p parses zero or more occurrences of p, separated and optionally ended by ';'. It returns a list of the results returned by p.

val semi_sep_end1 : ('a, 's) t -> ('a list, 's) t

semi_sep_end1 p parses one or more occurrences of p, separated and optionally ended by ';'. It returns a list of the results returned by p.

val semi_end : ('a, 's) t -> ('a list, 's) t

semi_end p parses zero or more occurrences of p, separated and ended by ';'. It returns a list of the results returned by p.

val semi_end1 : ('a, 's) t -> ('a list, 's) t

semi_sep_end1 p parses one or more occurrences of p, separated and ended by ';'. It returns a list of the results returned by p.

val comma_sep : ('a, 's) t -> ('a list, 's) t

comma_sep p parses zero or more occurrences of p, separated by ','. It returns a list of the results returned by p.

val comma_sep1 : ('a, 's) t -> ('a list, 's) t

comma_sep1 p parses one or more occurrences of p, separated by ','. It returns a list of the results returned by p.

val char_literal : (char, 's) t

Parses a character literal as defined in the OCaml language and returns the character. The literal may contain an escape sequence.

val string_literal : (string, 's) t

Parses a string literal as defined in the OCaml language and returns the string. The literal may contain escape sequences.

val decimal : (int, 's) t

Parses a decimal natural number and returns it as an integer value. Fails with a Message_error if the parsed number is larger than max_int.

val hexadecimal : (int, 's) t

Parses a hexadecimal natural number as defined in the OCaml language (prefixed with "0x" or "0X") and returns it as an integer value. Fails with a Message_error if the parsed number is larger than max_int.

val octal : (int, 's) t

Parses an octal natural number as defined in the OCaml language (prefixed with "0o" or "0O") and returns it as an integer value. Fails with a Message_error if the parsed number is larger than max_int.

val binary : (int, 's) t

Parses a binary natural number as defined in the OCaml language (prefixed with "0b" or "0B") and returns it as an integer value. Fails with a Message_error if the parsed number is larger than max_int.

val integer : (int, 's) t

Parses a decimal integer number and returns its value. Fails with a Message_error if the parsed number is smaller than min_int or larger than max_int.

val float : (float, 's) t

Parses floating-point literal as defined in the OCaml language and returns its value. Fails with a Message_error if the parsed number is not a valid representation of a float value.