diff --git a/HLint.hs b/HLint.hs index 1ba9cd181..f3dc8ff9a 100644 --- a/HLint.hs +++ b/HLint.hs @@ -18,7 +18,7 @@ error "use pure" = free . Pure ==> pure error "use wrap" = free . Free ==> wrap error "use extract" = termAnnotation . unTerm ==> extract -error "use unwrap" = tailF . unTerm ==> unwrap +error "use unwrap" = termSyntax . unTerm ==> unwrap error "avoid head" = head where note = "head is partial; consider using Data.Maybe.listToMaybe" diff --git a/src/Language/Markdown/Syntax.hs b/src/Language/Markdown/Syntax.hs index c28f35a67..ae9ba030f 100644 --- a/src/Language/Markdown/Syntax.hs +++ b/src/Language/Markdown/Syntax.hs @@ -20,7 +20,7 @@ import Data.Text.Encoding (encodeUtf8) import Data.Union import GHC.Stack import Language.Markdown as Grammar (Grammar(..)) -import Term (Term(..), TermF(..), unwrap, termAnnotation, tailF) +import Term (Term(..), TermF(..), unwrap) type Syntax = '[ Markup.Document @@ -69,14 +69,14 @@ paragraph = makeTerm <$> symbol Paragraph <*> children (Markup.Paragraph <$> man list :: Assignment list = (Term .) . (:<) <$> symbol List <*> ((\ (CMarkGFM.LIST CMarkGFM.ListAttributes{..}) -> case listType of CMarkGFM.BULLET_LIST -> inj . Markup.UnorderedList - CMarkGFM.ORDERED_LIST -> inj . Markup.OrderedList) . termAnnotation . tailF <$> currentNode <*> children (many item)) + CMarkGFM.ORDERED_LIST -> inj . Markup.OrderedList) . termAnnotation . termSyntax <$> currentNode <*> children (many item)) item :: Assignment item = makeTerm <$> symbol Item <*> children (many blockElement) section :: Assignment section = makeTerm <$> symbol Heading <*> (heading >>= \ headingTerm -> Markup.Section (level headingTerm) headingTerm <$> while (((<) `on` level) headingTerm) blockElement) - where heading = makeTerm <$> symbol Heading <*> ((\ (CMarkGFM.HEADING level) -> Markup.Heading level) . termAnnotation . tailF <$> currentNode <*> children (many inlineElement)) + where heading = makeTerm <$> symbol Heading <*> ((\ (CMarkGFM.HEADING level) -> Markup.Heading level) . termAnnotation . termSyntax <$> currentNode <*> children (many inlineElement)) level term = case term of _ | Just section <- prj (unwrap term) -> level (Markup.sectionHeading section) _ | Just heading <- prj (unwrap term) -> Markup.headingLevel heading @@ -86,7 +86,7 @@ blockQuote :: Assignment blockQuote = makeTerm <$> symbol BlockQuote <*> children (Markup.BlockQuote <$> many blockElement) codeBlock :: Assignment -codeBlock = makeTerm <$> symbol CodeBlock <*> ((\ (CMarkGFM.CODE_BLOCK language _) -> Markup.Code (nullText language)) . termAnnotation . tailF <$> currentNode <*> source) +codeBlock = makeTerm <$> symbol CodeBlock <*> ((\ (CMarkGFM.CODE_BLOCK language _) -> Markup.Code (nullText language)) . termAnnotation . termSyntax <$> currentNode <*> source) thematicBreak :: Assignment thematicBreak = makeTerm <$> token ThematicBreak <*> pure Markup.ThematicBreak @@ -124,10 +124,10 @@ htmlInline :: Assignment htmlInline = makeTerm <$> symbol HTMLInline <*> (Markup.HTMLBlock <$> source) link :: Assignment -link = makeTerm <$> symbol Link <*> ((\ (CMarkGFM.LINK url title) -> Markup.Link (encodeUtf8 url) (nullText title)) . termAnnotation . tailF <$> currentNode) <* advance +link = makeTerm <$> symbol Link <*> ((\ (CMarkGFM.LINK url title) -> Markup.Link (encodeUtf8 url) (nullText title)) . termAnnotation . termSyntax <$> currentNode) <* advance image :: Assignment -image = makeTerm <$> symbol Image <*> ((\ (CMarkGFM.IMAGE url title) -> Markup.Image (encodeUtf8 url) (nullText title)) . termAnnotation . tailF <$> currentNode) <* advance +image = makeTerm <$> symbol Image <*> ((\ (CMarkGFM.IMAGE url title) -> Markup.Image (encodeUtf8 url) (nullText title)) . termAnnotation . termSyntax <$> currentNode) <* advance code :: Assignment code = makeTerm <$> symbol Code <*> (Markup.Code Nothing <$> source) diff --git a/src/RWS.hs b/src/RWS.hs index 1ccb836f3..3df058806 100644 --- a/src/RWS.hs +++ b/src/RWS.hs @@ -273,7 +273,7 @@ pqGramDecorator pqGramDecorator getLabel p q = cata algebra where algebra term = let label = getLabel term in - Term.Term ((gram label :. termAnnotation term) :< assignParentAndSiblingLabels (tailF term) label) + Term.Term ((gram label :. termAnnotation term) :< assignParentAndSiblingLabels (termSyntax term) label) gram label = Gram (padToSize p []) (padToSize q (pure (Just label))) assignParentAndSiblingLabels functor label = (`evalState` (replicate (q `div` 2) Nothing <> siblingLabels functor)) (for functor (assignLabels label)) @@ -303,7 +303,7 @@ canCompareTerms canCompare = canCompare `on` unTerm -- | Recursively test the equality of two 'Term's in O(n). equalTerms :: Eq1 f => ComparabilityRelation f fields -> Term f (Record fields) -> Term f (Record fields) -> Bool equalTerms canCompare = go - where go a b = canCompareTerms canCompare a b && liftEq go (tailF (unTerm a)) (tailF (unTerm b)) + where go a b = canCompareTerms canCompare a b && liftEq go (termSyntax (unTerm a)) (termSyntax (unTerm b)) -- Instances diff --git a/src/Term.hs b/src/Term.hs index cea9098ab..b21ba6009 100644 --- a/src/Term.hs +++ b/src/Term.hs @@ -28,7 +28,7 @@ import Text.Show -- | A Term with an abstract syntax tree and an annotation. newtype Term syntax ann = Term { unTerm :: TermF syntax ann (Term syntax ann) } infixr 5 :< -data TermF syntax ann recur = (:<) { termAnnotation :: ann, tailF :: syntax recur } +data TermF syntax ann recur = (:<) { termAnnotation :: ann, termSyntax :: syntax recur } deriving (Eq, Foldable, Functor, Show, Traversable) -- | A Term with a Syntax leaf and a record of fields.