package mparser

  1. Overview
  2. Docs

Module MakeRegexp.TokensSource

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.

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

symbol sym parses the literal string sym and returns it.

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

skip_symbol sym is equivalent to skip (symbol sym).

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

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

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

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

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

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

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

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

Sourceval semi : (char, 's) t

Parses a semicolon ';'.

Sourceval comma : (char, 's) t

Parses a comma ','.

Sourceval colon : (char, 's) t

Parses a colon ':'.

Sourceval dot : (char, 's) t

Parses a dot '.'.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.