IdrisDoc: Text.Parser

Text.Parser

terminal : (tok -> Maybe a) -> Grammar tok True a

Succeeds if running the predicate on the next token returns Just x,
returning x. Otherwise fails.

some' : (p : Grammar tok True a) -> Grammar tok True (xs : List a ** NonEmpty xs)

Parse one or more instances of p, returning the parsed items and proof the resulting list is non-empty.

some : Grammar tok True a -> Grammar tok True (List a)

Parse one or more things

sepBy1' : (sep : Grammar tok True ()) -> (p : Grammar tok True a) -> Grammar tok True (xs : List a ** NonEmpty xs)

Parse one or more instances of p separated by s, returning the
parsed items and proof the resulting list is non-empty.

sepBy1 : Grammar tok True () -> Grammar tok True a -> Grammar tok True (List a)

Parse one or more things, separated by another thing

sepBy : Grammar tok True () -> Grammar tok True a -> Grammar tok False (List a)

Parse zero or more things, separated by another thing. May
match the empty input.

pure : (val : ty) -> Grammar tok False ty
peek : Grammar tok False tok

Look at the next token in the input

parse : (xs : List tok) -> (act : Grammar tok c ty) -> Either (ParseError tok) (ty, List tok)

Parse a list of tokens according to the given grammar. If successful,
returns a pair of the parse result and the unparsed tokens (the remaining
input).

optional : Grammar tok True a -> (ifNothing : a) -> Grammar tok False a

Optionally parse a thing, with a default value if the grammar doesn't
match. May match the empty input.

nextIs : (tok -> Bool) -> Grammar tok False tok

Check whether the next token satisfies a predicate

maybe : Grammar tok True a -> Grammar tok False (Maybe a)

Optionally parse a thing. If the grammar provides a default use optional instead.

many : Grammar tok True a -> Grammar tok False (List a)

Parse zero or more things (may match the empty input)

inf : Bool -> Type -> Type
fail : String -> Grammar tok c ty

Always fail with a message

eof : Grammar tok False ()

Succeed if the input is empty

commit : Grammar tok False ()

Commit to an alternative; if the current branch of an alternative
fails to parse, no more branches will be tried

between : (left : Grammar tok True ()) -> (right : Grammar tok True ()) -> (p : Grammar tok True a) -> Grammar tok True a

Parse an instance of p that is between left and right.

data ParseError : Type -> Type
Error : String -> List tok -> ParseError tok
data Grammar : (tok : Type) -> (consumes : Bool) -> Type -> Type

Description of a language's grammar. The tok parameter is the type
of tokens, and the consumes flag is True if the language is guaranteed
to be non-empty - that is, successfully parsing the language is guaranteed
to consume some input.

Empty : (val : ty) -> Grammar tok False ty
Terminal : (tok -> Maybe a) -> Grammar tok True a
NextIs : (tok -> Bool) -> Grammar tok False tok
EOF : Grammar tok False ()
Fail : String -> Grammar tok c ty
Commit : Grammar tok False ()
SeqEat : Grammar tok True a -> Inf (a -> Grammar tok c2 b) -> Grammar tok True b
SeqEmpty : Grammar tok c1 a -> (a -> Grammar tok c2 b) -> Grammar tok (c1 || Delay c2) b
Alt : Grammar tok c1 ty -> Grammar tok c2 ty -> Grammar tok (c1 && Delay c2) ty
(>>=) : Grammar tok c1 a -> inf c1 (a -> Grammar tok c2 b) -> Grammar tok (c1 || Delay c2) b

Sequence two grammars. If either consumes some input, the sequence is
guaranteed to consume some input. If the first one consumes input, the
second is allowed to be recursive (because it means some input has been
consumed and therefore the input is smaller)

Fixity
Left associative, precedence 5
(<|>) : Grammar tok c1 ty -> Grammar tok c2 ty -> Grammar tok (c1 && Delay c2) ty

Give two alternative grammars. If both consume, the combination is
guaranteed to consume.

Fixity
Left associative, precedence 3