mirror of
https://github.com/github/semantic.git
synced 2024-11-28 10:15:55 +03:00
Move parse back into semantic
This commit is contained in:
parent
8d989cdead
commit
01af025638
@ -186,6 +186,8 @@ library
|
||||
, Reprinting.Pipeline
|
||||
-- High-level flow & operational functionality (logging, stats, etc.)
|
||||
, Semantic.Analysis
|
||||
, Semantic.API.Parse
|
||||
, Semantic.API.Symbols
|
||||
, Semantic.AST
|
||||
, Semantic.CLI
|
||||
, Semantic.Config
|
||||
@ -264,6 +266,7 @@ library
|
||||
, scientific
|
||||
, semigroupoids
|
||||
, semilattices
|
||||
, servant
|
||||
, split
|
||||
, stm-chans
|
||||
, template-haskell
|
||||
|
46
src/Semantic/API/Parse.hs
Normal file
46
src/Semantic/API/Parse.hs
Normal file
@ -0,0 +1,46 @@
|
||||
{-# LANGUAGE GADTs, TypeOperators, DerivingStrategies #-}
|
||||
module Semantic.API.Parse (doParse, TermConstraints) where
|
||||
|
||||
import Analysis.ConstructorName (ConstructorName)
|
||||
import Control.Effect
|
||||
import Control.Effect.Error
|
||||
import Control.Exception
|
||||
import Data.Abstract.Declarations
|
||||
import Data.Aeson
|
||||
import Data.Bifunctor (first)
|
||||
import Data.Blob
|
||||
import Data.Language
|
||||
import Data.Location
|
||||
import Data.Term
|
||||
import qualified Data.Text as T
|
||||
import GHC.Generics
|
||||
import Parsing.Parser
|
||||
import qualified Proto3.Suite as Proto3
|
||||
import qualified Proto3.Suite.Types as P
|
||||
import Rendering.Symbol
|
||||
import Semantic.Task as Task
|
||||
import Servant.API
|
||||
import Tags.Taggable
|
||||
|
||||
type TermConstraints =
|
||||
'[ Taggable
|
||||
, Declarations1
|
||||
, ConstructorName
|
||||
, HasTextElement
|
||||
]
|
||||
|
||||
doParse :: (Member (Error SomeException) sig, Member Task sig, Carrier sig m, Monad m)
|
||||
=> Language -> Blob -> (Blob -> SomeTerm TermConstraints Location -> output) -> m output
|
||||
doParse lang blob render = case lang of
|
||||
Go -> render blob . SomeTerm <$> parse goParser blob
|
||||
Haskell -> render blob . SomeTerm <$> parse haskellParser blob
|
||||
Java -> render blob . SomeTerm <$> parse javaParser blob
|
||||
JavaScript -> render blob . SomeTerm <$> parse typescriptParser blob
|
||||
JSON -> render blob . SomeTerm <$> parse jsonParser blob
|
||||
JSX -> render blob . SomeTerm <$> parse typescriptParser blob
|
||||
Markdown -> render blob . SomeTerm <$> parse markdownParser blob
|
||||
Python -> render blob . SomeTerm <$> parse pythonParser blob
|
||||
Ruby -> render blob . SomeTerm <$> parse rubyParser blob
|
||||
TypeScript -> render blob . SomeTerm <$> parse typescriptParser blob
|
||||
PHP -> render blob . SomeTerm <$> parse phpParser blob
|
||||
_ -> noLanguageForBlob (blobPath blob)
|
44
src/Semantic/API/Symbols.hs
Normal file
44
src/Semantic/API/Symbols.hs
Normal file
@ -0,0 +1,44 @@
|
||||
{-# LANGUAGE GADTs, TypeOperators, DerivingStrategies #-}
|
||||
module Semantic.API.Symbols (parseToSymbols) where
|
||||
|
||||
import Analysis.ConstructorName (ConstructorName)
|
||||
import Control.Effect
|
||||
import Control.Effect.Error
|
||||
import Control.Exception
|
||||
import Data.Abstract.Declarations
|
||||
import Data.Aeson
|
||||
import Data.Bifunctor (first)
|
||||
import Data.Blob
|
||||
import Data.Language
|
||||
import Data.Location
|
||||
import Data.Term
|
||||
import qualified Data.Text as T
|
||||
import GHC.Generics
|
||||
import Parsing.Parser
|
||||
import qualified Proto3.Suite as Proto3
|
||||
import qualified Proto3.Suite.Types as P
|
||||
import Rendering.Symbol
|
||||
import Semantic.API.Parse
|
||||
import Semantic.Task as Task
|
||||
import Servant.API
|
||||
import Tags.Taggable
|
||||
|
||||
parseToSymbols :: ( Member (Error SomeException) sig
|
||||
, Member Distribute sig
|
||||
, Member Task sig
|
||||
, Carrier sig m
|
||||
, Monad m
|
||||
, Traversable t
|
||||
)
|
||||
=> Maybe String -> t Blob -> m [File]
|
||||
parseToSymbols fields = distributeFoldMap go
|
||||
where
|
||||
go :: (Member (Error SomeException) sig, Member Task sig, Carrier sig m, Monad m) => Blob -> m [File]
|
||||
go blob@Blob{..} = doParse blobLanguage blob render `catchError` (\e@(SomeException _) -> pure (pure emptyFile))
|
||||
where emptyFile = File (T.pack blobPath) (T.pack (show blobLanguage)) []
|
||||
|
||||
render :: Blob -> SomeTerm TermConstraints Location -> [File]
|
||||
render blob (SomeTerm term) = renderToSymbols symbolFields blob term
|
||||
|
||||
symbolFields :: SymbolFields
|
||||
symbolFields = maybe defaultSymbolFields parseSymbolFields fields
|
Loading…
Reference in New Issue
Block a user