From 8e9f71bbec90d74390cae13db6f091bc5609f79e Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Mon, 14 May 2012 22:13:30 +1000 Subject: Moved a number of article format parsing functions to a separate file --- Parse.hs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Parse.hs (limited to 'Parse.hs') diff --git a/Parse.hs b/Parse.hs new file mode 100644 index 0000000..769a883 --- /dev/null +++ b/Parse.hs @@ -0,0 +1,45 @@ +import Control.Monad( liftM ) +import qualified Data.Char as Char + + +getLines :: FilePath -> IO [String] +getLines = liftM lines . readFile + + +stripReturn :: String -> String +stripReturn s = if (last s == '\r') then init s else s + + +removeEscChars :: String -> String +removeEscChars [] = [] +removeEscChars (x:[]) = [x] +removeEscChars x = if (head x == '\\') + then (x!!1) : (removeEscChars . (drop 2) $ x) + else (head x) : (removeEscChars . tail $ x) + + +removeQuotes :: String -> String +removeQuotes = init . tail + + +separateBy :: String -> Char -> [String] +separateBy char list = + let f = (\x -> if (x == char) + then ' ' + else x) + in words . (map f) $ list + + +isComment :: String -> Bool +isComment = (==) '#' . head + + +isNumber :: String -> Bool +isNumber ('0':[]) = True +isNumber ('-':ns) + | (ns /= [] && head ns /= '0') = isNumber ns +isNumber n = all (Char.isNumber) n + + +isName :: String -> Bool +isName s = all ((==) '"') [head s, last s] -- cgit