This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "heist".

The branch, 0.2-dev has been updated
       via  f5fe8e847ea731a68587ad599ae218a715cd34ec (commit)
      from  34a38cb6057758b18120bcbfaa44921c400cd6ee (commit)


Summary of changes:
 heist.cabal                               |    5 +-
 src/Text/Templating/Heist/Internal.hs     |   62 +++++++++++++++--------------
 test/heist-testsuite.cabal                |    1 +
 test/suite/Text/Templating/Heist/Tests.hs |   29 ++++----------
 test/templates/attrs.tpl                  |    7 +--
 5 files changed, 46 insertions(+), 58 deletions(-)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit f5fe8e847ea731a68587ad599ae218a715cd34ec
Author: Mighty Byte <[email protected]>
Date:   Mon May 31 16:45:24 2010 -0400

    Changed attribute substitution delimiter to $(abc), nesting not supported.

diff --git a/heist.cabal b/heist.cabal
index e5d8a2a..79d5676 100644
--- a/heist.cabal
+++ b/heist.cabal
@@ -86,17 +86,18 @@ Library
     Text.Templating.Heist.Constants
 
   build-depends:
+    attoparsec >= 0.8.0.2 && < 0.9,
     base >= 4 && < 5,
     bytestring,
     containers,
     directory,
     directory-tree,
     filepath,
-    process,
     hexpat >= 0.16 && <0.17,
+    MonadCatchIO-transformers >= 0.2.1 && < 0.3,
     monads-fd,
+    process,
     random,
-    MonadCatchIO-transformers >= 0.2.1 && < 0.3,
     transformers
 
   if impl(ghc >= 6.12.0)
diff --git a/src/Text/Templating/Heist/Internal.hs 
b/src/Text/Templating/Heist/Internal.hs
index 9627bad..f9738b6 100644
--- a/src/Text/Templating/Heist/Internal.hs
+++ b/src/Text/Templating/Heist/Internal.hs
@@ -5,9 +5,11 @@
 module Text.Templating.Heist.Internal where
 
 ------------------------------------------------------------------------------
+import           Control.Applicative
 import           Control.Exception (SomeException)
 import           Control.Monad.CatchIO
 import           Control.Monad.RWS.Strict
+import qualified Data.Attoparsec.Char8 as AP
 import           Data.ByteString.Char8 (ByteString)
 import qualified Data.ByteString.Char8 as B
 import qualified Data.ByteString.Lazy as L
@@ -397,36 +399,36 @@ runNode n@(X.Element nm at ch) = do
 
 
 ------------------------------------------------------------------------------
--- | Parses an attribute with attribute variable substitution.
-parseAtt :: Monad m => ByteString -> TemplateMonad m ByteString
-parseAtt bs
-    | B.null bs = return B.empty
-    | otherwise = let (pre,rest) = B.span (/='{') bs in do
-        suffix <- if B.null rest
-            then return B.empty
-            else do (a,b) <- parseVar "" (B.tail rest)
-                    c <- parseAtt b
-                    return $ B.append a c
-        return $ B.append pre suffix
-
-
-------------------------------------------------------------------------------
--- | Parses an attribute variable token.  This token starts immediately after
--- the opening '{' and extends to the corresponding closing '}'.  The return
--- value is a tuple of the token's substituted value and the rest of the
--- ByteString to be parsed (starting immediately after the closing '}').
-parseVar :: Monad m => ByteString -> ByteString
-         -> TemplateMonad m (ByteString, ByteString)
-parseVar pre bs
-    | B.null bs = return (B.empty, B.empty)
-    | otherwise = let (name,rest) = B.span (\c -> c/='{' && c/='}') bs in do
-        if B.null rest
-            then return (B.empty, B.empty)
-            else case B.head rest of
-                     '{' -> do (a,b) <- parseVar "" (B.tail rest)
-                               parseVar (B.concat [pre, name, a]) b
-                     _   -> do s <- getAttributeSplice $ B.append pre name
-                               return (s, B.tail rest)
+-- | Parses an attribute for any identifier expressions and performs
+-- appropriate substitution.
+parseAtt bs = do
+    let ast = case AP.feed (AP.parse attParser bs) "" of
+            (AP.Fail _ _ _) -> []
+            (AP.Done _ res) -> res
+    chunks <- mapM cvt ast
+    return $ B.concat chunks
+  where
+    cvt (Literal bs) = return bs
+    cvt (Ident bs) = getAttributeSplice bs
+
+
+------------------------------------------------------------------------------
+-- | AST to hold attribute parsing structure.  This is necessary because
+-- attoparsec doesn't support parsers running in another monad.
+data AttAST = Literal ByteString |
+              Ident ByteString
+    deriving (Show)
+
+
+------------------------------------------------------------------------------
+-- | Parser for attribute variable substitution.
+attParser = AP.many1 (identParser <|> litParser)
+  where
+    escChar = (AP.char '\\' *> AP.anyChar) <|>
+              AP.satisfy (AP.notInClass "\\$")
+    litParser = Literal <$> (B.pack <$> AP.many1 escChar)
+    identParser = AP.string "$(" *>
+        (Ident <$> AP.takeWhile (/=')')) <* AP.string ")"
 
 
 ------------------------------------------------------------------------------
