Text.Parser.Token

parsers-0.12.12: Parsing combinators

Copyright | (c) Edward Kmett 2011 (c) Daan Leijen 1999-2001
License | BSD3
Maintainer | ekmett@gmail.com
Stability | experimental
Portability | non-portable
Safe Haskell | Trustworthy
Language | Haskell2010

Text.Parser.Token

Contents

- Token Parsing
  - Token Parsing Class
  - Token Parsing Transformers
  - Non-Token Parsers
- Identifiers
  - Lenses and Traversals

Description

Parsers that comprehend whitespace and identifier styles

    idStyle    = haskellIdents { styleReserved = ... }
    identifier = ident idStyle
    reserved   = reserve idStyle

Synopsis

- whiteSpace :: TokenParsing m => m ()
- charLiteral :: TokenParsing m => m Char
- stringLiteral :: (TokenParsing m, IsString s) => m s
- stringLiteral' :: (TokenParsing m, IsString s) => m s
- natural :: TokenParsing m => m Integer
- integer :: TokenParsing m => m Integer
- double :: TokenParsing m => m Double
- naturalOrDouble :: TokenParsing m => m (Either Integer Double)
- integerOrDouble :: TokenParsing m => m (Either Integer Double)
- scientific :: TokenParsing m => m Scientific
- naturalOrScientific :: TokenParsing m => m (Either Integer Scientific)
- integerOrScientific :: TokenParsing m => m (Either Integer Scientific)
- symbol :: TokenParsing m => String -> m String
- textSymbol :: TokenParsing m => Text -> m Text
- 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]
- class CharParsing m => TokenParsing (m :: Type -> Type) where
  - someSpace :: m ()
  - nesting :: m a -> m a
  - semi :: m Char
  - highlight :: Highlight -> m a -> m a
  - token :: m a -> m a
- newtype Unspaced (m :: Type -> Type) a = Unspaced {
  - runUnspaced :: m a
  }
- newtype Unlined (m :: Type -> Type) a = Unlined {
  - runUnlined :: m a
  }
- newtype Unhighlighted (m :: Type -> Type) a = Unhighlighted {
  - runUnhighlighted :: m a
  }
- decimal :: TokenParsing m => m Integer
- hexadecimal :: TokenParsing m => m Integer
- octal :: TokenParsing m => m Integer
- characterChar :: TokenParsing m => m Char
- integer' :: TokenParsing m => m Integer
- data IdentifierStyle (m :: Type -> Type) = IdentifierStyle {
  - _styleName :: String
  - _styleStart :: m Char
  - _styleLetter :: m Char
  - _styleReserved :: HashSet String
  - _styleHighlight :: Highlight
  - _styleReservedHighlight :: Highlight
  }
- liftIdentifierStyle :: forall (t :: (Type -> Type) -> Type -> Type) (m :: Type -> Type). (MonadTrans t, Monad m) => IdentifierStyle m -> IdentifierStyle (t m)
- ident :: (TokenParsing m, Monad m, IsString s) => IdentifierStyle m -> m s
- reserve :: (TokenParsing m, Monad m) => IdentifierStyle m -> String -> m ()
- reserveText :: (TokenParsing m, Monad m) => IdentifierStyle m -> Text -> m ()
- styleName :: forall f (m :: Type -> Type). Functor f => (String -> f String) -> IdentifierStyle m -> f (IdentifierStyle m)
- styleStart :: Functor f => (m Char -> f (m Char)) -> IdentifierStyle m -> f (IdentifierStyle m)
- styleLetter :: Functor f => (m Char -> f (m Char)) -> IdentifierStyle m -> f (IdentifierStyle m)
- styleChars :: Applicative f => (m Char -> f (n Char)) -> IdentifierStyle m -> f (IdentifierStyle n)
- styleReserved :: forall f (m :: Type -> Type). Functor f => (HashSet String -> f (HashSet String)) -> IdentifierStyle m -> f (IdentifierStyle m)
- styleHighlight :: forall f (m :: Type -> Type). Functor f => (Highlight -> f Highlight) -> IdentifierStyle m -> f (IdentifierStyle m)
- styleReservedHighlight :: forall f (m :: Type -> Type). Functor f => (Highlight -> f Highlight) -> IdentifierStyle m -> f (IdentifierStyle m)
- styleHighlights :: forall f (m :: Type -> Type). Applicative f => (Highlight -> f Highlight) -> IdentifierStyle m -> f (IdentifierStyle m)

