Portability | non-portable |
---|---|
Stability | experimental |
Maintainer | ekmett@gmail.com |
Safe Haskell | Safe-Infered |
Parsers that comprehend whitespace and identifier styles
idStyle = haskellIdentifierStyle { styleReserved = ... } identifier = ident haskellIdentifierStyle reserved = reserve haskellIdentifierStyle
- class CharParsing m => TokenParsing m where
- whiteSpace :: TokenParsing m => m ()
- token :: TokenParsing m => m a -> m a
- charLiteral :: TokenParsing m => m Char
- stringLiteral :: TokenParsing m => m String
- natural :: TokenParsing m => m Integer
- integer :: TokenParsing m => m Integer
- double :: TokenParsing m => m Double
- naturalOrDouble :: TokenParsing m => m (Either Integer Double)
- symbol :: TokenParsing m => String -> m String
- symbolic :: TokenParsing m => Char -> m Char
- parens :: TokenParsing m => m a -> m a
- braces :: TokenParsing m => m a -> m a
- angles :: TokenParsing m => m a -> m a
- brackets :: TokenParsing m => m a -> m a
- comma :: TokenParsing m => m Char
- colon :: TokenParsing m => m Char
- dot :: TokenParsing m => m Char
- semiSep :: TokenParsing m => m a -> m [a]
- semiSep1 :: TokenParsing m => m a -> m [a]
- commaSep :: TokenParsing m => m a -> m [a]
- commaSep1 :: TokenParsing m => m a -> m [a]
- data IdentifierStyle m = IdentifierStyle {
- styleName :: String
- styleStart :: m Char
- styleLetter :: m Char
- styleReserved :: HashSet String
- liftIdentifierStyle :: (MonadTrans t, Monad m) => IdentifierStyle m -> IdentifierStyle (t m)
- ident :: TokenParsing m => IdentifierStyle m -> m String
- reserve :: TokenParsing m => IdentifierStyle m -> String -> m ()
Documentation
class CharParsing m => TokenParsing m whereSource
Usually, someSpace consists of one or more occurrences of a space
.
Some parsers may choose to recognize line comments or block (multi line)
comments as white space as well.
Called when we enter a nested pair of symbols. Overloadable to enable disabling layout
The token parser |semi| parses the character ';' and skips any trailing white space. Returns the character ';'. Overloadable to permit automatic semicolon insertion or Haskell-style layout.
TokenParsing m => TokenParsing (IdentityT m) | |
(TokenParsing m, Monoid w) => TokenParsing (WriterT w m) | |
(TokenParsing m, Monoid w) => TokenParsing (WriterT w m) | |
TokenParsing m => TokenParsing (StateT s m) | |
TokenParsing m => TokenParsing (StateT s m) | |
TokenParsing m => TokenParsing (ReaderT e m) | |
(TokenParsing m, Monoid w) => TokenParsing (RWST r w s m) | |
(TokenParsing m, Monoid w) => TokenParsing (RWST r w s m) |
Token Parsers
whiteSpace :: TokenParsing m => m ()Source
Skip zero or more bytes worth of white space. More complex parsers are‗ free to consider comments as white space.
token :: TokenParsing m => m a -> m aSource
token p
first applies parser p
and then the whiteSpace
parser, returning the value of p
. Every lexical
token (token) is defined using token
, this way every parse
starts at a point without white space. Parsers that use token
are
called token parsers in this document.
The only point where the whiteSpace
parser should be
called explicitly is the start of the main parser in order to skip
any leading white space.
mainParser = sum <$ whiteSpace <*> many (token digit) <* eof
charLiteral :: TokenParsing m => m CharSource
This token parser parses a single literal character. Returns the literal character value. This parsers deals correctly with escape sequences. The literal character is parsed according to the grammar rules defined in the Haskell report (which matches most programming languages quite closely).
stringLiteral :: TokenParsing m => m StringSource
This token parser parses a literal string. Returns the literal string value. This parsers deals correctly with escape sequences and gaps. The literal string is parsed according to the grammar rules defined in the Haskell report (which matches most programming languages quite closely).
natural :: TokenParsing m => m IntegerSource
This token parser parses a natural number (a positive whole
number). Returns the value of the number. The number can be
specified in decimal
, hexadecimal
or
octal
. The number is parsed according to the grammar
rules in the Haskell report.
integer :: TokenParsing m => m IntegerSource
This token parser parses an integer (a whole number). This parser
is like natural
except that it can be prefixed with
sign (i.e. '-' or '+'). Returns the value of the number. The
number can be specified in decimal
, hexadecimal
or octal
. The number is parsed according
to the grammar rules in the Haskell report.
double :: TokenParsing m => m DoubleSource
This token parser parses a floating point value. Returns the value of the number. The number is parsed according to the grammar rules defined in the Haskell report.
naturalOrDouble :: TokenParsing m => m (Either Integer Double)Source
This token parser parses either natural
or a float
.
Returns the value of the number. This parsers deals with
any overlap in the grammar rules for naturals and floats. The number
is parsed according to the grammar rules defined in the Haskell report.
symbol :: TokenParsing m => String -> m StringSource
Token parser symbol s
parses string
s
and skips
trailing white space.
symbolic :: TokenParsing m => Char -> m CharSource
Token parser symbolic s
parses char
s
and skips
trailing white space.
parens :: TokenParsing m => m a -> m aSource
Token parser parens p
parses p
enclosed in parenthesis,
returning the value of p
.
braces :: TokenParsing m => m a -> m aSource
Token parser braces p
parses p
enclosed in braces ('{' and
'}'), returning the value of p
.
angles :: TokenParsing m => m a -> m aSource
Token parser angles p
parses p
enclosed in angle brackets ('<'
and '>'), returning the value of p
.
brackets :: TokenParsing m => m a -> m aSource
Token parser brackets p
parses p
enclosed in brackets ('['
and ']'), returning the value of p
.
comma :: TokenParsing m => m CharSource
Token parser comma
parses the character ',' and skips any
trailing white space. Returns the string ",".
colon :: TokenParsing m => m CharSource
Token parser colon
parses the character ':' and skips any
trailing white space. Returns the string ":".
dot :: TokenParsing m => m CharSource
Token parser dot
parses the character '.' and skips any
trailing white space. Returns the string ".".
semiSep :: TokenParsing m => m a -> m [a]Source
Token parser semiSep p
parses zero or more occurrences of p
separated by semi
. Returns a list of values returned by
p
.
semiSep1 :: TokenParsing m => m a -> m [a]Source
Token parser semiSep1 p
parses one or more occurrences of p
separated by semi
. Returns a list of values returned by p
.
commaSep :: TokenParsing m => m a -> m [a]Source
Token parser commaSep p
parses zero or more occurrences of
p
separated by comma
. Returns a list of values returned
by p
.
commaSep1 :: TokenParsing m => m a -> m [a]Source
Token parser commaSep1 p
parses one or more occurrences of
p
separated by comma
. Returns a list of values returned
by p
.
Identifiers
data IdentifierStyle m Source
IdentifierStyle | |
|
liftIdentifierStyle :: (MonadTrans t, Monad m) => IdentifierStyle m -> IdentifierStyle (t m)Source
Lift an identifier style into a monad transformer
ident :: TokenParsing m => IdentifierStyle m -> m StringSource
parse an non-reserved identifier or symbol
reserve :: TokenParsing m => IdentifierStyle m -> String -> m ()Source
parse a reserved operator or identifier using a given style