1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 17:04:47 +03:00

parserForLanguage does not take its argument in Maybe.

This commit is contained in:
Rob Rix 2017-09-29 14:25:39 -04:00
parent 32055efa42
commit 2f05a32997
2 changed files with 4 additions and 5 deletions

View File

@ -54,9 +54,8 @@ data Parser term where
LineByLineParser :: Parser (Term Syntax (Record DefaultFields)) LineByLineParser :: Parser (Term Syntax (Record DefaultFields))
-- | Return a 'Language'-specific 'Parser', if one exists, falling back to the 'LineByLineParser'. -- | Return a 'Language'-specific 'Parser', if one exists, falling back to the 'LineByLineParser'.
parserForLanguage :: Maybe Language -> Parser (Term Syntax (Record DefaultFields)) parserForLanguage :: Language -> Parser (Term Syntax (Record DefaultFields))
parserForLanguage Nothing = LineByLineParser parserForLanguage language = case language of
parserForLanguage (Just language) = case language of
Go -> TreeSitterParser tree_sitter_go Go -> TreeSitterParser tree_sitter_go
JavaScript -> TreeSitterParser tree_sitter_typescript JavaScript -> TreeSitterParser tree_sitter_typescript
JSON -> TreeSitterParser tree_sitter_json JSON -> TreeSitterParser tree_sitter_json

View File

@ -62,7 +62,7 @@ parseBlob renderer blob@Blob{..} = case (renderer, blobLanguage) of
(IdentityTermRenderer, Just Language.Python) -> pure Nothing (IdentityTermRenderer, Just Language.Python) -> pure Nothing
(IdentityTermRenderer, Just Language.TypeScript) -> pure Nothing (IdentityTermRenderer, Just Language.TypeScript) -> pure Nothing
(IdentityTermRenderer, _) -> Just <$> parse syntaxParser blob (IdentityTermRenderer, _) -> Just <$> parse syntaxParser blob
where syntaxParser = parserForLanguage blobLanguage where syntaxParser = maybe LineByLineParser parserForLanguage blobLanguage
diffBlobPairs :: Output output => DiffRenderer output -> [Both Blob] -> Task ByteString diffBlobPairs :: Output output => DiffRenderer output -> [Both Blob] -> Task ByteString
@ -101,7 +101,7 @@ diffBlobPair renderer blobs = case (renderer, effectiveLanguage) of
(SExpressionDiffRenderer, _) -> run (parse syntaxParser) diffSyntaxTerms (renderSExpressionDiff . bimap keepCategory keepCategory) (SExpressionDiffRenderer, _) -> run (parse syntaxParser) diffSyntaxTerms (renderSExpressionDiff . bimap keepCategory keepCategory)
(IdentityDiffRenderer, _) -> run (\ blob -> parse syntaxParser blob >>= decorate (syntaxDeclarationAlgebra blob)) diffSyntaxTerms Just (IdentityDiffRenderer, _) -> run (\ blob -> parse syntaxParser blob >>= decorate (syntaxDeclarationAlgebra blob)) diffSyntaxTerms Just
where effectiveLanguage = runBothWith (<|>) (blobLanguage <$> blobs) where effectiveLanguage = runBothWith (<|>) (blobLanguage <$> blobs)
syntaxParser = parserForLanguage effectiveLanguage syntaxParser = maybe LineByLineParser parserForLanguage effectiveLanguage
run :: Functor syntax => (Blob -> Task (Term syntax ann)) -> (Term syntax ann -> Term syntax ann -> Diff syntax ann ann) -> (Diff syntax ann ann -> output) -> Task output run :: Functor syntax => (Blob -> Task (Term syntax ann)) -> (Term syntax ann -> Term syntax ann -> Diff syntax ann ann) -> (Diff syntax ann ann -> output) -> Task output
run parse diff renderer = distributeFor blobs parse >>= runBothWith (diffTermPair blobs diff) >>= render renderer run parse diff renderer = distributeFor blobs parse >>= runBothWith (diffTermPair blobs diff) >>= render renderer