std.parser

A simple parser combinator library.

Types

type Position = Int

type Error = { position : std.parser.Position, message : String }

type ParseResult a = std.types.Result
        std.parser.Error
        { value : a, buffer : std.parser.OffsetString }

type Parser a = std.parser.OffsetString -> std.parser.ParseResult a

Parser is a monad which parses a String into structured values

Values

let functor : std.functor.Functor std.parser.Parser

A Functor represents an action on a parameterized type which does not change the structure with the mapped type.

The following laws should hold:

  • map id == id
  • map (f << g) == map f << map g

let applicative : std.applicative.Applicative std.parser.Parser

A Functor with application.

The following laws should hold:

  • wrap id <*> v = v
  • wrap (<<) <> u <> v <> w = u <> (v <*> w)
  • wrap f <*> wrap x = wrap (f x)
  • u <> wrap y = wrap (\g -> g x) <> u

let alternative : std.alternative.Alternative std.parser.Parser

A monoid on applicative functors.

let monad : std.monad.Monad std.parser.Parser

A generalised interface for imperatively sequencing actions

let parser : forall a . std.parser.Parser a -> std.parser.Parser a

The identity function, where id x == x

let any : std.parser.Parser Char

Parses any character. Only errors if the stream is out of input

let between l r x : forall a a0 a1 .
    std.parser.Parser a
        -> std.parser.Parser a0
        -> std.parser.Parser a1
        -> std.parser.Parser a1

Parses x between l and r, returning the result of x

let token expected : Char -> std.parser.Parser Char

Succeeds if the next token is expected

let many p : forall a . std.parser.Parser a -> std.parser.Parser (std.list.List a)

Parses with p zero or more times

let many1 p : forall a . std.parser.Parser a -> std.parser.Parser (std.list.List a)

Parses with p one or more times

let satisfy predicate : (Char -> std.types.Bool) -> std.parser.Parser Char

Succeeds if predicate returns True, fails if False is returned

let satisfy_map predicate : forall a . (Char -> std.types.Option a) -> std.parser.Parser a

Succeeds if predicate returns Some, fails if None is returned

let spaces : std.parser.Parser String

Skips over whitespace characters

let take1 predicate : (Char -> std.types.Bool) -> std.parser.Parser String

Parses one or more tokens passing predicate and returns the String between the start and end of those tokens

let lazy_parser f : forall a . (() -> std.parser.Parser a) -> std.parser.Parser a

Creates a parser from a factory function. Useful to prevent mutually recursive parser from looping forever

let fail message : forall a . String -> std.parser.Parser a

Fails the parser with message as the cause

let recognize p : forall a . std.parser.Parser a -> std.parser.Parser String

Parses using p and returns the String between the start and of what p parsed

let skip_many p : forall a . std.parser.Parser a -> std.parser.Parser ()

Parses with p zero or more times, ignoring the result of the parser

let skip_many1 p : forall a . std.parser.Parser a -> std.parser.Parser ()

Parses with p one or more times, ignoring the result of the parser

let one_of s : String -> std.parser.Parser Char

Parses one of the characters of s

let sep_by parser sep : forall a a0 .
    std.parser.Parser a
        -> std.parser.Parser a0
        -> std.parser.Parser (std.list.List a)

Parses parser separated by sep

let sep_by1 parser sep : forall a a0 .
    std.parser.Parser a
        -> std.parser.Parser a0
        -> std.parser.Parser (std.list.List a)

Parses at least one element of parser separated by sep

let chainl1 p op : forall a .
    std.parser.Parser a
        -> std.parser.Parser (a -> a -> a)
        -> std.parser.Parser a

Like sep_by1 but applies the function returned by op on the left fold of successive parses

let chainl p op v : forall a .
    std.parser.Parser a
        -> std.parser.Parser (a -> a -> a)
        -> a
        -> std.parser.Parser a

Like sep_by but applies the function returned by op on the left fold of successive parses

let <?> p message : forall a . std.parser.Parser a -> String -> std.parser.Parser a

Returns message as what was expected by p

let alpha_num : std.parser.Parser Char

Succeds if the next token is alphanumeric

let letter : std.parser.Parser Char

Succeds if the next token is a letter

let digit : std.parser.Parser Char

Succeds if the next token is a digit

let space : std.parser.Parser Char

Succeds if the next token is a space

let tab : std.parser.Parser Char

Succeds if the next token is a tab

let parse p input : forall a . std.parser.Parser a -> String -> std.types.Result String a

Parses input using p