@@ -379,18 +379,21 @@ charsInBalanced' open close = try $ do
379379 char close
380380 return $ concat raw
381381
382+-- Auxiliary functions for romanNumeral:
383+
384+lowercaseRomanDigits = ['i','v','x','l','c','d','m']
385+uppercaseRomanDigits = map toUpper lowercaseRomanDigits
386+
382387-- | Parses a roman numeral (uppercase or lowercase), returns number.
383388romanNumeral :: Bool -- ^ Uppercase if true
384389 -> GenParser Char st Int
385390romanNumeral upperCase = do
386− let charAnyCase c = char (if upperCase then toUpper c else c)
387− let one = charAnyCase 'i'
388− let five = charAnyCase 'v'
389− let ten = charAnyCase 'x'
390− let fifty = charAnyCase 'l'
391− let hundred = charAnyCase 'c'
392− let fivehundred = charAnyCase 'd'
393− let thousand = charAnyCase 'm'
391+ let romanDigits = if upperCase
392+ then uppercaseRomanDigits
393+ else lowercaseRomanDigits
394+ lookAhead $ oneOf romanDigits
395+ let [one, five, ten, fifty, hundred, fivehundred, thousand] =
396+ map char romanDigits
394397 thousands <- many thousand >>= (return . (1000 *) . length)
395398 ninehundreds <- option 0 $ try $ hundred >> thousand >> return 900
396399 fivehundreds <- many fivehundred >>= (return . (500 *) . length)