mirror of
https://github.com/github/semantic.git
synced 2025-01-03 13:02:37 +03:00
Eval test harness for Ruby
This commit is contained in:
parent
e0272ae982
commit
e46d92dc65
@ -2,19 +2,25 @@
|
|||||||
{-# LANGUAGE DataKinds, MonoLocalBinds, TypeOperators, TypeApplications #-}
|
{-# LANGUAGE DataKinds, MonoLocalBinds, TypeOperators, TypeApplications #-}
|
||||||
module Semantic.Util where
|
module Semantic.Util where
|
||||||
|
|
||||||
|
|
||||||
|
import Analysis.Abstract.Evaluating2
|
||||||
import Analysis.Declaration
|
import Analysis.Declaration
|
||||||
import Analysis.Abstract.Evaluating
|
|
||||||
import Control.Monad.IO.Class
|
import Control.Monad.IO.Class
|
||||||
|
import Data.Abstract.Address
|
||||||
|
import Data.Abstract.Store
|
||||||
|
import Data.Abstract.Value
|
||||||
import Data.Align.Generic
|
import Data.Align.Generic
|
||||||
import Data.Maybe
|
import Data.AST
|
||||||
|
import Data.Bifunctor.Join
|
||||||
import Data.Blob
|
import Data.Blob
|
||||||
import Data.Diff
|
import Data.Diff
|
||||||
import Data.Functor.Classes
|
import Data.Functor.Classes
|
||||||
import Data.Bifunctor.Join
|
import Data.Maybe
|
||||||
import Data.Range
|
import Data.Range
|
||||||
import Data.Record
|
import Data.Record
|
||||||
import Data.Span
|
import Data.Span
|
||||||
import Data.Term
|
import Data.Term
|
||||||
|
import Data.Union
|
||||||
import Diffing.Algorithm
|
import Diffing.Algorithm
|
||||||
import Diffing.Interpreter
|
import Diffing.Interpreter
|
||||||
import Parsing.Parser
|
import Parsing.Parser
|
||||||
@ -22,62 +28,62 @@ import Semantic
|
|||||||
import Semantic.IO as IO
|
import Semantic.IO as IO
|
||||||
import Semantic.Task
|
import Semantic.Task
|
||||||
|
|
||||||
import Data.AST
|
import qualified Language.Ruby.Assignment as Ruby
|
||||||
import Data.Union
|
|
||||||
import Data.Abstract.Value
|
|
||||||
import Data.Abstract.Store
|
|
||||||
import Data.Abstract.Address
|
|
||||||
import qualified Language.Python.Assignment as Python
|
|
||||||
|
|
||||||
type PythonValue = Value Precise (Term (Union Python.Syntax) (Record Location))
|
type RubyValue = Value Precise (Term (Union Ruby.Syntax2) (Record Location))
|
||||||
|
|
||||||
file :: MonadIO m => FilePath -> m Blob
|
file :: MonadIO m => FilePath -> m Blob
|
||||||
file path = fromJust <$> IO.readFile path (languageForFilePath path)
|
file path = fromJust <$> IO.readFile path (languageForFilePath path)
|
||||||
|
|
||||||
parsePythonFiles :: [FilePath] -> FilePath -> IO ([(Blob, Python.Term)], (Blob, Python.Term))
|
-- evaluatePythonFile :: FilePath -> _
|
||||||
parsePythonFiles paths entryPath = do
|
evaluateRubyFile path = file path
|
||||||
blobs <- traverse file paths
|
>>= runTask . parse rubyParser2
|
||||||
terms <- runTask $ traverse (parse pythonParser) blobs
|
>>= pure . Prelude.fst . evaluate @RubyValue
|
||||||
entryBlob <- file entryPath
|
|
||||||
entryTerm <- runTask (parse pythonParser entryBlob)
|
|
||||||
pure (zip blobs terms, (entryBlob, entryTerm))
|
|
||||||
|
|
||||||
evaluatePythonFiles :: [FilePath]
|
-- parsePythonFiles :: [FilePath] -> FilePath -> IO ([(Blob, Python.Term)], (Blob, Python.Term))
|
||||||
-> IO
|
-- parsePythonFiles paths entryPath = do
|
||||||
(Either
|
-- blobs <- traverse file paths
|
||||||
Prelude.String
|
-- terms <- runTask $ traverse (parse pythonParser) blobs
|
||||||
(Union
|
-- entryBlob <- file entryPath
|
||||||
(ValueConstructors Precise)
|
-- entryTerm <- runTask (parse pythonParser entryBlob)
|
||||||
(Term (Union Python.Syntax) (Record Location))),
|
-- pure (zip blobs terms, (entryBlob, entryTerm))
|
||||||
Store Precise PythonValue)
|
--
|
||||||
evaluatePythonFiles paths = do
|
-- evaluatePythonFiles :: [FilePath]
|
||||||
blobs@(b:bs) <- traverse file paths
|
-- -> IO
|
||||||
(t:ts) <- runTask $ traverse (parse pythonParser) blobs
|
-- (Either
|
||||||
pure $ evaluates @PythonValue (zip bs ts) (b, t)
|
-- Prelude.String
|
||||||
|
-- (Union
|
||||||
diffWithParser :: (HasField fields Data.Span.Span,
|
-- (ValueConstructors Precise)
|
||||||
HasField fields Range,
|
-- (Term (Union Python.Syntax) (Record Location))),
|
||||||
Eq1 syntax, Show1 syntax,
|
-- Store Precise PythonValue)
|
||||||
Traversable syntax, Functor syntax,
|
-- evaluatePythonFiles paths = do
|
||||||
Foldable syntax, Diffable syntax,
|
-- blobs@(b:bs) <- traverse file paths
|
||||||
GAlign syntax, HasDeclaration syntax)
|
-- (t:ts) <- runTask $ traverse (parse pythonParser) blobs
|
||||||
=>
|
-- pure $ evaluates @PythonValue (zip bs ts) (b, t)
|
||||||
Parser (Term syntax (Record fields))
|
--
|
||||||
-> BlobPair
|
-- diffWithParser :: (HasField fields Data.Span.Span,
|
||||||
-> Task (Diff syntax (Record (Maybe Declaration ': fields)) (Record (Maybe Declaration ': fields)))
|
-- HasField fields Range,
|
||||||
diffWithParser parser = run (\ blob -> parse parser blob >>= decorate (declarationAlgebra blob))
|
-- Eq1 syntax, Show1 syntax,
|
||||||
where
|
-- Traversable syntax, Functor syntax,
|
||||||
run parse blobs = bidistributeFor (runJoin blobs) parse parse >>= diffTermPair diffTerms
|
-- Foldable syntax, Diffable syntax,
|
||||||
|
-- GAlign syntax, HasDeclaration syntax)
|
||||||
diffBlobWithParser :: (HasField fields Data.Span.Span,
|
-- =>
|
||||||
HasField fields Range,
|
-- Parser (Term syntax (Record fields))
|
||||||
Eq1 syntax, Show1 syntax,
|
-- -> BlobPair
|
||||||
Traversable syntax, Functor syntax,
|
-- -> Task (Diff syntax (Record (Maybe Declaration ': fields)) (Record (Maybe Declaration ': fields)))
|
||||||
Foldable syntax, Diffable syntax,
|
-- diffWithParser parser = run (\ blob -> parse parser blob >>= decorate (declarationAlgebra blob))
|
||||||
GAlign syntax, HasDeclaration syntax)
|
-- where
|
||||||
=> Parser (Term syntax (Record fields))
|
-- run parse blobs = bidistributeFor (runJoin blobs) parse parse >>= diffTermPair diffTerms
|
||||||
-> Blob
|
--
|
||||||
-> Task (Term syntax (Record (Maybe Declaration : fields)))
|
-- diffBlobWithParser :: (HasField fields Data.Span.Span,
|
||||||
diffBlobWithParser parser = run (\ blob -> parse parser blob >>= decorate (declarationAlgebra blob))
|
-- HasField fields Range,
|
||||||
where
|
-- Eq1 syntax, Show1 syntax,
|
||||||
run parse = parse
|
-- Traversable syntax, Functor syntax,
|
||||||
|
-- Foldable syntax, Diffable syntax,
|
||||||
|
-- GAlign syntax, HasDeclaration syntax)
|
||||||
|
-- => Parser (Term syntax (Record fields))
|
||||||
|
-- -> Blob
|
||||||
|
-- -> Task (Term syntax (Record (Maybe Declaration : fields)))
|
||||||
|
-- diffBlobWithParser parser = run (\ blob -> parse parser blob >>= decorate (declarationAlgebra blob))
|
||||||
|
-- where
|
||||||
|
-- run parse = parse
|
||||||
|
Loading…
Reference in New Issue
Block a user