Skip to content

Instantly share code, notes, and snippets.

@oskimura
Created April 27, 2011 04:22
Show Gist options
  • Select an option

  • Save oskimura/943708 to your computer and use it in GitHub Desktop.

Select an option

Save oskimura/943708 to your computer and use it in GitHub Desktop.
適当につくったスクリプト
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