mirror of
https://github.com/github/semantic.git
synced 2024-12-27 00:44:57 +03:00
Define a ToC renderer.
This commit is contained in:
parent
a9dd289aae
commit
203d97d126
@ -48,6 +48,8 @@ deriving instance Show (DiffRenderer output)
|
||||
|
||||
-- | Specification of renderers for terms, producing output in the parameter type.
|
||||
data TermRenderer output where
|
||||
-- | Compute a table of contents for the term & encode it as JSON.
|
||||
ToCTermRenderer :: TermRenderer Summaries
|
||||
-- | Render to JSON with the format documented in docs/json-format.md under “Term.”
|
||||
JSONTermRenderer :: TermRenderer [Value]
|
||||
-- | Render to a 'ByteString' formatted as nested s-expressions.
|
||||
|
@ -45,6 +45,7 @@ parseBlobs renderer = fmap toS . distributeFoldMap (parseBlob renderer) . filter
|
||||
-- | A task to parse a 'SourceBlob' and render the resulting 'Term'.
|
||||
parseBlob :: TermRenderer output -> SourceBlob -> Task output
|
||||
parseBlob renderer blob@SourceBlob{..} = case (renderer, blobLanguage) of
|
||||
(ToCTermRenderer, _) -> parse syntaxParser source >>= decorate (syntaxDeclarationAlgebra source) >>= render (renderToCTerm blob)
|
||||
(JSONTermRenderer, Just Language.Markdown) -> parse markdownParser source >>= render (renderJSONTerm blob)
|
||||
(JSONTermRenderer, Just Language.Python) -> parse pythonParser source >>= render (renderJSONTerm blob)
|
||||
(JSONTermRenderer, _) -> parse syntaxParser source >>= decorate identifierAlgebra >>= render (renderJSONTerm blob)
|
||||
|
Loading…
Reference in New Issue
Block a user