graph-utils 0.3.6.1 → 0.3.7
raw patch · 2 files changed
+19/−16 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- Data/Graph/EasyGrapher/Quote.hs +17/−14
- graph-utils.cabal +2/−2
Data/Graph/EasyGrapher/Quote.hs view
@@ -1,6 +1,6 @@ {-# LANGUAGE TemplateHaskell, NamedFieldPuns, TupleSections, DeriveDataTypeable, NoMonomorphismRestriction #-}-module Data.Graph.EasyGrapher.Quote (gr) where+module Data.Graph.EasyGrapher.Quote (gr, deserialize) where import Language.Haskell.TH import Language.Haskell.TH.Quote import Text.Parsec hiding ((<|>), many, State, label)@@ -11,10 +11,9 @@ -- * Graph Parser parseGraph :: (Monad m) => (String, Int, Int) -> String -> m (EGGraph Value)-parseGraph (file, line, col) src = - case (parse p "" src) of- Left err -> fail $ show err- Right gr -> return gr+parseGraph (file, line, col) src = do+ ans <- runParserT p () "" src+ either (fail.show) return ans where p = do pos <- getPosition@@ -23,7 +22,7 @@ (flip setSourceLine) line $ (flip setSourceColumn) col $ pos- spaces *> lexeme(graphs)+ spaces *> lexeme(graphs) <* eof data Value = Val String | Var String deriving (Typeable, Data, Ord, Eq, Show) @@ -33,15 +32,21 @@ graphs = sepEndBy1 term (symbol ",") term = try edge <|> EGVertex <$> label edge = (:=>) <$> (label<* symbol "->") <*> label-label = var <|> (Val <$> deserialize <$> ident)+label = (Val <$> ident) <|> try (Val <$> lit) <|> var+lit = between (symbol "\"") (symbol "\"") (many $ noneOf "\"")+ <|> show <$> between (symbol "\'") (symbol "\'") (noneOf "'")+ <|> between (symbol "(") (symbol ")") (many $ noneOf ")") var = Var <$> (symbol "'" *> ident) ident = lexeme $ many1 alphaNum -deserialize :: (Data a, Typeable a, Read a) => String -> a-deserialize = read `extR` (id :: String -> String) -+-- |Wrap function for read (specialized for String & Char)+deserialize :: (Data a, Read a) => String -> a+deserialize = read `extR` (id :: String -> String) `extR` chShow+ where+ chShow [x] = x+ chShow x = read x --- | Quasi quoter for EGGraph+-- | Quasi quoter for 'EGGraph' gr :: QuasiQuoter gr = QuasiQuoter quoteGraphExp quoteGraphPat @@ -54,8 +59,7 @@ antiStrExp :: Value -> Maybe ExpQ antiStrExp (Var sym) = Just $ varE (mkName sym)-antiStrExp (Val a) = Just $ litE $ stringL a-antiStrExp _ = Nothing+antiStrExp (Val a) = Just $ appE (varE 'deserialize) $ litE $ stringL a quoteGraphPat :: String -> PatQ quoteGraphPat src = do@@ -67,4 +71,3 @@ antiStrPat :: Value -> Maybe PatQ antiStrPat (Var sym) = Just $ varP (mkName sym) antiStrPat (Val a) = Just $ litP $ stringL a-antiStrPat _ = Nothing
graph-utils.cabal view
@@ -1,5 +1,5 @@ Name: graph-utils-Version: 0.3.6.1+Version: 0.3.7 Synopsis: A simple wrapper & quasi quoter for fgl. Description:@@ -26,7 +26,7 @@ source-repository this type: git location: http://github.com/konn/graph-utils/tree/release- tag: rel-0.3.6.1+ tag: rel-0.3.7 Library Exposed-modules: Data.Graph.EasyGrapher, Data.Graph.PageRank