packages feed

haskellish 0.2.0 → 0.2.2

raw patch · 3 files changed

+74/−4 lines, 3 filesdep +containersdep +template-haskellPVP ok

version bump matches the API change (PVP)

Dependencies added: containers, template-haskell

API changes (from Hackage documentation)

+ Language.Haskellish: binaryApplication :: Haskellish st f -> Haskellish st a -> Haskellish st b -> Haskellish st (f, a, b)
+ Language.Haskellish: ifThenElse :: Haskellish st a -> Haskellish st b -> Haskellish st c -> Haskellish st (a, b, c)
+ Language.Haskellish.TH: grabExp :: String -> Q Exp
+ Language.Haskellish.TH: grabInfoMap :: [String] -> Q (Map String Info)

Files

Language/Haskellish.hs view
@@ -69,8 +69,8 @@   instance MonadState st (Haskellish st) where-  get = Haskellish (\st e -> return (st,st))-  put st = Haskellish (\_ e -> return ((),st))+  get = Haskellish (\st _ -> return (st,st))+  put st = Haskellish (\_ _ -> return ((),st))   instance MonadError String (Haskellish st) where@@ -159,6 +159,18 @@     f _ = Left ""     g l x = (Var l (UnQual l (Ident l x))) +ifThenElse :: Haskellish st a -> Haskellish st b -> Haskellish st c -> Haskellish st (a,b,c)+ifThenElse aP bP cP = Haskellish (\st e -> do+  (aExp,bExp,cExp) <- f e+  (a,st') <- runHaskellish aP st aExp+  (b,st'') <- runHaskellish bP st' bExp+  (c,st''') <- runHaskellish cP st'' cExp+  return ((a,b,c),st''')+  )+  where+    f (Paren _ x) = f x+    f (If _ x y z) = Right (x,y,z)+    f _ = Left ""  collectDoStatements :: Exp SrcSpanInfo -> [Exp SrcSpanInfo] collectDoStatements (Do _ xs) = catMaybes $ fmap f xs@@ -211,4 +223,20 @@   (x',st') <- runHaskellish x st e1   (f',st'') <- runHaskellish f st' e2   return (f' x',st'')+  )++-- | binaryApplication targets the specific situation of parsing a function that is applied to two+-- arguments, given parsers for the function and each of the two arguments. This is intended for rare+-- cases - in most cases, Haskellish's Applicative instance will be a preferred way of parsing function+-- application. Unlike the applicative instance, this function returns the three components (function+-- and two arguments) separately, ie. the function is not actually applied to its arguments in the return type.++binaryApplication :: Haskellish st f -> Haskellish st a -> Haskellish st b -> Haskellish st (f,a,b)+binaryApplication fP aP bP = Haskellish (\st e -> do+  (x,bE) <- applicationExpressions e+  (fE,aE) <- applicationExpressions x+  (f,st') <- runHaskellish fP st fE+  (a,st'') <- runHaskellish aP st' aE+  (b,st''') <- runHaskellish bP st'' bE+  return ((f,a,b),st''')   )
+ Language/Haskellish/TH.hs view
@@ -0,0 +1,38 @@+{-# LANGUAGE TemplateHaskell #-}++module Language.Haskellish.TH where++import Language.Haskell.TH+-- import Control.Monad+import Data.Map as Map+-- import Data.Set as Set++grabExp :: String -> Q Exp+grabExp x = varE $ mkName x++-- given a list of names of functions, make a map of that info+-- eg. as a splice that becomes a String: $(grabInfoMap ["f","g","h"] >>= (stringE . show))+grabInfoMap :: [String] -> Q (Map String Info)+grabInfoMap = sequence . Map.fromList . fmap (\x -> (x,reify $ mkName x))++{- infoToType :: Info -> Type+infoToType (VarI _ x _) = x -}++-- given a type, return a representation of it as [String] where+-- concatenating the strings produces a string that could be a legal name for a definition+-- and where each items from the list is also a legal name for a definition+{-+signature :: Type -> [String]+signature (AppT (AppT ArrowT x) y) = (concat $ signature x) : signature y+signature (AppT ListT x) = ["_LIST" ++ concat (signature x)]+signature (AppT (ConT x) (ConT y)) = [nameBase x ++ nameBase y]+signature (AppT x y) = nameForType x ++ "_OPEN_" ++ nameForType y ++ "_CLOSE_"+signature (ConT x) = nameBase x++-- given a map from names to Infos, generate a map from type-strings to names with that type-string+infoMapToTypeMap :: Map String Info -> Map String [String]+infoMapToTypeMap x = let+  allNamesAndTypes = fmap (nameForType . infoToType) x+  setOfAllTypes = (Set.fromList $ Map.elems allNamesAndTypes) :: Set String+  in Map.fromSet (\t -> Map.keys $ Map.filter (==t) allNamesAndTypes) setOfAllTypes+-}
haskellish.cabal view
@@ -1,5 +1,5 @@ name:                haskellish-version:             0.2.0+version:             0.2.2 synopsis:            For parsing Haskell-ish languages homepage:            http://github.com/dktr0/Haskellish license:             BSD3@@ -22,12 +22,16 @@    default-language:    Haskell2010 -  Exposed-modules:     Language.Haskellish+  Exposed-modules:+    Language.Haskellish+    Language.Haskellish.TH    Build-depends:       base >=4.8 && <5     , haskell-src-exts >=1.17.1 && <1.23     , mtl >= 2.2.2 && <2.3+    , template-haskell >= 2.10.0.0 && < 2.15+    , containers < 0.7  source-repository head   type:     git