From 203d97d1267e31779b7ec78fddf03849b0c50ff8 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 16 Jun 2017 12:32:26 -0400 Subject: [PATCH] Define a ToC renderer. --- src/Renderer.hs | 2 ++ src/Semantic.hs | 1 + 2 files changed, 3 insertions(+) diff --git a/src/Renderer.hs b/src/Renderer.hs index 38097f4c5..10a35a672 100644 --- a/src/Renderer.hs +++ b/src/Renderer.hs @@ -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. diff --git a/src/Semantic.hs b/src/Semantic.hs index 9f5a96346..dbf354b4f 100644 --- a/src/Semantic.hs +++ b/src/Semantic.hs @@ -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)