hpaco-lib 0.26.0.0 → 0.28.0.0
raw patch · 5 files changed
+111/−49 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Text.HPaco.Readers.Paco: cssPacoFlavor :: PacoFlavor
+ Text.HPaco.Readers.Paco: defaultPacoFlavor :: PacoFlavor
+ Text.HPaco.Readers.Paco: jinjaPacoFlavor :: PacoFlavor
+ Text.HPaco.Readers.Paco: readCapo' :: PacoFlavor -> Reader
+ Text.HPaco.Readers.Paco: readPaco' :: PacoFlavor -> Reader
+ Text.HPaco.Readers.Paco.ParserInternals: PacoFlavor :: (String, String) -> (String, String) -> (String, String) -> PacoFlavor
+ Text.HPaco.Readers.Paco.ParserInternals: cssPacoFlavor :: PacoFlavor
+ Text.HPaco.Readers.Paco.ParserInternals: data PacoFlavor
+ Text.HPaco.Readers.Paco.ParserInternals: defaultPacoFlavor :: PacoFlavor
+ Text.HPaco.Readers.Paco.ParserInternals: jinjaPacoFlavor :: PacoFlavor
+ Text.HPaco.Readers.Paco.ParserInternals: pfCommentMarkers :: PacoFlavor -> (String, String)
+ Text.HPaco.Readers.Paco.ParserInternals: pfInterpolationMarkers :: PacoFlavor -> (String, String)
+ Text.HPaco.Readers.Paco.ParserInternals: pfTagMarkers :: PacoFlavor -> (String, String)
+ Text.HPaco.Readers.Paco.ParserInternals: psFlavor :: PacoState -> PacoFlavor
- Text.HPaco.Readers.Paco.ParserInternals: PacoState :: FilePath -> [(String, Statement)] -> [String] -> Maybe String -> Reader -> PacoState
+ Text.HPaco.Readers.Paco.ParserInternals: PacoState :: FilePath -> [(String, Statement)] -> [String] -> Maybe String -> Reader -> PacoFlavor -> PacoState
Files
- Text/HPaco/Readers/Common.hs +9/−6
- Text/HPaco/Readers/Paco.hs +23/−9
- Text/HPaco/Readers/Paco/ParserInternals.hs +42/−7
- Text/HPaco/Readers/Paco/Statements.hs +36/−26
- hpaco-lib.cabal +1/−1
Text/HPaco/Readers/Common.hs view
@@ -69,12 +69,15 @@ escapedChar = do char '\\' c2 <- anyChar- return $ case c2 of- 'n' -> '\n'- 'r' -> '\r'- 'b' -> '\b'- 't' -> '\t'- otherwise -> c2+ case c2 of+ 'n' -> return '\n'+ 'r' -> return '\r'+ 'b' -> return '\b'+ 't' -> return '\t'+ 'u' -> do+ ds <- count 4 digit+ return . read $ "'\\u" ++ ds ++ "'"+ otherwise -> return c2 discard :: Parser s a -> Parser s () discard p = p >> return ()
Text/HPaco/Readers/Paco.hs view
@@ -1,6 +1,9 @@ module Text.HPaco.Readers.Paco ( readPaco , readCapo+ , readPaco'+ , readCapo'+ , defaultPacoFlavor, jinjaPacoFlavor, cssPacoFlavor ) where @@ -19,21 +22,32 @@ import System.IO.Strict import System.FilePath -readPaco = readRaw pacoDocument-readCapo = readRaw capoDocument+readPaco :: Reader+readPaco = readPaco' defaultPacoFlavor -readRawAuto parser filename =+readCapo :: Reader+readCapo = readCapo' defaultPacoFlavor++readPaco' :: PacoFlavor -> Reader+readPaco' flavor = readRaw pacoDocument flavor++readCapo' :: PacoFlavor -> Reader+readCapo' flavor = readRaw capoDocument flavor++readRawAuto :: Parser AST -> PacoFlavor -> Reader+readRawAuto parser flavor filename = case (takeExtension filename) of- ".capo" -> readCapo filename- ".paco" -> readPaco filename- otherwise -> readRaw parser filename+ ".capo" -> readCapo' flavor filename+ ".paco" -> readPaco' flavor filename+ otherwise -> readRaw parser flavor filename -readRaw :: Parser AST -> Reader-readRaw parser filename =+readRaw :: Parser AST -> PacoFlavor -> Reader+readRaw parser flavor filename = let pstate = defaultPacoState { psBasePath = takeDirectory filename , psIncludeExtension = renull $ takeExtension filename- , psHandleInclude = readRawAuto parser+ , psHandleInclude = readRawAuto parser flavor+ , psFlavor = flavor } in readRawWithState parser pstate filename where renull "" = Nothing
Text/HPaco/Readers/Paco/ParserInternals.hs view
@@ -2,6 +2,9 @@ module Text.HPaco.Readers.Paco.ParserInternals ( PacoState (..) , defaultPacoState+ , PacoFlavor (..)+ , defaultPacoFlavor+ , jinjaPacoFlavor, cssPacoFlavor , Text.Parsec.Error.ParseError , Parser , addDef, resolveDef@@ -26,14 +29,45 @@ instance Exception ParseError deriving instance Typeable ParseError -data PacoState = PacoState- { psBasePath :: FilePath- , psDefs :: [(String, Statement)]- , psDeps :: [String]- , psIncludeExtension :: Maybe String- , psHandleInclude :: Reader- }+data PacoFlavor =+ PacoFlavor+ { pfCommentMarkers :: (String, String)+ , pfInterpolationMarkers :: (String, String)+ , pfTagMarkers :: (String, String)+ } +defaultPacoFlavor :: PacoFlavor+defaultPacoFlavor =+ PacoFlavor+ { pfCommentMarkers = ( "{%--", "--%}" )+ , pfInterpolationMarkers = ( "{", "}" )+ , pfTagMarkers = ( "{%", "%}" )+ }++jinjaPacoFlavor =+ PacoFlavor+ { pfCommentMarkers = ( "{#", "#}" )+ , pfInterpolationMarkers = ( "{{", "}}" )+ , pfTagMarkers = ( "{%", "%}" )+ }++cssPacoFlavor =+ PacoFlavor+ { pfCommentMarkers = ( "/*--", "--*/" )+ , pfInterpolationMarkers = ( "/**", "**/" )+ , pfTagMarkers = ( "/*%", "%*/" )+ }++data PacoState =+ PacoState+ { psBasePath :: FilePath+ , psDefs :: [(String, Statement)]+ , psDeps :: [String]+ , psIncludeExtension :: Maybe String+ , psHandleInclude :: Reader+ , psFlavor :: PacoFlavor+ }+ type Parser a = ParsecT String PacoState IO a defaultPacoState :: PacoState@@ -43,6 +77,7 @@ , psDeps = [] , psIncludeExtension = Nothing , psHandleInclude = (\s t -> return defAST)+ , psFlavor = defaultPacoFlavor } addDef :: String -> Statement -> Parser ()
Text/HPaco/Readers/Paco/Statements.hs view
@@ -5,7 +5,7 @@ import Control.Monad import Control.Monad.IO.Class-import Control.Applicative ((<$>))+import Control.Applicative ((<$>), (<*>), some) import System.IO.Strict import System.FilePath import System.IO (withFile, IOMode (ReadMode))@@ -29,20 +29,20 @@ return [l,s] statement :: Parser Statement-statement = try ifStatement - <|> try withStatement- <|> try switchStatement- <|> try inlineCapoStatement- <|> try forStatement- <|> try defStatement- <|> try callStatement- <|> try literalBlock- <|> try commentStatement- <|> try includeStatement- <|> try interpolateStatement- <|> try newlineStatement- <|> try escapeSequenceStatement- <|> try rawTextStatement+statement = try ifStatement+ <|> try withStatement+ <|> try switchStatement+ <|> try inlineCapoStatement+ <|> try forStatement+ <|> try defStatement+ <|> try callStatement+ <|> try literalBlock+ <|> try commentStatement+ <|> try includeStatement+ <|> try interpolateStatement+ <|> try newlineStatement+ <|> try escapeSequenceStatement+ <|> try rawTextStatement lineNumberStatement :: Parser Statement lineNumberStatement = do@@ -51,10 +51,11 @@ commentStatement :: Parser Statement commentStatement = do- string "{%--"+ (markL, markR) <- pfCommentMarkers . psFlavor <$> getState+ string markL manyTill (try (discard commentStatement) <|> discard anyChar)- (try $ string "--%}")+ (try $ string markR) return NullStatement literalBlock :: Parser Statement@@ -78,12 +79,13 @@ interpolateStatement :: Parser Statement interpolateStatement = do- char '{'+ (markL, markR) <- pfInterpolationMarkers . psFlavor <$> getState+ string markL em <- option (Just EscapeHTML) escapeMode ss_ expr <- expression ss_- char '}'+ string markR let expr' = maybe expr (\m -> EscapeExpression m expr)@@ -92,8 +94,15 @@ rawTextStatement :: Parser Statement rawTextStatement = do- chrs <- many1 $ noneOf "{\\\n"+ chrs <- (:) <$> anyChar <*> manyTill anyChar (eof <|> delimiters) return $ PrintStatement $ StringLiteral chrs+ where+ delimiters = do+ (leftInterpolation, _) <- pfInterpolationMarkers . psFlavor <$> getState+ (leftComment, _) <- pfCommentMarkers . psFlavor <$> getState+ (leftTag, _) <- pfTagMarkers . psFlavor <$> getState+ lookAhead . some . mapM (try . string) $ [ leftTag, leftComment, leftInterpolation, "\n" ]+ return () newlineStatement :: Parser Statement newlineStatement = do@@ -218,15 +227,16 @@ return $ CallStatement name simpleTag tag = complexTag tag (return ())-complexTag tag inner = +complexTag tag inner = let go = do- string "{%" - ss_ - string tag - ss_ + (markL, markR) <- pfTagMarkers . psFlavor <$> getState+ string markL+ ss_+ string tag+ ss_ i <- inner ss_- string "%}" + string markR return i standalone = do assertStartOfLine
hpaco-lib.cabal view
@@ -1,5 +1,5 @@ name: hpaco-lib-version: 0.26.0.0+version: 0.28.0.0 synopsis: Modular template compiler library description: Template compiler library, compiles template code into PHP or Javascript, or interprets it directly.