Commits

Doug Burke committed 0593863

Formatter: more refactoring

Comments (0)

Files changed (3)

src/Swish/RDF/Formatter/Internal.hs

     , formatPlainLit
     , formatLangLit
     , formatTypedLit
+    , insertList
     )
 where
 
 import Control.Monad (liftM)
 import Control.Monad.State (State, get, put)
 
-import Data.List (delete, foldl', groupBy, partition)
+import Data.List (delete, foldl', groupBy, intersperse, partition)
 import Data.Monoid (Monoid(..), mconcat)
 import Data.Word
 
     | otherwise = mconcat [quoteText lit, "^^", showScopedName dtype]
                            
 	       
+{-
+Add a list inline. We are given the labels that constitute
+the list, in order, so just need to display them surrounded
+by ().
+-}
+insertList ::
+    (RDFLabel -> State a B.Builder)
+    -> [RDFLabel]
+    -> State a B.Builder
+insertList _ [] = return "()" -- QUS: can this happen in a valid graph?
+insertList f xs = do
+    ls <- mapM f xs
+    return $ mconcat ("( " : intersperse " " ls) `mappend` " )" 
+    
 --------------------------------------------------------------------------------
 --
 --  Copyright (c) 2003, Graham Klyne, 2009 Vasili I Galchin,

src/Swish/RDF/Formatter/N3.hs

 				    , formatPlainLit
 				    , formatLangLit
 				    , formatTypedLit
+				    , insertList
 				    ) 
 
 import Swish.Namespace (ScopedName)
 import Control.Monad.State (State, modify, get, gets, put, runState)
 
 import Data.Char (isDigit)
-import Data.List (intersperse)
 import Data.Monoid (Monoid(..))
 import Data.Word (Word32)
 
   return $ mconcat [" { ",f3str, f4str]
 
 {-
-Add a list inline. We are given the labels that constitute
-the list, in order, so just need to display them surrounded
-by ().
--}
-insertList :: [RDFLabel] -> Formatter B.Builder
-insertList [] = return "()" -- not convinced this can happen
-insertList xs = do
-  ls <- mapM (formatLabel ObjContext) xs
-  return $ mconcat ("( " : intersperse " " ls) `mappend` " )"
-    
-{-
 Add a blank node inline.
 -}
 
 formatLabel lctxt lab@(Blank (_:_)) = do
   mlst <- extractList lctxt lab
   case mlst of
-    Just lst -> insertList lst
+    Just lst -> insertList (formatLabel ObjContext) lst
     Nothing -> do
               mfml <- extractFormula lab
               case mfml of

src/Swish/RDF/Formatter/Turtle.hs

                                     , formatPlainLit
                                     , formatLangLit
                                     , formatTypedLit
+                                    , insertList
 				    )
 
 import Swish.RDF.Graph (
 import Control.Monad.State (State, modify, get, gets, put, runState)
 
 import Data.Char (isDigit)
-import Data.List (intersperse)
 import Data.Monoid (Monoid(..))
 import Data.Word (Word32)
 
     else return $ mconcat [prstr, " ", obstr]
 
 {-
-Add a list inline. We are given the labels that constitute
-the list, in order, so just need to display them surrounded
-by ().
--}
-insertList :: [RDFLabel] -> Formatter B.Builder
-insertList [] = return "()" -- not convinced this can happen
-insertList xs = do
-  ls <- mapM (formatLabel ObjContext) xs
-  return $ mconcat ("( " : intersperse " " ls) `mappend` " )"
-    
-{-
 Add a blank node inline.
 -}
 
 formatLabel lctxt lab@(Blank (_:_)) = do
   mlst <- extractList lctxt lab
   case mlst of
-    Just lst -> insertList lst
+    Just lst -> insertList (formatLabel ObjContext) lst
     Nothing -> do
       -- NOTE: unlike N3 we do not properly handle "formula"/named graphs
       -- also we only expand out bnodes into [...] format when it's a object.