ace-0.6: Attempto Controlled English parser and printer

Safe HaskellSafe-Inferred
LanguageHaskell98

ACE.Combinators

Description

Parser combinators.

Synopsis

Documentation

string :: Stream s m Token => Text -> ParsecT s u m Text Source

Match a word with the given string.

genitive :: Stream s m Token => ParsecT s u m Bool Source

Match a Saxon genitive.

number :: Stream s m Token => ParsecT s u m Integer Source

Match a word with the given string.

quoted :: Stream s m Token => ParsecT s u m Text Source

Quoted string.

comma :: Stream s m Token => ParsecT s u m () Source

A comma.

period :: Stream s m Token => ParsecT s u m () Source

A period.

strings :: Stream s m Token => [Text] -> ParsecT s u m () Source

Try to match all the given strings, or none at all.

satisfy :: Stream s m Token => (Token -> Maybe a) -> ParsecT s u m a Source

Satisfy the given predicate from the token stream.

anyToken :: Stream s m Token => ParsecT s u m Token Source

The parser anyToken accepts any kind of token. It is for example used to implement eof. Returns the accepted token.

tokenString :: Token -> [Char] Source

Make a string out of the token, for error message purposes.

tokenPosition :: SourcePos -> Token -> t -> SourcePos Source

Update the position by the token.

notFollowedBy :: Stream s m Token => ParsecT s u m Token -> ParsecT s u m () Source

notFollowedBy p only succeeds when parser p fails. This parser does not consume any input. This parser can be used to implement the 'longest match' rule. For example, when recognizing keywords (for example let), we want to make sure that a keyword is not followed by a legal identifier character, in which case the keyword is actually an identifier (for example lets). We can program this behaviour as follows:

 keywordLet  = try (do{ string "let"
                      ; notFollowedBy alphaNum
                      })

eof :: Stream s m Token => ParsecT s u m () Source

This parser only succeeds at the end of the input. This is not a primitive parser but it is defined using notFollowedBy.

 eof  = notFollowedBy anyToken <?> "end of input"