-- FIXME Extremely inefficient and messy, but good enough for now
getExpenses :: String -> Either ParseError [Expense]
getExpenses xs
  | null unparsed = Right res
  | otherwise = Left $ ParseError { line = l
                                  , col  = c
                                  , snip = s
                                  }
  where (res, unparsed) = last $ readP_to_S parseExpenses $ xs
        parsed = take (length xs - length unparsed) xs
        parsedL = lines parsed
        lastParsedL = last parsedL
        l = length parsedL
        -- +2: 1 for starting line index at 1, 1 for next (unparsed) char
        c = length lastParsedL + 2
        s = (take 10 lastParsedL) ++ "..." ++ (take n unparsed) ++ "..."
          where n = min 10 (case elemIndex '\n' unparsed of
                               Nothing -> 10
                               Just x -> x)
getExpenses :: String -> Either ParseError [Expense]
getExpenses xs
  | null unparsed = Right res
  | otherwise = Left $ ParseError { line = l
                                  , col  = c
                                  , snip = s
                                  }
  where (res, unparsed) = last $ readP_to_S parseExpenses $ xs
        parsed = take (length xs - length unparsed) xs
        parsedL = lines parsed
        lastParsedL = last parsedL
        l = length parsedL
        -- +2: 1 for starting line index at 1, 1 for next (unparsed) char
        c = length lastParsedL + 2
        s = (take 10 lastParsedL) ++ "..." ++ (take n unparsed) ++ "..."
          where n = min 10 (case elemIndex '\n' unparsed of
                               Nothing -> 10
                               Just x -> x)
getExpenses xs
  | null unparsed = Right res
  | otherwise = Left $ ParseError { line = l
                                  , col  = c
                                  , snip = s
                                  }
  where (res, unparsed) = last $ readP_to_S parseExpenses $ xs
        parsed = take (length xs - length unparsed) xs
        parsedL = lines parsed
        lastParsedL = last parsedL
        l = length parsedL
        -- +2: 1 for starting line index at 1, 1 for next (unparsed) char
        c = length lastParsedL + 2
        s = (take 10 lastParsedL) ++ "..." ++ (take n unparsed) ++ "..."
          where n = min 10 (case elemIndex '\n' unparsed of
                               Nothing -> 10
                               Just x -> x)