# Token Parsing

whiteSpace :: TokenParsing m => m () #

Skip zero or more bytes worth of white space. More complex parsers are free to consider comments as white space.

charLiteral :: TokenParsing m => m Char #

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, IsString s) => m s #

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).

stringLiteral' :: (TokenParsing m, IsString s) => m s #

This token parser behaves as `stringLiteral`, but for single-quoted strings.

natural :: TokenParsing m => m Integer #

This token parser parses a natural number (a non-negative 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 Integer #

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 Double #

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) #

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.

integerOrDouble :: TokenParsing m => m (Either Integer Double) #

This token parser is like `naturalOrDouble`, but handles leading `-` or `+`.

scientific :: TokenParsing m => m Scientific #

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.

naturalOrScientific :: TokenParsing m => m (Either Integer Scientific) #

This token parser parses either `natural` or a `scientific`. 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.

integerOrScientific :: TokenParsing m => m (Either Integer Scientific) #

This token parser is like `naturalOrScientific`, but handles leading `-` or `+`.

symbol :: TokenParsing m => String -> m String #

Token parser `symbol s` parses `string` `s` and skips trailing white space.

textSymbol :: TokenParsing m => Text -> m Text #

Token parser `textSymbol t` parses `text` `s` and skips trailing white space.

symbolic :: TokenParsing m => Char -> m Char #

Token parser `symbolic s` parses `char` `s` and skips trailing white space.

parens :: TokenParsing m => m a -> m a #

Token parser `parens p` parses `p` enclosed in parenthesis, returning the value of `p`.

braces :: TokenParsing m => m a -> m a #

Token parser `braces p` parses `p` enclosed in braces ('{' and '}'), returning the value of `p`.

angles :: TokenParsing m => m a -> m a #

Token parser `angles p` parses `p` enclosed in angle brackets ('<' and '>'), returning the value of `p`.

brackets :: TokenParsing m => m a -> m a #

Token parser `brackets p` parses `p` enclosed in brackets ('[' and ']'), returning the value of `p`.

comma :: TokenParsing m => m Char #

Token parser `comma` parses the character ',' and skips any trailing white space. Returns the string ",".

colon :: TokenParsing m => m Char #

Token parser `colon` parses the character ':' and skips any trailing white space. Returns the string ":".

dot :: TokenParsing m => m Char #

Token parser `dot` parses the character '.' and skips any trailing white space. Returns the string ".".

semiSep :: TokenParsing m => m a -> m [a] #

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] #

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] #

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] #

Token parser `commaSep1 p` parses one or more occurrences of `p` separated by `comma`. Returns a list of values returned by `p`.

## Token Parsing Class

class CharParsing m => TokenParsing (m :: Type -> Type) where #

Additional functionality that is needed to tokenize input while ignoring whitespace.

Minimal complete definition

Nothing

Methods

someSpace :: m () #

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.

nesting :: m a -> m a #

Called when we enter a nested pair of symbols. Overloadable to enable disabling layout

semi :: m Char #

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.

highlight :: Highlight -> m a -> m a #

Tag a region of parsed text with a bit of semantic information. Most parsers won't use this, but it is indispensible for highlighters.

token :: m a -> m a #

