mirror of
https://github.com/github/semantic.git
synced 2024-12-19 12:51:52 +03:00
Generalize SomeAnalysisParser over the term type.
This commit is contained in:
parent
c32bcc884f
commit
42a0ef63d2
@ -38,7 +38,7 @@ import Assigning.Assignment
|
||||
import qualified CMarkGFM
|
||||
import Data.Abstract.Evaluatable (HasPrelude)
|
||||
import Data.AST
|
||||
import Data.Graph.ControlFlowVertex (VertexDeclaration1)
|
||||
import Data.Graph.ControlFlowVertex (VertexDeclaration)
|
||||
import Data.Language
|
||||
import Data.Kind (Constraint)
|
||||
import qualified Data.Map as Map
|
||||
@ -70,20 +70,20 @@ import TreeSitter.Unmarshal
|
||||
|
||||
-- | A parser, suitable for program analysis, for some specific language, producing 'Term's whose syntax satisfies a list of typeclass constraints.
|
||||
data SomeAnalysisParser (constraint :: (* -> *) -> Constraint) ann where
|
||||
SomeAnalysisParser :: ( constraint syntax
|
||||
, VertexDeclaration1 syntax
|
||||
SomeAnalysisParser :: ( constraint term
|
||||
, VertexDeclaration term
|
||||
, HasPrelude lang
|
||||
)
|
||||
=> Parser (Term syntax ann)
|
||||
=> Parser (term ann)
|
||||
-> Proxy lang
|
||||
-> SomeAnalysisParser constraint ann
|
||||
|
||||
-- | A parser for some specific language, producing 'Term's whose syntax satisfies a list of typeclass constraints.
|
||||
someAnalysisParser :: ( constraint (Sum Go.Syntax)
|
||||
, constraint (Sum PHP.Syntax)
|
||||
, constraint (Sum Python.Syntax)
|
||||
, constraint (Sum Ruby.Syntax)
|
||||
, constraint (Sum TypeScript.Syntax)
|
||||
someAnalysisParser :: ( constraint (Term (Sum Go.Syntax))
|
||||
, constraint (Term (Sum PHP.Syntax))
|
||||
, constraint (Term (Sum Python.Syntax))
|
||||
, constraint (Term (Sum Ruby.Syntax))
|
||||
, constraint (Term (Sum TypeScript.Syntax))
|
||||
)
|
||||
=> proxy constraint -- ^ A proxy for the constraint required, e.g. @(Proxy \@Show1)@.
|
||||
-> Language -- ^ The 'Language' to select.
|
||||
|
@ -145,12 +145,12 @@ runGraph :: ( Member Distribute sig
|
||||
-> Project
|
||||
-> m (Graph ControlFlowVertex)
|
||||
runGraph ImportGraph _ project
|
||||
| SomeAnalysisParser parser (lang' :: Proxy lang) <- someAnalysisParser (Proxy :: Proxy AnalysisClasses) (projectLanguage project) = do
|
||||
| SomeAnalysisParser parser (lang' :: Proxy lang) <- someAnalysisParser (Proxy :: Proxy AnalyzeTerm) (projectLanguage project) = do
|
||||
let parse = if projectLanguage project == Language.Python then parsePythonPackage parser else fmap (fmap snd) . parsePackage parser
|
||||
package <- parse project
|
||||
runImportGraphToModuleInfos lang' package
|
||||
runGraph CallGraph includePackages project
|
||||
| SomeAnalysisParser parser lang <- someAnalysisParser (Proxy :: Proxy AnalysisClasses) (projectLanguage project) = do
|
||||
| SomeAnalysisParser parser lang <- someAnalysisParser (Proxy :: Proxy AnalyzeTerm) (projectLanguage project) = do
|
||||
let parse = if projectLanguage project == Language.Python then parsePythonPackage parser else fmap (fmap snd) . parsePackage parser
|
||||
package <- parse project
|
||||
modules <- topologicalSort <$> runImportGraphToModules lang package
|
||||
|
Loading…
Reference in New Issue
Block a user