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

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

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

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

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

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

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

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

  escapeEmpty, escapeGap :: m Char
  escapeEmpty :: m Char
escapeEmpty = Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'&'
  escapeGap :: m Char
escapeGap = m Char -> m ()
forall a. m a -> m ()
forall (m :: * -> *) a. Parsing m => m a -> m ()
skipSome m Char
forall (m :: * -> *). CharParsing m => m Char
space m () -> m Char -> m Char
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'\\' m Char -> String -> m Char
forall a. m a -> String -> m a
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 = m Integer -> m Integer
forall a. m a -> m a
forall (m :: * -> *) a. TokenParsing m => m a -> m a
token m Integer
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 = m Integer -> m Integer
forall a. m a -> m a
forall (m :: * -> *) a. TokenParsing m => m a -> m a
token (m Integer -> m Integer
forall a. m a -> m a
forall (m :: * -> *) a. TokenParsing m => m a -> m a
token (Highlight -> m (Integer -> Integer) -> m (Integer -> Integer)
forall a. Highlight -> m a -> m a
forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
Operator m (Integer -> Integer)
sgn m (Integer -> Integer) -> m Integer -> m Integer
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Integer
forall (m :: * -> *). TokenParsing m => m Integer
natural')) m Integer -> String -> m Integer
forall a. m a -> String -> m a
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"integer"
  where
  sgn :: m (Integer -> Integer)
  sgn :: m (Integer -> Integer)
sgn = Integer -> Integer
forall a. Num a => a -> a
negate (Integer -> Integer) -> m Char -> m (Integer -> Integer)
forall a b. a -> m b -> m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'-'
    m (Integer -> Integer)
-> m (Integer -> Integer) -> m (Integer -> Integer)
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Integer -> Integer
forall a. a -> a
id (Integer -> Integer) -> m Char -> m (Integer -> Integer)
forall a b. a -> m b -> m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'+'
    m (Integer -> Integer)
-> m (Integer -> Integer) -> m (Integer -> Integer)
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Integer -> Integer) -> m (Integer -> Integer)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Integer -> Integer
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 = m Double -> m Double
forall a. m a -> m a
forall (m :: * -> *) a. TokenParsing m => m a -> m a
token (Highlight -> m Double -> m Double
forall a. Highlight -> m a -> m a
forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
Number (Scientific -> Double
forall a. RealFloat a => Scientific -> a
Sci.toRealFloat (Scientific -> Double) -> m Scientific -> m Double
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Scientific
forall (m :: * -> *). TokenParsing m => m Scientific
floating) m Double -> String -> m Double
forall a. m a -> String -> m a
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 = (Scientific -> Double)
-> Either Integer Scientific -> Either Integer Double
forall a b. (a -> b) -> Either Integer a -> Either Integer b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Scientific -> Double
forall a. RealFloat a => Scientific -> a
Sci.toRealFloat (Either Integer Scientific -> Either Integer Double)
-> m (Either Integer Scientific) -> m (Either Integer Double)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (Either Integer Scientific)
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 = (Scientific -> Double)
-> Either Integer Scientific -> Either Integer Double
forall a b. (a -> b) -> Either Integer a -> Either Integer b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Scientific -> Double
forall a. RealFloat a => Scientific -> a
Sci.toRealFloat (Either Integer Scientific -> Either Integer Double)
-> m (Either Integer Scientific) -> m (Either Integer Double)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (Either Integer Scientific)
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 = m Scientific -> m Scientific
forall a. m a -> m a
forall (m :: * -> *) a. TokenParsing m => m a -> m a
token (Highlight -> m Scientific -> m Scientific
forall a. Highlight -> m a -> m a
forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
Number m Scientific
forall (m :: * -> *). TokenParsing m => m Scientific
floating m Scientific -> String -> m Scientific
forall a. m a -> String -> m a
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 = m (Either Integer Scientific) -> m (Either Integer Scientific)
forall a. m a -> m a
forall (m :: * -> *) a. TokenParsing m => m a -> m a
token (Highlight
-> m (Either Integer Scientific) -> m (Either Integer Scientific)
forall a. Highlight -> m a -> m a
forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
Number m (Either Integer Scientific)
forall (m :: * -> *).
TokenParsing m =>
m (Either Integer Scientific)
natFloating m (Either Integer Scientific)
-> String -> m (Either Integer Scientific)
forall a. m a -> String -> m a
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 = m (Either Integer Scientific) -> m (Either Integer Scientific)
forall a. m a -> m a
forall (m :: * -> *) a. TokenParsing m => m a -> m a
token (Highlight
-> m (Either Integer Scientific) -> m (Either Integer Scientific)
forall a. Highlight -> m a -> m a
forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
Number m (Either Integer Scientific)
ios m (Either Integer Scientific)
-> String -> m (Either Integer Scientific)
forall a. m a -> String -> m a
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"number")
  where ios :: m (Either Integer Scientific)
        ios :: m (Either Integer Scientific)
ios = Maybe Char
-> Either Integer Scientific -> Either Integer Scientific
forall {b} {b}.
(Num b, Num b) =>
Maybe Char -> Either b b -> Either b b
mneg (Maybe Char
 -> Either Integer Scientific -> Either Integer Scientific)
-> m (Maybe Char)
-> m (Either Integer Scientific -> Either Integer Scientific)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Char -> m (Maybe Char)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (String -> m Char
forall (m :: * -> *). CharParsing m => String -> m Char
oneOf String
"+-") m (Either Integer Scientific -> Either Integer Scientific)
-> m (Either Integer Scientific) -> m (Either Integer Scientific)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m (Either Integer Scientific)
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 = (b -> Either b b) -> (b -> Either b b) -> Either b b -> Either b b
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (b -> Either b b
forall a b. a -> Either a b
Left (b -> Either b b) -> (b -> b) -> b -> Either b b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> b
forall a. Num a => a -> a
negate) (b -> Either b b
forall a b. b -> Either a b
Right (b -> Either b b) -> (b -> b) -> b -> Either b b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> b
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 = m String -> m String
forall a. m a -> m a
forall (m :: * -> *) a. TokenParsing m => m a -> m a
token (Highlight -> m String -> m String
forall a. Highlight -> m a -> m a
forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
Symbol (String -> m String
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 = m Text -> m Text
forall a. m a -> m a
forall (m :: * -> *) a. TokenParsing m => m a -> m a
token (Highlight -> m Text -> m Text
forall a. Highlight -> m a -> m a
forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
Symbol (Text -> m Text
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 = m Char -> m Char
forall a. m a -> m a
forall (m :: * -> *) a. TokenParsing m => m a -> m a
token (Highlight -> m Char -> m Char
forall a. Highlight -> m a -> m a
forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
Symbol (Char -> m Char
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 = m a -> m a
forall a. m a -> m a
forall (m :: * -> *) a. TokenParsing m => m a -> m a
nesting (m a -> m a) -> (m a -> m a) -> m a -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m Char -> m Char -> m a -> m a
forall (m :: * -> *) bra ket a.
Applicative m =>
m bra -> m ket -> m a -> m a
between (Char -> m Char
forall (m :: * -> *). TokenParsing m => Char -> m Char
symbolic Char
'(') (Char -> m 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 = m a -> m a
forall a. m a -> m a
forall (m :: * -> *) a. TokenParsing m => m a -> m a
nesting (m a -> m a) -> (m a -> m a) -> m a -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m Char -> m Char -> m a -> m a
forall (m :: * -> *) bra ket a.
Applicative m =>
m bra -> m ket -> m a -> m a
between (Char -> m Char
forall (m :: * -> *). TokenParsing m => Char -> m Char
symbolic Char
'{') (Char -> m 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 = m a -> m a
forall a. m a -> m a
forall (m :: * -> *) a. TokenParsing m => m a -> m a
nesting (m a -> m a) -> (m a -> m a) -> m a -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m Char -> m Char -> m a -> m a
forall (m :: * -> *) bra ket a.
Applicative m =>
m bra -> m ket -> m a -> m a
between (Char -> m Char
forall (m :: * -> *). TokenParsing m => Char -> m Char
symbolic Char
'<') (Char -> m 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 = m a -> m a
forall a. m a -> m a
forall (m :: * -> *) a. TokenParsing m => m a -> m a
nesting (m a -> m a) -> (m a -> m a) -> m a -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m Char -> m Char -> m a -> m a
forall (m :: * -> *) bra ket a.
Applicative m =>
m bra -> m ket -> m a -> m a
between (Char -> m Char
forall (m :: * -> *). TokenParsing m => Char -> m Char
symbolic Char
'[') (Char -> m 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 = Char -> m Char
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 = Char -> m Char
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 = Char -> m Char
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 = m a -> m Char -> m [a]
forall (m :: * -> *) a sep. Alternative m => m a -> m sep -> m [a]
sepBy m a
p m Char
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 = m a -> m Char -> m [a]
forall (m :: * -> *) a sep. Alternative m => m a -> m sep -> m [a]
sepBy1 m a
p m Char
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 = m a -> m Char -> m [a]
forall (m :: * -> *) a sep. Alternative m => m a -> m sep -> m [a]
sepBy m a
p m Char
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 = m a -> m Char -> m [a]
forall (m :: * -> *) a sep. Alternative m => m a -> m sep -> m [a]
sepBy1 m a
p m Char
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 = m Char -> m ()
forall a. m a -> m ()
forall (m :: * -> *) a. Parsing m => m a -> m ()
skipSome ((Char -> Bool) -> m Char
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 = m a -> m a
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 = m Char -> m Char
forall a. m a -> m a
forall (m :: * -> *) a. TokenParsing m => m a -> m a
token ((Char -> Bool) -> m Char
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
satisfy (Char
';'Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
==) m Char -> String -> m Char
forall a. m a -> String -> m a
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 m a -> m () -> m a
forall a b. m a -> m b -> m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* (m ()
forall (m :: * -> *). TokenParsing m => m ()
someSpace m () -> m () -> m ()
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> () -> m ()
forall a. a -> m 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) = (s -> m (a, s)) -> StateT s m a
forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
Lazy.StateT ((s -> m (a, s)) -> StateT s m a)
-> (s -> m (a, s)) -> StateT s m a
forall a b. (a -> b) -> a -> b
$ m (a, s) -> m (a, s)
forall a. m a -> m a
forall (m :: * -> *) a. TokenParsing m => m a -> m a
nesting (m (a, s) -> m (a, s)) -> (s -> m (a, s)) -> s -> m (a, s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> m (a, s)
m
  {-# INLINE nesting #-}
  someSpace :: StateT s m ()
someSpace = m () -> StateT s m ()
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m ()
forall (m :: * -> *). TokenParsing m => m ()
someSpace
  {-# INLINE someSpace #-}
  semi :: StateT s m Char
semi      = m Char -> StateT s m Char
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m Char
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) = (s -> m (a, s)) -> StateT s m a
forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
Lazy.StateT ((s -> m (a, s)) -> StateT s m a)
-> (s -> m (a, s)) -> StateT s m a
forall a b. (a -> b) -> a -> b
$ Highlight -> m (a, s) -> m (a, s)
forall a. Highlight -> m a -> m a
forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
h (m (a, s) -> m (a, s)) -> (s -> m (a, s)) -> s -> m (a, s)
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) = (s -> m (a, s)) -> StateT s m a
forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
Strict.StateT ((s -> m (a, s)) -> StateT s m a)
-> (s -> m (a, s)) -> StateT s m a
forall a b. (a -> b) -> a -> b
$ m (a, s) -> m (a, s)
forall a. m a -> m a
forall (m :: * -> *) a. TokenParsing m => m a -> m a
nesting (m (a, s) -> m (a, s)) -> (s -> m (a, s)) -> s -> m (a, s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> m (a, s)
m
  {-# INLINE nesting #-}
  someSpace :: StateT s m ()
someSpace = m () -> StateT s m ()
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m ()
forall (m :: * -> *). TokenParsing m => m ()
someSpace
  {-# INLINE someSpace #-}
  semi :: StateT s m Char
semi      = m Char -> StateT s m Char
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m Char
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) = (s -> m (a, s)) -> StateT s m a
forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
Strict.StateT ((s -> m (a, s)) -> StateT s m a)
-> (s -> m (a, s)) -> StateT s m a
forall a b. (a -> b) -> a -> b
$ Highlight -> m (a, s) -> m (a, s)
forall a. Highlight -> m a -> m a
forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
h (m (a, s) -> m (a, s)) -> (s -> m (a, s)) -> s -> m (a, s)
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) = (e -> m a) -> ReaderT e m a
forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
ReaderT ((e -> m a) -> ReaderT e m a) -> (e -> m a) -> ReaderT e m a
forall a b. (a -> b) -> a -> b
$ m a -> m a
forall a. m a -> m a
forall (m :: * -> *) a. TokenParsing m => m a -> m a
nesting (m a -> m a) -> (e -> m a) -> e -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> m a
m
  {-# INLINE nesting #-}
  someSpace :: ReaderT e m ()
someSpace = m () -> ReaderT e m ()
forall (m :: * -> *) a. Monad m => m a -> ReaderT e m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m ()
forall (m :: * -> *). TokenParsing m => m ()
someSpace
  {-# INLINE someSpace #-}
  semi :: ReaderT e m Char
semi      = m Char -> ReaderT e m Char
forall (m :: * -> *) a. Monad m => m a -> ReaderT e m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m Char
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) = (e -> m a) -> ReaderT e m a
forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
ReaderT ((e -> m a) -> ReaderT e m a) -> (e -> m a) -> ReaderT e m a
forall a b. (a -> b) -> a -> b
$ Highlight -> m a -> m a
forall a. Highlight -> m a -> m a
forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
h (m a -> m a) -> (e -> m a) -> e -> m a
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) = m (a, w) -> WriterT w m a
forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
Strict.WriterT (m (a, w) -> WriterT w m a) -> m (a, w) -> WriterT w m a
forall a b. (a -> b) -> a -> b
$ m (a, w) -> m (a, w)
forall a. m a -> m a
forall (m :: * -> *) a. TokenParsing m => m a -> m a
nesting m (a, w)
m
  {-# INLINE nesting #-}
  someSpace :: WriterT w m ()
someSpace = m () -> WriterT w m ()
forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m ()
forall (m :: * -> *). TokenParsing m => m ()
someSpace
  {-# INLINE someSpace #-}
  semi :: WriterT w m Char
semi      = m Char -> WriterT w m Char
forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m Char
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) = m (a, w) -> WriterT w m a
forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
Strict.WriterT (m (a, w) -> WriterT w m a) -> m (a, w) -> WriterT w m a
forall a b. (a -> b) -> a -> b
$ Highlight -> m (a, w) -> m (a, w)
forall a. Highlight -> m a -> m a
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) = m (a, w) -> WriterT w m a
forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
Lazy.WriterT (m (a, w) -> WriterT w m a) -> m (a, w) -> WriterT w m a
forall a b. (a -> b) -> a -> b
$ m (a, w) -> m (a, w)
forall a. m a -> m a
forall (m :: * -> *) a. TokenParsing m => m a -> m a
nesting m (a, w)
m
  {-# INLINE nesting #-}
  someSpace :: WriterT w m ()
someSpace = m () -> WriterT w m ()
forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m ()
forall (m :: * -> *). TokenParsing m => m ()
someSpace
  {-# INLINE someSpace #-}
  semi :: WriterT w m Char
semi      = m Char -> WriterT w m Char
forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m Char
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) = m (a, w) -> WriterT w m a
forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
Lazy.WriterT (m (a, w) -> WriterT w m a) -> m (a, w) -> WriterT w m a
forall a b. (a -> b) -> a -> b
$ Highlight -> m (a, w) -> m (a, w)
forall a. Highlight -> m a -> m a
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) = (r -> s -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
Lazy.RWST ((r -> s -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \r
r s
s -> m (a, s, w) -> m (a, s, w)
forall a. m a -> m a
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 = m () -> RWST r w s m ()
forall (m :: * -> *) a. Monad m => m a -> RWST r w s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m ()
forall (m :: * -> *). TokenParsing m => m ()
someSpace
  {-# INLINE someSpace #-}
  semi :: RWST r w s m Char
semi      = m Char -> RWST r w s m Char
forall (m :: * -> *) a. Monad m => m a -> RWST r w s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m Char
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) = (r -> s -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
Lazy.RWST ((r -> s -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \r
r s
s -> Highlight -> m (a, s, w) -> m (a, s, w)
forall a. Highlight -> m a -> m a
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) = (r -> s -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
Strict.RWST ((r -> s -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \r
r s
s -> m (a, s, w) -> m (a, s, w)
forall a. m a -> m a
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 = m () -> RWST r w s m ()
forall (m :: * -> *) a. Monad m => m a -> RWST r w s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m ()
forall (m :: * -> *). TokenParsing m => m ()
someSpace
  {-# INLINE someSpace #-}
  semi :: RWST r w s m Char
semi      = m Char -> RWST r w s m Char
forall (m :: * -> *) a. Monad m => m a -> RWST r w s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m Char
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) = (r -> s -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
Strict.RWST ((r -> s -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \r
r s
s -> Highlight -> m (a, s, w) -> m (a, s, w)
forall a. Highlight -> m a -> m a
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 = m a -> IdentityT m a
forall {k} (f :: k -> *) (a :: k). f a -> IdentityT f a
IdentityT (m a -> IdentityT m a)
-> (IdentityT m a -> m a) -> IdentityT m a -> IdentityT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m a -> m a
forall a. m a -> m a
forall (m :: * -> *) a. TokenParsing m => m a -> m a
nesting (m a -> m a) -> (IdentityT m a -> m a) -> IdentityT m a -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IdentityT m a -> m a
forall {k} (f :: k -> *) (a :: k). IdentityT f a -> f a
runIdentityT
  {-# INLINE nesting #-}
  someSpace :: IdentityT m ()
someSpace = m () -> IdentityT m ()
forall (m :: * -> *) a. Monad m => m a -> IdentityT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m ()
forall (m :: * -> *). TokenParsing m => m ()
someSpace
  {-# INLINE someSpace #-}
  semi :: IdentityT m Char
semi      = m Char -> IdentityT m Char
forall (m :: * -> *) a. Monad m => m a -> IdentityT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m Char
forall (m :: * -> *). TokenParsing m => m Char
semi
  {-# INLINE semi #-}
  highlight :: forall a. Highlight -> IdentityT m a -> IdentityT m a
highlight Highlight
h = m a -> IdentityT m a
forall {k} (f :: k -> *) (a :: k). f a -> IdentityT f a
IdentityT (m a -> IdentityT m a)
-> (IdentityT m a -> m a) -> IdentityT m a -> IdentityT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Highlight -> m a -> m a
forall a. Highlight -> m a -> m a
forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
h (m a -> m a) -> (IdentityT m a -> m a) -> IdentityT m a -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IdentityT m a -> m a
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 = n }) (String -> IdentifierStyle m) -> f String -> f (IdentifierStyle m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> f String
f (IdentifierStyle m -> String
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 = n }) (m Char -> IdentifierStyle m)
-> f (m Char) -> f (IdentifierStyle m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Char -> f (m Char)
f (IdentifierStyle m -> m Char
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 = n }) (m Char -> IdentifierStyle m)
-> f (m Char) -> f (IdentifierStyle m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Char -> f (m Char)
f (IdentifierStyle m -> m Char
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, _styleLetter = m }) (n Char -> n Char -> IdentifierStyle n)
-> f (n Char) -> f (n Char -> IdentifierStyle n)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Char -> f (n Char)
f (IdentifierStyle m -> m Char
forall (m :: * -> *). IdentifierStyle m -> m Char
_styleStart IdentifierStyle m
is) f (n Char -> IdentifierStyle n)
-> f (n Char) -> f (IdentifierStyle n)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Char -> f (n Char)
f (IdentifierStyle m -> m Char
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 = n }) (HashSet String -> IdentifierStyle m)
-> f (HashSet String) -> f (IdentifierStyle m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> HashSet String -> f (HashSet String)
f (IdentifierStyle m -> HashSet String
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 = n }) (Highlight -> IdentifierStyle m)
-> f Highlight -> f (IdentifierStyle m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Highlight -> f Highlight
f (IdentifierStyle m -> Highlight
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 = n }) (Highlight -> IdentifierStyle m)
-> f Highlight -> f (IdentifierStyle m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Highlight -> f Highlight
f (IdentifierStyle m -> Highlight
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 = n, _styleReservedHighlight = m }) (Highlight -> Highlight -> IdentifierStyle m)
-> f Highlight -> f (Highlight -> IdentifierStyle m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Highlight -> f Highlight
f (IdentifierStyle m -> Highlight
forall (m :: * -> *). IdentifierStyle m -> Highlight
_styleHighlight IdentifierStyle m
is) f (Highlight -> IdentifierStyle m)
-> f Highlight -> f (IdentifierStyle m)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Highlight -> f Highlight
f (IdentifierStyle m -> Highlight
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 = Identity (IdentifierStyle (t m)) -> IdentifierStyle (t m)
forall a. Identity a -> a
runIdentity (Identity (IdentifierStyle (t m)) -> IdentifierStyle (t m))
-> (IdentifierStyle m -> Identity (IdentifierStyle (t m)))
-> IdentifierStyle m
-> IdentifierStyle (t m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (m Char -> Identity (t m Char))
-> IdentifierStyle m -> Identity (IdentifierStyle (t m))
forall (f :: * -> *) (m :: * -> *) (n :: * -> *).
Applicative f =>
(m Char -> f (n Char))
-> IdentifierStyle m -> f (IdentifierStyle n)
styleChars (t m Char -> Identity (t m Char)
forall a. a -> Identity a
Identity (t m Char -> Identity (t m Char))
-> (m Char -> t m Char) -> m Char -> Identity (t m Char)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m Char -> t m Char
forall (m :: * -> *) a. Monad m => m a -> t m a
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 = m () -> m ()
forall a. m a -> m a
forall (m :: * -> *) a. TokenParsing m => m a -> m a
token (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$ m () -> m ()
forall a. m a -> m a
forall (m :: * -> *) a. Parsing m => m a -> m a
try (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$ do
   String
_ <- Highlight -> m String -> m String
forall a. Highlight -> m a -> m a
forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight (IdentifierStyle m -> Highlight
forall (m :: * -> *). IdentifierStyle m -> Highlight
_styleReservedHighlight IdentifierStyle m
s) (m String -> m String) -> m String -> m String
forall a b. (a -> b) -> a -> b
$ String -> m String
forall (m :: * -> *). CharParsing m => String -> m String
string String
name
   m Char -> m ()
forall a. Show a => m a -> m ()
forall (m :: * -> *) a. (Parsing m, Show a) => m a -> m ()
notFollowedBy (IdentifierStyle m -> m Char
forall (m :: * -> *). IdentifierStyle m -> m Char
_styleLetter IdentifierStyle m
s) m () -> String -> m ()
forall a. m a -> String -> m a
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"end of " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
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 = m () -> m ()
forall a. m a -> m a
forall (m :: * -> *) a. TokenParsing m => m a -> m a
token (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$ m () -> m ()
forall a. m a -> m a
forall (m :: * -> *) a. Parsing m => m a -> m a
try (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$ do
   Text
_ <- Highlight -> m Text -> m Text
forall a. Highlight -> m a -> m a
forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight (IdentifierStyle m -> Highlight
forall (m :: * -> *). IdentifierStyle m -> Highlight
_styleReservedHighlight IdentifierStyle m
s) (m Text -> m Text) -> m Text -> m Text
forall a b. (a -> b) -> a -> b
$ Text -> m Text
forall (m :: * -> *). CharParsing m => Text -> m Text
text Text
name
   m Char -> m ()
forall a. Show a => m a -> m ()
forall (m :: * -> *) a. (Parsing m, Show a) => m a -> m ()
notFollowedBy (IdentifierStyle m -> m Char
forall (m :: * -> *). IdentifierStyle m -> m Char
_styleLetter IdentifierStyle m
s) m () -> String -> m ()
forall a. m a -> String -> m a
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"end of " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Text -> String
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 = (String -> s) -> m String -> m s
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> s
forall a. IsString a => String -> a
fromString (m String -> m s) -> m String -> m s
forall a b. (a -> b) -> a -> b
$ m String -> m String
forall a. m a -> m a
forall (m :: * -> *) a. TokenParsing m => m a -> m a
token (m String -> m String) -> m String -> m String
forall a b. (a -> b) -> a -> b
$ m String -> m String
forall a. m a -> m a
forall (m :: * -> *) a. Parsing m => m a -> m a
try (m String -> m String) -> m String -> m String
forall a b. (a -> b) -> a -> b
$ do
  String
name <- Highlight -> m String -> m String
forall a. Highlight -> m a -> m a
forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight (IdentifierStyle m -> Highlight
forall (m :: * -> *). IdentifierStyle m -> Highlight
_styleHighlight IdentifierStyle m
s)
          ((:) (Char -> String -> String) -> m Char -> m (String -> String)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IdentifierStyle m -> m Char
forall (m :: * -> *). IdentifierStyle m -> m Char
_styleStart IdentifierStyle m
s m (String -> String) -> m String -> m String
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Char -> m String
forall a. m a -> m [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (IdentifierStyle m -> m Char
forall (m :: * -> *). IdentifierStyle m -> m Char
_styleLetter IdentifierStyle m
s) m String -> String -> m String
forall a. m a -> String -> m a
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> IdentifierStyle m -> String
forall (m :: * -> *). IdentifierStyle m -> String
_styleName IdentifierStyle m
s)
  Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (String -> HashSet String -> Bool
forall a. (Eq a, Hashable a) => a -> HashSet a -> Bool
HashSet.member String
name (IdentifierStyle m -> HashSet String
forall (m :: * -> *). IdentifierStyle m -> HashSet String
_styleReserved IdentifierStyle m
s)) (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$ String -> m ()
forall a. String -> m a
forall (m :: * -> *) a. Parsing m => String -> m a
unexpected (String -> m ()) -> String -> m ()
forall a b. (a -> b) -> a -> b
$ String
"reserved " String -> String -> String
forall a. [a] -> [a] -> [a]
++ IdentifierStyle m -> String
forall (m :: * -> *). IdentifierStyle m -> String
_styleName IdentifierStyle m
s String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
forall a. Show a => a -> String
show String
name
  String -> m String
forall a. a -> m a
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 = m Char
forall (m :: * -> *). TokenParsing m => m Char
charLetter m Char -> m Char -> m Char
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> m Char
forall (m :: * -> *). TokenParsing m => m Char
charEscape m Char -> String -> m Char
forall a. m a -> String -> m a
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"literal character"
{-# INLINE characterChar #-}

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

charLetter :: forall (m :: * -> *). TokenParsing m => m Char
charLetter = (Char -> Bool) -> m Char
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
satisfy (\Char
c -> (Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'\'') Bool -> Bool -> Bool
&& (Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'\\') Bool -> Bool -> Bool
&& (Char
c Char -> Char -> Bool
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 m Char -> m Char -> m Char
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> m Char
charNum m Char -> m Char -> m Char
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> m Char
charAscii m Char -> m Char -> m Char
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> m Char
charControl) m Char -> String -> m Char
forall a. m a -> String -> m a
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"escape code"
  where
  charControl, charNum :: m Char
  charControl :: m Char
charControl = (\Char
c -> Int -> Char
forall a. Enum a => Int -> a
toEnum (Char -> Int
forall a. Enum a => a -> Int
fromEnum Char
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Char -> Int
forall a. Enum a => a -> Int
fromEnum Char
'@')) (Char -> Char) -> m Char -> m Char
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'^' m Char -> m Char -> m Char
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (m Char
forall (m :: * -> *). CharParsing m => m Char
upper m Char -> m Char -> m Char
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'@'))
  charNum :: m Char
charNum = Int -> Char
forall a. Enum a => Int -> a
toEnum (Int -> Char) -> m Int -> m Char
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
        m Int -> m Int -> m Int
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'o' m Char -> m Int -> m Int
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> Int -> m Int
bounded Int
8 Int
maxchar)
        m Int -> m Int -> m Int
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'x' m Char -> m Int -> m Int
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> Int -> m Int
bounded Int
16 Int
maxchar)
      maxchar :: Int
maxchar = Char -> Int
forall a. Enum a => a -> Int
fromEnum (Char
forall a. Bounded a => a
maxBound :: Char)

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

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

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

  charEsc :: m Char
  charEsc :: m Char
charEsc = [m Char] -> m Char
forall (m :: * -> *) a. Alternative m => [m a] -> m a
choice ([m Char] -> m Char) -> [m Char] -> m Char
forall a b. (a -> b) -> a -> b
$ (Char, Char) -> m Char
forall {f :: * -> *} {a}. CharParsing f => (Char, a) -> f a
parseEsc ((Char, Char) -> m Char) -> [(Char, Char)] -> [m Char]
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 a -> f Char -> f a
forall a b. a -> f b -> f a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> f Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
c
  escMap :: [(Char, Char)]
escMap = String -> String -> [(Char, Char)]
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 = [m Char] -> m Char
forall (m :: * -> *) a. Alternative m => [m a] -> m a
choice ([m Char] -> m Char) -> [m Char] -> m Char
forall a b. (a -> b) -> a -> b
$ (String, Char) -> m Char
forall {m :: * -> *} {a}. CharParsing m => (String, a) -> m a
parseAscii ((String, Char) -> m Char) -> [(String, Char)] -> [m Char]
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) = m a -> m a
forall a. m a -> m a
forall (m :: * -> *) a. Parsing m => m a -> m a
try (m a -> m a) -> m a -> m a
forall a b. (a -> b) -> a -> b
$ a
code a -> m String -> m a
forall a b. a -> m b -> m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ String -> m String
forall (m :: * -> *). CharParsing m => String -> m String
string String
asc
  asciiMap :: [(String, Char)]
asciiMap = [String] -> String -> [(String, Char)]
forall a b. [a] -> [b] -> [(a, b)]
zip ([String]
ascii3codes [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String]
ascii2codes) (String
ascii3 String -> String -> String
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' = Highlight -> m Integer -> m Integer
forall a. Highlight -> m a -> m a
forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
Number m Integer
forall (m :: * -> *). TokenParsing m => m Integer
nat m Integer -> String -> m Integer
forall a. m a -> String -> m a
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 =
  (Integer -> Char -> Integer) -> Integer -> String -> Integer
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (\Integer
x Char
d -> Integer
baseInteger -> Integer -> Integer
forall a. Num a => a -> a -> a
*Integer
x Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Int -> Integer
forall a. Integral a => a -> Integer
toInteger (Char -> Int
digitToInt Char
d)) Integer
0 (String -> Integer) -> m String -> m Integer
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Char -> m String
forall a. m a -> m [a]
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' = m Integer
forall (m :: * -> *). TokenParsing m => m Integer
int m Integer -> String -> m Integer
forall a. m a -> String -> m a
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 = Highlight -> m (Integer -> Integer) -> m (Integer -> Integer)
forall a. Highlight -> m a -> m a
forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight Highlight
Operator
     (m (Integer -> Integer) -> m (Integer -> Integer))
-> m (Integer -> Integer) -> m (Integer -> Integer)
forall a b. (a -> b) -> a -> b
$ Integer -> Integer
forall a. Num a => a -> a
negate (Integer -> Integer) -> m Char -> m (Integer -> Integer)
forall a b. a -> m b -> m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'-'
   m (Integer -> Integer)
-> m (Integer -> Integer) -> m (Integer -> Integer)
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Integer -> Integer
forall a. a -> a
id (Integer -> Integer) -> m Char -> m (Integer -> Integer)
forall a b. a -> m b -> m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'+'
   m (Integer -> Integer)
-> m (Integer -> Integer) -> m (Integer -> Integer)
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Integer -> Integer) -> m (Integer -> Integer)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Integer -> Integer
forall a. a -> a
id

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

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

  op :: Scientific -> Char -> Scientific
op Scientific
f Char
d = Scientific
f Scientific -> Scientific -> Scientific
forall a. Num a => a -> a -> a
+ Integer -> Int -> Scientific
Sci.scientific (Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Char -> Int
digitToInt Char
d)) (Scientific -> Int
Sci.base10Exponent Scientific
f Int -> Int -> Int
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)) ((Integer -> Integer) -> Integer -> Scientific)
-> m Char -> m ((Integer -> Integer) -> Integer -> Scientific)
forall a b. a -> m b -> m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ String -> m Char
forall (m :: * -> *). CharParsing m => String -> m Char
oneOf String
"eE" m ((Integer -> Integer) -> Integer -> Scientific)
-> m (Integer -> Integer) -> m (Integer -> Scientific)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m (Integer -> Integer)
forall (m :: * -> *). TokenParsing m => m (Integer -> Integer)
sign m (Integer -> Scientific) -> m Integer -> m Scientific
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (m Integer
forall (m :: * -> *). TokenParsing m => m Integer
decimal m Integer -> String -> m Integer
forall a. m a -> String -> m a
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"exponent")) m Scientific -> String -> m Scientific
forall a. m a -> String -> m a
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"exponent"

  power :: Integer -> Scientific
power = Integer -> Int -> Scientific
Sci.scientific Integer
1 (Int -> Scientific) -> (Integer -> Int) -> Integer -> Scientific
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Int
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
    = Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'0' m Char
-> m (Either Integer Scientific) -> m (Either Integer Scientific)
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> m (Either Integer Scientific)
forall (m :: * -> *).
TokenParsing m =>
m (Either Integer Scientific)
zeroNumFloat
  m (Either Integer Scientific)
-> m (Either Integer Scientific) -> m (Either Integer Scientific)
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> m (Either Integer Scientific)
forall (m :: * -> *).
TokenParsing m =>
m (Either Integer Scientific)
decimalFloat
zeroNumFloat :: forall (m :: * -> *).
TokenParsing m =>
m (Either Integer Scientific)
zeroNumFloat
    = Integer -> Either Integer Scientific
forall a b. a -> Either a b
Left (Integer -> Either Integer Scientific)
-> m Integer -> m (Either Integer Scientific)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (m Integer
forall (m :: * -> *). TokenParsing m => m Integer
hexadecimal m Integer -> m Integer -> m Integer
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> m Integer
forall (m :: * -> *). TokenParsing m => m Integer
octal)
  m (Either Integer Scientific)
-> m (Either Integer Scientific) -> m (Either Integer Scientific)
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> m (Either Integer Scientific)
forall (m :: * -> *).
TokenParsing m =>
m (Either Integer Scientific)
decimalFloat
  m (Either Integer Scientific)
-> m (Either Integer Scientific) -> m (Either Integer Scientific)
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Integer -> m Integer
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Integer
0 m Integer
-> m (Integer -> Either Integer Scientific)
-> m (Either Integer Scientific)
forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
<**> m (Integer -> Either Integer Scientific)
-> m (Integer -> Either Integer Scientific)
forall a. m a -> m a
forall (m :: * -> *) a. Parsing m => m a -> m a
try m (Integer -> Either Integer Scientific)
forall (m :: * -> *).
TokenParsing m =>
m (Integer -> Either Integer Scientific)
fractFloat
  m (Either Integer Scientific)
-> m (Either Integer Scientific) -> m (Either Integer Scientific)
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Either Integer Scientific -> m (Either Integer Scientific)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Integer -> Either Integer Scientific
forall a b. a -> Either a b
Left Integer
0)
decimalFloat :: forall (m :: * -> *).
TokenParsing m =>
m (Either Integer Scientific)
decimalFloat = m Integer
forall (m :: * -> *). TokenParsing m => m Integer
decimal m Integer
-> m (Integer -> Either Integer Scientific)
-> m (Either Integer Scientific)
forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
<**> (Integer -> Either Integer Scientific)
-> m (Integer -> Either Integer Scientific)
-> m (Integer -> Either Integer Scientific)
forall (m :: * -> *) a. Alternative m => a -> m a -> m a
option Integer -> Either Integer Scientific
forall a b. a -> Either a b
Left (m (Integer -> Either Integer Scientific)
-> m (Integer -> Either Integer Scientific)
forall a. m a -> m a
forall (m :: * -> *) a. Parsing m => m a -> m a
try m (Integer -> Either Integer Scientific)
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 = (Scientific -> Either Integer Scientific
forall a b. b -> Either a b
Right (Scientific -> Either Integer Scientific)
-> (Integer -> Scientific) -> Integer -> Either Integer Scientific
forall b c a. (b -> c) -> (a -> b) -> a -> c
.) ((Integer -> Scientific) -> Integer -> Either Integer Scientific)
-> m (Integer -> Scientific)
-> m (Integer -> Either Integer Scientific)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (Integer -> Scientific)
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 = Integer -> m Char -> m Integer
forall (m :: * -> *).
TokenParsing m =>
Integer -> m Char -> m Integer
number Integer
10 m Char
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 = String -> m Char
forall (m :: * -> *). CharParsing m => String -> m Char
oneOf String
"xX" m Char -> m Integer -> m Integer
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Integer -> m Char -> m Integer
forall (m :: * -> *).
TokenParsing m =>
Integer -> m Char -> m Integer
number Integer
16 m Char
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 = String -> m Char
forall (m :: * -> *). CharParsing m => String -> m Char
oneOf String
"oO" m Char -> m Integer -> m Integer
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Integer -> m Char -> m Integer
forall (m :: * -> *).
TokenParsing m =>
Integer -> m Char -> m Integer
number Integer
8 m Char
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 -> b) -> Unhighlighted m a -> Unhighlighted m b)
-> (forall a b. a -> Unhighlighted m b -> Unhighlighted m a)
-> Functor (Unhighlighted m)
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
$cfmap :: forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> Unhighlighted m a -> Unhighlighted m b
fmap :: forall a b. (a -> b) -> Unhighlighted m a -> Unhighlighted m b
$c<$ :: forall (m :: * -> *) a b.
Functor m =>
a -> Unhighlighted m b -> Unhighlighted m a
<$ :: forall a b. a -> Unhighlighted m b -> Unhighlighted m a
Functor,Functor (Unhighlighted m)
Functor (Unhighlighted m) =>
(forall a. a -> Unhighlighted m a)
-> (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 a b.
    Unhighlighted m a -> Unhighlighted m b -> Unhighlighted m b)
-> (forall a b.
    Unhighlighted m a -> Unhighlighted m b -> Unhighlighted m a)
-> Applicative (Unhighlighted m)
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
$cpure :: forall (m :: * -> *) a. Applicative m => a -> Unhighlighted m a
pure :: forall a. a -> Unhighlighted m a
$c<*> :: forall (m :: * -> *) a b.
Applicative m =>
Unhighlighted m (a -> b) -> Unhighlighted m a -> Unhighlighted m b
<*> :: forall a b.
Unhighlighted m (a -> b) -> Unhighlighted m a -> Unhighlighted m b
$cliftA2 :: forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c)
-> Unhighlighted m a -> Unhighlighted m b -> Unhighlighted m c
liftA2 :: forall a b c.
(a -> b -> c)
-> Unhighlighted m a -> Unhighlighted m b -> Unhighlighted m c
$c*> :: forall (m :: * -> *) a b.
Applicative m =>
Unhighlighted m a -> Unhighlighted m b -> Unhighlighted m b
*> :: 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 a
<* :: forall a b.
Unhighlighted m a -> Unhighlighted m b -> Unhighlighted m a
Applicative,Applicative (Unhighlighted m)
Applicative (Unhighlighted m) =>
(forall a. Unhighlighted m a)
-> (forall a.
    Unhighlighted m a -> Unhighlighted m a -> Unhighlighted m a)
-> (forall a. Unhighlighted m a -> Unhighlighted m [a])
-> (forall a. Unhighlighted m a -> Unhighlighted m [a])
-> Alternative (Unhighlighted m)
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
$cempty :: forall (m :: * -> *) a. Alternative m => Unhighlighted m a
empty :: forall a. Unhighlighted m a
$c<|> :: forall (m :: * -> *) a.
Alternative m =>
Unhighlighted m a -> Unhighlighted m a -> Unhighlighted m a
<|> :: forall a.
Unhighlighted m a -> Unhighlighted m a -> Unhighlighted m a
$csome :: forall (m :: * -> *) a.
Alternative m =>
Unhighlighted m a -> Unhighlighted m [a]
some :: forall a. Unhighlighted m a -> Unhighlighted m [a]
$cmany :: forall (m :: * -> *) a.
Alternative m =>
Unhighlighted m a -> Unhighlighted m [a]
many :: forall a. Unhighlighted m a -> Unhighlighted m [a]
Alternative,Applicative (Unhighlighted m)
Applicative (Unhighlighted m) =>
(forall a b.
 Unhighlighted m a -> (a -> Unhighlighted m b) -> Unhighlighted m b)
-> (forall a b.
    Unhighlighted m a -> Unhighlighted m b -> Unhighlighted m b)
-> (forall a. a -> Unhighlighted m a)
-> Monad (Unhighlighted m)
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
$c>>= :: forall (m :: * -> *) a b.
Monad m =>
Unhighlighted m a -> (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 -> Unhighlighted m b -> Unhighlighted m b
>> :: forall a b.
Unhighlighted m a -> Unhighlighted m b -> Unhighlighted m b
$creturn :: forall (m :: * -> *) a. Monad m => a -> Unhighlighted m a
return :: forall a. a -> Unhighlighted m a
Monad,Monad (Unhighlighted m)
Alternative (Unhighlighted m)
(Alternative (Unhighlighted m), Monad (Unhighlighted m)) =>
(forall a. Unhighlighted m a)
-> (forall a.
    Unhighlighted m a -> Unhighlighted m a -> Unhighlighted m a)
-> MonadPlus (Unhighlighted m)
forall a. Unhighlighted m a
forall a.
Unhighlighted m a -> Unhighlighted m a -> Unhighlighted m a
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
forall (m :: * -> *).
(Alternative m, Monad m) =>
(forall a. m a) -> (forall a. m a -> m a -> m a) -> MonadPlus m
$cmzero :: forall (m :: * -> *) a. MonadPlus m => Unhighlighted m a
mzero :: forall a. Unhighlighted m a
$cmplus :: 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
MonadPlus,Parsing (Unhighlighted m)
Unhighlighted m Char
Char -> Unhighlighted m Char
String -> Unhighlighted m String
Text -> Unhighlighted m Text
Parsing (Unhighlighted m) =>
((Char -> Bool) -> Unhighlighted m Char)
-> (Char -> Unhighlighted m Char)
-> (Char -> Unhighlighted m Char)
-> Unhighlighted m Char
-> (String -> Unhighlighted m String)
-> (Text -> Unhighlighted m Text)
-> CharParsing (Unhighlighted m)
(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
$csatisfy :: forall (m :: * -> *).
CharParsing m =>
(Char -> Bool) -> Unhighlighted m Char
satisfy :: (Char -> Bool) -> Unhighlighted m Char
$cchar :: forall (m :: * -> *). CharParsing m => Char -> Unhighlighted m Char
char :: Char -> Unhighlighted m Char
$cnotChar :: forall (m :: * -> *). CharParsing m => Char -> Unhighlighted m Char
notChar :: Char -> Unhighlighted m Char
$canyChar :: forall (m :: * -> *). CharParsing m => Unhighlighted m Char
anyChar :: Unhighlighted m Char
$cstring :: forall (m :: * -> *).
CharParsing m =>
String -> Unhighlighted m String
string :: String -> Unhighlighted m String
$ctext :: forall (m :: * -> *). CharParsing m => Text -> Unhighlighted m Text
text :: Text -> Unhighlighted m Text
CharParsing)

instance Parsing m => Parsing (Unhighlighted m) where
  try :: forall a. Unhighlighted m a -> Unhighlighted m a
try (Unhighlighted m a
m) = m a -> Unhighlighted m a
forall (m :: * -> *) a. m a -> Unhighlighted m a
Unhighlighted (m a -> Unhighlighted m a) -> m a -> Unhighlighted m a
forall a b. (a -> b) -> a -> b
$ m a -> m a
forall a. m a -> m a
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 = m a -> Unhighlighted m a
forall (m :: * -> *) a. m a -> Unhighlighted m a
Unhighlighted (m a -> Unhighlighted m a) -> m a -> Unhighlighted m a
forall a b. (a -> b) -> a -> b
$ m a
m m a -> String -> m a
forall a. m a -> String -> m a
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
l
  {-# INLINE (<?>) #-}
  unexpected :: forall a. String -> Unhighlighted m a
unexpected = m a -> Unhighlighted m a
forall (m :: * -> *) a. m a -> Unhighlighted m a
Unhighlighted (m a -> Unhighlighted m a)
-> (String -> m a) -> String -> Unhighlighted m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> m a
forall a. String -> m a
forall (m :: * -> *) a. Parsing m => String -> m a
unexpected
  {-# INLINE unexpected #-}
  eof :: Unhighlighted m ()
eof = m () -> Unhighlighted m ()
forall (m :: * -> *) a. m a -> Unhighlighted m a
Unhighlighted m ()
forall (m :: * -> *). Parsing m => m ()
eof
  {-# INLINE eof #-}
  notFollowedBy :: forall a. Show a => Unhighlighted m a -> Unhighlighted m ()
notFollowedBy (Unhighlighted m a
m) = m () -> Unhighlighted m ()
forall (m :: * -> *) a. m a -> Unhighlighted m a
Unhighlighted (m () -> Unhighlighted m ()) -> m () -> Unhighlighted m ()
forall a b. (a -> b) -> a -> b
$ m a -> m ()
forall a. Show a => m a -> m ()
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 = m a -> Unhighlighted m a
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 = m s -> Unhighlighted m s
forall (m :: * -> *) a. Monad m => m a -> Unhighlighted m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m s
forall s (m :: * -> *). MonadState s m => m s
Class.get
  {-# INLINE get #-}
  put :: s -> Unhighlighted m ()
put = m () -> Unhighlighted m ()
forall (m :: * -> *) a. Monad m => m a -> Unhighlighted m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> Unhighlighted m ())
-> (s -> m ()) -> s -> Unhighlighted m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> m ()
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 = m e -> Unhighlighted m e
forall (m :: * -> *) a. Monad m => m a -> Unhighlighted m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m e
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 = m a -> Unhighlighted m a
forall (m :: * -> *) a. m a -> Unhighlighted m a
Unhighlighted (m a -> Unhighlighted m a)
-> (Unhighlighted m a -> m a)
-> Unhighlighted m a
-> Unhighlighted m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (e -> e) -> m a -> m a
forall a. (e -> e) -> m a -> m a
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
Class.local e -> e
f (m a -> m a)
-> (Unhighlighted m a -> m a) -> Unhighlighted m a -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Unhighlighted m a -> m a
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 = m () -> Unhighlighted m ()
forall (m :: * -> *) a. Monad m => m a -> Unhighlighted m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> Unhighlighted m ())
-> (e -> m ()) -> e -> Unhighlighted m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> m ()
forall w (m :: * -> *). MonadWriter w m => w -> m ()
Class.tell
  {-# INLINE tell #-}
  listen :: forall a. Unhighlighted m a -> Unhighlighted m (a, e)
listen = m (a, e) -> Unhighlighted m (a, e)
forall (m :: * -> *) a. m a -> Unhighlighted m a
Unhighlighted (m (a, e) -> Unhighlighted m (a, e))
-> (Unhighlighted m a -> m (a, e))
-> Unhighlighted m a
-> Unhighlighted m (a, e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m a -> m (a, e)
forall a. m a -> m (a, e)
forall w (m :: * -> *) a. MonadWriter w m => m a -> m (a, w)
Class.listen (m a -> m (a, e))
-> (Unhighlighted m a -> m a) -> Unhighlighted m a -> m (a, e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Unhighlighted m a -> m a
forall (m :: * -> *) a. Unhighlighted m a -> m a
runUnhighlighted
  {-# INLINE listen #-}
  pass :: forall a. Unhighlighted m (a, e -> e) -> Unhighlighted m a
pass = m a -> Unhighlighted m a
forall (m :: * -> *) a. m a -> Unhighlighted m a
Unhighlighted (m a -> Unhighlighted m a)
-> (Unhighlighted m (a, e -> e) -> m a)
-> Unhighlighted m (a, e -> e)
-> Unhighlighted m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, e -> e) -> m a
forall a. m (a, e -> e) -> m a
forall w (m :: * -> *) a. MonadWriter w m => m (a, w -> w) -> m a
Class.pass (m (a, e -> e) -> m a)
-> (Unhighlighted m (a, e -> e) -> m (a, e -> e))
-> Unhighlighted m (a, e -> e)
-> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Unhighlighted m (a, e -> e) -> m (a, e -> e)
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) = m a -> Unhighlighted m a
forall (m :: * -> *) a. m a -> Unhighlighted m a
Unhighlighted (m a -> m a
forall a. m a -> m a
forall (m :: * -> *) a. TokenParsing m => m a -> m a
nesting m a
m)
  {-# INLINE nesting #-}
  someSpace :: Unhighlighted m ()
someSpace = m () -> Unhighlighted m ()
forall (m :: * -> *) a. m a -> Unhighlighted m a
Unhighlighted m ()
forall (m :: * -> *). TokenParsing m => m ()
someSpace
  {-# INLINE someSpace #-}
  semi :: Unhighlighted m Char
semi      = m Char -> Unhighlighted m Char
forall (m :: * -> *) a. m a -> Unhighlighted m a
Unhighlighted m Char
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 -> b) -> Unspaced m a -> Unspaced m b)
-> (forall a b. a -> Unspaced m b -> Unspaced m a)
-> Functor (Unspaced m)
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
$cfmap :: forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> Unspaced m a -> Unspaced m b
fmap :: forall a b. (a -> b) -> Unspaced m a -> Unspaced m b
$c<$ :: forall (m :: * -> *) a b.
Functor m =>
a -> Unspaced m b -> Unspaced m a
<$ :: forall a b. a -> Unspaced m b -> Unspaced m a
Functor,Functor (Unspaced m)
Functor (Unspaced m) =>
(forall a. a -> Unspaced m a)
-> (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 a b. Unspaced m a -> Unspaced m b -> Unspaced m b)
-> (forall a b. Unspaced m a -> Unspaced m b -> Unspaced m a)
-> Applicative (Unspaced m)
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
$cpure :: forall (m :: * -> *) a. Applicative m => a -> Unspaced m a
pure :: forall a. a -> Unspaced m a
$c<*> :: forall (m :: * -> *) a b.
Applicative m =>
Unspaced m (a -> b) -> Unspaced m a -> Unspaced m b
<*> :: forall a b. Unspaced m (a -> b) -> Unspaced m a -> Unspaced m b
$cliftA2 :: forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c) -> Unspaced m a -> Unspaced m b -> Unspaced m c
liftA2 :: forall a b c.
(a -> b -> c) -> Unspaced m a -> Unspaced m b -> Unspaced m c
$c*> :: forall (m :: * -> *) a b.
Applicative m =>
Unspaced m a -> Unspaced m b -> Unspaced m b
*> :: 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 a
<* :: forall a b. Unspaced m a -> Unspaced m b -> Unspaced m a
Applicative,Applicative (Unspaced m)
Applicative (Unspaced m) =>
(forall a. Unspaced m a)
-> (forall a. Unspaced m a -> Unspaced m a -> Unspaced m a)
-> (forall a. Unspaced m a -> Unspaced m [a])
-> (forall a. Unspaced m a -> Unspaced m [a])
-> Alternative (Unspaced m)
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
$cempty :: forall (m :: * -> *) a. Alternative m => Unspaced m a
empty :: forall a. Unspaced m a
$c<|> :: forall (m :: * -> *) a.
Alternative m =>
Unspaced m a -> Unspaced m a -> Unspaced m a
<|> :: forall a. Unspaced m a -> Unspaced m a -> Unspaced m a
$csome :: forall (m :: * -> *) a.
Alternative m =>
Unspaced m a -> Unspaced m [a]
some :: forall a. Unspaced m a -> Unspaced m [a]
$cmany :: forall (m :: * -> *) a.
Alternative m =>
Unspaced m a -> Unspaced m [a]
many :: forall a. Unspaced m a -> Unspaced m [a]
Alternative,Applicative (Unspaced m)
Applicative (Unspaced m) =>
(forall a b. Unspaced m a -> (a -> Unspaced m b) -> Unspaced m b)
-> (forall a b. Unspaced m a -> Unspaced m b -> Unspaced m b)
-> (forall a. a -> Unspaced m a)
-> Monad (Unspaced m)
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
$c>>= :: forall (m :: * -> *) a b.
Monad m =>
Unspaced m a -> (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 -> Unspaced m b -> Unspaced m b
>> :: forall a b. Unspaced m a -> Unspaced m b -> Unspaced m b
$creturn :: forall (m :: * -> *) a. Monad m => a -> Unspaced m a
return :: forall a. a -> Unspaced m a
Monad,Monad (Unspaced m)
Alternative (Unspaced m)
(Alternative (Unspaced m), Monad (Unspaced m)) =>
(forall a. Unspaced m a)
-> (forall a. Unspaced m a -> Unspaced m a -> Unspaced m a)
-> MonadPlus (Unspaced m)
forall a. Unspaced m a
forall a. Unspaced m a -> Unspaced m a -> Unspaced m a
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
forall (m :: * -> *).
(Alternative m, Monad m) =>
(forall a. m a) -> (forall a. m a -> m a -> m a) -> MonadPlus m
$cmzero :: forall (m :: * -> *) a. MonadPlus m => Unspaced m a
mzero :: forall a. Unspaced m a
$cmplus :: 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
MonadPlus,Parsing (Unspaced m)
Unspaced m Char
Char -> Unspaced m Char
String -> Unspaced m String
Text -> Unspaced m Text
Parsing (Unspaced m) =>
((Char -> Bool) -> Unspaced m Char)
-> (Char -> Unspaced m Char)
-> (Char -> Unspaced m Char)
-> Unspaced m Char
-> (String -> Unspaced m String)
-> (Text -> Unspaced m Text)
-> CharParsing (Unspaced m)
(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
$csatisfy :: forall (m :: * -> *).
CharParsing m =>
(Char -> Bool) -> Unspaced m Char
satisfy :: (Char -> Bool) -> Unspaced m Char
$cchar :: forall (m :: * -> *). CharParsing m => Char -> Unspaced m Char
char :: Char -> Unspaced m Char
$cnotChar :: forall (m :: * -> *). CharParsing m => Char -> Unspaced m Char
notChar :: Char -> Unspaced m Char
$canyChar :: forall (m :: * -> *). CharParsing m => Unspaced m Char
anyChar :: Unspaced m Char
$cstring :: forall (m :: * -> *). CharParsing m => String -> Unspaced m String
string :: String -> Unspaced m String
$ctext :: forall (m :: * -> *). CharParsing m => Text -> Unspaced m Text
text :: Text -> Unspaced m Text
CharParsing)

instance Parsing m => Parsing (Unspaced m) where
  try :: forall a. Unspaced m a -> Unspaced m a
try (Unspaced m a
m) = m a -> Unspaced m a
forall (m :: * -> *) a. m a -> Unspaced m a
Unspaced (m a -> Unspaced m a) -> m a -> Unspaced m a
forall a b. (a -> b) -> a -> b
$ m a -> m a
forall a. m a -> m a
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 = m a -> Unspaced m a
forall (m :: * -> *) a. m a -> Unspaced m a
Unspaced (m a -> Unspaced m a) -> m a -> Unspaced m a
forall a b. (a -> b) -> a -> b
$ m a
m m a -> String -> m a
forall a. m a -> String -> m a
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
l
  {-# INLINE (<?>) #-}
  unexpected :: forall a. String -> Unspaced m a
unexpected = m a -> Unspaced m a
forall (m :: * -> *) a. m a -> Unspaced m a
Unspaced (m a -> Unspaced m a) -> (String -> m a) -> String -> Unspaced m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> m a
forall a. String -> m a
forall (m :: * -> *) a. Parsing m => String -> m a
unexpected
  {-# INLINE unexpected #-}
  eof :: Unspaced m ()
eof = m () -> Unspaced m ()
forall (m :: * -> *) a. m a -> Unspaced m a
Unspaced m ()
forall (m :: * -> *). Parsing m => m ()
eof
  {-# INLINE eof #-}
  notFollowedBy :: forall a. Show a => Unspaced m a -> Unspaced m ()
notFollowedBy (Unspaced m a
m) = m () -> Unspaced m ()
forall (m :: * -> *) a. m a -> Unspaced m a
Unspaced (m () -> Unspaced m ()) -> m () -> Unspaced m ()
forall a b. (a -> b) -> a -> b
$ m a -> m ()
forall a. Show a => m a -> m ()
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 = m a -> Unspaced m a
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 = m s -> Unspaced m s
forall (m :: * -> *) a. Monad m => m a -> Unspaced m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m s
forall s (m :: * -> *). MonadState s m => m s
Class.get
  {-# INLINE get #-}
  put :: s -> Unspaced m ()
put = m () -> Unspaced m ()
forall (m :: * -> *) a. Monad m => m a -> Unspaced m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> Unspaced m ()) -> (s -> m ()) -> s -> Unspaced m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> m ()
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 = m e -> Unspaced m e
forall (m :: * -> *) a. Monad m => m a -> Unspaced m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m e
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 = m a -> Unspaced m a
forall (m :: * -> *) a. m a -> Unspaced m a
Unspaced (m a -> Unspaced m a)
-> (Unspaced m a -> m a) -> Unspaced m a -> Unspaced m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (e -> e) -> m a -> m a
forall a. (e -> e) -> m a -> m a
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
Class.local e -> e
f (m a -> m a) -> (Unspaced m a -> m a) -> Unspaced m a -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Unspaced m a -> m a
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 = m () -> Unspaced m ()
forall (m :: * -> *) a. Monad m => m a -> Unspaced m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> Unspaced m ()) -> (e -> m ()) -> e -> Unspaced m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> m ()
forall w (m :: * -> *). MonadWriter w m => w -> m ()
Class.tell
  {-# INLINE tell #-}
  listen :: forall a. Unspaced m a -> Unspaced m (a, e)
listen = m (a, e) -> Unspaced m (a, e)
forall (m :: * -> *) a. m a -> Unspaced m a
Unspaced (m (a, e) -> Unspaced m (a, e))
-> (Unspaced m a -> m (a, e)) -> Unspaced m a -> Unspaced m (a, e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m a -> m (a, e)
forall a. m a -> m (a, e)
forall w (m :: * -> *) a. MonadWriter w m => m a -> m (a, w)
Class.listen (m a -> m (a, e))
-> (Unspaced m a -> m a) -> Unspaced m a -> m (a, e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Unspaced m a -> m a
forall (m :: * -> *) a. Unspaced m a -> m a
runUnspaced
  {-# INLINE listen #-}
  pass :: forall a. Unspaced m (a, e -> e) -> Unspaced m a
pass = m a -> Unspaced m a
forall (m :: * -> *) a. m a -> Unspaced m a
Unspaced (m a -> Unspaced m a)
-> (Unspaced m (a, e -> e) -> m a)
-> Unspaced m (a, e -> e)
-> Unspaced m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, e -> e) -> m a
forall a. m (a, e -> e) -> m a
forall w (m :: * -> *) a. MonadWriter w m => m (a, w -> w) -> m a
Class.pass (m (a, e -> e) -> m a)
-> (Unspaced m (a, e -> e) -> m (a, e -> e))
-> Unspaced m (a, e -> e)
-> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Unspaced m (a, e -> e) -> m (a, e -> e)
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) = m a -> Unspaced m a
forall (m :: * -> *) a. m a -> Unspaced m a
Unspaced (m a -> m a
forall a. m a -> m a
forall (m :: * -> *) a. TokenParsing m => m a -> m a
nesting m a
m)
  {-# INLINE nesting #-}
  someSpace :: Unspaced m ()
someSpace = Unspaced m ()
forall a. Unspaced m a
forall (f :: * -> *) a. Alternative f => f a
empty
  {-# INLINE someSpace #-}
  semi :: Unspaced m Char
semi      = m Char -> Unspaced m Char
forall (m :: * -> *) a. m a -> Unspaced m a
Unspaced m Char
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) = m a -> Unspaced m a
forall (m :: * -> *) a. m a -> Unspaced m a
Unspaced (Highlight -> m a -> m a
forall a. Highlight -> m a -> m a
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 -> b) -> Unlined m a -> Unlined m b)
-> (forall a b. a -> Unlined m b -> Unlined m a)
-> Functor (Unlined m)
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
$cfmap :: forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> Unlined m a -> Unlined m b
fmap :: forall a b. (a -> b) -> Unlined m a -> Unlined m b
$c<$ :: forall (m :: * -> *) a b.
Functor m =>
a -> Unlined m b -> Unlined m a
<$ :: forall a b. a -> Unlined m b -> Unlined m a
Functor,Functor (Unlined m)
Functor (Unlined m) =>
(forall a. a -> Unlined m a)
-> (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 a b. Unlined m a -> Unlined m b -> Unlined m b)
-> (forall a b. Unlined m a -> Unlined m b -> Unlined m a)
-> Applicative (Unlined m)
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
$cpure :: forall (m :: * -> *) a. Applicative m => a -> Unlined m a
pure :: forall a. a -> Unlined m a
$c<*> :: forall (m :: * -> *) a b.
Applicative m =>
Unlined m (a -> b) -> Unlined m a -> Unlined m b
<*> :: forall a b. Unlined m (a -> b) -> Unlined m a -> Unlined m b
$cliftA2 :: forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c) -> Unlined m a -> Unlined m b -> Unlined m c
liftA2 :: forall a b c.
(a -> b -> c) -> Unlined m a -> Unlined m b -> Unlined m c
$c*> :: forall (m :: * -> *) a b.
Applicative m =>
Unlined m a -> Unlined m b -> Unlined m b
*> :: 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 a
<* :: forall a b. Unlined m a -> Unlined m b -> Unlined m a
Applicative,Applicative (Unlined m)
Applicative (Unlined m) =>
(forall a. Unlined m a)
-> (forall a. Unlined m a -> Unlined m a -> Unlined m a)
-> (forall a. Unlined m a -> Unlined m [a])
-> (forall a. Unlined m a -> Unlined m [a])
-> Alternative (Unlined m)
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
$cempty :: forall (m :: * -> *) a. Alternative m => Unlined m a
empty :: forall a. Unlined m a
$c<|> :: forall (m :: * -> *) a.
Alternative m =>
Unlined m a -> Unlined m a -> Unlined m a
<|> :: forall a. Unlined m a -> Unlined m a -> Unlined m a
$csome :: forall (m :: * -> *) a.
Alternative m =>
Unlined m a -> Unlined m [a]
some :: forall a. Unlined m a -> Unlined m [a]
$cmany :: forall (m :: * -> *) a.
Alternative m =>
Unlined m a -> Unlined m [a]
many :: forall a. Unlined m a -> Unlined m [a]
Alternative,Applicative (Unlined m)
Applicative (Unlined m) =>
(forall a b. Unlined m a -> (a -> Unlined m b) -> Unlined m b)
-> (forall a b. Unlined m a -> Unlined m b -> Unlined m b)
-> (forall a. a -> Unlined m a)
-> Monad (Unlined m)
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
$c>>= :: forall (m :: * -> *) a b.
Monad m =>
Unlined m a -> (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 -> Unlined m b -> Unlined m b
>> :: forall a b. Unlined m a -> Unlined m b -> Unlined m b
$creturn :: forall (m :: * -> *) a. Monad m => a -> Unlined m a
return :: forall a. a -> Unlined m a
Monad,Monad (Unlined m)
Alternative (Unlined m)
(Alternative (Unlined m), Monad (Unlined m)) =>
(forall a. Unlined m a)
-> (forall a. Unlined m a -> Unlined m a -> Unlined m a)
-> MonadPlus (Unlined m)
forall a. Unlined m a
forall a. Unlined m a -> Unlined m a -> Unlined m a
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
forall (m :: * -> *).
(Alternative m, Monad m) =>
(forall a. m a) -> (forall a. m a -> m a -> m a) -> MonadPlus m
$cmzero :: forall (m :: * -> *) a. MonadPlus m => Unlined m a
mzero :: forall a. Unlined m a
$cmplus :: 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
MonadPlus,Parsing (Unlined m)
Unlined m Char
Char -> Unlined m Char
String -> Unlined m String
Text -> Unlined m Text
Parsing (Unlined m) =>
((Char -> Bool) -> Unlined m Char)
-> (Char -> Unlined m Char)
-> (Char -> Unlined m Char)
-> Unlined m Char
-> (String -> Unlined m String)
-> (Text -> Unlined m Text)
-> CharParsing (Unlined m)
(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
$csatisfy :: forall (m :: * -> *).
CharParsing m =>
(Char -> Bool) -> Unlined m Char
satisfy :: (Char -> Bool) -> Unlined m Char
$cchar :: forall (m :: * -> *). CharParsing m => Char -> Unlined m Char
char :: Char -> Unlined m Char
$cnotChar :: forall (m :: * -> *). CharParsing m => Char -> Unlined m Char
notChar :: Char -> Unlined m Char
$canyChar :: forall (m :: * -> *). CharParsing m => Unlined m Char
anyChar :: Unlined m Char
$cstring :: forall (m :: * -> *). CharParsing m => String -> Unlined m String
string :: String -> Unlined m String
$ctext :: forall (m :: * -> *). CharParsing m => Text -> Unlined m Text
text :: Text -> Unlined m Text
CharParsing)

instance Parsing m => Parsing (Unlined m) where
  try :: forall a. Unlined m a -> Unlined m a
try (Unlined m a
m) = m a -> Unlined m a
forall (m :: * -> *) a. m a -> Unlined m a
Unlined (m a -> Unlined m a) -> m a -> Unlined m a
forall a b. (a -> b) -> a -> b
$ m a -> m a
forall a. m a -> m a
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 = m a -> Unlined m a
forall (m :: * -> *) a. m a -> Unlined m a
Unlined (m a -> Unlined m a) -> m a -> Unlined m a
forall a b. (a -> b) -> a -> b
$ m a
m m a -> String -> m a
forall a. m a -> String -> m a
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
l
  {-# INLINE (<?>) #-}
  unexpected :: forall a. String -> Unlined m a
unexpected = m a -> Unlined m a
forall (m :: * -> *) a. m a -> Unlined m a
Unlined (m a -> Unlined m a) -> (String -> m a) -> String -> Unlined m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> m a
forall a. String -> m a
forall (m :: * -> *) a. Parsing m => String -> m a
unexpected
  {-# INLINE unexpected #-}
  eof :: Unlined m ()
eof = m () -> Unlined m ()
forall (m :: * -> *) a. m a -> Unlined m a
Unlined m ()
forall (m :: * -> *). Parsing m => m ()
eof
  {-# INLINE eof #-}
  notFollowedBy :: forall a. Show a => Unlined m a -> Unlined m ()
notFollowedBy (Unlined m a
m) = m () -> Unlined m ()
forall (m :: * -> *) a. m a -> Unlined m a
Unlined (m () -> Unlined m ()) -> m () -> Unlined m ()
forall a b. (a -> b) -> a -> b
$ m a -> m ()
forall a. Show a => m a -> m ()
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 = m a -> Unlined m a
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 = m s -> Unlined m s
forall (m :: * -> *) a. Monad m => m a -> Unlined m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m s
forall s (m :: * -> *). MonadState s m => m s
Class.get
  {-# INLINE get #-}
  put :: s -> Unlined m ()
put = m () -> Unlined m ()
forall (m :: * -> *) a. Monad m => m a -> Unlined m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> Unlined m ()) -> (s -> m ()) -> s -> Unlined m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> m ()
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 = m e -> Unlined m e
forall (m :: * -> *) a. Monad m => m a -> Unlined m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m e
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 = m a -> Unlined m a
forall (m :: * -> *) a. m a -> Unlined m a
Unlined (m a -> Unlined m a)
-> (Unlined m a -> m a) -> Unlined m a -> Unlined m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (e -> e) -> m a -> m a
forall a. (e -> e) -> m a -> m a
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
Class.local e -> e
f (m a -> m a) -> (Unlined m a -> m a) -> Unlined m a -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Unlined m a -> m a
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 = m () -> Unlined m ()
forall (m :: * -> *) a. Monad m => m a -> Unlined m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> Unlined m ()) -> (e -> m ()) -> e -> Unlined m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> m ()
forall w (m :: * -> *). MonadWriter w m => w -> m ()
Class.tell
  {-# INLINE tell #-}
  listen :: forall a. Unlined m a -> Unlined m (a, e)
listen = m (a, e) -> Unlined m (a, e)
forall (m :: * -> *) a. m a -> Unlined m a
Unlined (m (a, e) -> Unlined m (a, e))
-> (Unlined m a -> m (a, e)) -> Unlined m a -> Unlined m (a, e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m a -> m (a, e)
forall a. m a -> m (a, e)
forall w (m :: * -> *) a. MonadWriter w m => m a -> m (a, w)
Class.listen (m a -> m (a, e))
-> (Unlined m a -> m a) -> Unlined m a -> m (a, e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Unlined m a -> m a
forall (m :: * -> *) a. Unlined m a -> m a
runUnlined
  {-# INLINE listen #-}
  pass :: forall a. Unlined m (a, e -> e) -> Unlined m a
pass = m a -> Unlined m a
forall (m :: * -> *) a. m a -> Unlined m a
Unlined (m a -> Unlined m a)
-> (Unlined m (a, e -> e) -> m a)
-> Unlined m (a, e -> e)
-> Unlined m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, e -> e) -> m a
forall a. m (a, e -> e) -> m a
forall w (m :: * -> *) a. MonadWriter w m => m (a, w -> w) -> m a
Class.pass (m (a, e -> e) -> m a)
-> (Unlined m (a, e -> e) -> m (a, e -> e))
-> Unlined m (a, e -> e)
-> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Unlined m (a, e -> e) -> m (a, e -> e)
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) = m a -> Unlined m a
forall (m :: * -> *) a. m a -> Unlined m a
Unlined (m a -> m a
forall a. m a -> m a
forall (m :: * -> *) a. TokenParsing m => m a -> m a
nesting m a
m)
  {-# INLINE nesting #-}
  someSpace :: Unlined m ()
someSpace = Unlined m Char -> Unlined m ()
forall a. Unlined m a -> Unlined m ()
forall (m :: * -> *) a. Parsing m => m a -> m ()
skipMany ((Char -> Bool) -> Unlined m Char
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
satisfy ((Char -> Bool) -> Unlined m Char)
-> (Char -> Bool) -> Unlined m Char
forall a b. (a -> b) -> a -> b
$ \Char
c -> Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'\n' Bool -> Bool -> Bool
&& Char -> Bool
isSpace Char
c)
  {-# INLINE someSpace #-}
  semi :: Unlined m Char
semi      = m Char -> Unlined m Char
forall (m :: * -> *) a. m a -> Unlined m a
Unlined m Char
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) = m a -> Unlined m a
forall (m :: * -> *) a. m a -> Unlined m a
Unlined (Highlight -> m a -> m a
forall a. Highlight -> m a -> m a
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