+inc :: Counter -> Counter
+inc = ((+) 4)
+
+setabsolute :: Counter -> Counter
+setabsolute x = x
+
+
+type DictLabel = (String -> Word32)
+
+init_labels :: DictLabel
+init_labels _ = 0xffffffff
+
+add_label :: DictLabel -> (String,Word32) -> DictLabel
+add_label dic (s,w)
+ | dic s /= 0xffffffff = error ("Label " ++ s ++ " already exists")
+ | otherwise = newdict
+ where
+ newdict str
+ | str == s = w
+ | otherwise = dic str
+
+
+convertDTF :: [(Int,String)] -> Counter -> Counter -> DictLabel -> (DictLabel, [DTF])
+convertDTF [] _ _ d = (d,[])
+convertDTF ((lno,str):xs) datacnt instrcnt dict =
+ (newdict, (DTF_Comment str):next)
+ where
+ (newdict,next) = convertDTF xs (inc datacnt) (inc instrcnt) dict
+
+testDTF :: String -> IO ()
+testDTF input =
+ case (parse parseDTFLine "" (input++"\n")) of
+ Left err -> do { putStr "failz"; print err}
+ Right x -> do { print x }
+
+parseDTFLine :: Parser DTF
+parseDTFLine = foldl1 (<|>) (fmap try lineFormats) <* char '\n'
+
+lineFormats = [lf_data, lf_comment, lf_label, lf_toparse, lf_org]
+
+lf_data = do string "data"; return $ DTF_Comment "lolz0"
+
+lf_comment = do
+ skipMany space
+ char ';'
+ comment <- many $ noneOf ['\n']
+ newline
+ return $ DTF_Comment comment
+
+lf_label = do string "label"; return $ DTF_Comment "lolz1"
+lf_toparse = do string "toparse"; return $ DTF_Comment "lolz2"
+lf_org = do string "org"; return $ DTF_Comment "lolz3"