packages feed

jmacro 0.1 → 0.1.1

raw patch · 3 files changed

+41/−17 lines, 3 files

Files

Language/Javascript/JMacro/QQ.hs view
@@ -15,6 +15,7 @@ module Language.Javascript.JMacro.QQ(jmacro,jmacroE) where import Prelude hiding (tail, init, head, last, minimum, maximum, foldr1, foldl1, (!!), read) import Control.Applicative hiding ((<|>),many,optional,(<*))+import Control.Arrow((&&&)) import Control.Monad.State.Strict import qualified Data.ByteString.Char8 as BS import Data.Char(digitToInt, toLower)@@ -31,16 +32,17 @@ import Text.ParserCombinators.Parsec import Text.ParserCombinators.Parsec.Expr import Text.ParserCombinators.Parsec.Error+import Text.ParserCombinators.Parsec.Pos import qualified Text.ParserCombinators.Parsec.Token as P import Text.ParserCombinators.Parsec.Language(javaStyle) --- import Text.Regex.PCRE.Light (compileM)+import Text.Regex.PCRE.Light (compileM)  import Language.Javascript.JMacro.Base  -- import Debug.Trace -compileM _ _ = Right "hack"+--compileM _ _ = Right "hack"  {--------------------------------------------------------------------   QuasiQuotation@@ -60,13 +62,11 @@                Left err -> fail (show err)  quoteJMExp :: String -> TH.ExpQ-quoteJMExp s = case parseJM s of+quoteJMExp s = do+    (f,p) <- (TH.loc_filename &&& TH.loc_start) <$> TH.location+    case parseJMPos s f p of                Right x -> jm2th x-               Left err -> do-                   (line,_) <- TH.loc_start <$> TH.location-                   let pos = errorPos err-                   let newPos = setSourceLine pos $ line + sourceLine pos - 1-                   fail (show $ setErrorPos newPos err)+               Left err -> fail (show err)  quoteJMPatE :: String -> TH.PatQ quoteJMPatE s = case parseJME s of@@ -74,14 +74,11 @@                Left err -> fail (show err)  quoteJMExpE :: String -> TH.ExpQ-quoteJMExpE s = case parseJME s of+quoteJMExpE s = do+    (f,p) <- (TH.loc_filename &&& TH.loc_start) <$> TH.location+    case parseJMEPos s f p of                Right x -> jm2th x-               Left err -> do-                   (line,_) <- TH.loc_start <$> TH.location-                   let pos = errorPos err-                   let newPos = setSourceLine pos $ line + sourceLine pos - 1-                   fail (show $ setErrorPos newPos err)-+               Left err -> fail (show err)  -- | Traverse a syntax tree, replace an identifier by an -- antiquotation of a free variable.@@ -175,6 +172,7 @@  lexer = P.makeTokenParser jsLang + jsLang :: P.LanguageDef () jsLang = javaStyle {            P.reservedNames = ["var","return","if","else","while","for","in","break","new","function","switch","case","default","fun"],@@ -210,6 +208,14 @@   y   return xr +parseJMPos :: String -> String -> (Int, Int) -> Either ParseError JStat+parseJMPos s f (p1,p2) = BlockStat <$> runParser jmacroParser () "" s+    where jmacroParser = do+            setPosition $ newPos f p1 p2+            ans <- statblock+            eof+            return ans+ parseJM :: String -> Either ParseError JStat parseJM s = BlockStat <$> runParser jmacroParser () "" s     where jmacroParser = do@@ -220,6 +226,14 @@ parseJME :: String -> Either ParseError JExpr parseJME s = runParser jmacroParserE () "" s     where jmacroParserE = do+            ans <- whiteSpace >> expr+            eof+            return ans++parseJMEPos :: String -> String -> (Int, Int) -> Either ParseError JExpr+parseJMEPos s f (p1,p2) = runParser jmacroParserE () "" s+    where jmacroParserE = do+            setPosition $ newPos f p1 p2             ans <- whiteSpace >> expr             eof             return ans
Language/Javascript/JMacro/Typed.hs view
@@ -20,6 +20,9 @@ import Debug.Trace  +--Type Parser+--primitives for arrays, strings+ --todo: collect errors --pretty types, bump down variable nums --infer missing vs. assert missing@@ -538,7 +541,11 @@         else return ()     case xr of       (JTSat _) -> xr <: y-      _ -> xr =.= y+      _ -> do+        yr <- resolveType y+        case yr of+          (JTSat _) -> yr <: xr+          _ -> xr =.= yr  (=.=) :: JType -> JType -> JMonad () x =.= y = do@@ -1170,9 +1177,12 @@         _ -> tyErr1 "Attempt to use 'for each in' construct with improper type" et       inConditional $ typecheck s     typecheck (ApplStat e args) = typecheck (ApplExpr e args) >> return JTStat+    typecheck (PostStat s e) = typecheck (PostExpr s e) >> return JTStat     typecheck BreakStat = return JTStat     --Switch     --Unsat $ Anti -- anti can take signature!?++---add special cases in selectors for lists, etc!  typecheckLhs :: JExpr -> JMonad JType typecheckLhs (SelExpr e1 ident@(StrI s)) = do
jmacro.cabal view
@@ -1,5 +1,5 @@ name:                jmacro-version:             0.1+version:             0.1.1 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