, 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(..))
| KeyDash -- ^ @- @
| KeyDashDash -- ^ @-- @
| KeySection !LevelSection -- ^ @# @
- | KeyBrackets !Name -- ^ @[ name ]@
+ | KeyBrackets !Name -- ^ @[name]@
| KeyDotSlash !PathFile -- ^ @./file @
deriving (Eq, Ord, Show)
-- | @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
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)
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 <>
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