Cosmetic changes.
authorJulien Moutinho <julm+hdoc@autogeree.net>
Tue, 26 Dec 2017 13:47:19 +0000 (14:47 +0100)
committerJulien Moutinho <julm+hdoc@autogeree.net>
Tue, 26 Dec 2017 13:47:19 +0000 (14:47 +0100)
Language/TCT/Tree.hs
Language/TCT/Write/XML.hs

index e711470ec7301086a85a461836a41b7e764f66dc..0d97ad90bc32cc9a2b9ec4a85b43e2906d3206d9 100644 (file)
@@ -6,9 +6,9 @@ module Language.TCT.Tree
  , Trees
  ) where
 
+import Control.Monad (Monad(..))
 import Data.Eq (Eq(..))
 import Data.Function (($))
-import Data.Functor ((<$>))
 import Data.Maybe (Maybe(..))
 import Data.Ord (Ordering(..), Ord(..))
 import Data.Semigroup (Semigroup(..))
@@ -38,7 +38,7 @@ data Key = KeyColon !Name !White     -- ^ @name: @
          | KeyDash                   -- ^ @- @
          | KeyDashDash               -- ^ @-- @
          | KeySection  !LevelSection -- ^ @# @
-         | KeyBrackets !Name         -- ^ @[ name ]@
+         | KeyBrackets !Name         -- ^ @[name]@
          | KeyDotSlash !PathFile     -- ^ @./file @
          deriving (Eq, Ord, Show)
 
@@ -56,7 +56,7 @@ type Rows = [Tree (Cell Key) (Cell Text)]
 
 -- | @appendRow rows row@ appends @row@ to @rows@.
 --
--- [@rows@] parent 'Rows', from closest to farest (non-strictly descending)
+-- [@rows@] parent 'Rows', from closest to farthest (non-strictly descending)
 -- [@row@]  next 'Row', from leftest column to rightest (non-stricly ascending)
 appendRow :: Rows -> Row -> Rows
 appendRow [] row = List.reverse row
@@ -101,8 +101,10 @@ appendRow rows@(parent:parents) row@(cell:cells) =
        collapseSection :: Column -> Rows -> Maybe (Int,Rows)
        collapseSection col xxs@(x:xs) | columnPos (posTree x) == col =
                case x of
-                TreeN (unCell -> KeySection lvl) _ -> Just (lvl,xxs)
-                _ -> (\(lvl,cs) -> (lvl,insertChild x cs)) <$> collapseSection col xs
+                TreeN (unCell -> KeySection lvl) _ -> Just (lvl, xxs)
+                _ -> do
+                       (lvl, cs) <- collapseSection col xs
+                       return (lvl, insertChild x cs)
        collapseSection _ _ = Nothing
 
 appendCellText :: Cell Text -> Cell Text -> Maybe (Cell Text)
index 9796843c6dbb86cf42031348036ca7dd64f196e2..93f4465e82bba94aa6c5bb1a7ae9696f40c7fb12 100644 (file)
@@ -91,22 +91,15 @@ instance Xmlify TCTs where
                                TreeN (Cell bp ep "ol") $
                                        ol >>= xmlify inh{inh_tree0=List.repeat xmlPara}
                        
-                        t@(Tree0 toks) :< ts | isTokenElem toks ->
-                               xmlify inh_orig t <>
-                               go inh ts
-                       
                         t@(Tree0 toks) :< ts ->
                                case inh_tree0 inh of
-                                [] ->
-                                       xmlify inh_orig t <>
-                                       go inh{inh_tree0=[]} ts
-                                x:xs ->
-                                       case Seq.viewl toks of
-                                        EmptyL -> go inh{inh_tree0=xs} ts
-                                        Cell bp _ep _ :< _ ->
-                                               (<| go inh{inh_tree0=xs} ts) $
-                                               x bp $
-                                                       xmlify inh_orig t
+                                []                   -> xmlify inh_orig t <> go inh ts
+                                _ | isTokenElem toks -> xmlify inh_orig t <> go inh ts
+                                tree0:inh_tree0 ->
+                                       (case Seq.viewl toks of
+                                        EmptyL -> id
+                                        Cell bp _ep _ :< _ -> (tree0 bp (xmlify inh_orig t) <|)) $
+                                       go inh{inh_tree0} ts
                        
                         t:<ts ->
                                xmlify inh_orig t <>
@@ -214,7 +207,8 @@ instance Xmlify (Cell Token) where
                 TokenPair (PairElem name attrs) ts ->
                        Seq.singleton $
                        TreeN (cell $ xmlLocalName name) $
-                               xmlAttrs (Seq.fromList $ (\(_wh,Attr{..}) -> cell (xmlLocalName attr_name,attr_value)) <$> attrs) <>
+                               xmlAttrs (Seq.fromList $ (\(_wh,Attr{..}) ->
+                                       cell (xmlLocalName attr_name,attr_value)) <$> attrs) <>
                                xmlify inh ts
                 TokenPair p ts ->
                        let (o,c) = pairBorders p ts in