Created
December 30, 2010 20:39
-
-
Save snoyberg/760275 to your computer and use it in GitHub Desktop.
Determine Hamlet, Cassius and Julius templates used by a Yesod application
This file contains 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
{-# LANGUAGE OverloadedStrings #-} | |
import Language.Haskell.Parser | |
import Language.Haskell.Syntax | |
import System.Environment | |
import qualified Data.Text.Lazy as T | |
import qualified Data.Text.Lazy.IO as T | |
import Data.Attoparsec.Text.Lazy | |
import Control.Applicative ((<|>)) | |
import Data.Maybe (catMaybes) | |
import Data.Char (isSpace) | |
main = do | |
[x] <- getArgs | |
y <- T.readFile x | |
let z = parse (many $ (parser <|> (anyChar >> return Nothing))) y | |
case z of | |
Fail{} -> return () | |
Done _ r -> print $ catMaybes r | |
data TempType = Hamlet | Cassius | Julius | Widget | |
deriving Show | |
parser = do | |
typ <- (string "$(hamletFile " >> return Hamlet) | |
<|> (string "$(cassiusFile " >> return Cassius) | |
<|> (string "$(juliusFile " >> return Julius) | |
<|> (string "$(widgetFile " >> return Widget) | |
skipWhile isSpace | |
_ <- char '"' | |
x <- many1 $ satisfy (/= '"') | |
_ <- char '"' | |
skipWhile isSpace | |
_ <- char ')' | |
return $ Just (typ, x) |
This file contains 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment