1
1
mirror of https://github.com/github/semantic.git synced 2025-01-03 21:16:12 +03:00

Eval test harness for Ruby

This commit is contained in:
Timothy Clem 2018-02-16 13:37:56 -08:00
parent e0272ae982
commit e46d92dc65

View File

@ -2,19 +2,25 @@
{-# LANGUAGE DataKinds, MonoLocalBinds, TypeOperators, TypeApplications #-}
module Semantic.Util where
import Analysis.Abstract.Evaluating2
import Analysis.Declaration
import Analysis.Abstract.Evaluating
import Control.Monad.IO.Class
import Data.Abstract.Address
import Data.Abstract.Store
import Data.Abstract.Value
import Data.Align.Generic
import Data.Maybe
import Data.AST
import Data.Bifunctor.Join
import Data.Blob
import Data.Diff
import Data.Functor.Classes
import Data.Bifunctor.Join
import Data.Maybe
import Data.Range
import Data.Record
import Data.Span
import Data.Term
import Data.Union
import Diffing.Algorithm
import Diffing.Interpreter
import Parsing.Parser
@ -22,62 +28,62 @@ import Semantic
import Semantic.IO as IO
import Semantic.Task
import Data.AST
import Data.Union
import Data.Abstract.Value
import Data.Abstract.Store
import Data.Abstract.Address
import qualified Language.Python.Assignment as Python
import qualified Language.Ruby.Assignment as Ruby
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 path = fromJust <$> IO.readFile path (languageForFilePath path)
parsePythonFiles :: [FilePath] -> FilePath -> IO ([(Blob, Python.Term)], (Blob, Python.Term))
parsePythonFiles paths entryPath = do
blobs <- traverse file paths
terms <- runTask $ traverse (parse pythonParser) blobs
entryBlob <- file entryPath
entryTerm <- runTask (parse pythonParser entryBlob)
pure (zip blobs terms, (entryBlob, entryTerm))
-- evaluatePythonFile :: FilePath -> _
evaluateRubyFile path = file path
>>= runTask . parse rubyParser2
>>= pure . Prelude.fst . evaluate @RubyValue
evaluatePythonFiles :: [FilePath]
-> IO
(Either
Prelude.String
(Union
(ValueConstructors Precise)
(Term (Union Python.Syntax) (Record Location))),
Store Precise PythonValue)
evaluatePythonFiles paths = do
blobs@(b:bs) <- traverse file paths
(t:ts) <- runTask $ traverse (parse pythonParser) blobs
pure $ evaluates @PythonValue (zip bs ts) (b, t)
diffWithParser :: (HasField fields Data.Span.Span,
HasField fields Range,
Eq1 syntax, Show1 syntax,
Traversable syntax, Functor syntax,
Foldable syntax, Diffable syntax,
GAlign syntax, HasDeclaration syntax)
=>
Parser (Term syntax (Record fields))
-> BlobPair
-> Task (Diff syntax (Record (Maybe Declaration ': fields)) (Record (Maybe Declaration ': fields)))
diffWithParser parser = run (\ blob -> parse parser blob >>= decorate (declarationAlgebra blob))
where
run parse blobs = bidistributeFor (runJoin blobs) parse parse >>= diffTermPair diffTerms
diffBlobWithParser :: (HasField fields Data.Span.Span,
HasField fields Range,
Eq1 syntax, Show1 syntax,
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
-- parsePythonFiles :: [FilePath] -> FilePath -> IO ([(Blob, Python.Term)], (Blob, Python.Term))
-- parsePythonFiles paths entryPath = do
-- blobs <- traverse file paths
-- terms <- runTask $ traverse (parse pythonParser) blobs
-- entryBlob <- file entryPath
-- entryTerm <- runTask (parse pythonParser entryBlob)
-- pure (zip blobs terms, (entryBlob, entryTerm))
--
-- evaluatePythonFiles :: [FilePath]
-- -> IO
-- (Either
-- Prelude.String
-- (Union
-- (ValueConstructors Precise)
-- (Term (Union Python.Syntax) (Record Location))),
-- Store Precise PythonValue)
-- evaluatePythonFiles paths = do
-- blobs@(b:bs) <- traverse file paths
-- (t:ts) <- runTask $ traverse (parse pythonParser) blobs
-- pure $ evaluates @PythonValue (zip bs ts) (b, t)
--
-- diffWithParser :: (HasField fields Data.Span.Span,
-- HasField fields Range,
-- Eq1 syntax, Show1 syntax,
-- Traversable syntax, Functor syntax,
-- Foldable syntax, Diffable syntax,
-- GAlign syntax, HasDeclaration syntax)
-- =>
-- Parser (Term syntax (Record fields))
-- -> BlobPair
-- -> Task (Diff syntax (Record (Maybe Declaration ': fields)) (Record (Maybe Declaration ': fields)))
-- diffWithParser parser = run (\ blob -> parse parser blob >>= decorate (declarationAlgebra blob))
-- where
-- run parse blobs = bidistributeFor (runJoin blobs) parse parse >>= diffTermPair diffTerms
--
-- diffBlobWithParser :: (HasField fields Data.Span.Span,
-- HasField fields Range,
-- Eq1 syntax, Show1 syntax,
-- 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