1
1
mirror of https://github.com/github/semantic.git synced 2024-12-27 17:05:33 +03:00

Use the while combinator to define section assignment.

This commit is contained in:
Rob Rix 2017-06-08 12:32:47 -04:00
parent 9ac5d17acd
commit 152c1e9530

View File

@ -70,12 +70,7 @@ item :: Assignment
item = makeTerm <$> symbol Item <*> children (many blockElement)
section :: Assignment
section = makeTerm <$> symbol Heading <*> do
headingTerm <- heading
fmap (Markup.Section headingTerm) . many $ do
element <- blockElement
guard (level headingTerm < level element)
pure element
section = makeTerm <$> symbol Heading <*> (heading >>= \ headingTerm -> Markup.Section headingTerm <$> while (((<) `on` level) headingTerm) blockElement)
where heading = makeTerm <$> symbol Heading <*> (Markup.Heading <$> project (\ ((CMark.HEADING level :. _) :< _) -> level) <*> children (many inlineElement))
level term = case term of
_ | Just section <- prj (unwrap term) -> level (Markup.sectionHeading section)