packages feed

jmacro 0.1.1 → 0.1.2

raw patch · 4 files changed

+31/−15 lines, 4 filesdep +pcre-lightdep +syb

Dependencies added: pcre-light, syb

Files

Language/Javascript/JMacro.hs view
@@ -1,4 +1,3 @@------------------------------------------------------------------------------ {- | Module      :  Language.Javascript.JMacro Copyright   :  (c) Gershom Bazerman, 2009@@ -44,7 +43,7 @@  > renderJs [$jmacroE|foo (x,y)|]] -While the above is an error. (i.e. standard javascript function application cannot seperate the leading parenthesis of the argument from+While the above is an error. (i.e. standard javascript function application cannot seperate the leading parenthesis of the argument from the function being applied)  > \x -> [$jmacroE|foo `(x)`|]] @@ -54,18 +53,17 @@  Meanwhile, the above lambda is in Javascript, and brings the variable into scope both in javascript and in the enclosed antiquotes. The expression is a Javascript function that takes an x, and yields an expression produced by the application of the Haskell function foo as applied to the identifier x (which is of type JExpr -- i.e. a Javascript expression). -Other than that, the language is essentially Javascript (1.5). Note however that one must use semicolons in a principled fashion -- i.e. to end statements consistently. Otherwise, the parser will mistake the whitespace for a whitespace application, and odd things will occur.+Other than that, the language is essentially Javascript (1.5). Note however that one must use semicolons in a principled fashion -- i.e. to end statements consistently. Otherwise, the parser will mistake the whitespace for a whitespace application, and odd things will occur. A further gotcha exists in regex literals, whicch cannot begin with a space. @x / 5 / 4@ parses as ((x / 5) / 4). However, @x /5 / 4@ will parse as x(/5 /, 4). Such are the perils of operators used as delimeters in the presence of whitespace application.  Additional datatypes can be marshalled to Javascript by proper instance declarations for the ToJExpr class.  An experimental typechecker is available in the Typed module.  -}------------------------------------------------------------------------------  module Language.Javascript.JMacro (-  module Language.Javascript.JMacro.Base,-  module Language.Javascript.JMacro.QQ+  module Language.Javascript.JMacro.QQ,+  module Language.Javascript.JMacro.Base  ) where  import Prelude hiding (tail, init, head, last, minimum, maximum, foldr1, foldl1, (!!), read)
Language/Javascript/JMacro/Base.hs view
@@ -22,12 +22,12 @@   withHygiene,   -- * Display/Output   renderJs, JsToDoc(..),-  -- * ad-hoc data marshalling+  -- * Ad-hoc data marshalling   ToJExpr(..),-  -- * helpful combinators+  -- * Occasionally helpful combinators   jLam, jVar, jFor, jForIn, jForEachIn,   expr2stat, ToStat(..), nullStat,-  -- * hash combinators+  -- * Hash combinators   jhEmpty, jhSingle, jhAdd, jhFromList,   -- * utility   jsSaturate@@ -270,6 +270,8 @@   Saturation --------------------------------------------------------------------} +-- | Given an optional prefix, fills in all free variable names with a supply+-- of names generated by the prefix. jsSaturate :: (JMacro a) => Maybe String -> a -> a jsSaturate str x = evalState (jsSaturate_ x) (newIdentSupply str) 
Language/Javascript/JMacro/QQ.hs view
@@ -467,12 +467,12 @@                 (const (return x))                 (parseExp x) -    valExpr = ValExpr <$> (num <|> negnum <|> str <|> regex <|> list <|> hash <|> func <|> var) <?> "value"+    valExpr = ValExpr <$> (num <|> negnum <|> str <|> try regex <|> list <|> hash <|> func <|> var) <?> "value"         where num = either JInt JDouble <$> try natFloat               negnum = either (JInt . negate) (JDouble . negate) <$> try (char '-' >> natFloat)               str   = JStr   <$> (myStringLiteral '"' <|> myStringLiteral '\'')               regex = do-                s <- myStringLiteral '/'+                s <- myRegexLiteral                 case compileM (BS.pack s) [] of                   Right _ -> return (JRegEx s)                   Left err -> fail ("Parse error in regexp: " ++ err)@@ -487,11 +487,11 @@               statOrEblock  = try (ReturnStat <$> expr `folBy` '}') <|> (l2s <$> statblock)               propPair = liftM2 (,) myIdent (colon >> expr) ---notFolBy a b = a <* notFollowedBy (char b)+notFolBy a b = a <* notFollowedBy (char b) folBy :: JMParser a -> Char -> JMParser a folBy a b = a <* (lookAhead (char b) >>= const (return ())) args' :: JMParser [JExpr]-args' = parens $ commaSep expr+args' = parens' $ commaSep expr  --Parsers without Lexeme @@ -590,6 +590,21 @@     return x  where myChar = do          c <- noneOf [t]+         case c of+           '\\' -> do+                  c2 <- anyChar+                  return [c,c2]+           '\n' -> return "\\n"+           _ -> return [c]++myRegexLiteral :: JMParser String+myRegexLiteral = do+    char '/' `notFolBy` ' '+    x <- concat <$> many myChar+    char '/'+    return x+ where myChar = do+         c <- noneOf ['/']          case c of            '\\' -> do                   c2 <- anyChar
jmacro.cabal view
@@ -1,5 +1,5 @@ name:                jmacro-version:             0.1.1+version:             0.1.2 synopsis:            QuasiQuotation library for programmatic generation of Javascript code. description:         Javascript syntax, functional syntax, hygeinic names, compile-time guarantees of syntactic correctness, limited typechecking. category:            Language@@ -13,7 +13,8 @@   library-  build-depends:     base >= 4, base < 5, containers, pretty, safe >= 0.2, parsec >= 2.1, template-haskell >= 2.3, mtl, haskell-src-meta, bytestring >= 0.9+  build-depends:     base >= 4, base < 5, containers, pretty, safe >= 0.2, parsec >= 2.1, pcre-light,+                     template-haskell >= 2.3, mtl, haskell-src-meta, bytestring >= 0.9, syb   exposed-modules:   Language.Javascript.JMacro                      Language.Javascript.JMacro.Util                      Language.Javascript.JMacro.Typed