3a_asm: FEATURE/FIX: proper line numbers on parsing error
[calu.git] / 3a_asm / DT.hs
index 213a5c381763458c02ae842d707d1954d8b1a479..c80186ca399447d171e1eae70e7f17f99427f9ee 100644 (file)
@@ -17,12 +17,12 @@ import Control.Applicative hiding ((<|>))
 
 
 -- parsing --
-instruction :: Dict -> Parser Word32
-instruction dict = foldl1 (<|>) (fmap (\x -> try (x dict)) instructions) <* char '\n'
+instruction :: LineNo -> Dict -> Parser Word32
+instruction lno dict = foldl1 (<|>) (fmap (\x -> try (x dict)) instructions) <* char '\n' <?> (". something at line " ++ show lno ++ " is wrong (ignore line 1 hint above, but pay attention for possible line offset due to #include).")
 
 testins :: String -> IO ()
 testins input =
-       case (parse (instruction dict) "" (input++"\n")) of
+       case (parse (instruction dict) "" (input++"\n")) of
                Left err -> do { putStr "fail :/\n"; print err}
                Right x -> do { printf "0x%08X\n" x }
        where
@@ -38,6 +38,7 @@ iLabel d@(aktadr,_) = do {i <- (iLit d); return $ ((i - aktadr)`div`4) .&. 0xfff
 
 iLit :: Dict -> Parser Word32
 iLit (_,d) = do
+       parseMySpaces
        val <- expr d;
        try (do {
                string "@hi"; parseMySpaces;