53 lines
1.3 KiB
Haskell
53 lines
1.3 KiB
Haskell
module CardParser where
|
|
|
|
import Magic
|
|
import Mana
|
|
import ManaParser
|
|
import Text.ParserCombinators.Parsec
|
|
|
|
test_card = unlines $ [ "AEther Adept"
|
|
, "1UU"
|
|
, "Creature -- Human Wizard"
|
|
, "2/2"
|
|
, "When AEther Adept enters the battlefield, return target creature to its owner's hand."
|
|
, "M11-C, M12-U"
|
|
]
|
|
|
|
card :: Parser Card
|
|
card = do
|
|
name' <- line
|
|
mana' <- (option (Cost [] [] []) (mana_line))
|
|
abilities' <- (manyTill line (try $ lookAhead sets_line))
|
|
sets' <- sets_line
|
|
let t = snd $ last sets'
|
|
return $ Card t name' mana' abilities'
|
|
|
|
line :: Parser String
|
|
line = do
|
|
text <- many (noneOf "\n")
|
|
char '\n'
|
|
return text
|
|
|
|
mana_line :: Parser Cost
|
|
mana_line = do
|
|
mana' <- mana
|
|
char '\n'
|
|
return mana'
|
|
|
|
sets_line :: Parser [(String, Rarity)]
|
|
sets_line = do
|
|
sets <- sepBy set (string ", ")
|
|
return sets
|
|
|
|
set :: Parser (String, Rarity)
|
|
set = do
|
|
set' <- many1 (noneOf "\n-")
|
|
char '-'
|
|
rarity' <- oneOf "LCURMS"
|
|
case rarity' of
|
|
'L' -> return (set', Land)
|
|
'C' -> return (set', Common)
|
|
'U' -> return (set', Uncommon)
|
|
'R' -> return (set', Rare)
|
|
'M' -> return (set', Mythic)
|
|
'S' -> return (set', Special)
|