{-# LANGUAGE OverloadedStrings #-}
module Data.SCargot.Comments
(
withLispComments
, withOctothorpeComments
, withPercentComments
, withPercentBlockComments
, withCLikeLineComments
, withCLikeBlockComments
, withCLikeComments
, withHaskellLineComments
, withHaskellBlockComments
, withHaskellComments
, lineComment
, simpleBlockComment
) where
import Text.Parsec ( (<|>)
, anyChar
, manyTill
, noneOf
, skipMany
, string
)
import Data.SCargot.Parse ( Comment
, SExprParser
, setComment
)
lineComment :: String -> Comment
String
s = String -> ParsecT Text () Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
s ParsecT Text () Identity String -> Comment -> Comment
forall a b.
ParsecT Text () Identity a
-> ParsecT Text () Identity b -> ParsecT Text () Identity b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text () Identity Char -> Comment
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany (String -> ParsecT Text () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
noneOf String
"\n") Comment -> Comment -> Comment
forall a b.
ParsecT Text () Identity a
-> ParsecT Text () Identity b -> ParsecT Text () Identity b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> () -> Comment
forall a. a -> ParsecT Text () Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
simpleBlockComment :: String -> String -> Comment
String
begin String
end =
String -> ParsecT Text () Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
begin ParsecT Text () Identity String
-> ParsecT Text () Identity String
-> ParsecT Text () Identity String
forall a b.
ParsecT Text () Identity a
-> ParsecT Text () Identity b -> ParsecT Text () Identity b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
ParsecT Text () Identity Char
-> ParsecT Text () Identity String
-> ParsecT Text () Identity String
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT Text () Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
anyChar (String -> ParsecT Text () Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
end) ParsecT Text () Identity String -> Comment -> Comment
forall a b.
ParsecT Text () Identity a
-> ParsecT Text () Identity b -> ParsecT Text () Identity b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
() -> Comment
forall a. a -> ParsecT Text () Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
withLispComments :: SExprParser t a -> SExprParser t a
= Comment -> SExprParser t a -> SExprParser t a
forall a c. Comment -> SExprParser a c -> SExprParser a c
setComment (String -> Comment
lineComment String
";")
withCLikeLineComments :: SExprParser t a -> SExprParser t a
= Comment -> SExprParser t a -> SExprParser t a
forall a c. Comment -> SExprParser a c -> SExprParser a c
setComment (String -> Comment
lineComment String
"//")
withCLikeBlockComments :: SExprParser t a -> SExprParser t a
= Comment -> SExprParser t a -> SExprParser t a
forall a c. Comment -> SExprParser a c -> SExprParser a c
setComment (String -> String -> Comment
simpleBlockComment String
"/*" String
"*/")
withCLikeComments :: SExprParser t a -> SExprParser t a
= Comment -> SExprParser t a -> SExprParser t a
forall a c. Comment -> SExprParser a c -> SExprParser a c
setComment (String -> Comment
lineComment String
"//" Comment -> Comment -> Comment
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
String -> String -> Comment
simpleBlockComment String
"/*" String
"*/")
withHaskellLineComments :: SExprParser t a -> SExprParser t a
= Comment -> SExprParser t a -> SExprParser t a
forall a c. Comment -> SExprParser a c -> SExprParser a c
setComment (String -> Comment
lineComment String
"--")
withHaskellBlockComments :: SExprParser t a -> SExprParser t a
= Comment -> SExprParser t a -> SExprParser t a
forall a c. Comment -> SExprParser a c -> SExprParser a c
setComment (String -> String -> Comment
simpleBlockComment String
"{-" String
"-}")
withHaskellComments :: SExprParser t a -> SExprParser t a
= Comment -> SExprParser t a -> SExprParser t a
forall a c. Comment -> SExprParser a c -> SExprParser a c
setComment (String -> Comment
lineComment String
"--" Comment -> Comment -> Comment
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
String -> String -> Comment
simpleBlockComment String
"{-" String
"-}")
withOctothorpeComments :: SExprParser t a -> SExprParser t a
= Comment -> SExprParser t a -> SExprParser t a
forall a c. Comment -> SExprParser a c -> SExprParser a c
setComment (String -> Comment
lineComment String
"#")
withPercentComments :: SExprParser t a -> SExprParser t a
= Comment -> SExprParser t a -> SExprParser t a
forall a c. Comment -> SExprParser a c -> SExprParser a c
setComment (String -> Comment
lineComment String
"%")
withPercentBlockComments :: SExprParser t a -> SExprParser t a
= Comment -> SExprParser t a -> SExprParser t a
forall a c. Comment -> SExprParser a c -> SExprParser a c
setComment (String -> String -> Comment
simpleBlockComment String
"%{" String
"%}")