    module Text.Read.HT where

    {-| Parse a string containing an infix operator. -}
    {-# INLINE readsInfixPrec #-}
    readsInfixPrec :: (Read a, Read b) =>
       String -> Int -> Int -> (a -> b -> c) -> ReadS c
    readsInfixPrec :: String -> Int -> Int -> (a -> b -> c) -> ReadS c
    readsInfixPrec opStr :: String
    opStr opPrec :: Int
    opPrec prec :: Int
    prec cons :: a -> b -> c
    cons =
       Bool -> ReadS c -> ReadS c
    forall a. Bool -> ReadS a -> ReadS a
    readParen
         (Int
    prec Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    >= Int
    opPrec)
         ((\s :: String
    s -> [((b -> c) -> String -> b -> c
    forall a b. a -> b -> a
    const ((b -> c) -> String -> b -> c)
    -> (a -> b -> c) -> a -> String -> b -> c
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> b -> c
    cons, String
    s)]) ReadS (a -> String -> b -> c)
    -> ReadS a -> ReadS (String -> b -> c)
    forall b c. ReadS (b -> c) -> ReadS b -> ReadS c
    .>
          Int -> ReadS a
    forall a. Read a => Int -> ReadS a
    readsPrec Int
    opPrec ReadS (String -> b -> c) -> ReadS String -> ReadS (b -> c)
    forall b c. ReadS (b -> c) -> ReadS b -> ReadS c
    .>
          (((String, String) -> Bool)
    -> [(String, String)] -> [(String, String)]
    forall a. (a -> Bool) -> [a] -> [a]
    filter ((String
    opStrString -> String -> Bool
    forall a. Eq a => a -> a -> Bool
    ==)(String -> Bool)
    -> ((String, String) -> String) -> (String, String) -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .(String, String) -> String
    forall a b. (a, b) -> a
    fst) ([(String, String)] -> [(String, String)])
    -> ReadS String -> ReadS String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ReadS String
    lex) ReadS (b -> c) -> ReadS b -> ReadS c
    forall b c. ReadS (b -> c) -> ReadS b -> ReadS c
    .>
          Int -> ReadS b
    forall a. Read a => Int -> ReadS a
    readsPrec Int
    opPrec)

    {-| Compose two parsers sequentially. -}
    infixl 9 .>
    (.>) :: ReadS (b -> c) -> ReadS b -> ReadS c
    .> :: ReadS (b -> c) -> ReadS b -> ReadS c
    (.>) ra :: ReadS (b -> c)
    ra rb :: ReadS b
    rb =
       ((b -> c, String) -> [(c, String)])
    -> [(b -> c, String)] -> [(c, String)]
    forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
    concatMap (\(f :: b -> c
    f,rest :: String
    rest) -> ((b, String) -> (c, String)) -> [(b, String)] -> [(c, String)]
    forall a b. (a -> b) -> [a] -> [b]
    map (\(b :: b
    b, rest' :: String
    rest') -> (b -> c
    f b
    b, String
    rest')) (ReadS b
    rb String
    rest)) ([(b -> c, String)] -> [(c, String)]) -> ReadS (b -> c) -> ReadS c
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ReadS (b -> c)
    ra

    readMany :: (Read a) => String -> [a]
    readMany :: String -> [a]
    readMany x :: String
    x =
       let contReadList :: [(a, String)] -> [a]
    contReadList []     = []
           contReadList (y :: (a, String)
    y:[]) = (a, String) -> a
    forall a b. (a, b) -> a
    fst (a, String)
    y a -> [a] -> [a]
    forall a. a -> [a] -> [a]
    : String -> [a]
    forall a. Read a => String -> [a]
    readMany ((a, String) -> String
    forall a b. (a, b) -> b
    snd (a, String)
    y)
           contReadList _      = String -> [a]
    forall a. HasCallStack => String -> a
    error "readMany: ambiguous parses"
       in  [(a, String)] -> [a]
    forall a. Read a => [(a, String)] -> [a]
    contReadList (ReadS a
    forall a. Read a => ReadS a
    reads String
    x)

    maybeRead :: Read a => String -> Maybe a
    maybeRead :: String -> Maybe a
    maybeRead str :: String
    str =
       case ReadS a
    forall a. Read a => ReadS a
    reads String
    str of
          [(x :: a
    x,"")] -> a -> Maybe a
    forall a. a -> Maybe a
    Just a
    x
          _ -> Maybe a
    forall a. Maybe a
    Nothing