mirror of
https://github.com/github/semantic.git
synced 2024-12-20 13:21:59 +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 qualified CMarkGFM
|
||||||
import Data.Abstract.Evaluatable (HasPrelude)
|
import Data.Abstract.Evaluatable (HasPrelude)
|
||||||
import Data.AST
|
import Data.AST
|
||||||
import Data.Graph.ControlFlowVertex (VertexDeclaration1)
|
import Data.Graph.ControlFlowVertex (VertexDeclaration)
|
||||||
import Data.Language
|
import Data.Language
|
||||||
import Data.Kind (Constraint)
|
import Data.Kind (Constraint)
|
||||||
import qualified Data.Map as Map
|
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.
|
-- | 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
|
data SomeAnalysisParser (constraint :: (* -> *) -> Constraint) ann where
|
||||||
SomeAnalysisParser :: ( constraint syntax
|
SomeAnalysisParser :: ( constraint term
|
||||||
, VertexDeclaration1 syntax
|
, VertexDeclaration term
|
||||||
, HasPrelude lang
|
, HasPrelude lang
|
||||||
)
|
)
|
||||||
=> Parser (Term syntax ann)
|
=> Parser (term ann)
|
||||||
-> Proxy lang
|
-> Proxy lang
|
||||||
-> SomeAnalysisParser constraint ann
|
-> SomeAnalysisParser constraint ann
|
||||||
|
|
||||||
-- | A parser for some specific language, producing 'Term's whose syntax satisfies a list of typeclass constraints.
|
-- | A parser for some specific language, producing 'Term's whose syntax satisfies a list of typeclass constraints.
|
||||||
someAnalysisParser :: ( constraint (Sum Go.Syntax)
|
someAnalysisParser :: ( constraint (Term (Sum Go.Syntax))
|
||||||
, constraint (Sum PHP.Syntax)
|
, constraint (Term (Sum PHP.Syntax))
|
||||||
, constraint (Sum Python.Syntax)
|
, constraint (Term (Sum Python.Syntax))
|
||||||
, constraint (Sum Ruby.Syntax)
|
, constraint (Term (Sum Ruby.Syntax))
|
||||||
, constraint (Sum TypeScript.Syntax)
|
, constraint (Term (Sum TypeScript.Syntax))
|
||||||
)
|
)
|
||||||
=> proxy constraint -- ^ A proxy for the constraint required, e.g. @(Proxy \@Show1)@.
|
=> proxy constraint -- ^ A proxy for the constraint required, e.g. @(Proxy \@Show1)@.
|
||||||
-> Language -- ^ The 'Language' to select.
|
-> Language -- ^ The 'Language' to select.
|
||||||
|
@ -145,12 +145,12 @@ runGraph :: ( Member Distribute sig
|
|||||||
-> Project
|
-> Project
|
||||||
-> m (Graph ControlFlowVertex)
|
-> m (Graph ControlFlowVertex)
|
||||||
runGraph ImportGraph _ project
|
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
|
let parse = if projectLanguage project == Language.Python then parsePythonPackage parser else fmap (fmap snd) . parsePackage parser
|
||||||
package <- parse project
|
package <- parse project
|
||||||
runImportGraphToModuleInfos lang' package
|
runImportGraphToModuleInfos lang' package
|
||||||
runGraph CallGraph includePackages project
|
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
|
let parse = if projectLanguage project == Language.Python then parsePythonPackage parser else fmap (fmap snd) . parsePackage parser
|
||||||
package <- parse project
|
package <- parse project
|
||||||
modules <- topologicalSort <$> runImportGraphToModules lang package
|
modules <- topologicalSort <$> runImportGraphToModules lang package
|
||||||
|
Loading…
Reference in New Issue
Block a user