packages feed

jmacro 0.6.7 → 0.6.8

raw patch · 3 files changed

+28/−17 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

Language/Javascript/JMacro.hs view
@@ -18,11 +18,11 @@  The above produces the id function at the top level. -> renderJs [$jmacro|var id = \x -> x|]+> renderJs [$jmacro|var id = \x -> x;|]  So does the above here. However, as id is brought into scope by the keyword var, you do not get a variable named id in the generated javascript, but a variable with an arbitrary unique identifier. -> renderJs [$jmacro|var !id = \x -> x|]+> renderJs [$jmacro|var !id = \x -> x;|]  The above, by using the bang special form in a var declaration, produces a variable that really is named id. 
Language/Javascript/JMacro/Base.hs view
@@ -385,19 +385,31 @@ -- | Apply a transformation to a fully saturated syntax tree, -- taking care to return any free variables back to their free state -- following the transformation. As the transformation preserves--- free variables, it is hygienic. Cannot be used nested.-withHygiene:: JMacro a => (a -> a) -> a -> a-withHygiene f x = jfromGADT $ case mx of-              JMGStat _  -> jtoGADT $ UnsatBlock (jsUnsat_ is' x'')-              JMGExpr _  -> jtoGADT $ UnsatExpr  (jsUnsat_ is' x'')-              JMGVal  _  -> jtoGADT $ UnsatVal   (jsUnsat_ is' x'')-              JMGId _ -> jtoGADT $ f x-    where (x', (StrI l:_)) = runState (runIdentSupply $ jsSaturate_ x) is-          x'' = f x'-          is = newIdentSupply (Just "inSat")-          lastVal = readNote "inSat" (drop 6 l) :: Int-          is' = take lastVal is-          mx = jtoGADT x+-- free variables, it is hygienic.+withHygiene ::  JMacro a => (a -> a) -> a -> a+withHygiene f x = jfromGADT $ case jtoGADT x of+    JMGExpr z -> JMGExpr $ UnsatExpr $ inScope z+    JMGStat z -> JMGStat $ UnsatBlock $ inScope z+    JMGVal  z -> JMGVal $ UnsatVal $ inScope z+    JMGId _ -> jtoGADT $ f x+    where+        inScope z = IS $ do+            ([StrI a], b) <- splitAt 1 `fmap` get+            put b+            return $ withHygiene_ a f z++withHygiene_ :: JMacro a => String -> (a -> a) -> a -> a+withHygiene_ un f x = jfromGADT $ case jtoGADT x of+    JMGStat _ -> jtoGADT $ UnsatBlock (jsUnsat_ is' x'')+    JMGExpr _ -> jtoGADT $ UnsatExpr (jsUnsat_ is' x'')+    JMGVal  _ -> jtoGADT $ UnsatVal (jsUnsat_ is' x'')+    JMGId _ -> jtoGADT $ f x+    where+        (x', (StrI l : _)) = runState (runIdentSupply $ jsSaturate_ x) is +        is' = take lastVal is+        x'' = f x'+        lastVal = readNote ("inSat" ++ un) (reverse . takeWhile (/= '_') . reverse $ l) :: Int+        is = newIdentSupply $ Just ("inSat" ++ un)  -- | Takes a fully saturated expression and transforms it to use unique variables that respect scope. scopify :: JStat -> JStat
jmacro.cabal view
@@ -1,5 +1,5 @@ name:                jmacro-version:             0.6.7+version:             0.6.8 synopsis:            QuasiQuotation library for programmatic generation of Javascript code. description:         Javascript syntax, functional syntax, hygienic names, compile-time guarantees of syntactic correctness, limited typechecking. Additional documentation available at <http://www.haskell.org/haskellwiki/Jmacro> category:            Language@@ -19,7 +19,6 @@                      Language.Javascript.JMacro.TypeCheck                      Language.Javascript.JMacro.Types                      Language.Javascript.JMacro.Prelude-                     -- Language.Javascript.JMacro.Rpc   other-modules:     Language.Javascript.JMacro.Base                      Language.Javascript.JMacro.QQ                      Language.Javascript.JMacro.ParseTH