From 6872baa09077eab887bb5d164d1d2b66fb031d78 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 11 May 2018 14:53:22 -0400 Subject: [PATCH] Serialize terms to s-expressions. --- src/Rendering/Renderer.hs | 2 +- src/Semantic/Parse.hs | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Rendering/Renderer.hs b/src/Rendering/Renderer.hs index d125a87f7..956ed92b9 100644 --- a/src/Rendering/Renderer.hs +++ b/src/Rendering/Renderer.hs @@ -55,7 +55,7 @@ data TermRenderer output where -- | 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. - SExpressionTermRenderer :: TermRenderer ByteString + SExpressionTermRenderer :: TermRenderer Builder -- | Render to a list of tags (deprecated). TagsTermRenderer :: TermRenderer [Value] -- | Render to a list of symbols. diff --git a/src/Semantic/Parse.hs b/src/Semantic/Parse.hs index 8adecfd8f..f6b2e955a 100644 --- a/src/Semantic/Parse.hs +++ b/src/Semantic/Parse.hs @@ -8,7 +8,6 @@ import Analysis.PackageDef (HasPackageDef, packageDefAlgebra) import Data.Blob import Data.JSON.Fields import Data.Output -import Data.Record import Parsing.Parser import Prologue hiding (MonadError(..)) import Rendering.Graph @@ -30,7 +29,7 @@ parseBlob renderer blob@Blob{..} | Just (SomeParser parser) <- someParser (Proxy :: Proxy '[ConstructorName, HasPackageDef, HasDeclaration, IdentifierName, Foldable, Functor, ToJSONFields1]) <$> blobLanguage = parse parser blob >>= case renderer of JSONTermRenderer -> decorate constructorLabel >=> decorate identifierLabel >=> render (renderJSONTerm blob) - SExpressionTermRenderer -> decorate constructorLabel . (Nil <$) >=> render renderSExpressionTerm + SExpressionTermRenderer -> serialize SExpression TagsTermRenderer -> decorate (declarationAlgebra blob) >=> render (renderToTags blob) ImportsTermRenderer -> decorate (declarationAlgebra blob) >=> decorate (packageDefAlgebra blob) >=> render (renderToImports blob) SymbolsTermRenderer fields -> decorate (declarationAlgebra blob) >=> render (renderToSymbols fields blob) @@ -49,7 +48,7 @@ astParseBlobs renderer blobs = toOutput' <$> distributeFoldMap (WrapTask . astPa astParseBlob renderer blob@Blob{..} | Just (SomeASTParser parser) <- someASTParser <$> blobLanguage = parse parser blob >>= case renderer of - SExpressionTermRenderer -> render renderSExpressionAST + SExpressionTermRenderer -> serialize SExpression JSONTermRenderer -> render (renderJSONTerm' blob) _ -> pure $ throwError (SomeException (FormatNotSupported "Only SExpression and JSON output supported for tree-sitter ASTs.")) | otherwise = throwError (SomeException (NoLanguageForBlob blobPath))