Commits

Doug Burke committed dac5119

Formatter: more internal clean up

  • Participants
  • Parent commits 8a73e8e

Comments (0)

Files changed (2)

File src/Swish/RDF/Formatter/N3.hs

   )
 
 import Control.Monad (liftM, void)
-import Control.Monad.State (State, modify, get, put, runState)
+import Control.Monad.State (State, modify, get, gets, put, runState)
 
 import Data.Char (isDigit)
 import Data.List (intersperse)
     , traceBuf  = []
     }
 
-getIndent :: Formatter B.Builder
-getIndent = indent `liftM` get
-
 setIndent :: B.Builder -> Formatter ()
 setIndent ind = modify $ \st -> st { indent = ind }
 
-getLineBreak :: Formatter Bool
-getLineBreak = lineBreak `liftM` get
-
 setLineBreak :: Bool -> Formatter ()
 setLineBreak brk = modify $ \st -> st { lineBreak = brk }
 
-getNgs :: Formatter NodeGenState
-getNgs = nodeGenSt `liftM` get
-
 setNgs :: NodeGenState -> Formatter ()
 setNgs ngs = modify $ \st -> st { nodeGenSt = ngs }
 
-getPrefixes :: Formatter NamespaceMap
-getPrefixes = prefixes `liftM` get
-
 setPrefixes :: NamespaceMap -> Formatter ()
 setPrefixes pmap = modify $ \st -> st { prefixes = pmap }
 
-getSubjs :: Formatter (SubjTree RDFLabel)
-getSubjs = subjs `liftM` get
-
 setSubjs :: SubjTree RDFLabel -> Formatter ()
 setSubjs sl = modify $ \st -> st { subjs = sl }
 
-getProps :: Formatter (PredTree RDFLabel)
-getProps = props `liftM` get
-
 setProps :: PredTree RDFLabel -> Formatter ()
 setProps ps = modify $ \st -> st { props = ps }
 
   put $ st { objs = os }
 -}
 
-getBnodesCheck :: Formatter [RDFLabel]
-getBnodesCheck = bNodesCheck `liftM` get
-
 {-
 addTrace :: String -> Formatter ()
 addTrace tr = do
 -}
 extractList :: LabelContext -> RDFLabel -> Formatter (Maybe [RDFLabel])
 extractList lctxt ln = do
-  osubjs <- getSubjs
-  oprops <- getProps
+  osubjs <- gets subjs
+  oprops <- gets props
   case maybeExtractList osubjs oprops lctxt ln of
     Just (ls, osubjs', oprops') -> do
       setSubjs osubjs'
 
 insertFormula :: RDFGraph -> Formatter B.Builder
 insertFormula gr = do
-  pmap0 <- getPrefixes
-  ngs0  <- getNgs
-  ind   <- getIndent
+  pmap0 <- gets prefixes
+  ngs0  <- gets nodeGenSt
+  ind   <- gets indent
   let grm = formatGraph (ind `mappend` "    ") "" True False
             (setNamespaces emptyNamespaceMap gr)
 
 
 nextLine :: B.Builder -> Formatter B.Builder
 nextLine str = do
-  ind <- getIndent
-  brk <- getLineBreak
+  ind <- gets indent
+  brk <- gets lineBreak
   if brk
     then return $ ind `mappend` str
     else do
               case mfml of
                 Just fml -> insertFormula fml
                 Nothing -> do
-                          nb1 <- getBnodesCheck
+                          nb1 <- gets bNodesCheck
                           if lctxt /= PredContext && lab `notElem` nb1
                             then insertBnode lctxt lab
                             else formatNodeId lab
   case lookup sn specialTable of
     Just txt -> return $ quoteB True txt -- TODO: do we need to quote?
     Nothing -> do
-      pr <- getPrefixes
+      pr <- gets prefixes
       queueFormula lab
       return $ formatScopedName sn pr
 
 
 mapBlankNode :: RDFLabel -> Formatter B.Builder
 mapBlankNode lab = do
-  ngs <- getNgs
+  ngs <- gets nodeGenSt
   let (lval, mngs) = getBNodeLabel lab ngs
   case mngs of
     Just ngs' -> setNgs ngs'

File src/Swish/RDF/Formatter/Turtle.hs

 import Swish.RDF.Vocabulary (rdfType, rdfNil)
 
 import Control.Monad (liftM)
-import Control.Monad.State (State, modify, get, put, runState)
+import Control.Monad.State (State, modify, get, gets, put, runState)
 
 import Data.Char (isDigit)
 import Data.List (intersperse)
     , traceBuf  = []
     }
 
-getIndent :: Formatter B.Builder
-getIndent = indent `liftM` get
-
 setIndent :: B.Builder -> Formatter ()
 setIndent ind = modify $ \st -> st { indent = ind }
 
-getLineBreak :: Formatter Bool
-getLineBreak = lineBreak `liftM` get
-
 setLineBreak :: Bool -> Formatter ()
 setLineBreak brk = modify $ \st -> st { lineBreak = brk }
 
-getNgs :: Formatter NodeGenState
-getNgs = nodeGenSt `liftM` get
-
 setNgs :: NodeGenState -> Formatter ()
 setNgs ngs = modify $ \st -> st { nodeGenSt = ngs }
 
-getPrefixes :: Formatter NamespaceMap
-getPrefixes = prefixes `liftM` get
-
-getSubjs :: Formatter (SubjTree RDFLabel)
-getSubjs = subjs `liftM` get
-
 setSubjs :: SubjTree RDFLabel -> Formatter ()
 setSubjs sl = modify $ \st -> st { subjs = sl }
 
-getProps :: Formatter (PredTree RDFLabel)
-getProps = props `liftM` get
-
 setProps :: PredTree RDFLabel -> Formatter ()
 setProps ps = modify $ \st -> st { props = ps }
 
   put $ st { objs = os }
 -}
 
-getBnodesCheck :: Formatter [RDFLabel]
-getBnodesCheck = bNodesCheck `liftM` get
-
 {-
 addTrace :: String -> Formatter ()
 addTrace tr = do
 -}
 extractList :: LabelContext -> RDFLabel -> Formatter (Maybe [RDFLabel])
 extractList lctxt ln = do
-  osubjs <- getSubjs
-  oprops <- getProps
+  osubjs <- gets subjs
+  oprops <- gets props
   case maybeExtractList osubjs oprops lctxt ln of
     Just (ls, osubjs', oprops') -> do
       setSubjs osubjs'
 
 nextLine :: B.Builder -> Formatter B.Builder
 nextLine str = do
-  ind <- getIndent
-  brk <- getLineBreak
+  ind <- gets indent
+  brk <- gets lineBreak
   if brk
     then return $ ind `mappend` str
     else 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.
       -- although we need to handle [] for the subject.
-      nb1 <- getBnodesCheck
+      nb1 <- gets bNodesCheck
       if lctxt /= PredContext && lab `notElem` nb1
         then insertBnode lctxt lab
         else formatNodeId lab
   | ctxt == PredContext && sn == rdfType = return "a"
   | ctxt == ObjContext  && sn == rdfNil  = return "()"
   | otherwise = do
-  pr <- getPrefixes
+  pr <- gets prefixes
   return $ formatScopedName sn pr
 
 formatLabel _ (Lit lit) = return $ formatPlainLit lit
 
 mapBlankNode :: RDFLabel -> Formatter B.Builder
 mapBlankNode lab = do
-  ngs <- getNgs
+  ngs <- gets nodeGenSt
   let (lval, mngs) = getBNodeLabel lab ngs
   case mngs of
     Just ngs' -> setNgs ngs'