2012-03-02 15:50:49 +00:00
|
|
|
module ManaParser where
|
|
|
|
|
|
|
|
import Mana
|
|
|
|
import Text.ParserCombinators.Parsec
|
|
|
|
|
|
|
|
mana :: Parser Cost
|
|
|
|
mana = do
|
|
|
|
colorless' <- (many colorless)
|
|
|
|
colored' <- (many colored)
|
2012-03-05 23:06:22 +00:00
|
|
|
hybrid' <- (manyTill hybrid $ try $ lookAhead $ many phyrexian)
|
2012-03-02 15:50:49 +00:00
|
|
|
phyrexian' <- (many phyrexian)
|
|
|
|
return $ Cost (colorless' ++ colored') hybrid' phyrexian'
|
|
|
|
|
|
|
|
standard :: Parser Standard
|
|
|
|
standard = colorless <|> colored
|
|
|
|
|
|
|
|
colorless :: Parser Standard
|
|
|
|
colorless = do
|
|
|
|
mana <- many1 digit
|
|
|
|
return $ Standard (read mana :: Int) Colorless
|
|
|
|
|
|
|
|
colored :: Parser Standard
|
|
|
|
colored =
|
|
|
|
do
|
|
|
|
mana <- many1 (oneOf ("Uu"))
|
|
|
|
return $ Standard (length mana) Blue
|
|
|
|
<|> do
|
|
|
|
mana <- many1 (oneOf ("Rr"))
|
|
|
|
return $ Standard (length mana) Red
|
|
|
|
<|> do
|
|
|
|
mana <- many1 (oneOf ("Bb"))
|
|
|
|
return $ Standard (length mana) Black
|
|
|
|
<|> do
|
|
|
|
mana <- many1 (oneOf ("Gg"))
|
|
|
|
return $ Standard (length mana) Green
|
|
|
|
<|> do
|
|
|
|
mana <- many1 (oneOf ("Ww"))
|
|
|
|
return $ Standard (length mana) White
|
|
|
|
|
|
|
|
hybrid :: Parser Hybrid
|
|
|
|
hybrid =
|
|
|
|
do
|
|
|
|
char '('
|
|
|
|
standard' <- standard
|
|
|
|
char '/'
|
|
|
|
standard'' <- standard
|
|
|
|
char ')'
|
|
|
|
return $ Hybrid standard' standard''
|
|
|
|
|
|
|
|
phyrexian :: Parser Phyrexian
|
|
|
|
phyrexian =
|
|
|
|
do
|
|
|
|
char '('
|
|
|
|
standard' <- standard
|
|
|
|
string "/p)"
|
|
|
|
return $ Phyrexian standard'
|