    {-# LANGUAGE CPP #-}
    {-# LANGUAGE DeriveFunctor #-}
    {-# LANGUAGE LambdaCase #-}
    {-# LANGUAGE ScopedTypeVariables #-}
    module Test.Hspec.Core.Formatters.Pretty.Parser (
      Value(..)
    , parseValue
    ) where

    import           Prelude ()
    import           Test.Hspec.Core.Compat hiding (Alternative(..), read, exp)

    import           Language.Haskell.Lexer hiding (Token, Pos(..))
    import qualified Language.Haskell.Lexer as Lexer

    type Name = String

    data Value =
        Char Char
      | String String
      | Number String
      | Operator Value Name Value
      | Record Name [(Name, Value)]
      | Constructor Name [Value]
      | Tuple [Value]
      | List [Value]
      deriving (Value -> Value -> Bool
    (Value -> Value -> Bool) -> (Value -> Value -> Bool) -> Eq Value
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: Value -> Value -> Bool
    == :: Value -> Value -> Bool
    $c/= :: Value -> Value -> Bool
    /= :: Value -> Value -> Bool
    Eq, Int -> Value -> ShowS
    [Value] -> ShowS
    Value -> [Char]
    (Int -> Value -> ShowS)
    -> (Value -> [Char]) -> ([Value] -> ShowS) -> Show Value
    forall a.
    (Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> Value -> ShowS
    showsPrec :: Int -> Value -> ShowS
    $cshow :: Value -> [Char]
    show :: Value -> [Char]
    $cshowList :: [Value] -> ShowS
    showList :: [Value] -> ShowS
    Show)

    type Token = (TokenType, String)

    type TokenType = Lexer.Token

    #ifndef __MHS__
    newtype Parser a = Parser {
    #else
    data Parser a = Parser {
    #endif
      forall a. Parser a -> [Token] -> Maybe (a, [Token])
    runParser :: [Token] -> Maybe (a, [Token])
    } deriving (forall a b. (a -> b) -> Parser a -> Parser b)
    -> (forall a b. a -> Parser b -> Parser a) -> Functor Parser
    forall a b. a -> Parser b -> Parser a
    forall a b. (a -> b) -> Parser a -> Parser b
    forall (f :: * -> *).
    (forall a b. (a -> b) -> f a -> f b)
    -> (forall a b. a -> f b -> f a) -> Functor f
    $cfmap :: forall a b. (a -> b) -> Parser a -> Parser b
    fmap :: forall a b. (a -> b) -> Parser a -> Parser b
    $c<$ :: forall a b. a -> Parser b -> Parser a
    <$ :: forall a b. a -> Parser b -> Parser a
    Functor

    instance Applicative Parser where
      pure :: forall a. a -> Parser a
    pure a
    a = ([Token] -> Maybe (a, [Token])) -> Parser a
    forall a. ([Token] -> Maybe (a, [Token])) -> Parser a
    Parser (([Token] -> Maybe (a, [Token])) -> Parser a)
    -> ([Token] -> Maybe (a, [Token])) -> Parser a
    forall a b. (a -> b) -> a -> b
    $ \ [Token]
    input -> (a, [Token]) -> Maybe (a, [Token])
    forall a. a -> Maybe a
    Just (a
    a, [Token]
    input)
      <*> :: forall a b. Parser (a -> b) -> Parser a -> Parser b
    (<*>) = Parser (a -> b) -> Parser a -> Parser b
    forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
    ap

    instance Monad Parser where
      return :: forall a. a -> Parser a
    return = a -> Parser a
    forall a. a -> Parser a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure
      Parser a
    p1 >>= :: forall a b. Parser a -> (a -> Parser b) -> Parser b
    >>= a -> Parser b
    p2 = ([Token] -> Maybe (b, [Token])) -> Parser b
    forall a. ([Token] -> Maybe (a, [Token])) -> Parser a
    Parser (([Token] -> Maybe (b, [Token])) -> Parser b)
    -> ([Token] -> Maybe (b, [Token])) -> Parser b
    forall a b. (a -> b) -> a -> b
    $ Parser a -> [Token] -> Maybe (a, [Token])
    forall a. Parser a -> [Token] -> Maybe (a, [Token])
    runParser Parser a
    p1 ([Token] -> Maybe (a, [Token]))
    -> ((a, [Token]) -> Maybe (b, [Token]))
    -> [Token]
    -> Maybe (b, [Token])
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> (a -> [Token] -> Maybe (b, [Token]))
    -> (a, [Token]) -> Maybe (b, [Token])
    forall a b c. (a -> b -> c) -> (a, b) -> c
    uncurry (Parser b -> [Token] -> Maybe (b, [Token])
    forall a. Parser a -> [Token] -> Maybe (a, [Token])
    runParser (Parser b -> [Token] -> Maybe (b, [Token]))
    -> (a -> Parser b) -> a -> [Token] -> Maybe (b, [Token])
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> Parser b
    p2)

    parseValue :: String -> Maybe Value
    parseValue :: [Char] -> Maybe Value
    parseValue [Char]
    input = case Parser Value -> [Token] -> Maybe (Value, [Token])
    forall a. Parser a -> [Token] -> Maybe (a, [Token])
    runParser Parser Value
    exp ([Char] -> [Token]
    tokenize [Char]
    input) of
      Just (Value
    v, []) -> Value -> Maybe Value
    forall a. a -> Maybe a
    Just Value
    v
      Maybe (Value, [Token])
    _ -> Maybe Value
    forall a. Maybe a
    Nothing

    tokenize :: String -> [Token]
    tokenize :: [Char] -> [Token]
    tokenize = [Token] -> [Token]
    go ([Token] -> [Token]) -> ([Char] -> [Token]) -> [Char] -> [Token]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ((TokenType, (Pos, [Char])) -> Token)
    -> [(TokenType, (Pos, [Char]))] -> [Token]
    forall a b. (a -> b) -> [a] -> [b]
    map (((Pos, [Char]) -> [Char]) -> (TokenType, (Pos, [Char])) -> Token
    forall a b. (a -> b) -> (TokenType, a) -> (TokenType, b)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap (Pos, [Char]) -> [Char]
    forall a b. (a, b) -> b
    snd) ([(TokenType, (Pos, [Char]))] -> [Token])
    -> ([Char] -> [(TokenType, (Pos, [Char]))]) -> [Char] -> [Token]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [(TokenType, (Pos, [Char]))] -> [(TokenType, (Pos, [Char]))]
    rmSpace ([(TokenType, (Pos, [Char]))] -> [(TokenType, (Pos, [Char]))])
    -> ([Char] -> [(TokenType, (Pos, [Char]))])
    -> [Char]
    -> [(TokenType, (Pos, [Char]))]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Char] -> [(TokenType, (Pos, [Char]))]
    lexerPass0
      where
        go :: [Token] -> [Token]
        go :: [Token] -> [Token]
    go [Token]
    tokens = case [Token]
    tokens of
          [] -> []
          (TokenType
    Varsym, [Char]
    "-") : (TokenType
    IntLit, [Char]
    n) : [Token]
    xs -> (TokenType
    IntLit, [Char]
    "-" [Char] -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ [Char]
    n) Token -> [Token] -> [Token]
    forall a. a -> [a] -> [a]
    : [Token] -> [Token]
    go [Token]
    xs
          (TokenType
    Varsym, [Char]
    "-") : (TokenType
    FloatLit, [Char]
    n) : [Token]
    xs -> (TokenType
    FloatLit, [Char]
    "-" [Char] -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ [Char]
    n) Token -> [Token] -> [Token]
    forall a. a -> [a] -> [a]
    : [Token] -> [Token]
    go [Token]
    xs
          Token
    x : [Token]
    xs -> Token
    x Token -> [Token] -> [Token]
    forall a. a -> [a] -> [a]
    : [Token] -> [Token]
    go [Token]
    xs

    exp :: Parser Value
    exp :: Parser Value
    exp = Parser Value
    infixexp

    infixexp :: Parser Value
    infixexp :: Parser Value
    infixexp = (Value -> Parser Value) -> Parser Value -> Parser Value
    forall a. (Value -> Parser a) -> Parser a -> Parser a
    aexp Value -> Parser Value
    accept Parser Value
    reject
      where
        accept :: Value -> Parser Value
        accept :: Value -> Parser Value
    accept Value
    value = Parser Token
    peek Parser Token -> (Token -> Parser Value) -> Parser Value
    forall a b. Parser a -> (a -> Parser b) -> Parser b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= \ case
          (TokenType
    Varsym, [Char]
    "%") -> Parser ()
    skip Parser () -> Parser Value -> Parser Value
    forall a b. Parser a -> Parser b -> Parser b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> Value -> [Char] -> Value -> Value
    Operator Value
    value [Char]
    "%" (Value -> Value) -> Parser Value -> Parser Value
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Parser Value
    exp
          (TokenType
    Consym, [Char]
    name) -> Parser ()
    skip Parser () -> Parser Value -> Parser Value
    forall a b. Parser a -> Parser b -> Parser b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> Value -> [Char] -> Value -> Value
    Operator Value
    value [Char]
    name (Value -> Value) -> Parser Value -> Parser Value
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Parser Value
    exp
          Token
    _ -> Value -> Parser Value
    forall a. a -> Parser a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Value
    value

        reject :: Parser Value
        reject :: Parser Value
    reject = Parser Token
    next Parser Token -> (Token -> Parser Value) -> Parser Value
    forall a b. Parser a -> (a -> Parser b) -> Parser b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= Token -> Parser Value
    forall a. Token -> Parser a
    unexpected

    aexp :: forall a. (Value -> Parser a) -> Parser a -> Parser a
    aexp :: forall a. (Value -> Parser a) -> Parser a -> Parser a
    aexp Value -> Parser a
    continue Parser a
    done = Parser Token
    peek Parser Token -> (Token -> Parser a) -> Parser a
    forall a b. Parser a -> (a -> Parser b) -> Parser b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= \ case
      (TokenType
    CharLit, [Char]
    value) -> (Char -> Value) -> [Char] -> Parser a
    forall v. Read v => (v -> Value) -> [Char] -> Parser a
    read Char -> Value
    Char [Char]
    value
      (TokenType
    StringLit, [Char]
    value) -> ([Char] -> Value) -> [Char] -> Parser a
    forall v. Read v => (v -> Value) -> [Char] -> Parser a
    read [Char] -> Value
    String [Char]
    value
      (TokenType
    IntLit, [Char]
    value) -> [Char] -> Parser a
    number [Char]
    value
      (TokenType
    FloatLit, [Char]
    value) -> [Char] -> Parser a
    number [Char]
    value
      (TokenType
    Conid, [Char]
    name) -> Parser Value -> Parser a
    accept (Parser Value -> Parser a) -> Parser Value -> Parser a
    forall a b. (a -> b) -> a -> b
    $ [Char] -> Parser Value
    constructor [Char]
    name
      (TokenType
    Special, [Char]
    "(") -> Parser Value -> Parser a
    accept Parser Value
    tuple
      (TokenType
    Special, [Char]
    "[") -> Parser Value -> Parser a
    accept Parser Value
    list
      Token
    _ -> Parser a
    done
      where
        read :: Read v => (v -> Value) -> String -> Parser a
        read :: forall v. Read v => (v -> Value) -> [Char] -> Parser a
    read v -> Value
    c [Char]
    v = Parser ()
    skip Parser () -> Parser Value -> Parser Value
    forall a b. Parser a -> Parser b -> Parser b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> v -> Value
    c (v -> Value) -> Parser v -> Parser Value
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> [Char] -> Parser v
    forall a. Read a => [Char] -> Parser a
    readValue [Char]
    v Parser Value -> (Value -> Parser a) -> Parser a
    forall a b. Parser a -> (a -> Parser b) -> Parser b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= Value -> Parser a
    continue

        number :: String -> Parser a
        number :: [Char] -> Parser a
    number [Char]
    value = Parser ()
    skip Parser () -> Parser a -> Parser a
    forall a b. Parser a -> Parser b -> Parser b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> Value -> Parser a
    continue ([Char] -> Value
    Number [Char]
    value)

        accept :: Parser Value -> Parser a
        accept :: Parser Value -> Parser a
    accept Parser Value
    action = Parser ()
    skip Parser () -> Parser Value -> Parser Value
    forall a b. Parser a -> Parser b -> Parser b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> Parser Value
    action Parser Value -> (Value -> Parser a) -> Parser a
    forall a b. Parser a -> (a -> Parser b) -> Parser b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= Value -> Parser a
    continue

    constructor :: String -> Parser Value
    constructor :: [Char] -> Parser Value
    constructor [Char]
    name = Parser Token
    peek Parser Token -> (Token -> Parser Value) -> Parser Value
    forall a b. Parser a -> (a -> Parser b) -> Parser b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= \ case
      (TokenType
    Special, [Char]
    "{") -> Parser ()
    skip Parser () -> Parser Value -> Parser Value
    forall a b. Parser a -> Parser b -> Parser b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> [Char] -> [([Char], Value)] -> Value
    Record [Char]
    name ([([Char], Value)] -> Value)
    -> Parser [([Char], Value)] -> Parser Value
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Parser ([Char], Value) -> [Char] -> Parser [([Char], Value)]
    forall a. Parser a -> [Char] -> Parser [a]
    commaSeparated Parser ([Char], Value)
    field [Char]
    "}"
        where
          field :: Parser (Name, Value)
          field :: Parser ([Char], Value)
    field = (,) ([Char] -> Value -> ([Char], Value))
    -> Parser [Char] -> Parser (Value -> ([Char], Value))
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> TokenType -> Parser [Char]
    require TokenType
    Varid Parser (Value -> ([Char], Value))
    -> Parser () -> Parser (Value -> ([Char], Value))
    forall a b. Parser a -> Parser b -> Parser a
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <* Parser ()
    equals Parser (Value -> ([Char], Value))
    -> Parser Value -> Parser ([Char], Value)
    forall a b. Parser (a -> b) -> Parser a -> Parser b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> Parser Value
    exp

      Token
    _ -> [Char] -> [Value] -> Value
    Constructor [Char]
    name ([Value] -> Value) -> Parser [Value] -> Parser Value
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Parser [Value]
    parameters
        where
          parameters :: Parser [Value]
          parameters :: Parser [Value]
    parameters = (Value -> Parser [Value]) -> Parser [Value] -> Parser [Value]
    forall a. (Value -> Parser a) -> Parser a -> Parser a
    aexp Value -> Parser [Value]
    more Parser [Value]
    done

          more :: Value -> Parser [Value]
          more :: Value -> Parser [Value]
    more Value
    v = (:) Value
    v ([Value] -> [Value]) -> Parser [Value] -> Parser [Value]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Parser [Value]
    parameters

          done :: Parser [Value]
          done :: Parser [Value]
    done = [Value] -> Parser [Value]
    forall a. a -> Parser a
    forall (m :: * -> *) a. Monad m => a -> m a
    return []

    tuple :: Parser Value
    tuple :: Parser Value
    tuple = [Value] -> Value
    Tuple ([Value] -> Value) -> Parser [Value] -> Parser Value
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Parser Value -> [Char] -> Parser [Value]
    forall a. Parser a -> [Char] -> Parser [a]
    commaSeparated Parser Value
    exp [Char]
    ")"

    list :: Parser Value
    list :: Parser Value
    list = [Value] -> Value
    List ([Value] -> Value) -> Parser [Value] -> Parser Value
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Parser Value -> [Char] -> Parser [Value]
    forall a. Parser a -> [Char] -> Parser [a]
    commaSeparated Parser Value
    exp [Char]
    "]"

    commaSeparated :: forall a. Parser a -> String -> Parser [a]
    commaSeparated :: forall a. Parser a -> [Char] -> Parser [a]
    commaSeparated Parser a
    item [Char]
    close = Parser Token
    peek Parser Token -> (Token -> Parser [a]) -> Parser [a]
    forall a b. Parser a -> (a -> Parser b) -> Parser b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= \ case
      (TokenType
    Special, [Char]
    c) | [Char]
    c [Char] -> [Char] -> Bool
    forall a. Eq a => a -> a -> Bool
    == [Char]
    close -> Parser ()
    skip Parser () -> Parser [a] -> Parser [a]
    forall a b. Parser a -> Parser b -> Parser b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> [a] -> Parser [a]
    forall a. a -> Parser a
    forall (m :: * -> *) a. Monad m => a -> m a
    return []
      Token
    _ -> Parser [a]
    items
      where
        items :: Parser [a]
        items :: Parser [a]
    items = (:) (a -> [a] -> [a]) -> Parser a -> Parser ([a] -> [a])
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Parser a
    item Parser ([a] -> [a]) -> Parser [a] -> Parser [a]
    forall a b. Parser (a -> b) -> Parser a -> Parser b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> Parser [a]
    moreItems

        moreItems :: Parser [a]
        moreItems :: Parser [a]
    moreItems = Parser Token
    next Parser Token -> (Token -> Parser [a]) -> Parser [a]
    forall a b. Parser a -> (a -> Parser b) -> Parser b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= \ case
          (TokenType
    Special, [Char]
    c)
            | [Char]
    c [Char] -> [Char] -> Bool
    forall a. Eq a => a -> a -> Bool
    == [Char]
    "," -> Parser [a]
    items
            | [Char]
    c [Char] -> [Char] -> Bool
    forall a. Eq a => a -> a -> Bool
    == [Char]
    close -> [a] -> Parser [a]
    forall a. a -> Parser a
    forall (m :: * -> *) a. Monad m => a -> m a
    return []
          Token
    t -> Token -> Parser [a]
    forall a. Token -> Parser a
    unexpected Token
    t

    equals :: Parser ()
    equals :: Parser ()
    equals = Token -> Parser ()
    requireToken (TokenType
    Reservedop, [Char]
    "=")

    require :: TokenType -> Parser String
    require :: TokenType -> Parser [Char]
    require TokenType
    expected = Parser Token
    next Parser Token -> (Token -> Parser [Char]) -> Parser [Char]
    forall a b. Parser a -> (a -> Parser b) -> Parser b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= \ case
      (TokenType
    token, [Char]
    v) | TokenType
    token TokenType -> TokenType -> Bool
    forall a. Eq a => a -> a -> Bool
    == TokenType
    expected -> [Char] -> Parser [Char]
    forall a. a -> Parser a
    forall (m :: * -> *) a. Monad m => a -> m a
    return [Char]
    v
      Token
    token -> Token -> Parser [Char]
    forall a. Token -> Parser a
    unexpected Token
    token

    requireToken :: Token -> Parser ()
    requireToken :: Token -> Parser ()
    requireToken Token
    expected = Parser Token
    next Parser Token -> (Token -> Parser ()) -> Parser ()
    forall a b. Parser a -> (a -> Parser b) -> Parser b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= \ case
      Token
    token | Token
    token Token -> Token -> Bool
    forall a. Eq a => a -> a -> Bool
    == Token
    expected -> () -> Parser ()
    forall a. a -> Parser a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ()
      Token
    token -> Token -> Parser ()
    forall a. Token -> Parser a
    unexpected Token
    token

    peek :: Parser Token
    peek :: Parser Token
    peek = ([Token] -> Maybe (Token, [Token])) -> Parser Token
    forall a. ([Token] -> Maybe (a, [Token])) -> Parser a
    Parser (([Token] -> Maybe (Token, [Token])) -> Parser Token)
    -> ([Token] -> Maybe (Token, [Token])) -> Parser Token
    forall a b. (a -> b) -> a -> b
    $ \ [Token]
    input -> case [Token]
    input of
      Token
    t : [Token]
    _ -> (Token, [Token]) -> Maybe (Token, [Token])
    forall a. a -> Maybe a
    Just (Token
    t, [Token]
    input)
      [] -> (Token, [Token]) -> Maybe (Token, [Token])
    forall a. a -> Maybe a
    Just ((TokenType
    GotEOF, [Char]
    ""), [Token]
    input)

    next :: Parser Token
    next :: Parser Token
    next = ([Token] -> Maybe (Token, [Token])) -> Parser Token
    forall a. ([Token] -> Maybe (a, [Token])) -> Parser a
    Parser (([Token] -> Maybe (Token, [Token])) -> Parser Token)
    -> ([Token] -> Maybe (Token, [Token])) -> Parser Token
    forall a b. (a -> b) -> a -> b
    $ \ case
      Token
    t : [Token]
    ts -> (Token, [Token]) -> Maybe (Token, [Token])
    forall a. a -> Maybe a
    Just (Token
    t, [Token]
    ts)
      [Token]
    ts -> (Token, [Token]) -> Maybe (Token, [Token])
    forall a. a -> Maybe a
    Just ((TokenType
    GotEOF, [Char]
    ""), [Token]
    ts)

    skip :: Parser ()
    skip :: Parser ()
    skip = ([Token] -> Maybe ((), [Token])) -> Parser ()
    forall a. ([Token] -> Maybe (a, [Token])) -> Parser a
    Parser (([Token] -> Maybe ((), [Token])) -> Parser ())
    -> ([Token] -> Maybe ((), [Token])) -> Parser ()
    forall a b. (a -> b) -> a -> b
    $ \ case
      Token
    _ : [Token]
    ts -> ((), [Token]) -> Maybe ((), [Token])
    forall a. a -> Maybe a
    Just ((), [Token]
    ts)
      [Token]
    ts -> ((), [Token]) -> Maybe ((), [Token])
    forall a. a -> Maybe a
    Just ((), [Token]
    ts)

    empty :: Parser a
    empty :: forall a. Parser a
    empty = ([Token] -> Maybe (a, [Token])) -> Parser a
    forall a. ([Token] -> Maybe (a, [Token])) -> Parser a
    Parser (([Token] -> Maybe (a, [Token])) -> Parser a)
    -> ([Token] -> Maybe (a, [Token])) -> Parser a
    forall a b. (a -> b) -> a -> b
    $ Maybe (a, [Token]) -> [Token] -> Maybe (a, [Token])
    forall a b. a -> b -> a
    const Maybe (a, [Token])
    forall a. Maybe a
    Nothing

    readValue :: Read a => String -> Parser a
    readValue :: forall a. Read a => [Char] -> Parser a
    readValue = Parser a -> (a -> Parser a) -> Maybe a -> Parser a
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe Parser a
    forall a. Parser a
    empty a -> Parser a
    forall a. a -> Parser a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (Maybe a -> Parser a) -> ([Char] -> Maybe a) -> [Char] -> Parser a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Char] -> Maybe a
    forall a. Read a => [Char] -> Maybe a
    readMaybe

    unexpected :: Token -> Parser a
    unexpected :: forall a. Token -> Parser a
    unexpected Token
    _ = Parser a
    forall a. Parser a
    empty

    -- unexpected :: HasCallStack => (Token, String) -> Parser a
    -- unexpected = error . show