`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.

Alternatively, one might define `token` as first parsing `whiteSpace` and then parser `p`. By parsing whiteSpace first, the parser is able to return before parsing additional whiteSpace, improving laziness.

    mainParser  = sum <$ whiteSpace <*> many (token digit) <* eof

#### Instances

Instances details

TokenParsing ReadP # |
Instance details Defined in Text.Parser.Token Methods someSpace :: ReadP () # nesting :: ReadP a -> ReadP a # semi :: ReadP Char # highlight :: Highlight -> ReadP a -> ReadP a # token :: ReadP a -> ReadP a #
Chunk t => TokenParsing (Parser t) # |
Instance details Defined in Text.Parser.Token Methods someSpace :: Parser t () # nesting :: Parser t a -> Parser t a # semi :: Parser t Char # highlight :: Highlight -> Parser t a -> Parser t a # token :: Parser t a -> Parser t a #
TokenParsing m => TokenParsing (Unhighlighted m) # |
Instance details Defined in Text.Parser.Token Methods someSpace :: Unhighlighted m () # nesting :: Unhighlighted m a -> Unhighlighted m a # semi :: Unhighlighted m Char # highlight :: Highlight -> Unhighlighted m a -> Unhighlighted m a # token :: Unhighlighted m a -> Unhighlighted m a #
TokenParsing m => TokenParsing (Unlined m) # |
Instance details Defined in Text.Parser.Token Methods someSpace :: Unlined m () # nesting :: Unlined m a -> Unlined m a # semi :: Unlined m Char # highlight :: Highlight -> Unlined m a -> Unlined m a # token :: Unlined m a -> Unlined m a #
TokenParsing m => TokenParsing (Unspaced m) # |
Instance details Defined in Text.Parser.Token Methods someSpace :: Unspaced m () # nesting :: Unspaced m a -> Unspaced m a # semi :: Unspaced m Char # highlight :: Highlight -> Unspaced m a -> Unspaced m a # token :: Unspaced m a -> Unspaced m a #
(TokenParsing m, MonadPlus m) => TokenParsing (IdentityT m) # |
Instance details Defined in Text.Parser.Token Methods someSpace :: IdentityT m () # nesting :: IdentityT m a -> IdentityT m a # semi :: IdentityT m Char # highlight :: Highlight -> IdentityT m a -> IdentityT m a # token :: IdentityT m a -> IdentityT m a #
(TokenParsing m, MonadPlus m) => TokenParsing (ReaderT e m) # |
Instance details Defined in Text.Parser.Token Methods someSpace :: ReaderT e m () # nesting :: ReaderT e m a -> ReaderT e m a # semi :: ReaderT e m Char # highlight :: Highlight -> ReaderT e m a -> ReaderT e m a # token :: ReaderT e m a -> ReaderT e m a #
(TokenParsing m, MonadPlus m) => TokenParsing (StateT s m) # |
Instance details Defined in Text.Parser.Token Methods someSpace :: StateT s m () # nesting :: StateT s m a -> StateT s m a # semi :: StateT s m Char # highlight :: Highlight -> StateT s m a -> StateT s m a # token :: StateT s m a -> StateT s m a #
(TokenParsing m, MonadPlus m) => TokenParsing (StateT s m) # |
Instance details Defined in Text.Parser.Token Methods someSpace :: StateT s m () # nesting :: StateT s m a -> StateT s m a # semi :: StateT s m Char # highlight :: Highlight -> StateT s m a -> StateT s m a # token :: StateT s m a -> StateT s m a #
(TokenParsing m, MonadPlus m, Monoid w) => TokenParsing (WriterT w m) # |
Instance details Defined in Text.Parser.Token Methods someSpace :: WriterT w m () # nesting :: WriterT w m a -> WriterT w m a # semi :: WriterT w m Char # highlight :: Highlight -> WriterT w m a -> WriterT w m a # token :: WriterT w m a -> WriterT w m a #
(TokenParsing m, MonadPlus m, Monoid w) => TokenParsing (WriterT w m) # |
Instance details Defined in Text.Parser.Token Methods someSpace :: WriterT w m () # nesting :: WriterT w m a -> WriterT w m a # semi :: WriterT w m Char # highlight :: Highlight -> WriterT w m a -> WriterT w m a # token :: WriterT w m a -> WriterT w m a #
Stream s m Char => TokenParsing (ParsecT s u m) # |
Instance details Defined in Text.Parser.Token Methods someSpace :: ParsecT s u m () # nesting :: ParsecT s u m a -> ParsecT s u m a # semi :: ParsecT s u m Char # highlight :: Highlight -> ParsecT s u m a -> ParsecT s u m a # token :: ParsecT s u m a -> ParsecT s u m a #
(TokenParsing m, MonadPlus m, Monoid w) => TokenParsing (RWST r w s m) # |
Instance details Defined in Text.Parser.Token Methods someSpace :: RWST r w s m () # nesting :: RWST r w s m a -> RWST r w s m a # semi :: RWST r w s m Char # highlight :: Highlight -> RWST r w s m a -> RWST r w s m a # token :: RWST r w s m a -> RWST r w s m a #
(TokenParsing m, MonadPlus m, Monoid w) => TokenParsing (RWST r w s m) # |
Instance details Defined in Text.Parser.Token Methods someSpace :: RWST r w s m () # nesting :: RWST r w s m a -> RWST r w s m a # semi :: RWST r w s m Char # highlight :: Highlight -> RWST r w s m a -> RWST r w s m a # token :: RWST r w s m a -> RWST r w s m a #

## Token Parsing Transformers

newtype Unspaced (m :: Type -> Type) a #

This is a parser transformer you can use to disable the automatic trailing space consumption of a Token parser.

Constructors

Unspaced |
Fields runUnspaced :: m a

#### Instances

Instances details

MonadTrans Unspaced # |
Instance details Defined in Text.Parser.Token Methods lift :: Monad m => m a -> Unspaced m a #
MonadReader e m => MonadReader e (Unspaced m) # |
Instance details Defined in Text.Parser.Token Methods ask :: Unspaced m e # local :: (e -> e) -> Unspaced m a -> Unspaced m a # reader :: (e -> a) -> Unspaced m a #
MonadState s m => MonadState s (Unspaced m) # |
Instance details Defined in Text.Parser.Token Methods get :: Unspaced m s # put :: s -> Unspaced m () # state :: (s -> (a, s)) -> Unspaced m a #
MonadWriter e m => MonadWriter e (Unspaced m) # |
Instance details Defined in Text.Parser.Token Methods writer :: (a, e) -> Unspaced m a # tell :: e -> Unspaced m () # listen :: Unspaced m a -> Unspaced m (a, e) # pass :: Unspaced m (a, e -> e) -> Unspaced m a #
Alternative m => Alternative (Unspaced m) # |
Instance details Defined in Text.Parser.Token Methods empty :: Unspaced m a # (<|>) :: Unspaced m a -> Unspaced m a -> Unspaced m a # some :: Unspaced m a -> Unspaced m [a] # many :: Unspaced m a -> Unspaced m [a] #
Applicative m => Applicative (Unspaced m) # |
Instance details Defined in Text.Parser.Token Methods pure :: a -> Unspaced m a # (<*>) :: Unspaced m (a -> b) -> Unspaced m a -> Unspaced m b # liftA2 :: (a -> b -> c) -> Unspaced m a -> Unspaced m b -> Unspaced m c # (*>) :: Unspaced m a -> Unspaced m b -> Unspaced m b # (<*) :: Unspaced m a -> Unspaced m b -> Unspaced m a #
Functor m => Functor (Unspaced m) # |
Instance details Defined in Text.Parser.Token Methods fmap :: (a -> b) -> Unspaced m a -> Unspaced m b # (<$) :: a -> Unspaced m b -> Unspaced m a #
Monad m => Monad (Unspaced m) # |
Instance details Defined in Text.Parser.Token Methods (>>=) :: Unspaced m a -> (a -> Unspaced m b) -> Unspaced m b # (>>) :: Unspaced m a -> Unspaced m b -> Unspaced m b # return :: a -> Unspaced m a #
MonadPlus m => MonadPlus (Unspaced m) # |
Instance details Defined in Text.Parser.Token Methods mzero :: Unspaced m a # mplus :: Unspaced m a -> Unspaced m a -> Unspaced m a #
CharParsing m => CharParsing (Unspaced m) # |
Instance details Defined in Text.Parser.Token Methods satisfy :: (Char -> Bool) -> Unspaced m Char # char :: Char -> Unspaced m Char # notChar :: Char -> Unspaced m Char # anyChar :: Unspaced m Char # string :: String -> Unspaced m String # text :: Text -> Unspaced m Text #
Parsing m => Parsing (Unspaced m) # |
Instance details Defined in Text.Parser.Token Methods try :: Unspaced m a -> Unspaced m a # (<?>) :: Unspaced m a -> String -> Unspaced m a # skipMany :: Unspaced m a -> Unspaced m () # skipSome :: Unspaced m a -> Unspaced m () # unexpected :: String -> Unspaced m a # eof :: Unspaced m () # notFollowedBy :: Show a => Unspaced m a -> Unspaced m () #
TokenParsing m => TokenParsing (Unspaced m) # |
Instance details Defined in Text.Parser.Token Methods someSpace :: Unspaced m () # nesting :: Unspaced m a -> Unspaced m a # semi :: Unspaced m Char # highlight :: Highlight -> Unspaced m a -> Unspaced m a # token :: Unspaced m a -> Unspaced m a #

newtype Unlined (m :: Type -> Type) a #

This is a parser transformer you can use to disable the automatic trailing newline (but not whitespace-in-general) consumption of a Token parser.

Constructors

Unlined |
Fields runUnlined :: m a

#### Instances

Instances details

MonadTrans Unlined # |
Instance details Defined in Text.Parser.Token Methods lift :: Monad m => m a -> Unlined m a #
MonadReader e m => MonadReader e (Unlined m) # |
Instance details Defined in Text.Parser.Token Methods ask :: Unlined m e # local :: (e -> e) -> Unlined m a -> Unlined m a # reader :: (e -> a) -> Unlined m a #
MonadState s m => MonadState s (Unlined m) # |
Instance details Defined in Text.Parser.Token Methods get :: Unlined m s # put :: s -> Unlined m () # state :: (s -> (a, s)) -> Unlined m a #
MonadWriter e m => MonadWriter e (Unlined m) # |
Instance details Defined in Text.Parser.Token Methods writer :: (a, e) -> Unlined m a # tell :: e -> Unlined m () # listen :: Unlined m a -> Unlined m (a, e) # pass :: Unlined m (a, e -> e) -> Unlined m a #
Alternative m => Alternative (Unlined m) # |
Instance details Defined in Text.Parser.Token Methods empty :: Unlined m a # (<|>) :: Unlined m a -> Unlined m a -> Unlined m a # some :: Unlined m a -> Unlined m [a] # many :: Unlined m a -> Unlined m [a] #
Applicative m => Applicative (Unlined m) # |
Instance details Defined in Text.Parser.Token Methods pure :: a -> Unlined m a # (<*>) :: Unlined m (a -> b) -> Unlined m a -> Unlined m b # liftA2 :: (a -> b -> c) -> Unlined m a -> Unlined m b -> Unlined m c # (*>) :: Unlined m a -> Unlined m b -> Unlined m b # (<*) :: Unlined m a -> Unlined m b -> Unlined m a #
Functor m => Functor (Unlined m) # |
Instance details Defined in Text.Parser.Token Methods fmap :: (a -> b) -> Unlined m a -> Unlined m b # (<$) :: a -> Unlined m b -> Unlined m a #
Monad m => Monad (Unlined m) # |
Instance details Defined in Text.Parser.Token Methods (>>=) :: Unlined m a -> (a -> Unlined m b) -> Unlined m b # (>>) :: Unlined m a -> Unlined m b -> Unlined m b # return :: a -> Unlined m a #
MonadPlus m => MonadPlus (Unlined m) # |
Instance details Defined in Text.Parser.Token Methods mzero :: Unlined m a # mplus :: Unlined m a -> Unlined m a -> Unlined m a #
CharParsing m => CharParsing (Unlined m) # |
Instance details Defined in Text.Parser.Token Methods satisfy :: (Char -> Bool) -> Unlined m Char # char :: Char -> Unlined m Char # notChar :: Char -> Unlined m Char # anyChar :: Unlined m Char # string :: String -> Unlined m String # text :: Text -> Unlined m Text #
Parsing m => Parsing (Unlined m) # |
Instance details Defined in Text.Parser.Token Methods try :: Unlined m a -> Unlined m a # (<?>) :: Unlined m a -> String -> Unlined m a # skipMany :: Unlined m a -> Unlined m () # skipSome :: Unlined m a -> Unlined m () # unexpected :: String -> Unlined m a # eof :: Unlined m () # notFollowedBy :: Show a => Unlined m a -> Unlined m () #
TokenParsing m => TokenParsing (Unlined m) # |
Instance details Defined in Text.Parser.Token Methods someSpace :: Unlined m () # nesting :: Unlined m a -> Unlined m a # semi :: Unlined m Char # highlight :: Highlight -> Unlined m a -> Unlined m a # token :: Unlined m a -> Unlined m a #

newtype Unhighlighted (m :: Type -> Type) a #

This is a parser transformer you can use to disable syntax highlighting over a range of text you are parsing.

Constructors

Unhighlighted |
Fields runUnhighlighted :: m a

#### Instances

Instances details

MonadTrans Unhighlighted # |
Instance details Defined in Text.Parser.Token Methods lift :: Monad m => m a -> Unhighlighted m a #
MonadReader e m => MonadReader e (Unhighlighted m) # |
Instance details Defined in Text.Parser.Token Methods ask :: Unhighlighted m e # local :: (e -> e) -> Unhighlighted m a -> Unhighlighted m a # reader :: (e -> a) -> Unhighlighted m a #
MonadState s m => MonadState s (Unhighlighted m) # |
Instance details Defined in Text.Parser.Token Methods get :: Unhighlighted m s # put :: s -> Unhighlighted m () # state :: (s -> (a, s)) -> Unhighlighted m a #
MonadWriter e m => MonadWriter e (Unhighlighted m) # |
Instance details Defined in Text.Parser.Token Methods writer :: (a, e) -> Unhighlighted m a # tell :: e -> Unhighlighted m () # listen :: Unhighlighted m a -> Unhighlighted m (a, e) # pass :: Unhighlighted m (a, e -> e) -> Unhighlighted m a #
Alternative m => Alternative (Unhighlighted m) # |
Instance details Defined in Text.Parser.Token Methods empty :: Unhighlighted m a # (<|>) :: Unhighlighted m a -> Unhighlighted m a -> Unhighlighted m a # some :: Unhighlighted m a -> Unhighlighted m [a] # many :: Unhighlighted m a -> Unhighlighted m [a] #
Applicative m => Applicative (Unhighlighted m) # |
Instance details Defined in Text.Parser.Token Methods pure :: a -> Unhighlighted m a # (<*>) :: Unhighlighted m (a -> b) -> Unhighlighted m a -> Unhighlighted m b # liftA2 :: (a -> b -> c) -> Unhighlighted m a -> Unhighlighted m b -> Unhighlighted m c # (*>) :: Unhighlighted m a -> Unhighlighted m b -> Unhighlighted m b # (<*) :: Unhighlighted m a -> Unhighlighted m b -> Unhighlighted m a #
Functor m => Functor (Unhighlighted m) # |
Instance details Defined in Text.Parser.Token Methods fmap :: (a -> b) -> Unhighlighted m a -> Unhighlighted m b # (<$) :: a -> Unhighlighted m b -> Unhighlighted m a #
Monad m => Monad (Unhighlighted m) # |
Instance details Defined in Text.Parser.Token Methods (>>=) :: Unhighlighted m a -> (a -> Unhighlighted m b) -> Unhighlighted m b # (>>) :: Unhighlighted m a -> Unhighlighted m b -> Unhighlighted m b # return :: a -> Unhighlighted m a #
MonadPlus m => MonadPlus (Unhighlighted m) # |
Instance details Defined in Text.Parser.Token Methods mzero :: Unhighlighted m a # mplus :: Unhighlighted m a -> Unhighlighted m a -> Unhighlighted m a #
CharParsing m => CharParsing (Unhighlighted m) # |
Instance details Defined in Text.Parser.Token Methods satisfy :: (Char -> Bool) -> Unhighlighted m Char # char :: Char -> Unhighlighted m Char # notChar :: Char -> Unhighlighted m Char # anyChar :: Unhighlighted m Char # string :: String -> Unhighlighted m String # text :: Text -> Unhighlighted m Text #
Parsing m => Parsing (Unhighlighted m) # |
Instance details Defined in Text.Parser.Token Methods try :: Unhighlighted m a -> Unhighlighted m a # (<?>) :: Unhighlighted m a -> String -> Unhighlighted m a # skipMany :: Unhighlighted m a -> Unhighlighted m () # skipSome :: Unhighlighted m a -> Unhighlighted m () # unexpected :: String -> Unhighlighted m a # eof :: Unhighlighted m () # notFollowedBy :: Show a => Unhighlighted m a -> Unhighlighted m () #
TokenParsing m => TokenParsing (Unhighlighted m) # |
Instance details Defined in Text.Parser.Token Methods someSpace :: Unhighlighted m () # nesting :: Unhighlighted m a -> Unhighlighted m a # semi :: Unhighlighted m Char # highlight :: Highlight -> Unhighlighted m a -> Unhighlighted m a # token :: Unhighlighted m a -> Unhighlighted m a #

## Non-Token Parsers

decimal :: TokenParsing m => m Integer #

Parses a non-negative whole number in the decimal system. Returns the value of the number.

This parser does NOT swallow trailing whitespace

hexadecimal :: TokenParsing m => m Integer #

Parses a non-negative whole number in the hexadecimal system. The number should be prefixed with "x" or "X". Returns the value of the number.

This parser does NOT swallow trailing whitespace

octal :: TokenParsing m => m Integer #

Parses a non-negative whole number in the octal system. The number should be prefixed with "o" or "O". Returns the value of the number.

This parser does NOT swallow trailing whitespace

characterChar :: TokenParsing m => m Char #

This parser parses a character literal without the surrounding quotation marks.

This parser does NOT swallow trailing whitespace

integer' :: TokenParsing m => m Integer #

This 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.

This parser does NOT swallow trailing whitespace.

Also, unlike the `integer` parser, this parser does not admit spaces between the sign and the number.

# Identifiers

data IdentifierStyle (m :: Type -> Type) #

Used to describe an input style for constructors, values, operators, etc.

Constructors

IdentifierStyle |
Fields _styleName :: String _styleStart :: m Char _styleLetter :: m Char _styleReserved :: HashSet String _styleHighlight :: Highlight _styleReservedHighlight :: Highlight

liftIdentifierStyle :: forall (t :: (Type -> Type) -> Type -> Type) (m :: Type -> Type). (MonadTrans t, Monad m) => IdentifierStyle m -> IdentifierStyle (t m) #

Lift an identifier style into a monad transformer

Using `over` from the `lens` package:

    liftIdentifierStyle = over styleChars lift

ident :: (TokenParsing m, Monad m, IsString s) => IdentifierStyle m -> m s #

Parse a non-reserved identifier or symbol

reserve :: (TokenParsing m, Monad m) => IdentifierStyle m -> String -> m () #

parse a reserved operator or identifier using a given style

reserveText :: (TokenParsing m, Monad m) => IdentifierStyle m -> Text -> m () #

parse a reserved operator or identifier using a given style given `Text`.

## Lenses and Traversals

styleName :: forall f (m :: Type -> Type). Functor f => (String -> f String) -> IdentifierStyle m -> f (IdentifierStyle m) #

This lens can be used to update the name for this style of identifier.

    styleName :: Lens' (IdentifierStyle m) String

styleStart :: Functor f => (m Char -> f (m Char)) -> IdentifierStyle m -> f (IdentifierStyle m) #

This lens can be used to update the action used to recognize the first letter in an identifier.

    styleStart :: Lens' (IdentifierStyle m) (m Char)

styleLetter :: Functor f => (m Char -> f (m Char)) -> IdentifierStyle m -> f (IdentifierStyle m) #

This lens can be used to update the action used to recognize subsequent letters in an identifier.

    styleLetter :: Lens' (IdentifierStyle m) (m Char)

styleChars :: Applicative f => (m Char -> f (n Char)) -> IdentifierStyle m -> f (IdentifierStyle n) #

This is a traversal of both actions in contained in an `IdentifierStyle`.

    styleChars :: Traversal (IdentifierStyle m) (IdentifierStyle n) (m Char) (n Char)

styleReserved :: forall f (m :: Type -> Type). Functor f => (HashSet String -> f (HashSet String)) -> IdentifierStyle m -> f (IdentifierStyle m) #

This is a lens that can be used to modify the reserved identifier set.

    styleReserved :: Lens' (IdentifierStyle m) (HashSet String)

styleHighlight :: forall f (m :: Type -> Type). Functor f => (Highlight -> f Highlight) -> IdentifierStyle m -> f (IdentifierStyle m) #

This is a lens that can be used to modify the highlight used for this identifier set.

    styleHighlight :: Lens' (IdentifierStyle m) Highlight

styleReservedHighlight :: forall f (m :: Type -> Type). Functor f => (Highlight -> f Highlight) -> IdentifierStyle m -> f (IdentifierStyle m) #

This is a lens that can be used to modify the highlight used for reserved identifiers in this identifier set.

    styleReservedHighlight :: Lens' (IdentifierStyle m) Highlight

styleHighlights :: forall f (m :: Type -> Type). Applicative f => (Highlight -> f Highlight) -> IdentifierStyle m -> f (IdentifierStyle m) #

This is a traversal that can be used to modify the highlights used for both non-reserved and reserved identifiers in this identifier set.

    styleHighlights :: Traversal' (IdentifierStyle m) Highlight