module Musicology.Pitch.Internal
  ( parseInt
  , parseInt'
  , munchChar
  , munchChar1
  )
where

import qualified Text.ParserCombinators.ReadP  as R
import           Data.Char                      ( isDigit )

parseInt :: R.ReadP Int
parseInt :: ReadP Int
parseInt = do
  sign <- String -> ReadP String -> ReadP String
forall a. a -> ReadP a -> ReadP a
R.option String
"" (ReadP String -> ReadP String) -> ReadP String -> ReadP String
forall a b. (a -> b) -> a -> b
$ String -> ReadP String
R.string String
"-"
  dgts <- R.munch1 isDigit
  pure $ read $ sign <> dgts

parseInt' :: R.ReadP Int
parseInt' :: ReadP Int
parseInt' = String -> Int
forall a. Read a => String -> a
read (String -> Int) -> ReadP String -> ReadP Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Char -> Bool) -> ReadP String
R.munch Char -> Bool
isDigit

munchChar :: Char -> R.ReadP String
munchChar :: Char -> ReadP String
munchChar Char
c = (Char -> Bool) -> ReadP String
R.munch (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
c)

munchChar1 :: Char -> R.ReadP String
munchChar1 :: Char -> ReadP String
munchChar1 Char
c = (Char -> Bool) -> ReadP String
R.munch1 (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
c)