Automatically generate documentation from comments in R7RS Scheme code
git clone https://git.8pit.net/scmdoc.git
1module SchemeDoc.Parser.Util where 2 3import Control.Monad (void) 4import Numeric (readHex) 5import Text.ParserCombinators.Parsec 6 7-- Parse a hexadecimal number without a prefix. 8hex :: Parser Int 9hex = fmap readHex' hexDigits10 where11 -- Due to hexDigits, readHex should always read the full string.12 -- XXX: Technically R⁷RS does not allow upper case hex letters.13 readHex' = fst . head . readHex14 hexDigits = many1 (oneOf "0123456789abcdefABCDEF")1516-- Bind a given character to the given result.17bind :: String -> a -> Parser a18bind str val = val <$ string str1920-- Like skipMany but without the many part.21skip :: Parser a -> Parser ()22skip = void2324-- Runs both parsers and returns the result of the first.25terminatedBy :: Parser a -> Parser b -> Parser a26terminatedBy p1 p2 = do27 r <- p128 _ <- p229 return r3031-- Like manyTill but preserve the terminator in the return value.32manyTill' :: Parser a -> Parser a -> Parser [a]33manyTill' p end = scan34 where35 scan =36 do x <- end; return [x]37 <|> do x <- p; xs <- scan; return (x : xs)3839------------------------------------------------------------------------4041-- Remove all Nothing value from a List of Maybe monads.42filterJust :: [Maybe a] -> [a]43filterJust =44 foldr45 ( \x acc -> case x of46 Nothing -> acc47 Just x' -> x' : acc48 )49 []