never executed always true always false
    1 module Parse.Common
    2     ( sectionedGroup, pair
    3     , commented, preCommented, postCommented, withEol
    4     , checkMultiline
    5     ) where
    6 
    7 import AST.V0_16
    8 import Text.Parsec
    9 import Parse.Helpers
   10 import Parse.Whitespace
   11 import Parse.IParser
   12 import Parse.Comments
   13 
   14 
   15 --
   16 -- Structure
   17 --
   18 
   19 
   20 pair :: IParser a -> IParser sep -> IParser b -> IParser (Pair a b)
   21 pair a sep b =
   22     checkMultiline $ Pair <$> postCommented a <* sep <*> preCommented b
   23 
   24 
   25 sectionedGroup :: IParser a -> IParser (Sequence a, Comments)
   26 sectionedGroup term =
   27     let
   28         step leading terms =
   29             do
   30                 pre <- whitespace
   31                 (C eol first) <- withEol term
   32                 preSep <- whitespace
   33                 hasMore <- choice [ comma *> return True, return False ]
   34                 if hasMore
   35                     then step preSep (C (leading, pre, eol) first : terms)
   36                     else return (Sequence $ reverse (C (leading, pre, eol) first : terms), preSep)
   37     in
   38         choice
   39             [ try $ step [] []
   40             , (,) (Sequence []) <$> whitespace
   41             ]
   42 
   43 
   44 --
   45 -- Other helpers
   46 --
   47 
   48 
   49 checkMultiline :: IParser (ForceMultiline -> a) -> IParser a
   50 checkMultiline inner =
   51     do
   52         (a, multiline) <- trackNewline inner
   53         return $ a (ForceMultiline $ multilineToBool multiline)