Created
April 27, 2011 04:22
-
-
Save oskimura/943708 to your computer and use it in GitHub Desktop.
適当につくったスクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Control.Applicative | |
| import Control.Monad | |
| import Text.Printf | |
| splitBy :: (a -> Bool) -> [a] -> [[a]] | |
| splitBy p [] = [] | |
| splitBy p xs = a : (splitBy p $ dropWhile p $ b) | |
| where | |
| (a, b) = break p xs | |
| split :: String -> [String] | |
| split = splitBy (=='/') | |
| format (a, b, c, d) = printf "%s, %s, %s, %s\n" a b c $ d | |
| f fn = (entity, command, cond, sql) | |
| where | |
| dirs = split fn | |
| (sql:entity:_) = reverse $ dirs | |
| (command,cond) = g sql | |
| g xs = snd . head . filter ((==True).fst) . map (phi xs) $ commands | |
| where | |
| commands = ["find","insert","update","count","delete","execute"] | |
| phi xs c = (\(a,b) -> ((a==c),(a,f b))) . splitAt n $ xs | |
| where n = length c | |
| f txt = if (==".sql"). reverse . take 4 . reverse $ txt | |
| then reverse . drop 4 . reverse $ txt | |
| else txt | |
| main = do { t <- lines <$> readFile "t" | |
| ; mapM_ (format . f) $ t | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment