{-# LANGUAGE RankNTypes #-}
module Commonmark.Syntax
( SyntaxSpec(..)
, defaultSyntaxSpec
)
where
import Text.Parsec (ParsecT)
import Commonmark.Tokens (Tok)
import Commonmark.Types
import Commonmark.Blocks
import Commonmark.Inlines
data SyntaxSpec m il bl = SyntaxSpec
{ forall (m :: * -> *) il bl.
SyntaxSpec m il bl -> [BlockSpec m il bl]
syntaxBlockSpecs :: [BlockSpec m il bl]
, forall (m :: * -> *) il bl.
SyntaxSpec m il bl -> [BracketedSpec il]
syntaxBracketedSpecs :: [BracketedSpec il]
, forall (m :: * -> *) il bl.
SyntaxSpec m il bl -> [FormattingSpec il]
syntaxFormattingSpecs :: [FormattingSpec il]
, forall (m :: * -> *) il bl.
SyntaxSpec m il bl -> [InlineParser m il]
syntaxInlineParsers :: [InlineParser m il]
, forall (m :: * -> *) il bl.
SyntaxSpec m il bl -> [BlockParser m il bl bl]
syntaxFinalParsers :: [BlockParser m il bl bl]
, forall (m :: * -> *) il bl.
SyntaxSpec m il bl
-> forall u (m1 :: * -> *).
Monad m1 =>
[ParsecT [Tok] u m1 Attributes]
syntaxAttributeParsers
:: forall u m1 . Monad m1 => [ParsecT [Tok] u m1 Attributes]
}
instance Semigroup (SyntaxSpec m il bl) where
SyntaxSpec [BlockSpec m il bl]
bl1 [BracketedSpec il]
br1 [FormattingSpec il]
fo1 [InlineParser m il]
il1 [BlockParser m il bl bl]
fp1 forall u (m1 :: * -> *).
Monad m1 =>
[ParsecT [Tok] u m1 Attributes]
ap1 <> :: SyntaxSpec m il bl -> SyntaxSpec m il bl -> SyntaxSpec m il bl
<> SyntaxSpec [BlockSpec m il bl]
bl2 [BracketedSpec il]
br2 [FormattingSpec il]
fo2 [InlineParser m il]
il2 [BlockParser m il bl bl]
fp2 forall u (m1 :: * -> *).
Monad m1 =>
[ParsecT [Tok] u m1 Attributes]
ap2
= forall (m :: * -> *) il bl.
[BlockSpec m il bl]
-> [BracketedSpec il]
-> [FormattingSpec il]
-> [InlineParser m il]
-> [BlockParser m il bl bl]
-> (forall u (m1 :: * -> *).
Monad m1 =>
[ParsecT [Tok] u m1 Attributes])
-> SyntaxSpec m il bl
SyntaxSpec (forall (m :: * -> *) il bl.
[BlockSpec m il bl] -> [BlockSpec m il bl]
removeDuplicateBlockSpecs forall a b. (a -> b) -> a -> b
$ [BlockSpec m il bl]
bl1 forall a. Semigroup a => a -> a -> a
<> [BlockSpec m il bl]
bl2)
([BracketedSpec il]
br1 forall a. Semigroup a => a -> a -> a
<> [BracketedSpec il]
br2) ([FormattingSpec il]
fo1 forall a. Semigroup a => a -> a -> a
<> [FormattingSpec il]
fo2) ([InlineParser m il]
il1 forall a. Semigroup a => a -> a -> a
<> [InlineParser m il]
il2)
([BlockParser m il bl bl]
fp1 forall a. Semigroup a => a -> a -> a
<> [BlockParser m il bl bl]
fp2) (forall u (m1 :: * -> *).
Monad m1 =>
[ParsecT [Tok] u m1 Attributes]
ap1 forall a. Semigroup a => a -> a -> a
<> forall u (m1 :: * -> *).
Monad m1 =>
[ParsecT [Tok] u m1 Attributes]
ap2)
instance Monoid (SyntaxSpec m il bl) where
mempty :: SyntaxSpec m il bl
mempty = forall (m :: * -> *) il bl.
[BlockSpec m il bl]
-> [BracketedSpec il]
-> [FormattingSpec il]
-> [InlineParser m il]
-> [BlockParser m il bl bl]
-> (forall u (m1 :: * -> *).
Monad m1 =>
[ParsecT [Tok] u m1 Attributes])
-> SyntaxSpec m il bl
SyntaxSpec forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty
mappend :: SyntaxSpec m il bl -> SyntaxSpec m il bl -> SyntaxSpec m il bl
mappend = forall a. Semigroup a => a -> a -> a
(<>)
removeDuplicateBlockSpecs :: [BlockSpec m il bl] -> [BlockSpec m il bl]
removeDuplicateBlockSpecs :: forall (m :: * -> *) il bl.
[BlockSpec m il bl] -> [BlockSpec m il bl]
removeDuplicateBlockSpecs [] = []
removeDuplicateBlockSpecs (BlockSpec m il bl
b:[BlockSpec m il bl]
bs) =
BlockSpec m il bl
b forall a. a -> [a] -> [a]
: forall (m :: * -> *) il bl.
[BlockSpec m il bl] -> [BlockSpec m il bl]
removeDuplicateBlockSpecs (forall a. (a -> Bool) -> [a] -> [a]
filter ((forall a. Eq a => a -> a -> Bool
/= forall (m :: * -> *) il bl. BlockSpec m il bl -> Text
blockType BlockSpec m il bl
b) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) il bl. BlockSpec m il bl -> Text
blockType) [BlockSpec m il bl]
bs)
defaultSyntaxSpec :: (Monad m, IsBlock il bl, IsInline il)
=> SyntaxSpec m il bl
defaultSyntaxSpec :: forall (m :: * -> *) il bl.
(Monad m, IsBlock il bl, IsInline il) =>
SyntaxSpec m il bl
defaultSyntaxSpec = SyntaxSpec
{ syntaxBlockSpecs :: [BlockSpec m il bl]
syntaxBlockSpecs = forall (m :: * -> *) il bl.
(Monad m, IsBlock il bl) =>
[BlockSpec m il bl]
defaultBlockSpecs
, syntaxBracketedSpecs :: [BracketedSpec il]
syntaxBracketedSpecs = forall il. IsInline il => [BracketedSpec il]
defaultBracketedSpecs
, syntaxFormattingSpecs :: [FormattingSpec il]
syntaxFormattingSpecs = forall il. IsInline il => [FormattingSpec il]
defaultFormattingSpecs
, syntaxInlineParsers :: [InlineParser m il]
syntaxInlineParsers = [forall (m :: * -> *) a. (Monad m, IsInline a) => InlineParser m a
defaultInlineParser]
, syntaxFinalParsers :: [BlockParser m il bl bl]
syntaxFinalParsers = []
, syntaxAttributeParsers :: forall u (m1 :: * -> *).
Monad m1 =>
[ParsecT [Tok] u m1 Attributes]
syntaxAttributeParsers = []
}