-- | Parsers for pitch class sets and sequences, and for 'SRO's.
module Music.Theory.Z.Morris_1987.Parse where

import Data.Char {- base -}

-- | Parse a /pitch class object/ string.  Each 'Char' is either a
-- number, a space which is ignored, or a letter name for the numbers
-- 10 ('t' or 'a' or 'A') or 11 ('e' or 'B' or 'b').
--
-- > pco "13te" == [1,3,10,11]
-- > pco "13te" == pco "13ab"
pco :: Num n => String -> [n]
pco :: forall n. Num n => String -> [n]
pco String
s =
    let s' :: String
s' = forall a. (a -> Bool) -> [a] -> [a]
dropWhile Char -> Bool
isSpace String
s
        s'' :: String
s'' = forall a. (a -> Bool) -> [a] -> [a]
takeWhile (forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` String
"0123456789taAebB") String
s'
        f :: Char -> a
f Char
c | Char
c forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` String
"taA" = a
10
            | Char
c forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` String
"ebB" = a
11
            | Bool
otherwise = forall a. Num a => Integer -> a
fromInteger (forall a. Read a => String -> a
read [Char
c])
    in forall a b. (a -> b) -> [a] -> [b]
map forall {a}. Num a => Char -> a
f String
s''