diff --git a/test/heist-testsuite.cabal b/test/heist-testsuite.cabal
index 5e56f95..51e13df 100644
--- a/test/heist-testsuite.cabal
+++ b/test/heist-testsuite.cabal
@@ -9,6 +9,7 @@ Executable testsuite
 
    build-depends:
      QuickCheck >= 2,
+     attoparsec >= 0.8.0.2 && < 0.9,
      base >= 4 && < 5,
      bytestring,
      containers,
diff --git a/test/suite/Text/Templating/Heist/Tests.hs 
b/test/suite/Text/Templating/Heist/Tests.hs
index 758a957..d71042f 100644
--- a/test/suite/Text/Templating/Heist/Tests.hs
+++ b/test/suite/Text/Templating/Heist/Tests.hs
@@ -117,29 +117,16 @@ attrSubst :: H.Assertion
 attrSubst = do
     ets <- loadT "templates"
     let ts = either (error "Error loading templates") id ets
-    check ts ("a", "42") "pre_meaning_of_everything_post"
-    check ts ("a", "64") "pre_power_of_two_post"
-    check ts ("b", "42") "pre_MEANING_OF_EVERYTHING_post"
-    check ts ("b", "64") "pre_POWER_OF_TWO_post"
-    emptyPV ts
-    single ts
-    partial ts
+    check (setTs "meaning_of_everything" ts) "pre_meaning_of_everything_post"
+    check ts "pre__post"
   where
-    setTs (char, ind) = bindSplice "char" (return [X.Text char]) .
-                        bindSplice "ind" (return [X.Text ind])
-    check ts arg str = do
-        res <- renderTemplate (setTs arg ts) "attrs"
-        H.assertBool ("attr subst "++(show arg)) $
+    setTs val = bindSplice "foo" (return [X.Text val])
+    check ts str = do
+        res <- renderTemplate ts "attrs"
+        H.assertBool ("attr subst "++(show str)) $
             not $ B.null $ snd $ B.breakSubstring str $ fromJust res
-    emptyPV ts = do
-        res <- runTemplateMonad ts (X.Text "") $ parseVar "" ""
-        H.assertEqual "emptyParseVar" res ("", "")
-    single ts = do
-        res <- runTemplateMonad ts (X.Text "") $ parseVar "" "{abc}"
-        H.assertEqual "singleParseVar" res ("", "")
-    partial ts = do
-        res <- runTemplateMonad ts (X.Text "") $ parseVar "" "{abc"
-        H.assertEqual "partialParseVar" res ("", "")
+        H.assertBool ("attr subst foo") $
+            not $ B.null $ snd $ B.breakSubstring "$(foo)" $ fromJust res
 
 -- dotdotTest :: H.Assertion
 -- dotdotTest = do
diff --git a/test/templates/attrs.tpl b/test/templates/attrs.tpl
index 3166ccb..282d487 100644
--- a/test/templates/attrs.tpl
+++ b/test/templates/attrs.tpl
@@ -1,6 +1,3 @@
-<bind tag="att_a_42">meaning_of_everything</bind>
-<bind tag="att_a_64">power_of_two</bind>
-<bind tag="att_b_42">MEANING_OF_EVERYTHING</bind>
-<bind tag="att_b_64">POWER_OF_TWO</bind>
 <mytag flag="">Empty attribute</mytag>
-<div id="pre_{att_{char}_{ind}}_post"/>
+<mytag flag="abc\$(foo)">No ident capture</mytag>
+<div id="pre_$(foo)_post"/>
-----------------------------------------------------------------------


hooks/post-receive
-- 
heist
_______________________________________________
Snap mailing list
[email protected]
http://mailman-mail5.webfaction.com/listinfo/snap

Reply via email to