3a_asm: .ifill magic :)
[calu.git] / 3a_asm / Main.hs
index 8160012fd09585ae1191b745804bcb996c57e596..08522c658d34fabbc0d97ac1cb7d2744d543418c 100644 (file)
@@ -140,7 +140,7 @@ testDTF input =
 parseDTFLine :: [DictElem] -> Parser DTF
 parseDTFLine dict = foldl1 (<|>) (fmap (\x -> try (x dict)) lineFormats) <* char '\n'
 
-lineFormats = [lf_define, lf_sdata, lf_stext, lf_org, lf_data, lf_comment, lf_toparse, lf_label]
+lineFormats = [lf_define, lf_sdata, lf_stext, lf_org, lf_data, lf_ifill, lf_comment, lf_toparse, lf_label]
 
 -- helper
 parseIdent :: Parser String
@@ -182,6 +182,17 @@ lf_data d = do
        comment <- try(parseComment) <|> parseMySpaces
        return $ DTF_Fill r val (fill ++ (if repeat == "1" then "" else repeat) ++ code) l comment
 
+lf_ifill d = do
+       l <- try (parseLabel) <|> string ""
+       skipMany space
+       fill <- string ".ifill "
+       code <- many1 $ noneOf "\n;"
+       let val = case parse (instruction (0,d)) "" (code++"\n") of
+               Right v -> v
+               Left err -> error $ show err
+       comment <- try(parseComment) <|> parseMySpaces
+       return $ DTF_Fill 1 val (fill ++ code) l comment
+
 lf_comment _ = do
        comment <- parseComment
        return $ DTF_Comment comment