1
1
mirror of https://github.com/github/semantic.git synced 2024-12-25 07:55:12 +03:00

Rename termSyntax to termOut.

This commit is contained in:
Rob Rix 2017-09-11 15:24:09 -04:00
parent 825990cfce
commit c29a9671f0
4 changed files with 9 additions and 9 deletions

View File

@ -18,7 +18,7 @@ error "use pure" = free . Pure ==> pure
error "use wrap" = free . Free ==> wrap error "use wrap" = free . Free ==> wrap
error "use extract" = termAnnotation . unTerm ==> extract error "use extract" = termAnnotation . unTerm ==> extract
error "use unwrap" = termSyntax . unTerm ==> unwrap error "use unwrap" = termOut . unTerm ==> unwrap
error "avoid head" = head error "avoid head" = head
where note = "head is partial; consider using Data.Maybe.listToMaybe" where note = "head is partial; consider using Data.Maybe.listToMaybe"

View File

@ -69,14 +69,14 @@ paragraph = makeTerm <$> symbol Paragraph <*> children (Markup.Paragraph <$> man
list :: Assignment list :: Assignment
list = (Term .) . (:<) <$> symbol List <*> ((\ (CMarkGFM.LIST CMarkGFM.ListAttributes{..}) -> case listType of list = (Term .) . (:<) <$> symbol List <*> ((\ (CMarkGFM.LIST CMarkGFM.ListAttributes{..}) -> case listType of
CMarkGFM.BULLET_LIST -> inj . Markup.UnorderedList CMarkGFM.BULLET_LIST -> inj . Markup.UnorderedList
CMarkGFM.ORDERED_LIST -> inj . Markup.OrderedList) . termAnnotation . termSyntax <$> currentNode <*> children (many item)) CMarkGFM.ORDERED_LIST -> inj . Markup.OrderedList) . termAnnotation . termOut <$> currentNode <*> children (many item))
item :: Assignment item :: Assignment
item = makeTerm <$> symbol Item <*> children (many blockElement) item = makeTerm <$> symbol Item <*> children (many blockElement)
section :: Assignment section :: Assignment
section = makeTerm <$> symbol Heading <*> (heading >>= \ headingTerm -> Markup.Section (level headingTerm) headingTerm <$> while (((<) `on` level) headingTerm) blockElement) 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 . termSyntax <$> currentNode <*> children (many inlineElement)) where heading = makeTerm <$> symbol Heading <*> ((\ (CMarkGFM.HEADING level) -> Markup.Heading level) . termAnnotation . termOut <$> currentNode <*> children (many inlineElement))
level term = case term of level term = case term of
_ | Just section <- prj (unwrap term) -> level (Markup.sectionHeading section) _ | Just section <- prj (unwrap term) -> level (Markup.sectionHeading section)
_ | Just heading <- prj (unwrap term) -> Markup.headingLevel heading _ | Just heading <- prj (unwrap term) -> Markup.headingLevel heading
@ -86,7 +86,7 @@ blockQuote :: Assignment
blockQuote = makeTerm <$> symbol BlockQuote <*> children (Markup.BlockQuote <$> many blockElement) blockQuote = makeTerm <$> symbol BlockQuote <*> children (Markup.BlockQuote <$> many blockElement)
codeBlock :: Assignment codeBlock :: Assignment
codeBlock = makeTerm <$> symbol CodeBlock <*> ((\ (CMarkGFM.CODE_BLOCK language _) -> Markup.Code (nullText language)) . termAnnotation . termSyntax <$> currentNode <*> source) codeBlock = makeTerm <$> symbol CodeBlock <*> ((\ (CMarkGFM.CODE_BLOCK language _) -> Markup.Code (nullText language)) . termAnnotation . termOut <$> currentNode <*> source)
thematicBreak :: Assignment thematicBreak :: Assignment
thematicBreak = makeTerm <$> token ThematicBreak <*> pure Markup.ThematicBreak thematicBreak = makeTerm <$> token ThematicBreak <*> pure Markup.ThematicBreak
@ -124,10 +124,10 @@ htmlInline :: Assignment
htmlInline = makeTerm <$> symbol HTMLInline <*> (Markup.HTMLBlock <$> source) htmlInline = makeTerm <$> symbol HTMLInline <*> (Markup.HTMLBlock <$> source)
link :: Assignment link :: Assignment
link = makeTerm <$> symbol Link <*> ((\ (CMarkGFM.LINK url title) -> Markup.Link (encodeUtf8 url) (nullText title)) . termAnnotation . termSyntax <$> currentNode) <* advance link = makeTerm <$> symbol Link <*> ((\ (CMarkGFM.LINK url title) -> Markup.Link (encodeUtf8 url) (nullText title)) . termAnnotation . termOut <$> currentNode) <* advance
image :: Assignment image :: Assignment
image = makeTerm <$> symbol Image <*> ((\ (CMarkGFM.IMAGE url title) -> Markup.Image (encodeUtf8 url) (nullText title)) . termAnnotation . termSyntax <$> currentNode) <* advance image = makeTerm <$> symbol Image <*> ((\ (CMarkGFM.IMAGE url title) -> Markup.Image (encodeUtf8 url) (nullText title)) . termAnnotation . termOut <$> currentNode) <* advance
code :: Assignment code :: Assignment
code = makeTerm <$> symbol Code <*> (Markup.Code Nothing <$> source) code = makeTerm <$> symbol Code <*> (Markup.Code Nothing <$> source)

View File

@ -272,7 +272,7 @@ pqGramDecorator
pqGramDecorator getLabel p q = cata algebra pqGramDecorator getLabel p q = cata algebra
where where
algebra term = let label = getLabel term in algebra term = let label = getLabel term in
Term.Term ((gram label :. termAnnotation term) :< assignParentAndSiblingLabels (termSyntax term) label) Term.Term ((gram label :. termAnnotation term) :< assignParentAndSiblingLabels (termOut term) label)
gram label = Gram (padToSize p []) (padToSize q (pure (Just 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)) assignParentAndSiblingLabels functor label = (`evalState` (replicate (q `div` 2) Nothing <> siblingLabels functor)) (for functor (assignLabels label))
@ -302,7 +302,7 @@ canCompareTerms canCompare = canCompare `on` unTerm
-- | Recursively test the equality of two 'Term's in O(n). -- | 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 :: Eq1 f => ComparabilityRelation f fields -> Term f (Record fields) -> Term f (Record fields) -> Bool
equalTerms canCompare = go equalTerms canCompare = go
where go a b = canCompareTerms canCompare a b && liftEq go (termSyntax (unTerm a)) (termSyntax (unTerm b)) where go a b = canCompareTerms canCompare a b && liftEq go (termOut (unTerm a)) (termOut (unTerm b))
-- Instances -- Instances

View File

@ -30,7 +30,7 @@ import Text.Show
newtype Term syntax ann = Term { unTerm :: TermF syntax ann (Term syntax ann) } newtype Term syntax ann = Term { unTerm :: TermF syntax ann (Term syntax ann) }
infixr 5 :< infixr 5 :<
data TermF syntax ann recur = (:<) { termAnnotation :: ann, termSyntax :: syntax recur } data TermF syntax ann recur = (:<) { termAnnotation :: ann, termOut :: syntax recur }
deriving (Eq, Foldable, Functor, Show, Traversable) deriving (Eq, Foldable, Functor, Show, Traversable)
-- | A Term with a Syntax leaf and a record of fields. -- | A Term with a Syntax leaf and a record of fields.