std.parser
A simple parser combinator library.
Types
type Position = Int
type ParseResult a = Result Error { value : a, buffer : OffsetString }
type Parser a = OffsetString -> ParseResult a
Parser
is a monad which parses a String
into structured values
Values
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
#[implicit]
let applicative : Applicative 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
#[implicit]
let alternative : Alternative Parser
A monoid on applicative functors.
A generalised interface for imperatively sequencing actions
The identity function, where id x == x
Parses any character. Only errors if the stream is out of input
Parses x
between l
and r
, returning the result of x
Succeeds if the next token is expected
Parses with p
zero or more times
Parses with p
one or more times
Succeeds if predicate
returns True, fails if False
is returned
let satisfy_map predicate : forall a . (Char -> Option a) -> Parser a
Succeeds if predicate
returns Some
, fails if None
is returned
Skips over whitespace characters
Parses one or more tokens passing predicate
and returns the String
between the start and
end of those tokens
Parses zero or more tokens passing predicate
and returns the String
between the start and
end of those tokens
let lazy_parser f : forall a . (() -> Parser a) -> Parser a
Creates a parser from a factory function. Useful to prevent mutually recursive parser from looping forever
Fails the parser with message
as the cause
Parses using p
and returns the String
between the start and of what p
parsed
Parses with p
zero or more times, ignoring the result of the parser
let skip_many1 p : forall a . Parser a -> Parser ()
Parses with p
one or more times, ignoring the result of the parser
Parses one of the characters of s
Parses parser
separated by sep
Parses at least one element of parser
separated by sep
Like sep_by1
but applies the function returned by op
on the left fold of successive parses
Like sep_by
but applies the function returned by op
on the left fold of successive parses
Returns message
as what was expected by p
Succeds if the next token is alphanumeric
Succeds if the next token is a letter
Succeds if the next token is a digit
Succeds if the next token is a space
Succeds if the next token is a tab
Parses input
using p