{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE UndecidableInstances #-}
#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702
{-# LANGUAGE Trustworthy #-}
{-# OPTIONS_GHC -fno-warn-incomplete-uni-patterns #-}
#endif
{-# OPTIONS_GHC -fspec-constr -fspec-constr-count=8 #-}
-----------------------------------------------------------------------------
-- |
-- Module      :  Text.Parser.Token
-- Copyright   :  (c) Edward Kmett 2011
--                (c) Daan Leijen 1999-2001
-- License     :  BSD3
--
-- Maintainer  :  ekmett@gmail.com
-- Stability   :  experimental
-- Portability :  non-portable
--
-- Parsers that comprehend whitespace and identifier styles
--
-- > idStyle    = haskellIdents { styleReserved = ... }
-- > identifier = ident idStyle
-- > reserved   = reserve idStyle
--
-----------------------------------------------------------------------------
module Text.Parser.Token
  (
  -- * Token Parsing
    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]
  -- ** Token Parsing Class
  , TokenParsing(..)
  -- ** Token Parsing Transformers
  , Unspaced(..)
  , Unlined(..)
  , Unhighlighted(..)
  -- ** /Non-Token/ Parsers
  , 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
  -- * Identifiers
  , IdentifierStyle(..)
  , liftIdentifierStyle -- :: (MonadTrans t, Monad m) => IdentifierStyle m -> IdentifierStyle (t m)
  , ident           -- :: (TokenParsing m, IsString s) => IdentifierStyle m -> m s
  , reserve         -- :: TokenParsing m => IdentifierStyle m -> String -> m ()
  , reserveText     -- :: TokenParsing m => IdentifierStyle m -> Text -> m ()
  -- ** Lenses and Traversals
  , styleName
  , styleStart
  , styleLetter
  , styleChars
  , styleReserved
  , styleHighlight
  , styleReservedHighlight
  , styleHighlights
  ) where

import Control.Applicative
import Control.Monad (MonadPlus(..), when)
import Control.Monad.Trans.Class
import Control.Monad.Trans.State.Lazy as Lazy
import Control.Monad.Trans.State.Strict as Strict
import Control.Monad.Trans.Writer.Lazy as Lazy
import Control.Monad.Trans.Writer.Strict as Strict
import Control.Monad.Trans.RWS.Lazy as Lazy
import Control.Monad.Trans.RWS.Strict as Strict
import Control.Monad.Trans.Reader
import Control.Monad.Trans.Identity
import Control.Monad.State.Class as Class
import Control.Monad.Reader.Class as Class
import Control.Monad.Writer.Class as Class
import Data.Char
import Data.Functor.Identity
import qualified Data.HashSet as HashSet
import Data.HashSet (HashSet)
import Data.List (foldl', transpose)
#if __GLASGOW_HASKELL__ < 710
import Data.Monoid
#endif
import Data.Scientific ( Scientific )
import qualified Data.Scientific as Sci
import Data.String
import Data.Text hiding (empty,zip,foldl',take,map,length,splitAt,null,transpose)
import Numeric (showIntAtBase)
import qualified Text.ParserCombinators.ReadP as ReadP
import Text.Parser.Char
import Text.Parser.Combinators
import Text.Parser.Token.Highlight

#ifdef MIN_VERSION_parsec
import qualified Text.Parsec as Parsec
#endif

#ifdef MIN_VERSION_attoparsec
import qualified Data.Attoparsec.Types as Att
#endif

-- | Skip zero or more bytes worth of white space. More complex parsers are
-- free to consider comments as white space.
whiteSpace :: TokenParsing m => m ()
whiteSpace :: forall (m :: * -> *). TokenParsing m => m ()
whiteSpace = forall (m :: * -> *). TokenParsing m => m ()
someSpace forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
{-# INLINE whiteSpace #-}

-- | 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).
charLiteral :: forall m. TokenParsing m => m Char
charLiteral :: forall (m :: * -> *). TokenParsing m => m Char
charLiteral = forall (m :: * -> *) a. TokenParsing m => m a -> m a
token (forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
CharLiteral m Char
lit) where
  lit :: m Char
  lit :: m Char
lit = forall (m :: * -> *) bra ket a.
Applicative m =>
m bra -> m ket -> m a -> m a
between (forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'\'') (forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'\'' forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"end of character") forall (m :: * -> *). TokenParsing m => m Char
characterChar
    forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"character"
{-# INLINE charLiteral #-}

-- | 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 :: forall m s. (TokenParsing m, IsString s) => m s
stringLiteral :: forall (m :: * -> *) s. (TokenParsing m, IsString s) => m s
stringLiteral = forall a. IsString a => String -> a
fromString forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. TokenParsing m => m a -> m a
token (forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
StringLiteral m String
lit) where
  lit :: m [Char]
  lit :: m String
lit = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
Prelude.foldr (forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. a -> a
id (:)) String
""
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) bra ket a.
Applicative m =>
m bra -> m ket -> m a -> m a
between (forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'"') (forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'"' forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"end of string") (forall (f :: * -> *) a. Alternative f => f a -> f [a]
many m (Maybe Char)
stringChar)
    forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"string"

  stringChar :: m (Maybe Char)
  stringChar :: m (Maybe Char)
stringChar = forall a. a -> Maybe a
Just forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Char
stringLetter
           forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> m (Maybe Char)
stringEscape
       forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"string character"

  stringLetter :: m Char
  stringLetter :: m Char
stringLetter = forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
satisfy (\Char
c -> (Char
c forall a. Eq a => a -> a -> Bool
/= Char
'"') Bool -> Bool -> Bool
&& (Char
c forall a. Eq a => a -> a -> Bool
/= Char
'\\') Bool -> Bool -> Bool
&& (Char
c forall a. Ord a => a -> a -> Bool
> Char
'\026'))

  stringEscape :: m (Maybe Char)
  stringEscape :: m (Maybe Char)
stringEscape = forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
EscapeCode forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'\\' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> m (Maybe Char)
esc where
    esc :: m (Maybe Char)
    esc :: m (Maybe Char)
esc = forall a. Maybe a
Nothing forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ m Char
escapeGap
      forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall a. Maybe a
Nothing forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ m Char
escapeEmpty
      forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall a. a -> Maybe a
Just forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). TokenParsing m => m Char
escapeCode

  escapeEmpty, escapeGap :: m Char
  escapeEmpty :: m Char
escapeEmpty = forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'&'
  escapeGap :: m Char
escapeGap = forall (m :: * -> *) a. Parsing m => m a -> m ()
skipSome forall (m :: * -> *). CharParsing m => m Char
space forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'\\' forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"end of string gap")
{-# INLINE stringLiteral #-}

-- | This token parser behaves as 'stringLiteral', but for single-quoted
-- strings.
stringLiteral' :: forall m s. (TokenParsing m, IsString s) => m s
stringLiteral' :: forall (m :: * -> *) s. (TokenParsing m, IsString s) => m s
stringLiteral' = forall a. IsString a => String -> a
fromString forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. TokenParsing m => m a -> m a
token (forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
StringLiteral m String
lit) where
  lit :: m [Char]
  lit :: m String
lit = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
Prelude.foldr (forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. a -> a
id (:)) String
""
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) bra ket a.
Applicative m =>
m bra -> m ket -> m a -> m a
between (forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'\'') (forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'\'' forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"end of string") (forall (f :: * -> *) a. Alternative f => f a -> f [a]
many m (Maybe Char)
stringChar)
    forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"string"

  stringChar :: m (Maybe Char)
  stringChar :: m (Maybe Char)
stringChar = forall a. a -> Maybe a
Just forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Char
stringLetter
           forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> m (Maybe Char)
stringEscape
       forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"string character"

  stringLetter :: m Char
  stringLetter :: m Char
stringLetter = forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
satisfy (\Char
c -> (Char
c forall a. Eq a => a -> a -> Bool
/= Char
'\'') Bool -> Bool -> Bool
&& (Char
c forall a. Eq a => a -> a -> Bool
/= Char
'\\') Bool -> Bool -> Bool
&& (Char
c forall a. Ord a => a -> a -> Bool
> Char
'\026'))

  stringEscape :: m (Maybe Char)
  stringEscape :: m (Maybe Char)
stringEscape = forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
EscapeCode forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'\\' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> m (Maybe Char)
esc where
    esc :: m (Maybe Char)
    esc :: m (Maybe Char)
esc = forall a. Maybe a
Nothing forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ m Char
escapeGap
      forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall a. Maybe a
Nothing forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ m Char
escapeEmpty
      forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall a. a -> Maybe a
Just forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). TokenParsing m => m Char
escapeCode

  escapeEmpty, escapeGap :: m Char
  escapeEmpty :: m Char
escapeEmpty = forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'&'
  escapeGap :: m Char
escapeGap = forall (m :: * -> *) a. Parsing m => m a -> m ()
skipSome forall (m :: * -> *). CharParsing m => m Char
space forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'\\' forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"end of string gap")
{-# INLINE stringLiteral' #-}

-- | 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.
natural :: TokenParsing m => m Integer
natural :: forall (m :: * -> *). TokenParsing m => m Integer
natural = forall (m :: * -> *) a. TokenParsing m => m a -> m a
token forall (m :: * -> *). TokenParsing m => m Integer
natural'
{-# INLINE natural #-}

-- | 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.
integer :: forall m. TokenParsing m => m Integer
integer :: forall (m :: * -> *). TokenParsing m => m Integer
integer = forall (m :: * -> *) a. TokenParsing m => m a -> m a
token (forall (m :: * -> *) a. TokenParsing m => m a -> m a
token (forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
Operator m (Integer -> Integer)
sgn forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (m :: * -> *). TokenParsing m => m Integer
natural')) forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"integer"
  where
  sgn :: m (Integer -> Integer)
  sgn :: m (Integer -> Integer)
sgn = forall a. Num a => a -> a
negate forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'-'
    forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall a. a -> a
id forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'+'
    forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. a -> a
id
{-# INLINE integer #-}

-- | 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.
double :: TokenParsing m => m Double
double :: forall (m :: * -> *). TokenParsing m => m Double
double = forall (m :: * -> *) a. TokenParsing m => m a -> m a
token (forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
Number (forall a. RealFloat a => Scientific -> a
Sci.toRealFloat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). TokenParsing m => m Scientific
floating) forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"double")
{-# INLINE 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.
naturalOrDouble :: TokenParsing m => m (Either Integer Double)
naturalOrDouble :: forall (m :: * -> *). TokenParsing m => m (Either Integer Double)
naturalOrDouble = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. RealFloat a => Scientific -> a
Sci.toRealFloat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *).
TokenParsing m =>
m (Either Integer Scientific)
naturalOrScientific
{-# INLINE naturalOrDouble #-}

-- | This token parser is like 'naturalOrDouble', but handles
-- leading @-@ or @+@.
integerOrDouble :: TokenParsing m => m (Either Integer Double)
integerOrDouble :: forall (m :: * -> *). TokenParsing m => m (Either Integer Double)
integerOrDouble = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. RealFloat a => Scientific -> a
Sci.toRealFloat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *).
TokenParsing m =>
m (Either Integer Scientific)
integerOrScientific
{-# INLINE integerOrDouble #-}

-- | 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.
scientific :: TokenParsing m => m Scientific
scientific :: forall (m :: * -> *). TokenParsing m => m Scientific
scientific = forall (m :: * -> *) a. TokenParsing m => m a -> m a
token (forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
Number forall (m :: * -> *). TokenParsing m => m Scientific
floating forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"scientific")
{-# INLINE 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.
naturalOrScientific :: TokenParsing m => m (Either Integer Scientific)
naturalOrScientific :: forall (m :: * -> *).
TokenParsing m =>
m (Either Integer Scientific)
naturalOrScientific = forall (m :: * -> *) a. TokenParsing m => m a -> m a
token (forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
Number forall (m :: * -> *).
TokenParsing m =>
m (Either Integer Scientific)
natFloating forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"number")
{-# INLINE naturalOrScientific #-}

-- | This token parser is like 'naturalOrScientific', but handles
-- leading @-@ or @+@.
integerOrScientific :: forall m. TokenParsing m => m (Either Integer Scientific)
integerOrScientific :: forall (m :: * -> *).
TokenParsing m =>
m (Either Integer Scientific)
integerOrScientific = forall (m :: * -> *) a. TokenParsing m => m a -> m a
token (forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
Number m (Either Integer Scientific)
ios forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"number")
  where ios :: m (Either Integer Scientific)
        ios :: m (Either Integer Scientific)
ios = forall {b} {b}.
(Num b, Num b) =>
Maybe Char -> Either b b -> Either b b
mneg forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (forall (m :: * -> *). CharParsing m => String -> m Char
oneOf String
"+-") forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (m :: * -> *).
TokenParsing m =>
m (Either Integer Scientific)
natFloating

        mneg :: Maybe Char -> Either b b -> Either b b
mneg (Just Char
'-') Either b b
nd = forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall a b. a -> Either a b
Left forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Num a => a -> a
negate) (forall a b. b -> Either a b
Right forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Num a => a -> a
negate) Either b b
nd
        mneg Maybe Char
_          Either b b
nd = Either b b
nd
{-# INLINE integerOrScientific #-}


-- | Token parser @symbol s@ parses 'string' @s@ and skips
-- trailing white space.
symbol :: TokenParsing m => String -> m String
symbol :: forall (m :: * -> *). TokenParsing m => String -> m String
symbol String
name = forall (m :: * -> *) a. TokenParsing m => m a -> m a
token (forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
Symbol (forall (m :: * -> *). CharParsing m => String -> m String
string String
name))
{-# INLINE symbol #-}

-- | Token parser @textSymbol t@ parses 'text' @s@ and skips
-- trailing white space.
textSymbol :: TokenParsing m => Text -> m Text
textSymbol :: forall (m :: * -> *). TokenParsing m => Text -> m Text
textSymbol Text
name = forall (m :: * -> *) a. TokenParsing m => m a -> m a
token (forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
Symbol (forall (m :: * -> *). CharParsing m => Text -> m Text
text Text
name))
{-# INLINE textSymbol #-}

-- | Token parser @symbolic s@ parses 'char' @s@ and skips
-- trailing white space.
symbolic :: TokenParsing m => Char -> m Char
symbolic :: forall (m :: * -> *). TokenParsing m => Char -> m Char
symbolic Char
name = forall (m :: * -> *) a. TokenParsing m => m a -> m a
token (forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
Symbol (forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
name))
{-# INLINE symbolic #-}

-- | Token parser @parens p@ parses @p@ enclosed in parenthesis,
-- returning the value of @p@.
parens :: TokenParsing m => m a -> m a
parens :: forall (m :: * -> *) a. TokenParsing m => m a -> m a
parens = forall (m :: * -> *) a. TokenParsing m => m a -> m a
nesting forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) bra ket a.
Applicative m =>
m bra -> m ket -> m a -> m a
between (forall (m :: * -> *). TokenParsing m => Char -> m Char
symbolic Char
'(') (forall (m :: * -> *). TokenParsing m => Char -> m Char
symbolic Char
')')
{-# INLINE parens #-}

-- | Token parser @braces p@ parses @p@ enclosed in braces (\'{\' and
-- \'}\'), returning the value of @p@.
braces :: TokenParsing m => m a -> m a
braces :: forall (m :: * -> *) a. TokenParsing m => m a -> m a
braces = forall (m :: * -> *) a. TokenParsing m => m a -> m a
nesting forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) bra ket a.
Applicative m =>
m bra -> m ket -> m a -> m a
between (forall (m :: * -> *). TokenParsing m => Char -> m Char
symbolic Char
'{') (forall (m :: * -> *). TokenParsing m => Char -> m Char
symbolic Char
'}')
{-# INLINE braces #-}

-- | Token parser @angles p@ parses @p@ enclosed in angle brackets (\'\<\'
-- and \'>\'), returning the value of @p@.
angles :: TokenParsing m => m a -> m a
angles :: forall (m :: * -> *) a. TokenParsing m => m a -> m a
angles = forall (m :: * -> *) a. TokenParsing m => m a -> m a
nesting forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) bra ket a.
Applicative m =>
m bra -> m ket -> m a -> m a
between (forall (m :: * -> *). TokenParsing m => Char -> m Char
symbolic Char
'<') (forall (m :: * -> *). TokenParsing m => Char -> m Char
symbolic Char
'>')
{-# INLINE angles #-}

-- | Token parser @brackets p@ parses @p@ enclosed in brackets (\'[\'
-- and \']\'), returning the value of @p@.
brackets :: TokenParsing m => m a -> m a
brackets :: forall (m :: * -> *) a. TokenParsing m => m a -> m a
brackets = forall (m :: * -> *) a. TokenParsing m => m a -> m a
nesting forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) bra ket a.
Applicative m =>
m bra -> m ket -> m a -> m a
between (forall (m :: * -> *). TokenParsing m => Char -> m Char
symbolic Char
'[') (forall (m :: * -> *). TokenParsing m => Char -> m Char
symbolic Char
']')
{-# INLINE brackets #-}

-- | Token parser @comma@ parses the character \',\' and skips any
-- trailing white space. Returns the string \",\".
comma :: TokenParsing m => m Char
comma :: forall (m :: * -> *). TokenParsing m => m Char
comma = forall (m :: * -> *). TokenParsing m => Char -> m Char
symbolic Char
','
{-# INLINE comma #-}

-- | Token parser @colon@ parses the character \':\' and skips any
-- trailing white space. Returns the string \":\".
colon :: TokenParsing m => m Char
colon :: forall (m :: * -> *). TokenParsing m => m Char
colon = forall (m :: * -> *). TokenParsing m => Char -> m Char
symbolic Char
':'
{-# INLINE colon #-}

-- | Token parser @dot@ parses the character \'.\' and skips any
-- trailing white space. Returns the string \".\".
dot :: TokenParsing m => m Char
dot :: forall (m :: * -> *). TokenParsing m => m Char
dot = forall (m :: * -> *). TokenParsing m => Char -> m Char
symbolic Char
'.'
{-# INLINE dot #-}

-- | Token parser @semiSep p@ parses /zero/ or more occurrences of @p@
-- separated by 'semi'. Returns a list of values returned by @p@.
semiSep :: TokenParsing m => m a -> m [a]
semiSep :: forall (m :: * -> *) a. TokenParsing m => m a -> m [a]
semiSep m a
p = forall (m :: * -> *) a sep. Alternative m => m a -> m sep -> m [a]
sepBy m a
p forall (m :: * -> *). TokenParsing m => m Char
semi
{-# INLINE semiSep #-}

-- | Token parser @semiSep1 p@ parses /one/ or more occurrences of @p@
-- separated by 'semi'. Returns a list of values returned by @p@.
semiSep1 :: TokenParsing m => m a -> m [a]
semiSep1 :: forall (m :: * -> *) a. TokenParsing m => m a -> m [a]
semiSep1 m a
p = forall (m :: * -> *) a sep. Alternative m => m a -> m sep -> m [a]
sepBy1 m a
p forall (m :: * -> *). TokenParsing m => m Char
semi
{-# INLINE semiSep1 #-}

-- | Token parser @commaSep p@ parses /zero/ or more occurrences of
-- @p@ separated by 'comma'. Returns a list of values returned
-- by @p@.
commaSep :: TokenParsing m => m a -> m [a]
commaSep :: forall (m :: * -> *) a. TokenParsing m => m a -> m [a]
commaSep m a
p = forall (m :: * -> *) a sep. Alternative m => m a -> m sep -> m [a]
sepBy m a
p forall (m :: * -> *). TokenParsing m => m Char
comma
{-# INLINE commaSep #-}

-- | Token parser @commaSep1 p@ parses /one/ or more occurrences of
-- @p@ separated by 'comma'. Returns a list of values returned
-- by @p@.
commaSep1 :: TokenParsing m => m a -> m [a]
commaSep1 :: forall (m :: * -> *) a. TokenParsing m => m a -> m [a]
commaSep1 m a
p = forall (m :: * -> *) a sep. Alternative m => m a -> m sep -> m [a]
sepBy1 m a
p forall (m :: * -> *). TokenParsing m => m Char
comma
{-# INLINE commaSep1 #-}

-- | Additional functionality that is needed to tokenize input while ignoring whitespace.
class CharParsing m => TokenParsing m where
  -- | 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.
  someSpace :: m ()
  someSpace = forall (m :: * -> *) a. Parsing m => m a -> m ()
skipSome (forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
satisfy Char -> Bool
isSpace)
  {-# INLINE someSpace #-}

  -- | Called when we enter a nested pair of symbols.
  -- Overloadable to enable disabling layout
  nesting :: m a -> m a
  nesting = forall a. a -> a
id
  {-# INLINE nesting #-}

  -- | 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.
  semi :: m Char
  semi = forall (m :: * -> *) a. TokenParsing m => m a -> m a
token (forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
satisfy (Char
';'forall a. Eq a => a -> a -> Bool
==) forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
";")
  {-# INLINE semi #-}

  -- | Tag a region of parsed text with a bit of semantic information.
  -- Most parsers won't use this, but it is indispensible for highlighters.
  highlight :: Highlight -> m a -> m a
  highlight Highlight
_ m a
a = m a
a
  {-# INLINE highlight #-}

  -- | @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
  token :: m a -> m a
  token m a
p = m a
p forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* (forall (m :: * -> *). TokenParsing m => m ()
someSpace forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (f :: * -> *) a. Applicative f => a -> f a
pure ())

instance (TokenParsing m, MonadPlus m) => TokenParsing (Lazy.StateT s m) where
  nesting :: forall a. StateT s m a -> StateT s m a
nesting (Lazy.StateT s -> m (a, s)
m) = forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
Lazy.StateT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. TokenParsing m => m a -> m a
nesting forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> m (a, s)
m
  {-# INLINE nesting #-}
  someSpace :: StateT s m ()
someSpace = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall (m :: * -> *). TokenParsing m => m ()
someSpace
  {-# INLINE someSpace #-}
  semi :: StateT s m Char
semi      = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall (m :: * -> *). TokenParsing m => m Char
semi
  {-# INLINE semi #-}
  highlight :: forall a. Highlight -> StateT s m a -> StateT s m a
highlight Highlight
h (Lazy.StateT s -> m (a, s)
m) = forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
Lazy.StateT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
h forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> m (a, s)
m
  {-# INLINE highlight #-}

instance (TokenParsing m, MonadPlus m) => TokenParsing (Strict.StateT s m) where
  nesting :: forall a. StateT s m a -> StateT s m a
nesting (Strict.StateT s -> m (a, s)
m) = forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
Strict.StateT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. TokenParsing m => m a -> m a
nesting forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> m (a, s)
m
  {-# INLINE nesting #-}
  someSpace :: StateT s m ()
someSpace = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall (m :: * -> *). TokenParsing m => m ()
someSpace
  {-# INLINE someSpace #-}
  semi :: StateT s m Char
semi      = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall (m :: * -> *). TokenParsing m => m Char
semi
  {-# INLINE semi #-}
  highlight :: forall a. Highlight -> StateT s m a -> StateT s m a
highlight Highlight
h (Strict.StateT s -> m (a, s)
m) = forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
Strict.StateT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
h forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> m (a, s)
m
  {-# INLINE highlight #-}

instance (TokenParsing m, MonadPlus m) => TokenParsing (ReaderT e m) where
  nesting :: forall a. ReaderT e m a -> ReaderT e m a
nesting (ReaderT e -> m a
m) = forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
ReaderT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. TokenParsing m => m a -> m a
nesting forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> m a
m
  {-# INLINE nesting #-}
  someSpace :: ReaderT e m ()
someSpace = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall (m :: * -> *). TokenParsing m => m ()
someSpace
  {-# INLINE someSpace #-}
  semi :: ReaderT e m Char
semi      = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall (m :: * -> *). TokenParsing m => m Char
semi
  {-# INLINE semi #-}
  highlight :: forall a. Highlight -> ReaderT e m a -> ReaderT e m a
highlight Highlight
h (ReaderT e -> m a
m) = forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
ReaderT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
h forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> m a
m
  {-# INLINE highlight #-}

instance (TokenParsing m, MonadPlus m, Monoid w) => TokenParsing (Strict.WriterT w m) where
  nesting :: forall a. WriterT w m a -> WriterT w m a
nesting (Strict.WriterT m (a, w)
m) = forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
Strict.WriterT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. TokenParsing m => m a -> m a
nesting m (a, w)
m
  {-# INLINE nesting #-}
  someSpace :: WriterT w m ()
someSpace = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall (m :: * -> *). TokenParsing m => m ()
someSpace
  {-# INLINE someSpace #-}
  semi :: WriterT w m Char
semi      = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall (m :: * -> *). TokenParsing m => m Char
semi
  {-# INLINE semi #-}
  highlight :: forall a. Highlight -> WriterT w m a -> WriterT w m a
highlight Highlight
h (Strict.WriterT m (a, w)
m) = forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
Strict.WriterT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
h m (a, w)
m
  {-# INLINE highlight #-}

instance (TokenParsing m, MonadPlus m, Monoid w) => TokenParsing (Lazy.WriterT w m) where
  nesting :: forall a. WriterT w m a -> WriterT w m a
nesting (Lazy.WriterT m (a, w)
m) = forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
Lazy.WriterT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. TokenParsing m => m a -> m a
nesting m (a, w)
m
  {-# INLINE nesting #-}
  someSpace :: WriterT w m ()
someSpace = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall (m :: * -> *). TokenParsing m => m ()
someSpace
  {-# INLINE someSpace #-}
  semi :: WriterT w m Char
semi      = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall (m :: * -> *). TokenParsing m => m Char
semi
  {-# INLINE semi #-}
  highlight :: forall a. Highlight -> WriterT w m a -> WriterT w m a
highlight Highlight
h (Lazy.WriterT m (a, w)
m) = forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
Lazy.WriterT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
h m (a, w)
m
  {-# INLINE highlight #-}

instance (TokenParsing m, MonadPlus m, Monoid w) => TokenParsing (Lazy.RWST r w s m) where
  nesting :: forall a. RWST r w s m a -> RWST r w s m a
nesting (Lazy.RWST r -> s -> m (a, s, w)
m) = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
Lazy.RWST forall a b. (a -> b) -> a -> b
$ \r
r s
s -> forall (m :: * -> *) a. TokenParsing m => m a -> m a
nesting (r -> s -> m (a, s, w)
m r
r s
s)
  {-# INLINE nesting #-}
  someSpace :: RWST r w s m ()
someSpace = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall (m :: * -> *). TokenParsing m => m ()
someSpace
  {-# INLINE someSpace #-}
  semi :: RWST r w s m Char
semi      = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall (m :: * -> *). TokenParsing m => m Char
semi
  {-# INLINE semi #-}
  highlight :: forall a. Highlight -> RWST r w s m a -> RWST r w s m a
highlight Highlight
h (Lazy.RWST r -> s -> m (a, s, w)
m) = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
Lazy.RWST forall a b. (a -> b) -> a -> b
$ \r
r s
s -> forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
h (r -> s -> m (a, s, w)
m r
r s
s)
  {-# INLINE highlight #-}

instance (TokenParsing m, MonadPlus m, Monoid w) => TokenParsing (Strict.RWST r w s m) where
  nesting :: forall a. RWST r w s m a -> RWST r w s m a
nesting (Strict.RWST r -> s -> m (a, s, w)
m) = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
Strict.RWST forall a b. (a -> b) -> a -> b
$ \r
r s
s -> forall (m :: * -> *) a. TokenParsing m => m a -> m a
nesting (r -> s -> m (a, s, w)
m r
r s
s)
  {-# INLINE nesting #-}
  someSpace :: RWST r w s m ()
someSpace = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall (m :: * -> *). TokenParsing m => m ()
someSpace
  {-# INLINE someSpace #-}
  semi :: RWST r w s m Char
semi      = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall (m :: * -> *). TokenParsing m => m Char
semi
  {-# INLINE semi #-}
  highlight :: forall a. Highlight -> RWST r w s m a -> RWST r w s m a
highlight Highlight
h (Strict.RWST r -> s -> m (a, s, w)
m) = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
Strict.RWST forall a b. (a -> b) -> a -> b
$ \r
r s
s -> forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
h (r -> s -> m (a, s, w)
m r
r s
s)
  {-# INLINE highlight #-}

instance (TokenParsing m, MonadPlus m) => TokenParsing (IdentityT m) where
  nesting :: forall a. IdentityT m a -> IdentityT m a
nesting = forall {k} (f :: k -> *) (a :: k). f a -> IdentityT f a
IdentityT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. TokenParsing m => m a -> m a
nesting forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). IdentityT f a -> f a
runIdentityT
  {-# INLINE nesting #-}
  someSpace :: IdentityT m ()
someSpace = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall (m :: * -> *). TokenParsing m => m ()
someSpace
  {-# INLINE someSpace #-}
  semi :: IdentityT m Char
semi      = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall (m :: * -> *). TokenParsing m => m Char
semi
  {-# INLINE semi #-}
  highlight :: forall a. Highlight -> IdentityT m a -> IdentityT m a
highlight Highlight
h = forall {k} (f :: k -> *) (a :: k). f a -> IdentityT f a
IdentityT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
h forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). IdentityT f a -> f a
runIdentityT
  {-# INLINE highlight #-}

-- | Used to describe an input style for constructors, values, operators, etc.
data IdentifierStyle m = IdentifierStyle
  { forall (m :: * -> *). IdentifierStyle m -> String
_styleName              :: String
  , forall (m :: * -> *). IdentifierStyle m -> m Char
_styleStart             :: m Char
  , forall (m :: * -> *). IdentifierStyle m -> m Char
_styleLetter            :: m Char
  , forall (m :: * -> *). IdentifierStyle m -> HashSet String
_styleReserved          :: HashSet String
  , forall (m :: * -> *). IdentifierStyle m -> Highlight
_styleHighlight         :: Highlight
  , forall (m :: * -> *). IdentifierStyle m -> Highlight
_styleReservedHighlight :: Highlight
  }

-- | This lens can be used to update the name for this style of identifier.
--
-- @'styleName' :: Lens' ('IdentifierStyle' m) 'String'@
styleName :: Functor f => (String -> f String) -> IdentifierStyle m -> f (IdentifierStyle m)
styleName :: forall (f :: * -> *) (m :: * -> *).
Functor f =>
(String -> f String) -> IdentifierStyle m -> f (IdentifierStyle m)
styleName String -> f String
f IdentifierStyle m
is = (\String
n -> IdentifierStyle m
is { _styleName :: String
_styleName = String
n }) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> f String
f (forall (m :: * -> *). IdentifierStyle m -> String
_styleName IdentifierStyle m
is)
{-# INLINE styleName #-}

-- | This lens can be used to update the action used to recognize the first letter in an identifier.
--
-- @'styleStart' :: Lens' ('IdentifierStyle' m) (m 'Char')@
styleStart :: Functor f => (m Char -> f (m Char)) -> IdentifierStyle m -> f (IdentifierStyle m)
styleStart :: forall (f :: * -> *) (m :: * -> *).
Functor f =>
(m Char -> f (m Char))
-> IdentifierStyle m -> f (IdentifierStyle m)
styleStart m Char -> f (m Char)
f IdentifierStyle m
is = (\m Char
n -> IdentifierStyle m
is { _styleStart :: m Char
_styleStart = m Char
n }) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Char -> f (m Char)
f (forall (m :: * -> *). IdentifierStyle m -> m Char
_styleStart IdentifierStyle m
is)
{-# INLINE styleStart #-}

-- | This lens can be used to update the action used to recognize subsequent letters in an identifier.
--
-- @'styleLetter' :: Lens' ('IdentifierStyle' m) (m 'Char')@
styleLetter :: Functor f => (m Char -> f (m Char)) -> IdentifierStyle m -> f (IdentifierStyle m)
styleLetter :: forall (f :: * -> *) (m :: * -> *).
Functor f =>
(m Char -> f (m Char))
-> IdentifierStyle m -> f (IdentifierStyle m)
styleLetter m Char -> f (m Char)
f IdentifierStyle m
is = (\m Char
n -> IdentifierStyle m
is { _styleLetter :: m Char
_styleLetter = m Char
n }) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Char -> f (m Char)
f (forall (m :: * -> *). IdentifierStyle m -> m Char
_styleLetter IdentifierStyle m
is)
{-# INLINE styleLetter #-}

-- | This is a traversal of both actions in contained in an 'IdentifierStyle'.
--
-- @'styleChars' :: Traversal ('IdentifierStyle' m) ('IdentifierStyle' n) (m 'Char') (n 'Char')@
styleChars :: Applicative f => (m Char -> f (n Char)) -> IdentifierStyle m -> f (IdentifierStyle n)
styleChars :: forall (f :: * -> *) (m :: * -> *) (n :: * -> *).
Applicative f =>
(m Char -> f (n Char))
-> IdentifierStyle m -> f (IdentifierStyle n)
styleChars m Char -> f (n Char)
f IdentifierStyle m
is = (\n Char
n n Char
m -> IdentifierStyle m
is { _styleStart :: n Char
_styleStart = n Char
n, _styleLetter :: n Char
_styleLetter = n Char
m }) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Char -> f (n Char)
f (forall (m :: * -> *). IdentifierStyle m -> m Char
_styleStart IdentifierStyle m
is) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Char -> f (n Char)
f (forall (m :: * -> *). IdentifierStyle m -> m Char
_styleLetter IdentifierStyle m
is)
{-# INLINE styleChars #-}

-- | This is a lens that can be used to modify the reserved identifier set.
--
-- @'styleReserved' :: Lens' ('IdentifierStyle' m) ('HashSet' 'String')@
styleReserved :: Functor f => (HashSet String -> f (HashSet String)) -> IdentifierStyle m -> f (IdentifierStyle m)
styleReserved :: forall (f :: * -> *) (m :: * -> *).
Functor f =>
(HashSet String -> f (HashSet String))
-> IdentifierStyle m -> f (IdentifierStyle m)
styleReserved HashSet String -> f (HashSet String)
f IdentifierStyle m
is = (\HashSet String
n -> IdentifierStyle m
is { _styleReserved :: HashSet String
_styleReserved = HashSet String
n }) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> HashSet String -> f (HashSet String)
f (forall (m :: * -> *). IdentifierStyle m -> HashSet String
_styleReserved IdentifierStyle m
is)
{-# INLINE styleReserved #-}

-- | This is a lens that can be used to modify the highlight used for this identifier set.
--
-- @'styleHighlight' :: Lens' ('IdentifierStyle' m) 'Highlight'@
styleHighlight :: Functor f => (Highlight -> f Highlight) -> IdentifierStyle m -> f (IdentifierStyle m)
styleHighlight :: forall (f :: * -> *) (m :: * -> *).
Functor f =>
(Highlight -> f Highlight)
-> IdentifierStyle m -> f (IdentifierStyle m)
styleHighlight Highlight -> f Highlight
f IdentifierStyle m
is = (\Highlight
n -> IdentifierStyle m
is { _styleHighlight :: Highlight
_styleHighlight = Highlight
n }) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Highlight -> f Highlight
f (forall (m :: * -> *). IdentifierStyle m -> Highlight
_styleHighlight IdentifierStyle m
is)
{-# INLINE styleHighlight #-}

-- | 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'@
styleReservedHighlight :: Functor f => (Highlight -> f Highlight) -> IdentifierStyle m -> f (IdentifierStyle m)
styleReservedHighlight :: forall (f :: * -> *) (m :: * -> *).
Functor f =>
(Highlight -> f Highlight)
-> IdentifierStyle m -> f (IdentifierStyle m)
styleReservedHighlight Highlight -> f Highlight
f IdentifierStyle m
is = (\Highlight
n -> IdentifierStyle m
is { _styleReservedHighlight :: Highlight
_styleReservedHighlight = Highlight
n }) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Highlight -> f Highlight
f (forall (m :: * -> *). IdentifierStyle m -> Highlight
_styleReservedHighlight IdentifierStyle m
is)
{-# INLINE styleReservedHighlight #-}

-- | 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'@
styleHighlights :: Applicative f => (Highlight -> f Highlight) -> IdentifierStyle m -> f (IdentifierStyle m)
styleHighlights :: forall (f :: * -> *) (m :: * -> *).
Applicative f =>
(Highlight -> f Highlight)
-> IdentifierStyle m -> f (IdentifierStyle m)
styleHighlights Highlight -> f Highlight
f IdentifierStyle m
is = (\Highlight
n Highlight
m -> IdentifierStyle m
is { _styleHighlight :: Highlight
_styleHighlight = Highlight
n, _styleReservedHighlight :: Highlight
_styleReservedHighlight = Highlight
m }) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Highlight -> f Highlight
f (forall (m :: * -> *). IdentifierStyle m -> Highlight
_styleHighlight IdentifierStyle m
is) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Highlight -> f Highlight
f (forall (m :: * -> *). IdentifierStyle m -> Highlight
_styleReservedHighlight IdentifierStyle m
is)
{-# INLINE styleHighlights #-}

-- | Lift an identifier style into a monad transformer
--
-- Using @over@ from the @lens@ package:
--
-- @'liftIdentifierStyle' = over 'styleChars' 'lift'@
liftIdentifierStyle :: (MonadTrans t, Monad m) => IdentifierStyle m -> IdentifierStyle (t m)
liftIdentifierStyle :: forall (t :: (* -> *) -> * -> *) (m :: * -> *).
(MonadTrans t, Monad m) =>
IdentifierStyle m -> IdentifierStyle (t m)
liftIdentifierStyle = forall a. Identity a -> a
runIdentity forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) (m :: * -> *) (n :: * -> *).
Applicative f =>
(m Char -> f (n Char))
-> IdentifierStyle m -> f (IdentifierStyle n)
styleChars (forall a. a -> Identity a
Identity forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift)
{-# INLINE liftIdentifierStyle #-}

-- | parse a reserved operator or identifier using a given style
reserve :: (TokenParsing m, Monad m) => IdentifierStyle m -> String -> m ()
reserve :: forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m -> String -> m ()
reserve IdentifierStyle m
s String
name = forall (m :: * -> *) a. TokenParsing m => m a -> m a
token forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Parsing m => m a -> m a
try forall a b. (a -> b) -> a -> b
$ do
   String
_ <- forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight (forall (m :: * -> *). IdentifierStyle m -> Highlight
_styleReservedHighlight IdentifierStyle m
s) forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). CharParsing m => String -> m String
string String
name
   forall (m :: * -> *) a. (Parsing m, Show a) => m a -> m ()
notFollowedBy (forall (m :: * -> *). IdentifierStyle m -> m Char
_styleLetter IdentifierStyle m
s) forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"end of " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show String
name
{-# INLINE reserve #-}

-- | parse a reserved operator or identifier using a given style given 'Text'.
reserveText :: (TokenParsing m, Monad m) => IdentifierStyle m -> Text -> m ()
reserveText :: forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m -> Text -> m ()
reserveText IdentifierStyle m
s Text
name = forall (m :: * -> *) a. TokenParsing m => m a -> m a
token forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Parsing m => m a -> m a
try forall a b. (a -> b) -> a -> b
$ do
   Text
_ <- forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight (forall (m :: * -> *). IdentifierStyle m -> Highlight
_styleReservedHighlight IdentifierStyle m
s) forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). CharParsing m => Text -> m Text
text Text
name
   forall (m :: * -> *) a. (Parsing m, Show a) => m a -> m ()
notFollowedBy (forall (m :: * -> *). IdentifierStyle m -> m Char
_styleLetter IdentifierStyle m
s) forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"end of " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show Text
name
{-# INLINE reserveText #-}

-- | Parse a non-reserved identifier or symbol
ident :: (TokenParsing m, Monad m, IsString s) => IdentifierStyle m -> m s
ident :: forall (m :: * -> *) s.
(TokenParsing m, Monad m, IsString s) =>
IdentifierStyle m -> m s
ident IdentifierStyle m
s = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. IsString a => String -> a
fromString forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. TokenParsing m => m a -> m a
token forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Parsing m => m a -> m a
try forall a b. (a -> b) -> a -> b
$ do
  String
name <- forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight (forall (m :: * -> *). IdentifierStyle m -> Highlight
_styleHighlight IdentifierStyle m
s)
          ((:) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). IdentifierStyle m -> m Char
_styleStart IdentifierStyle m
s forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (forall (m :: * -> *). IdentifierStyle m -> m Char
_styleLetter IdentifierStyle m
s) forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> forall (m :: * -> *). IdentifierStyle m -> String
_styleName IdentifierStyle m
s)
  forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (forall a. (Eq a, Hashable a) => a -> HashSet a -> Bool
HashSet.member String
name (forall (m :: * -> *). IdentifierStyle m -> HashSet String
_styleReserved IdentifierStyle m
s)) forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Parsing m => String -> m a
unexpected forall a b. (a -> b) -> a -> b
$ String
"reserved " forall a. [a] -> [a] -> [a]
++ forall (m :: * -> *). IdentifierStyle m -> String
_styleName IdentifierStyle m
s forall a. [a] -> [a] -> [a]
++ String
" " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show String
name
  forall (m :: * -> *) a. Monad m => a -> m a
return String
name
{-# INLINE ident #-}

-- * Utilities

-- | This parser parses a character literal without the surrounding quotation marks.
--
-- This parser does NOT swallow trailing whitespace

characterChar :: TokenParsing m => m Char

charEscape, charLetter :: TokenParsing m => m Char
characterChar :: forall (m :: * -> *). TokenParsing m => m Char
characterChar = forall (m :: * -> *). TokenParsing m => m Char
charLetter forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (m :: * -> *). TokenParsing m => m Char
charEscape forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"literal character"
{-# INLINE characterChar #-}

charEscape :: forall (m :: * -> *). TokenParsing m => m Char
charEscape = forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
EscapeCode forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'\\' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). TokenParsing m => m Char
escapeCode
{-# INLINE charEscape #-}

charLetter :: forall (m :: * -> *). TokenParsing m => m Char
charLetter = forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
satisfy (\Char
c -> (Char
c forall a. Eq a => a -> a -> Bool
/= Char
'\'') Bool -> Bool -> Bool
&& (Char
c forall a. Eq a => a -> a -> Bool
/= Char
'\\') Bool -> Bool -> Bool
&& (Char
c forall a. Ord a => a -> a -> Bool
> Char
'\026'))
{-# INLINE charLetter #-}

-- | This 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).
--
-- This parser does NOT swallow trailing whitespace

escapeCode :: forall m. TokenParsing m => m Char
escapeCode :: forall (m :: * -> *). TokenParsing m => m Char
escapeCode = (m Char
charEsc forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> m Char
charNum forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> m Char
charAscii forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> m Char
charControl) forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"escape code"
  where
  charControl, charNum :: m Char
  charControl :: m Char
charControl = (\Char
c -> forall a. Enum a => Int -> a
toEnum (forall a. Enum a => a -> Int
fromEnum Char
c forall a. Num a => a -> a -> a
- forall a. Enum a => a -> Int
fromEnum Char
'@')) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'^' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (forall (m :: * -> *). CharParsing m => m Char
upper forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'@'))
  charNum :: m Char
charNum = forall a. Enum a => Int -> a
toEnum forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Int
num
    where
      num :: m Int
      num :: m Int
num = Int -> Int -> m Int
bounded Int
10 Int
maxchar
        forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'o' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> Int -> m Int
bounded Int
8 Int
maxchar)
        forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'x' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> Int -> m Int
bounded Int
16 Int
maxchar)
      maxchar :: Int
maxchar = forall a. Enum a => a -> Int
fromEnum (forall a. Bounded a => a
maxBound :: Char)

  bounded :: Int -> Int -> m Int
  bounded :: Int -> Int -> m Int
bounded Int
base Int
bnd = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (\Int
x Char
d -> Int
base forall a. Num a => a -> a -> a
* Int
x forall a. Num a => a -> a -> a
+ Char -> Int
digitToInt Char
d) Int
0
                 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [m Char] -> [Int] -> m String
bounded' (forall a. Int -> [a] -> [a]
take Int
base [m Char]
thedigits) (forall a b. (a -> b) -> [a] -> [b]
map Char -> Int
digitToInt forall a b. (a -> b) -> a -> b
$ forall a.
(Integral a, Show a) =>
a -> (Int -> Char) -> a -> String -> String
showIntAtBase Int
base Int -> Char
intToDigit Int
bnd String
"")
    where
      thedigits :: [m Char]
      thedigits :: [m Char]
thedigits = forall a b. (a -> b) -> [a] -> [b]
map forall (m :: * -> *). CharParsing m => Char -> m Char
char [Char
'0'..Char
'9'] forall a. [a] -> [a] -> [a]
++ forall a b. (a -> b) -> [a] -> [b]
map forall (m :: * -> *). CharParsing m => String -> m Char
oneOf (forall a. [[a]] -> [[a]]
transpose [[Char
'A'..Char
'F'],[Char
'a'..Char
'f']])

      toomuch :: m a
      toomuch :: forall a. m a
toomuch = forall (m :: * -> *) a. Parsing m => String -> m a
unexpected String
"out-of-range numeric escape sequence"

      bounded', bounded'' :: [m Char] -> [Int] -> m [Char]
      bounded' :: [m Char] -> [Int] -> m String
bounded' dps :: [m Char]
dps@(m Char
zero:[m Char]
_) [Int]
bds = forall (m :: * -> *) a. Parsing m => m a -> m ()
skipSome m Char
zero forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ([] forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) a. (Parsing m, Show a) => m a -> m ()
notFollowedBy (forall (m :: * -> *) a. Alternative m => [m a] -> m a
choice [m Char]
dps) forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [m Char] -> [Int] -> m String
bounded'' [m Char]
dps [Int]
bds)
                              forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [m Char] -> [Int] -> m String
bounded'' [m Char]
dps [Int]
bds
      bounded' []           [Int]
_   = forall a. HasCallStack => String -> a
error String
"bounded called with base 0"
      bounded'' :: [m Char] -> [Int] -> m String
bounded'' [m Char]
dps []         = [] forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) a. (Parsing m, Show a) => m a -> m ()
notFollowedBy (forall (m :: * -> *) a. Alternative m => [m a] -> m a
choice [m Char]
dps) forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall a. m a
toomuch
      bounded'' [m Char]
dps (Int
bd : [Int]
bds) = let anyd :: m Char
                                     anyd :: m Char
anyd = forall (m :: * -> *) a. Alternative m => [m a] -> m a
choice [m Char]
dps

                                     nomore :: m ()
                                     nomore :: m ()
nomore = forall (m :: * -> *) a. (Parsing m, Show a) => m a -> m ()
notFollowedBy m Char
anyd forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall a. m a
toomuch
                                     ([m Char]
low, m Char
ex : [m Char]
high) = forall a. Int -> [a] -> ([a], [a])
splitAt Int
bd [m Char]
dps
                                  in ((:) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. Alternative m => [m a] -> m a
choice [m Char]
low forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall {t} {f :: * -> *} {a}.
(Ord t, Num t, Alternative f) =>
t -> f a -> f [a]
atMost (forall (t :: * -> *) a. Foldable t => t a -> Int
length [Int]
bds) m Char
anyd) forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* m ()
nomore
                                     forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ((:) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Char
ex forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ([] forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ m ()
nomore forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [m Char] -> [Int] -> m String
bounded'' [m Char]
dps [Int]
bds))
                                     forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> if Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Int]
bds)
                                            then (:) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. Alternative m => [m a] -> m a
choice [m Char]
high forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall {t} {f :: * -> *} {a}.
(Ord t, Num t, Alternative f) =>
t -> f a -> f [a]
atMost (forall (t :: * -> *) a. Foldable t => t a -> Int
length [Int]
bds forall a. Num a => a -> a -> a
- Int
1) m Char
anyd forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* m ()
nomore
                                            else forall (f :: * -> *) a. Alternative f => f a
empty
      atMost :: t -> f a -> f [a]
atMost t
n f a
p | t
n forall a. Ord a => a -> a -> Bool
<= t
0    = forall (f :: * -> *) a. Applicative f => a -> f a
pure []
                 | Bool
otherwise = ((:) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f a
p forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> t -> f a -> f [a]
atMost (t
n forall a. Num a => a -> a -> a
- t
1) f a
p) forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (f :: * -> *) a. Applicative f => a -> f a
pure []

  charEsc :: m Char
  charEsc :: m Char
charEsc = forall (m :: * -> *) a. Alternative m => [m a] -> m a
choice forall a b. (a -> b) -> a -> b
$ forall {f :: * -> *} {a}. CharParsing f => (Char, a) -> f a
parseEsc forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(Char, Char)]
escMap

  parseEsc :: (Char, a) -> f a
parseEsc (Char
c,a
code) = a
code forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
c
  escMap :: [(Char, Char)]
escMap = forall a b. [a] -> [b] -> [(a, b)]
zip String
"abfnrtv\\\"\'" String
"\a\b\f\n\r\t\v\\\"\'"

  charAscii :: m Char
  charAscii :: m Char
charAscii = forall (m :: * -> *) a. Alternative m => [m a] -> m a
choice forall a b. (a -> b) -> a -> b
$ forall {m :: * -> *} {a}. CharParsing m => (String, a) -> m a
parseAscii forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(String, Char)]
asciiMap

  parseAscii :: (String, a) -> m a
parseAscii (String
asc,a
code) = forall (m :: * -> *) a. Parsing m => m a -> m a
try forall a b. (a -> b) -> a -> b
$ a
code forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *). CharParsing m => String -> m String
string String
asc
  asciiMap :: [(String, Char)]
asciiMap = forall a b. [a] -> [b] -> [(a, b)]
zip ([String]
ascii3codes forall a. [a] -> [a] -> [a]
++ [String]
ascii2codes) (String
ascii3 forall a. [a] -> [a] -> [a]
++ String
ascii2)
  ascii2codes, ascii3codes :: [String]
  ascii2codes :: [String]
ascii2codes = [ String
"BS",String
"HT",String
"LF",String
"VT",String
"FF",String
"CR",String
"SO"
                , String
"SI",String
"EM",String
"FS",String
"GS",String
"RS",String
"US",String
"SP"]
  ascii3codes :: [String]
ascii3codes = [String
"NUL",String
"SOH",String
"STX",String
"ETX",String
"EOT",String
"ENQ",String
"ACK"
                ,String
"BEL",String
"DLE",String
"DC1",String
"DC2",String
"DC3",String
"DC4",String
"NAK"
                ,String
"SYN",String
"ETB",String
"CAN",String
"SUB",String
"ESC",String
"DEL"]
  ascii2, ascii3 :: String
  ascii2 :: String
ascii2 = String
"\BS\HT\LF\VT\FF\CR\SO\SI\EM\FS\GS\RS\US\SP"
  ascii3 :: String
ascii3 = String
"\NUL\SOH\STX\ETX\EOT\ENQ\ACK\BEL\DLE\DC1\DC2\DC3\DC4\NAK\SYN\ETB\CAN\SUB\ESC\DEL"

-- | This 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.
--
-- This parser does NOT swallow trailing whitespace.
natural' :: TokenParsing m => m Integer
natural' :: forall (m :: * -> *). TokenParsing m => m Integer
natural' = forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
Number forall (m :: * -> *). TokenParsing m => m Integer
nat forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"natural"

number :: TokenParsing m => Integer -> m Char -> m Integer
number :: forall (m :: * -> *).
TokenParsing m =>
Integer -> m Char -> m Integer
number Integer
base m Char
baseDigit =
  forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (\Integer
x Char
d -> Integer
baseforall a. Num a => a -> a -> a
*Integer
x forall a. Num a => a -> a -> a
+ forall a. Integral a => a -> Integer
toInteger (Char -> Int
digitToInt Char
d)) Integer
0 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (f :: * -> *) a. Alternative f => f a -> f [a]
some m Char
baseDigit

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

integer' :: TokenParsing m => m Integer
integer' :: forall (m :: * -> *). TokenParsing m => m Integer
integer' = forall (m :: * -> *). TokenParsing m => m Integer
int forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"integer"
{-# INLINE integer' #-}

sign :: TokenParsing m => m (Integer -> Integer)
sign :: forall (m :: * -> *). TokenParsing m => m (Integer -> Integer)
sign = forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
Operator
     forall a b. (a -> b) -> a -> b
$ forall a. Num a => a -> a
negate forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'-'
   forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall a. a -> a
id forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'+'
   forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. a -> a
id

int :: TokenParsing m => m Integer
int :: forall (m :: * -> *). TokenParsing m => m Integer
int = {-token-} forall (m :: * -> *). TokenParsing m => m (Integer -> Integer)
sign forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
Number forall (m :: * -> *). TokenParsing m => m Integer
nat
nat, zeroNumber :: TokenParsing m => m Integer
nat :: forall (m :: * -> *). TokenParsing m => m Integer
nat = forall (m :: * -> *). TokenParsing m => m Integer
zeroNumber forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (m :: * -> *). TokenParsing m => m Integer
decimal
zeroNumber :: forall (m :: * -> *). TokenParsing m => m Integer
zeroNumber = forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'0' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (forall (m :: * -> *). TokenParsing m => m Integer
hexadecimal forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (m :: * -> *). TokenParsing m => m Integer
octal forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (m :: * -> *). TokenParsing m => m Integer
decimal forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (f :: * -> *) a. Applicative f => a -> f a
pure Integer
0) forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
""

floating :: TokenParsing m => m Scientific
floating :: forall (m :: * -> *). TokenParsing m => m Scientific
floating = forall (m :: * -> *). TokenParsing m => m Integer
decimal forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
<**> forall (m :: * -> *). TokenParsing m => m (Integer -> Scientific)
fractExponent
{-# INLINE floating #-}

fractExponent :: forall m. TokenParsing m => m (Integer -> Scientific)
fractExponent :: forall (m :: * -> *). TokenParsing m => m (Integer -> Scientific)
fractExponent = (\Scientific
fract Scientific
expo Integer
n -> (forall a. Num a => Integer -> a
fromInteger Integer
n forall a. Num a => a -> a -> a
+ Scientific
fract) forall a. Num a => a -> a -> a
* Scientific
expo) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Scientific
fraction forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (m :: * -> *) a. Alternative m => a -> m a -> m a
option Scientific
1 m Scientific
exponent'
            forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (\Scientific
expo Integer
n -> forall a. Num a => Integer -> a
fromInteger Integer
n forall a. Num a => a -> a -> a
* Scientific
expo) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Scientific
exponent'
 where
  fraction :: m Scientific
  fraction :: m Scientific
fraction = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' Scientific -> Char -> Scientific
op Scientific
0 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'.' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (forall (f :: * -> *) a. Alternative f => f a -> f [a]
some forall (m :: * -> *). CharParsing m => m Char
digit forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"fraction"))

  op :: Scientific -> Char -> Scientific
op Scientific
f Char
d = Scientific
f forall a. Num a => a -> a -> a
+ Integer -> Int -> Scientific
Sci.scientific (forall a b. (Integral a, Num b) => a -> b
fromIntegral (Char -> Int
digitToInt Char
d)) (Scientific -> Int
Sci.base10Exponent Scientific
f forall a. Num a => a -> a -> a
- Int
1)

  exponent' :: m Scientific
  exponent' :: m Scientific
exponent' = ((\Integer -> Integer
f Integer
e -> Integer -> Scientific
power (Integer -> Integer
f Integer
e)) forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *). CharParsing m => String -> m Char
oneOf String
"eE" forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (m :: * -> *). TokenParsing m => m (Integer -> Integer)
sign forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (forall (m :: * -> *). TokenParsing m => m Integer
decimal forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"exponent")) forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"exponent"

  power :: Integer -> Scientific
power = Integer -> Int -> Scientific
Sci.scientific Integer
1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Num a => Integer -> a
fromInteger


natFloating, zeroNumFloat, decimalFloat :: TokenParsing m => m (Either Integer Scientific)
natFloating :: forall (m :: * -> *).
TokenParsing m =>
m (Either Integer Scientific)
natFloating
    = forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'0' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *).
TokenParsing m =>
m (Either Integer Scientific)
zeroNumFloat
  forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (m :: * -> *).
TokenParsing m =>
m (Either Integer Scientific)
decimalFloat
zeroNumFloat :: forall (m :: * -> *).
TokenParsing m =>
m (Either Integer Scientific)
zeroNumFloat
    = forall a b. a -> Either a b
Left forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall (m :: * -> *). TokenParsing m => m Integer
hexadecimal forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (m :: * -> *). TokenParsing m => m Integer
octal)
  forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (m :: * -> *).
TokenParsing m =>
m (Either Integer Scientific)
decimalFloat
  forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (f :: * -> *) a. Applicative f => a -> f a
pure Integer
0 forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
<**> forall (m :: * -> *) a. Parsing m => m a -> m a
try forall (m :: * -> *).
TokenParsing m =>
m (Integer -> Either Integer Scientific)
fractFloat
  forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall a b. a -> Either a b
Left Integer
0)
decimalFloat :: forall (m :: * -> *).
TokenParsing m =>
m (Either Integer Scientific)
decimalFloat = forall (m :: * -> *). TokenParsing m => m Integer
decimal forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
<**> forall (m :: * -> *) a. Alternative m => a -> m a -> m a
option forall a b. a -> Either a b
Left (forall (m :: * -> *) a. Parsing m => m a -> m a
try forall (m :: * -> *).
TokenParsing m =>
m (Integer -> Either Integer Scientific)
fractFloat)

fractFloat :: TokenParsing m => m (Integer -> Either Integer Scientific)
fractFloat :: forall (m :: * -> *).
TokenParsing m =>
m (Integer -> Either Integer Scientific)
fractFloat = (forall a b. b -> Either a b
Right forall b c a. (b -> c) -> (a -> b) -> a -> c
.) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). TokenParsing m => m (Integer -> Scientific)
fractExponent
{-# INLINE fractFloat #-}

-- | Parses a non-negative whole number in the decimal system. Returns the
-- value of the number.
--
-- This parser does NOT swallow trailing whitespace
decimal :: TokenParsing m => m Integer
decimal :: forall (m :: * -> *). TokenParsing m => m Integer
decimal = forall (m :: * -> *).
TokenParsing m =>
Integer -> m Char -> m Integer
number Integer
10 forall (m :: * -> *). CharParsing m => m Char
digit
{-# INLINE decimal #-}

-- | 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
hexadecimal :: TokenParsing m => m Integer
hexadecimal :: forall (m :: * -> *). TokenParsing m => m Integer
hexadecimal = forall (m :: * -> *). CharParsing m => String -> m Char
oneOf String
"xX" forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *).
TokenParsing m =>
Integer -> m Char -> m Integer
number Integer
16 forall (m :: * -> *). CharParsing m => m Char
hexDigit
{-# INLINE hexadecimal #-}

-- | 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
octal :: TokenParsing m => m Integer
octal :: forall (m :: * -> *). TokenParsing m => m Integer
octal = forall (m :: * -> *). CharParsing m => String -> m Char
oneOf String
"oO" forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *).
TokenParsing m =>
Integer -> m Char -> m Integer
number Integer
8 forall (m :: * -> *). CharParsing m => m Char
octDigit
{-# INLINE octal #-}

-- | This is a parser transformer you can use to disable syntax highlighting
-- over a range of text you are parsing.
newtype Unhighlighted m a = Unhighlighted { forall (m :: * -> *) a. Unhighlighted m a -> m a
runUnhighlighted :: m a }
  deriving (forall a b. a -> Unhighlighted m b -> Unhighlighted m a
forall a b. (a -> b) -> Unhighlighted m a -> Unhighlighted m b
forall (m :: * -> *) a b.
Functor m =>
a -> Unhighlighted m b -> Unhighlighted m a
forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> Unhighlighted m a -> Unhighlighted m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Unhighlighted m b -> Unhighlighted m a
$c<$ :: forall (m :: * -> *) a b.
Functor m =>
a -> Unhighlighted m b -> Unhighlighted m a
fmap :: forall a b. (a -> b) -> Unhighlighted m a -> Unhighlighted m b
$cfmap :: forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> Unhighlighted m a -> Unhighlighted m b
Functor,forall a. a -> Unhighlighted m a
forall a b.
Unhighlighted m a -> Unhighlighted m b -> Unhighlighted m a
forall a b.
Unhighlighted m a -> Unhighlighted m b -> Unhighlighted m b
forall a b.
Unhighlighted m (a -> b) -> Unhighlighted m a -> Unhighlighted m b
forall a b c.
(a -> b -> c)
-> Unhighlighted m a -> Unhighlighted m b -> Unhighlighted m c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
forall {m :: * -> *}. Applicative m => Functor (Unhighlighted m)
forall (m :: * -> *) a. Applicative m => a -> Unhighlighted m a
forall (m :: * -> *) a b.
Applicative m =>
Unhighlighted m a -> Unhighlighted m b -> Unhighlighted m a
forall (m :: * -> *) a b.
Applicative m =>
Unhighlighted m a -> Unhighlighted m b -> Unhighlighted m b
forall (m :: * -> *) a b.
Applicative m =>
Unhighlighted m (a -> b) -> Unhighlighted m a -> Unhighlighted m b
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c)
-> Unhighlighted m a -> Unhighlighted m b -> Unhighlighted m c
<* :: forall a b.
Unhighlighted m a -> Unhighlighted m b -> Unhighlighted m a
$c<* :: forall (m :: * -> *) a b.
Applicative m =>
Unhighlighted m a -> Unhighlighted m b -> Unhighlighted m a
*> :: forall a b.
Unhighlighted m a -> Unhighlighted m b -> Unhighlighted m b
$c*> :: forall (m :: * -> *) a b.
Applicative m =>
Unhighlighted m a -> Unhighlighted m b -> Unhighlighted m b
liftA2 :: forall a b c.
(a -> b -> c)
-> Unhighlighted m a -> Unhighlighted m b -> Unhighlighted m c
$cliftA2 :: forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c)
-> Unhighlighted m a -> Unhighlighted m b -> Unhighlighted m c
<*> :: forall a b.
Unhighlighted m (a -> b) -> Unhighlighted m a -> Unhighlighted m b
$c<*> :: forall (m :: * -> *) a b.
Applicative m =>
Unhighlighted m (a -> b) -> Unhighlighted m a -> Unhighlighted m b
pure :: forall a. a -> Unhighlighted m a
$cpure :: forall (m :: * -> *) a. Applicative m => a -> Unhighlighted m a
Applicative,forall a. Unhighlighted m a
forall a. Unhighlighted m a -> Unhighlighted m [a]
forall a.
Unhighlighted m a -> Unhighlighted m a -> Unhighlighted m a
forall (f :: * -> *).
Applicative f
-> (forall a. f a)
-> (forall a. f a -> f a -> f a)
-> (forall a. f a -> f [a])
-> (forall a. f a -> f [a])
-> Alternative f
forall {m :: * -> *}.
Alternative m =>
Applicative (Unhighlighted m)
forall (m :: * -> *) a. Alternative m => Unhighlighted m a
forall (m :: * -> *) a.
Alternative m =>
Unhighlighted m a -> Unhighlighted m [a]
forall (m :: * -> *) a.
Alternative m =>
Unhighlighted m a -> Unhighlighted m a -> Unhighlighted m a
many :: forall a. Unhighlighted m a -> Unhighlighted m [a]
$cmany :: forall (m :: * -> *) a.
Alternative m =>
Unhighlighted m a -> Unhighlighted m [a]
some :: forall a. Unhighlighted m a -> Unhighlighted m [a]
$csome :: forall (m :: * -> *) a.
Alternative m =>
Unhighlighted m a -> Unhighlighted m [a]
<|> :: forall a.
Unhighlighted m a -> Unhighlighted m a -> Unhighlighted m a
$c<|> :: forall (m :: * -> *) a.
Alternative m =>
Unhighlighted m a -> Unhighlighted m a -> Unhighlighted m a
empty :: forall a. Unhighlighted m a
$cempty :: forall (m :: * -> *) a. Alternative m => Unhighlighted m a
Alternative,forall a. a -> Unhighlighted m a
forall a b.
Unhighlighted m a -> Unhighlighted m b -> Unhighlighted m b
forall a b.
Unhighlighted m a -> (a -> Unhighlighted m b) -> Unhighlighted m b
forall {m :: * -> *}. Monad m => Applicative (Unhighlighted m)
forall (m :: * -> *) a. Monad m => a -> Unhighlighted m a
forall (m :: * -> *) a b.
Monad m =>
Unhighlighted m a -> Unhighlighted m b -> Unhighlighted m b
forall (m :: * -> *) a b.
Monad m =>
Unhighlighted m a -> (a -> Unhighlighted m b) -> Unhighlighted m b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: forall a. a -> Unhighlighted m a
$creturn :: forall (m :: * -> *) a. Monad m => a -> Unhighlighted m a
>> :: forall a b.
Unhighlighted m a -> Unhighlighted m b -> Unhighlighted m b
$c>> :: forall (m :: * -> *) a b.
Monad m =>
Unhighlighted m a -> Unhighlighted m b -> Unhighlighted m b
>>= :: forall a b.
Unhighlighted m a -> (a -> Unhighlighted m b) -> Unhighlighted m b
$c>>= :: forall (m :: * -> *) a b.
Monad m =>
Unhighlighted m a -> (a -> Unhighlighted m b) -> Unhighlighted m b
Monad,forall a. Unhighlighted m a
forall a.
Unhighlighted m a -> Unhighlighted m a -> Unhighlighted m a
forall (m :: * -> *).
Alternative m
-> Monad m
-> (forall a. m a)
-> (forall a. m a -> m a -> m a)
-> MonadPlus m
forall {m :: * -> *}. MonadPlus m => Monad (Unhighlighted m)
forall {m :: * -> *}. MonadPlus m => Alternative (Unhighlighted m)
forall (m :: * -> *) a. MonadPlus m => Unhighlighted m a
forall (m :: * -> *) a.
MonadPlus m =>
Unhighlighted m a -> Unhighlighted m a -> Unhighlighted m a
mplus :: forall a.
Unhighlighted m a -> Unhighlighted m a -> Unhighlighted m a
$cmplus :: forall (m :: * -> *) a.
MonadPlus m =>
Unhighlighted m a -> Unhighlighted m a -> Unhighlighted m a
mzero :: forall a. Unhighlighted m a
$cmzero :: forall (m :: * -> *) a. MonadPlus m => Unhighlighted m a
MonadPlus,Unhighlighted m Char
Char -> Unhighlighted m Char
String -> Unhighlighted m String
Text -> Unhighlighted m Text
(Char -> Bool) -> Unhighlighted m Char
forall (m :: * -> *).
Parsing m
-> ((Char -> Bool) -> m Char)
-> (Char -> m Char)
-> (Char -> m Char)
-> m Char
-> (String -> m String)
-> (Text -> m Text)
-> CharParsing m
forall {m :: * -> *}. CharParsing m => Parsing (Unhighlighted m)
forall (m :: * -> *). CharParsing m => Unhighlighted m Char
forall (m :: * -> *). CharParsing m => Char -> Unhighlighted m Char
forall (m :: * -> *).
CharParsing m =>
String -> Unhighlighted m String
forall (m :: * -> *). CharParsing m => Text -> Unhighlighted m Text
forall (m :: * -> *).
CharParsing m =>
(Char -> Bool) -> Unhighlighted m Char
text :: Text -> Unhighlighted m Text
$ctext :: forall (m :: * -> *). CharParsing m => Text -> Unhighlighted m Text
string :: String -> Unhighlighted m String
$cstring :: forall (m :: * -> *).
CharParsing m =>
String -> Unhighlighted m String
anyChar :: Unhighlighted m Char
$canyChar :: forall (m :: * -> *). CharParsing m => Unhighlighted m Char
notChar :: Char -> Unhighlighted m Char
$cnotChar :: forall (m :: * -> *). CharParsing m => Char -> Unhighlighted m Char
char :: Char -> Unhighlighted m Char
$cchar :: forall (m :: * -> *). CharParsing m => Char -> Unhighlighted m Char
satisfy :: (Char -> Bool) -> Unhighlighted m Char
$csatisfy :: forall (m :: * -> *).
CharParsing m =>
(Char -> Bool) -> Unhighlighted m Char
CharParsing)

instance Parsing m => Parsing (Unhighlighted m) where
  try :: forall a. Unhighlighted m a -> Unhighlighted m a
try (Unhighlighted m a
m) = forall (m :: * -> *) a. m a -> Unhighlighted m a
Unhighlighted forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Parsing m => m a -> m a
try m a
m
  {-# INLINE try #-}
  Unhighlighted m a
m <?> :: forall a. Unhighlighted m a -> String -> Unhighlighted m a
<?> String
l = forall (m :: * -> *) a. m a -> Unhighlighted m a
Unhighlighted forall a b. (a -> b) -> a -> b
$ m a
m forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
l
  {-# INLINE (<?>) #-}
  unexpected :: forall a. String -> Unhighlighted m a
unexpected = forall (m :: * -> *) a. m a -> Unhighlighted m a
Unhighlighted forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. Parsing m => String -> m a
unexpected
  {-# INLINE unexpected #-}
  eof :: Unhighlighted m ()
eof = forall (m :: * -> *) a. m a -> Unhighlighted m a
Unhighlighted forall (m :: * -> *). Parsing m => m ()
eof
  {-# INLINE eof #-}
  notFollowedBy :: forall a. Show a => Unhighlighted m a -> Unhighlighted m ()
notFollowedBy (Unhighlighted m a
m) = forall (m :: * -> *) a. m a -> Unhighlighted m a
Unhighlighted forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. (Parsing m, Show a) => m a -> m ()
notFollowedBy m a
m
  {-# INLINE notFollowedBy #-}


instance MonadTrans Unhighlighted where
  lift :: forall (m :: * -> *) a. Monad m => m a -> Unhighlighted m a
lift = forall (m :: * -> *) a. m a -> Unhighlighted m a
Unhighlighted
  {-# INLINE lift #-}

instance MonadState s m => MonadState s (Unhighlighted m) where
  get :: Unhighlighted m s
get = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall s (m :: * -> *). MonadState s m => m s
Class.get
  {-# INLINE get #-}
  put :: s -> Unhighlighted m ()
put = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s (m :: * -> *). MonadState s m => s -> m ()
Class.put
  {-# INLINE put #-}

instance MonadReader e m => MonadReader e (Unhighlighted m) where
  ask :: Unhighlighted m e
ask = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall r (m :: * -> *). MonadReader r m => m r
Class.ask
  {-# INLINE ask #-}
  local :: forall a. (e -> e) -> Unhighlighted m a -> Unhighlighted m a
local e -> e
f = forall (m :: * -> *) a. m a -> Unhighlighted m a
Unhighlighted forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
Class.local e -> e
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. Unhighlighted m a -> m a
runUnhighlighted
  {-# INLINE local #-}

instance MonadWriter e m => MonadWriter e (Unhighlighted m) where
  tell :: e -> Unhighlighted m ()
tell = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall w (m :: * -> *). MonadWriter w m => w -> m ()
Class.tell
  {-# INLINE tell #-}
  listen :: forall a. Unhighlighted m a -> Unhighlighted m (a, e)
listen = forall (m :: * -> *) a. m a -> Unhighlighted m a
Unhighlighted forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall w (m :: * -> *) a. MonadWriter w m => m a -> m (a, w)
Class.listen forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. Unhighlighted m a -> m a
runUnhighlighted
  {-# INLINE listen #-}
  pass :: forall a. Unhighlighted m (a, e -> e) -> Unhighlighted m a
pass = forall (m :: * -> *) a. m a -> Unhighlighted m a
Unhighlighted forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall w (m :: * -> *) a. MonadWriter w m => m (a, w -> w) -> m a
Class.pass forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. Unhighlighted m a -> m a
runUnhighlighted
  {-# INLINE pass #-}

instance TokenParsing m => TokenParsing (Unhighlighted m) where
  nesting :: forall a. Unhighlighted m a -> Unhighlighted m a
nesting (Unhighlighted m a
m) = forall (m :: * -> *) a. m a -> Unhighlighted m a
Unhighlighted (forall (m :: * -> *) a. TokenParsing m => m a -> m a
nesting m a
m)
  {-# INLINE nesting #-}
  someSpace :: Unhighlighted m ()
someSpace = forall (m :: * -> *) a. m a -> Unhighlighted m a
Unhighlighted forall (m :: * -> *). TokenParsing m => m ()
someSpace
  {-# INLINE someSpace #-}
  semi :: Unhighlighted m Char
semi      = forall (m :: * -> *) a. m a -> Unhighlighted m a
Unhighlighted forall (m :: * -> *). TokenParsing m => m Char
semi
  {-# INLINE semi #-}
  highlight :: forall a. Highlight -> Unhighlighted m a -> Unhighlighted m a
highlight Highlight
_ Unhighlighted m a
m = Unhighlighted m a
m
  {-# INLINE highlight #-}

-- | This is a parser transformer you can use to disable the automatic trailing
-- space consumption of a Token parser.
newtype Unspaced m a = Unspaced { forall (m :: * -> *) a. Unspaced m a -> m a
runUnspaced :: m a }
  deriving (forall a b. a -> Unspaced m b -> Unspaced m a
forall a b. (a -> b) -> Unspaced m a -> Unspaced m b
forall (m :: * -> *) a b.
Functor m =>
a -> Unspaced m b -> Unspaced m a
forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> Unspaced m a -> Unspaced m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Unspaced m b -> Unspaced m a
$c<$ :: forall (m :: * -> *) a b.
Functor m =>
a -> Unspaced m b -> Unspaced m a
fmap :: forall a b. (a -> b) -> Unspaced m a -> Unspaced m b
$cfmap :: forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> Unspaced m a -> Unspaced m b
Functor,forall a. a -> Unspaced m a
forall a b. Unspaced m a -> Unspaced m b -> Unspaced m a
forall a b. Unspaced m a -> Unspaced m b -> Unspaced m b
forall a b. Unspaced m (a -> b) -> Unspaced m a -> Unspaced m b
forall a b c.
(a -> b -> c) -> Unspaced m a -> Unspaced m b -> Unspaced m c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
forall {m :: * -> *}. Applicative m => Functor (Unspaced m)
forall (m :: * -> *) a. Applicative m => a -> Unspaced m a
forall (m :: * -> *) a b.
Applicative m =>
Unspaced m a -> Unspaced m b -> Unspaced m a
forall (m :: * -> *) a b.
Applicative m =>
Unspaced m a -> Unspaced m b -> Unspaced m b
forall (m :: * -> *) a b.
Applicative m =>
Unspaced m (a -> b) -> Unspaced m a -> Unspaced m b
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c) -> Unspaced m a -> Unspaced m b -> Unspaced m c
<* :: forall a b. Unspaced m a -> Unspaced m b -> Unspaced m a
$c<* :: forall (m :: * -> *) a b.
Applicative m =>
Unspaced m a -> Unspaced m b -> Unspaced m a
*> :: forall a b. Unspaced m a -> Unspaced m b -> Unspaced m b
$c*> :: forall (m :: * -> *) a b.
Applicative m =>
Unspaced m a -> Unspaced m b -> Unspaced m b
liftA2 :: forall a b c.
(a -> b -> c) -> Unspaced m a -> Unspaced m b -> Unspaced m c
$cliftA2 :: forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c) -> Unspaced m a -> Unspaced m b -> Unspaced m c
<*> :: forall a b. Unspaced m (a -> b) -> Unspaced m a -> Unspaced m b
$c<*> :: forall (m :: * -> *) a b.
Applicative m =>
Unspaced m (a -> b) -> Unspaced m a -> Unspaced m b
pure :: forall a. a -> Unspaced m a
$cpure :: forall (m :: * -> *) a. Applicative m => a -> Unspaced m a
Applicative,forall a. Unspaced m a
forall a. Unspaced m a -> Unspaced m [a]
forall a. Unspaced m a -> Unspaced m a -> Unspaced m a
forall (f :: * -> *).
Applicative f
-> (forall a. f a)
-> (forall a. f a -> f a -> f a)
-> (forall a. f a -> f [a])
-> (forall a. f a -> f [a])
-> Alternative f
forall {m :: * -> *}. Alternative m => Applicative (Unspaced m)
forall (m :: * -> *) a. Alternative m => Unspaced m a
forall (m :: * -> *) a.
Alternative m =>
Unspaced m a -> Unspaced m [a]
forall (m :: * -> *) a.
Alternative m =>
Unspaced m a -> Unspaced m a -> Unspaced m a
many :: forall a. Unspaced m a -> Unspaced m [a]
$cmany :: forall (m :: * -> *) a.
Alternative m =>
Unspaced m a -> Unspaced m [a]
some :: forall a. Unspaced m a -> Unspaced m [a]
$csome :: forall (m :: * -> *) a.
Alternative m =>
Unspaced m a -> Unspaced m [a]
<|> :: forall a. Unspaced m a -> Unspaced m a -> Unspaced m a
$c<|> :: forall (m :: * -> *) a.
Alternative m =>
Unspaced m a -> Unspaced m a -> Unspaced m a
empty :: forall a. Unspaced m a
$cempty :: forall (m :: * -> *) a. Alternative m => Unspaced m a
Alternative,forall a. a -> Unspaced m a
forall a b. Unspaced m a -> Unspaced m b -> Unspaced m b
forall a b. Unspaced m a -> (a -> Unspaced m b) -> Unspaced m b
forall {m :: * -> *}. Monad m => Applicative (Unspaced m)
forall (m :: * -> *) a. Monad m => a -> Unspaced m a
forall (m :: * -> *) a b.
Monad m =>
Unspaced m a -> Unspaced m b -> Unspaced m b
forall (m :: * -> *) a b.
Monad m =>
Unspaced m a -> (a -> Unspaced m b) -> Unspaced m b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: forall a. a -> Unspaced m a
$creturn :: forall (m :: * -> *) a. Monad m => a -> Unspaced m a
>> :: forall a b. Unspaced m a -> Unspaced m b -> Unspaced m b
$c>> :: forall (m :: * -> *) a b.
Monad m =>
Unspaced m a -> Unspaced m b -> Unspaced m b
>>= :: forall a b. Unspaced m a -> (a -> Unspaced m b) -> Unspaced m b
$c>>= :: forall (m :: * -> *) a b.
Monad m =>
Unspaced m a -> (a -> Unspaced m b) -> Unspaced m b
Monad,forall a. Unspaced m a
forall a. Unspaced m a -> Unspaced m a -> Unspaced m a
forall (m :: * -> *).
Alternative m
-> Monad m
-> (forall a. m a)
-> (forall a. m a -> m a -> m a)
-> MonadPlus m
forall {m :: * -> *}. MonadPlus m => Monad (Unspaced m)
forall {m :: * -> *}. MonadPlus m => Alternative (Unspaced m)
forall (m :: * -> *) a. MonadPlus m => Unspaced m a
forall (m :: * -> *) a.
MonadPlus m =>
Unspaced m a -> Unspaced m a -> Unspaced m a
mplus :: forall a. Unspaced m a -> Unspaced m a -> Unspaced m a
$cmplus :: forall (m :: * -> *) a.
MonadPlus m =>
Unspaced m a -> Unspaced m a -> Unspaced m a
mzero :: forall a. Unspaced m a
$cmzero :: forall (m :: * -> *) a. MonadPlus m => Unspaced m a
MonadPlus,Unspaced m Char
Char -> Unspaced m Char
String -> Unspaced m String
Text -> Unspaced m Text
(Char -> Bool) -> Unspaced m Char
forall (m :: * -> *).
Parsing m
-> ((Char -> Bool) -> m Char)
-> (Char -> m Char)
-> (Char -> m Char)
-> m Char
-> (String -> m String)
-> (Text -> m Text)
-> CharParsing m
forall {m :: * -> *}. CharParsing m => Parsing (Unspaced m)
forall (m :: * -> *). CharParsing m => Unspaced m Char
forall (m :: * -> *). CharParsing m => Char -> Unspaced m Char
forall (m :: * -> *). CharParsing m => String -> Unspaced m String
forall (m :: * -> *). CharParsing m => Text -> Unspaced m Text
forall (m :: * -> *).
CharParsing m =>
(Char -> Bool) -> Unspaced m Char
text :: Text -> Unspaced m Text
$ctext :: forall (m :: * -> *). CharParsing m => Text -> Unspaced m Text
string :: String -> Unspaced m String
$cstring :: forall (m :: * -> *). CharParsing m => String -> Unspaced m String
anyChar :: Unspaced m Char
$canyChar :: forall (m :: * -> *). CharParsing m => Unspaced m Char
notChar :: Char -> Unspaced m Char
$cnotChar :: forall (m :: * -> *). CharParsing m => Char -> Unspaced m Char
char :: Char -> Unspaced m Char
$cchar :: forall (m :: * -> *). CharParsing m => Char -> Unspaced m Char
satisfy :: (Char -> Bool) -> Unspaced m Char
$csatisfy :: forall (m :: * -> *).
CharParsing m =>
(Char -> Bool) -> Unspaced m Char
CharParsing)

instance Parsing m => Parsing (Unspaced m) where
  try :: forall a. Unspaced m a -> Unspaced m a
try (Unspaced m a
m) = forall (m :: * -> *) a. m a -> Unspaced m a
Unspaced forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Parsing m => m a -> m a
try m a
m
  {-# INLINE try #-}
  Unspaced m a
m <?> :: forall a. Unspaced m a -> String -> Unspaced m a
<?> String
l = forall (m :: * -> *) a. m a -> Unspaced m a
Unspaced forall a b. (a -> b) -> a -> b
$ m a
m forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
l
  {-# INLINE (<?>) #-}
  unexpected :: forall a. String -> Unspaced m a
unexpected = forall (m :: * -> *) a. m a -> Unspaced m a
Unspaced forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. Parsing m => String -> m a
unexpected
  {-# INLINE unexpected #-}
  eof :: Unspaced m ()
eof = forall (m :: * -> *) a. m a -> Unspaced m a
Unspaced forall (m :: * -> *). Parsing m => m ()
eof
  {-# INLINE eof #-}
  notFollowedBy :: forall a. Show a => Unspaced m a -> Unspaced m ()
notFollowedBy (Unspaced m a
m) = forall (m :: * -> *) a. m a -> Unspaced m a
Unspaced forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. (Parsing m, Show a) => m a -> m ()
notFollowedBy m a
m
  {-# INLINE notFollowedBy #-}

instance MonadTrans Unspaced where
  lift :: forall (m :: * -> *) a. Monad m => m a -> Unspaced m a
lift = forall (m :: * -> *) a. m a -> Unspaced m a
Unspaced
  {-# INLINE lift #-}

instance MonadState s m => MonadState s (Unspaced m) where
  get :: Unspaced m s
get = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall s (m :: * -> *). MonadState s m => m s
Class.get
  {-# INLINE get #-}
  put :: s -> Unspaced m ()
put = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s (m :: * -> *). MonadState s m => s -> m ()
Class.put
  {-# INLINE put #-}

instance MonadReader e m => MonadReader e (Unspaced m) where
  ask :: Unspaced m e
ask = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall r (m :: * -> *). MonadReader r m => m r
Class.ask
  {-# INLINE ask #-}
  local :: forall a. (e -> e) -> Unspaced m a -> Unspaced m a
local e -> e
f = forall (m :: * -> *) a. m a -> Unspaced m a
Unspaced forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
Class.local e -> e
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. Unspaced m a -> m a
runUnspaced
  {-# INLINE local #-}

instance MonadWriter e m => MonadWriter e (Unspaced m) where
  tell :: e -> Unspaced m ()
tell = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall w (m :: * -> *). MonadWriter w m => w -> m ()
Class.tell
  {-# INLINE tell #-}
  listen :: forall a. Unspaced m a -> Unspaced m (a, e)
listen = forall (m :: * -> *) a. m a -> Unspaced m a
Unspaced forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall w (m :: * -> *) a. MonadWriter w m => m a -> m (a, w)
Class.listen forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. Unspaced m a -> m a
runUnspaced
  {-# INLINE listen #-}
  pass :: forall a. Unspaced m (a, e -> e) -> Unspaced m a
pass = forall (m :: * -> *) a. m a -> Unspaced m a
Unspaced forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall w (m :: * -> *) a. MonadWriter w m => m (a, w -> w) -> m a
Class.pass forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. Unspaced m a -> m a
runUnspaced
  {-# INLINE pass #-}

instance TokenParsing m => TokenParsing (Unspaced m) where
  nesting :: forall a. Unspaced m a -> Unspaced m a
nesting (Unspaced m a
m) = forall (m :: * -> *) a. m a -> Unspaced m a
Unspaced (forall (m :: * -> *) a. TokenParsing m => m a -> m a
nesting m a
m)
  {-# INLINE nesting #-}
  someSpace :: Unspaced m ()
someSpace = forall (f :: * -> *) a. Alternative f => f a
empty
  {-# INLINE someSpace #-}
  semi :: Unspaced m Char
semi      = forall (m :: * -> *) a. m a -> Unspaced m a
Unspaced forall (m :: * -> *). TokenParsing m => m Char
semi
  {-# INLINE semi #-}
  highlight :: forall a. Highlight -> Unspaced m a -> Unspaced m a
highlight Highlight
h (Unspaced m a
m) = forall (m :: * -> *) a. m a -> Unspaced m a
Unspaced (forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
h m a
m)
  {-# INLINE highlight #-}

-- | This is a parser transformer you can use to disable the automatic trailing
-- newline (but not whitespace-in-general) consumption of a Token parser.
newtype Unlined m a = Unlined { forall (m :: * -> *) a. Unlined m a -> m a
runUnlined :: m a }
  deriving (forall a b. a -> Unlined m b -> Unlined m a
forall a b. (a -> b) -> Unlined m a -> Unlined m b
forall (m :: * -> *) a b.
Functor m =>
a -> Unlined m b -> Unlined m a
forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> Unlined m a -> Unlined m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Unlined m b -> Unlined m a
$c<$ :: forall (m :: * -> *) a b.
Functor m =>
a -> Unlined m b -> Unlined m a
fmap :: forall a b. (a -> b) -> Unlined m a -> Unlined m b
$cfmap :: forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> Unlined m a -> Unlined m b
Functor,forall a. a -> Unlined m a
forall a b. Unlined m a -> Unlined m b -> Unlined m a
forall a b. Unlined m a -> Unlined m b -> Unlined m b
forall a b. Unlined m (a -> b) -> Unlined m a -> Unlined m b
forall a b c.
(a -> b -> c) -> Unlined m a -> Unlined m b -> Unlined m c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
forall {m :: * -> *}. Applicative m => Functor (Unlined m)
forall (m :: * -> *) a. Applicative m => a -> Unlined m a
forall (m :: * -> *) a b.
Applicative m =>
Unlined m a -> Unlined m b -> Unlined m a
forall (m :: * -> *) a b.
Applicative m =>
Unlined m a -> Unlined m b -> Unlined m b
forall (m :: * -> *) a b.
Applicative m =>
Unlined m (a -> b) -> Unlined m a -> Unlined m b
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c) -> Unlined m a -> Unlined m b -> Unlined m c
<* :: forall a b. Unlined m a -> Unlined m b -> Unlined m a
$c<* :: forall (m :: * -> *) a b.
Applicative m =>
Unlined m a -> Unlined m b -> Unlined m a
*> :: forall a b. Unlined m a -> Unlined m b -> Unlined m b
$c*> :: forall (m :: * -> *) a b.
Applicative m =>
Unlined m a -> Unlined m b -> Unlined m b
liftA2 :: forall a b c.
(a -> b -> c) -> Unlined m a -> Unlined m b -> Unlined m c
$cliftA2 :: forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c) -> Unlined m a -> Unlined m b -> Unlined m c
<*> :: forall a b. Unlined m (a -> b) -> Unlined m a -> Unlined m b
$c<*> :: forall (m :: * -> *) a b.
Applicative m =>
Unlined m (a -> b) -> Unlined m a -> Unlined m b
pure :: forall a. a -> Unlined m a
$cpure :: forall (m :: * -> *) a. Applicative m => a -> Unlined m a
Applicative,forall a. Unlined m a
forall a. Unlined m a -> Unlined m [a]
forall a. Unlined m a -> Unlined m a -> Unlined m a
forall (f :: * -> *).
Applicative f
-> (forall a. f a)
-> (forall a. f a -> f a -> f a)
-> (forall a. f a -> f [a])
-> (forall a. f a -> f [a])
-> Alternative f
forall {m :: * -> *}. Alternative m => Applicative (Unlined m)
forall (m :: * -> *) a. Alternative m => Unlined m a
forall (m :: * -> *) a.
Alternative m =>
Unlined m a -> Unlined m [a]
forall (m :: * -> *) a.
Alternative m =>
Unlined m a -> Unlined m a -> Unlined m a
many :: forall a. Unlined m a -> Unlined m [a]
$cmany :: forall (m :: * -> *) a.
Alternative m =>
Unlined m a -> Unlined m [a]
some :: forall a. Unlined m a -> Unlined m [a]
$csome :: forall (m :: * -> *) a.
Alternative m =>
Unlined m a -> Unlined m [a]
<|> :: forall a. Unlined m a -> Unlined m a -> Unlined m a
$c<|> :: forall (m :: * -> *) a.
Alternative m =>
Unlined m a -> Unlined m a -> Unlined m a
empty :: forall a. Unlined m a
$cempty :: forall (m :: * -> *) a. Alternative m => Unlined m a
Alternative,forall a. a -> Unlined m a
forall a b. Unlined m a -> Unlined m b -> Unlined m b
forall a b. Unlined m a -> (a -> Unlined m b) -> Unlined m b
forall {m :: * -> *}. Monad m => Applicative (Unlined m)
forall (m :: * -> *) a. Monad m => a -> Unlined m a
forall (m :: * -> *) a b.
Monad m =>
Unlined m a -> Unlined m b -> Unlined m b
forall (m :: * -> *) a b.
Monad m =>
Unlined m a -> (a -> Unlined m b) -> Unlined m b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: forall a. a -> Unlined m a
$creturn :: forall (m :: * -> *) a. Monad m => a -> Unlined m a
>> :: forall a b. Unlined m a -> Unlined m b -> Unlined m b
$c>> :: forall (m :: * -> *) a b.
Monad m =>
Unlined m a -> Unlined m b -> Unlined m b
>>= :: forall a b. Unlined m a -> (a -> Unlined m b) -> Unlined m b
$c>>= :: forall (m :: * -> *) a b.
Monad m =>
Unlined m a -> (a -> Unlined m b) -> Unlined m b
Monad,forall a. Unlined m a
forall a. Unlined m a -> Unlined m a -> Unlined m a
forall (m :: * -> *).
Alternative m
-> Monad m
-> (forall a. m a)
-> (forall a. m a -> m a -> m a)
-> MonadPlus m
forall {m :: * -> *}. MonadPlus m => Monad (Unlined m)
forall {m :: * -> *}. MonadPlus m => Alternative (Unlined m)
forall (m :: * -> *) a. MonadPlus m => Unlined m a
forall (m :: * -> *) a.
MonadPlus m =>
Unlined m a -> Unlined m a -> Unlined m a
mplus :: forall a. Unlined m a -> Unlined m a -> Unlined m a
$cmplus :: forall (m :: * -> *) a.
MonadPlus m =>
Unlined m a -> Unlined m a -> Unlined m a
mzero :: forall a. Unlined m a
$cmzero :: forall (m :: * -> *) a. MonadPlus m => Unlined m a
MonadPlus,Unlined m Char
Char -> Unlined m Char
String -> Unlined m String
Text -> Unlined m Text
(Char -> Bool) -> Unlined m Char
forall (m :: * -> *).
Parsing m
-> ((Char -> Bool) -> m Char)
-> (Char -> m Char)
-> (Char -> m Char)
-> m Char
-> (String -> m String)
-> (Text -> m Text)
-> CharParsing m
forall {m :: * -> *}. CharParsing m => Parsing (Unlined m)
forall (m :: * -> *). CharParsing m => Unlined m Char
forall (m :: * -> *). CharParsing m => Char -> Unlined m Char
forall (m :: * -> *). CharParsing m => String -> Unlined m String
forall (m :: * -> *). CharParsing m => Text -> Unlined m Text
forall (m :: * -> *).
CharParsing m =>
(Char -> Bool) -> Unlined m Char
text :: Text -> Unlined m Text
$ctext :: forall (m :: * -> *). CharParsing m => Text -> Unlined m Text
string :: String -> Unlined m String
$cstring :: forall (m :: * -> *). CharParsing m => String -> Unlined m String
anyChar :: Unlined m Char
$canyChar :: forall (m :: * -> *). CharParsing m => Unlined m Char
notChar :: Char -> Unlined m Char
$cnotChar :: forall (m :: * -> *). CharParsing m => Char -> Unlined m Char
char :: Char -> Unlined m Char
$cchar :: forall (m :: * -> *). CharParsing m => Char -> Unlined m Char
satisfy :: (Char -> Bool) -> Unlined m Char
$csatisfy :: forall (m :: * -> *).
CharParsing m =>
(Char -> Bool) -> Unlined m Char
CharParsing)

instance Parsing m => Parsing (Unlined m) where
  try :: forall a. Unlined m a -> Unlined m a
try (Unlined m a
m) = forall (m :: * -> *) a. m a -> Unlined m a
Unlined forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Parsing m => m a -> m a
try m a
m
  {-# INLINE try #-}
  Unlined m a
m <?> :: forall a. Unlined m a -> String -> Unlined m a
<?> String
l = forall (m :: * -> *) a. m a -> Unlined m a
Unlined forall a b. (a -> b) -> a -> b
$ m a
m forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
l
  {-# INLINE (<?>) #-}
  unexpected :: forall a. String -> Unlined m a
unexpected = forall (m :: * -> *) a. m a -> Unlined m a
Unlined forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. Parsing m => String -> m a
unexpected
  {-# INLINE unexpected #-}
  eof :: Unlined m ()
eof = forall (m :: * -> *) a. m a -> Unlined m a
Unlined forall (m :: * -> *). Parsing m => m ()
eof
  {-# INLINE eof #-}
  notFollowedBy :: forall a. Show a => Unlined m a -> Unlined m ()
notFollowedBy (Unlined m a
m) = forall (m :: * -> *) a. m a -> Unlined m a
Unlined forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. (Parsing m, Show a) => m a -> m ()
notFollowedBy m a
m
  {-# INLINE notFollowedBy #-}

instance MonadTrans Unlined where
  lift :: forall (m :: * -> *) a. Monad m => m a -> Unlined m a
lift = forall (m :: * -> *) a. m a -> Unlined m a
Unlined
  {-# INLINE lift #-}

instance MonadState s m => MonadState s (Unlined m) where
  get :: Unlined m s
get = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall s (m :: * -> *). MonadState s m => m s
Class.get
  {-# INLINE get #-}
  put :: s -> Unlined m ()
put = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s (m :: * -> *). MonadState s m => s -> m ()
Class.put
  {-# INLINE put #-}

instance MonadReader e m => MonadReader e (Unlined m) where
  ask :: Unlined m e
ask = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall r (m :: * -> *). MonadReader r m => m r
Class.ask
  {-# INLINE ask #-}
  local :: forall a. (e -> e) -> Unlined m a -> Unlined m a
local e -> e
f = forall (m :: * -> *) a. m a -> Unlined m a
Unlined forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
Class.local e -> e
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. Unlined m a -> m a
runUnlined
  {-# INLINE local #-}

instance MonadWriter e m => MonadWriter e (Unlined m) where
  tell :: e -> Unlined m ()
tell = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall w (m :: * -> *). MonadWriter w m => w -> m ()
Class.tell
  {-# INLINE tell #-}
  listen :: forall a. Unlined m a -> Unlined m (a, e)
listen = forall (m :: * -> *) a. m a -> Unlined m a
Unlined forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall w (m :: * -> *) a. MonadWriter w m => m a -> m (a, w)
Class.listen forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. Unlined m a -> m a
runUnlined
  {-# INLINE listen #-}
  pass :: forall a. Unlined m (a, e -> e) -> Unlined m a
pass = forall (m :: * -> *) a. m a -> Unlined m a
Unlined forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall w (m :: * -> *) a. MonadWriter w m => m (a, w -> w) -> m a
Class.pass forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. Unlined m a -> m a
runUnlined
  {-# INLINE pass #-}

instance TokenParsing m => TokenParsing (Unlined m) where
  nesting :: forall a. Unlined m a -> Unlined m a
nesting (Unlined m a
m) = forall (m :: * -> *) a. m a -> Unlined m a
Unlined (forall (m :: * -> *) a. TokenParsing m => m a -> m a
nesting m a
m)
  {-# INLINE nesting #-}
  someSpace :: Unlined m ()
someSpace = forall (m :: * -> *) a. Parsing m => m a -> m ()
skipMany (forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
satisfy forall a b. (a -> b) -> a -> b
$ \Char
c -> Char
c forall a. Eq a => a -> a -> Bool
/= Char
'\n' Bool -> Bool -> Bool
&& Char -> Bool
isSpace Char
c)
  {-# INLINE someSpace #-}
  semi :: Unlined m Char
semi      = forall (m :: * -> *) a. m a -> Unlined m a
Unlined forall (m :: * -> *). TokenParsing m => m Char
semi
  {-# INLINE semi #-}
  highlight :: forall a. Highlight -> Unlined m a -> Unlined m a
highlight Highlight
h (Unlined m a
m) = forall (m :: * -> *) a. m a -> Unlined m a
Unlined (forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
h m a
m)
  {-# INLINE highlight #-}

#ifdef MIN_VERSION_parsec
instance Parsec.Stream s m Char => TokenParsing (Parsec.ParsecT s u m)
#endif

#ifdef MIN_VERSION_attoparsec
instance Att.Chunk t => TokenParsing (Att.Parser t)
#endif

instance TokenParsing ReadP.ReadP