mirror of
https://github.com/github/semantic.git
synced 2024-12-29 18:06:14 +03:00
Merge remote-tracking branch 'origin/master' into build-fix-em-ups
This commit is contained in:
commit
e580051a66
@ -51,6 +51,7 @@ library
|
|||||||
, Data.Abstract.Live
|
, Data.Abstract.Live
|
||||||
, Data.Abstract.ModuleTable
|
, Data.Abstract.ModuleTable
|
||||||
, Data.Abstract.Number
|
, Data.Abstract.Number
|
||||||
|
, Data.Abstract.Path
|
||||||
, Data.Abstract.Type
|
, Data.Abstract.Type
|
||||||
, Data.Abstract.Value
|
, Data.Abstract.Value
|
||||||
-- General datatype definitions & generic algorithms
|
-- General datatype definitions & generic algorithms
|
||||||
@ -99,6 +100,7 @@ library
|
|||||||
, Language.JSON.Assignment
|
, Language.JSON.Assignment
|
||||||
, Language.Ruby.Grammar
|
, Language.Ruby.Grammar
|
||||||
, Language.Ruby.Assignment
|
, Language.Ruby.Assignment
|
||||||
|
, Language.Ruby.Syntax
|
||||||
, Language.TypeScript.Assignment
|
, Language.TypeScript.Assignment
|
||||||
, Language.TypeScript.Grammar
|
, Language.TypeScript.Grammar
|
||||||
, Language.TypeScript.Syntax
|
, Language.TypeScript.Syntax
|
||||||
@ -208,6 +210,7 @@ test-suite test
|
|||||||
other-modules: Assigning.Assignment.Spec
|
other-modules: Assigning.Assignment.Spec
|
||||||
, Analysis.Go.Spec
|
, Analysis.Go.Spec
|
||||||
, Analysis.Python.Spec
|
, Analysis.Python.Spec
|
||||||
|
, Analysis.Ruby.Spec
|
||||||
, Analysis.TypeScript.Spec
|
, Analysis.TypeScript.Spec
|
||||||
, Data.Diff.Spec
|
, Data.Diff.Spec
|
||||||
, Data.Functor.Classes.Generic.Spec
|
, Data.Functor.Classes.Generic.Spec
|
||||||
|
@ -14,7 +14,6 @@ import Control.Monad.Effect.Reader
|
|||||||
import Control.Monad.Effect.State
|
import Control.Monad.Effect.State
|
||||||
import Data.Abstract.Configuration
|
import Data.Abstract.Configuration
|
||||||
import Data.Abstract.Evaluatable
|
import Data.Abstract.Evaluatable
|
||||||
import Data.Abstract.Address
|
|
||||||
import Data.Abstract.ModuleTable
|
import Data.Abstract.ModuleTable
|
||||||
import Data.Abstract.Value
|
import Data.Abstract.Value
|
||||||
import Data.Blob
|
import Data.Blob
|
||||||
@ -81,12 +80,11 @@ type EvaluatingEffects term value
|
|||||||
= '[ Fail -- Failure with an error message
|
= '[ Fail -- Failure with an error message
|
||||||
, Reader (EnvironmentFor value) -- Local environment (e.g. binding over a closure)
|
, Reader (EnvironmentFor value) -- Local environment (e.g. binding over a closure)
|
||||||
, State (EnvironmentFor value) -- Global (imperative) environment
|
, State (EnvironmentFor value) -- Global (imperative) environment
|
||||||
, State (HeapFor value) -- The heap
|
, State (HeapFor value) -- The heap
|
||||||
, Reader (ModuleTable [term]) -- Cache of unevaluated modules
|
, Reader (ModuleTable [term]) -- Cache of unevaluated modules
|
||||||
, State (ModuleTable (EnvironmentFor value)) -- Cache of evaluated modules
|
, State (ModuleTable (EnvironmentFor value)) -- Cache of evaluated modules
|
||||||
|
, State (ExportsFor value) -- Exports (used to filter environments when they are imported)
|
||||||
, State (Map Name (Name, Maybe (Address (LocationFor value) value))) -- Set of exports
|
, State (IntMap.IntMap term) -- For jumps
|
||||||
, State (IntMap.IntMap term) -- For jumps
|
|
||||||
]
|
]
|
||||||
|
|
||||||
instance Members '[Fail, State (IntMap.IntMap term)] effects => MonadControl term (Evaluating term value effects) where
|
instance Members '[Fail, State (IntMap.IntMap term)] effects => MonadControl term (Evaluating term value effects) where
|
||||||
@ -98,13 +96,13 @@ instance Members '[Fail, State (IntMap.IntMap term)] effects => MonadControl ter
|
|||||||
|
|
||||||
goto label = IntMap.lookup label <$> raise get >>= maybe (fail ("unknown label: " <> show label)) pure
|
goto label = IntMap.lookup label <$> raise get >>= maybe (fail ("unknown label: " <> show label)) pure
|
||||||
|
|
||||||
instance Members '[State (Map Name (Name, Maybe (Address (LocationFor value) value))), Reader (EnvironmentFor value), State (EnvironmentFor value)] effects => MonadEnvironment value (Evaluating term value effects) where
|
instance Members '[State (ExportsFor value), Reader (EnvironmentFor value), State (EnvironmentFor value)] effects => MonadEnvironment value (Evaluating term value effects) where
|
||||||
getGlobalEnv = raise get
|
getGlobalEnv = raise get
|
||||||
putGlobalEnv = raise . put
|
putGlobalEnv = raise . put
|
||||||
withGlobalEnv s = raise . localState s . lower
|
withGlobalEnv s = raise . localState s . lower
|
||||||
|
|
||||||
addExport key = raise . modify . Map.insert key
|
|
||||||
getExports = raise get
|
getExports = raise get
|
||||||
|
putExports = raise . put
|
||||||
withExports s = raise . localState s . lower
|
withExports s = raise . localState s . lower
|
||||||
|
|
||||||
askLocalEnv = raise ask
|
askLocalEnv = raise ask
|
||||||
|
@ -18,6 +18,7 @@ import Data.Abstract.FreeVariables
|
|||||||
import qualified Data.Syntax as Syntax
|
import qualified Data.Syntax as Syntax
|
||||||
import qualified Data.Syntax.Declaration as Declaration
|
import qualified Data.Syntax.Declaration as Declaration
|
||||||
import qualified Data.Syntax.Expression as Expression
|
import qualified Data.Syntax.Expression as Expression
|
||||||
|
import qualified Language.Ruby.Syntax as Ruby.Syntax
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import qualified Data.Text.Encoding as T
|
import qualified Data.Text.Encoding as T
|
||||||
import qualified Language.Markdown.Syntax as Markdown
|
import qualified Language.Markdown.Syntax as Markdown
|
||||||
@ -98,54 +99,59 @@ instance CustomHasDeclaration whole Declaration.Function where
|
|||||||
-- Do not summarize anonymous functions
|
-- Do not summarize anonymous functions
|
||||||
| isEmpty identifierAnn = Nothing
|
| isEmpty identifierAnn = Nothing
|
||||||
-- Named functions
|
-- Named functions
|
||||||
| otherwise = Just $ FunctionDeclaration (getSource identifierAnn) (getFunctionSource blob (In ann decl)) blobLanguage
|
| otherwise = Just $ FunctionDeclaration (getSource blobSource identifierAnn) (getFunctionSource blob (In ann decl)) blobLanguage
|
||||||
where getSource = toText . flip Source.slice blobSource . getField
|
where isEmpty = (== 0) . rangeLength . getField
|
||||||
isEmpty = (== 0) . rangeLength . getField
|
|
||||||
|
|
||||||
-- | Produce a 'MethodDeclaration' for 'Declaration.Method' nodes. If the method’s receiver is non-empty (defined as having a non-empty 'Range'), the 'declarationIdentifier' will be formatted as 'receiver.method_name'; otherwise it will be simply 'method_name'.
|
-- | Produce a 'MethodDeclaration' for 'Declaration.Method' nodes. If the method’s receiver is non-empty (defined as having a non-empty 'Range'), the 'declarationIdentifier' will be formatted as 'receiver.method_name'; otherwise it will be simply 'method_name'.
|
||||||
instance CustomHasDeclaration whole Declaration.Method where
|
instance CustomHasDeclaration whole Declaration.Method where
|
||||||
customToDeclaration blob@Blob{..} ann decl@(Declaration.Method _ (Term (In receiverAnn receiverF), _) (Term (In identifierAnn _), _) _ _)
|
customToDeclaration blob@Blob{..} ann decl@(Declaration.Method _ (Term (In receiverAnn receiverF), _) (Term (In identifierAnn _), _) _ _)
|
||||||
-- Methods without a receiver
|
-- Methods without a receiver
|
||||||
| isEmpty receiverAnn = Just $ MethodDeclaration (getSource identifierAnn) (getMethodSource blob (In ann decl)) blobLanguage Nothing
|
| isEmpty receiverAnn = Just $ MethodDeclaration (getSource blobSource identifierAnn) (getMethodSource blob (In ann decl)) blobLanguage Nothing
|
||||||
-- Methods with a receiver type and an identifier (e.g. (a *Type) in Go).
|
-- Methods with a receiver type and an identifier (e.g. (a *Type) in Go).
|
||||||
| blobLanguage == Just Go
|
| blobLanguage == Just Go
|
||||||
, [ _, Term (In receiverType _) ] <- toList receiverF = Just $ MethodDeclaration (getSource identifierAnn) (getMethodSource blob (In ann decl)) blobLanguage (Just (getSource receiverType))
|
, [ _, Term (In receiverType _) ] <- toList receiverF = Just $ MethodDeclaration (getSource blobSource identifierAnn) (getMethodSource blob (In ann decl)) blobLanguage (Just (getSource blobSource receiverType))
|
||||||
-- Methods with a receiver (class methods) are formatted like `receiver.method_name`
|
-- Methods with a receiver (class methods) are formatted like `receiver.method_name`
|
||||||
| otherwise = Just $ MethodDeclaration (getSource identifierAnn) (getMethodSource blob (In ann decl)) blobLanguage (Just (getSource receiverAnn))
|
| otherwise = Just $ MethodDeclaration (getSource blobSource identifierAnn) (getMethodSource blob (In ann decl)) blobLanguage (Just (getSource blobSource receiverAnn))
|
||||||
where getSource = toText . flip Source.slice blobSource . getField
|
where isEmpty = (== 0) . rangeLength . getField
|
||||||
isEmpty = (== 0) . rangeLength . getField
|
|
||||||
|
|
||||||
-- | Produce a 'ClassDeclaration' for 'Declaration.Class' nodes.
|
-- | Produce a 'ClassDeclaration' for 'Declaration.Class' nodes.
|
||||||
instance CustomHasDeclaration whole Declaration.Class where
|
instance CustomHasDeclaration whole Declaration.Class where
|
||||||
customToDeclaration blob@Blob{..} ann decl@(Declaration.Class _ (Term (In identifierAnn _), _) _ _)
|
customToDeclaration blob@Blob{..} ann decl@(Declaration.Class _ (Term (In identifierAnn _), _) _ _)
|
||||||
-- Classes
|
= Just $ ClassDeclaration (getSource blobSource identifierAnn) (getClassSource blob (In ann decl)) blobLanguage
|
||||||
= Just $ ClassDeclaration (getSource identifierAnn) (getClassSource blob (In ann decl)) blobLanguage
|
|
||||||
where getSource = toText . flip Source.slice blobSource . getField
|
|
||||||
|
|
||||||
instance CustomHasDeclaration (Union fs) Declaration.Import where
|
instance CustomHasDeclaration (Union fs) Declaration.Import where
|
||||||
customToDeclaration Blob{..} _ (Declaration.Import (Term (In fromAnn _), _) symbols)
|
customToDeclaration Blob{..} _ (Declaration.Import (Term (In fromAnn _), _) symbols _)
|
||||||
= Just $ ImportDeclaration ((stripQuotes . getSource) fromAnn) "" (fmap getSymbol symbols) blobLanguage
|
= Just $ ImportDeclaration ((stripQuotes . getSource blobSource) fromAnn) "" (fmap getSymbol symbols) blobLanguage
|
||||||
where
|
where
|
||||||
stripQuotes = T.dropAround (`elem` ['"', '\''])
|
|
||||||
getSource = toText . flip Source.slice blobSource . getField
|
|
||||||
getSymbol = let f = (T.decodeUtf8 . friendlyName) in bimap f f
|
getSymbol = let f = (T.decodeUtf8 . friendlyName) in bimap f f
|
||||||
|
|
||||||
instance (Syntax.Identifier :< fs) => CustomHasDeclaration (Union fs) Declaration.QualifiedImport where
|
instance (Syntax.Identifier :< fs) => CustomHasDeclaration (Union fs) Declaration.QualifiedImport where
|
||||||
customToDeclaration Blob{..} _ (Declaration.QualifiedImport (Term (In fromAnn _), _) (Term (In aliasAnn aliasF), _) symbols)
|
customToDeclaration Blob{..} _ (Declaration.QualifiedImport (Term (In fromAnn _), _) (Term (In aliasAnn aliasF), _) symbols)
|
||||||
| Just (Syntax.Identifier alias) <- prj aliasF = Just $ ImportDeclaration ((stripQuotes . getSource) fromAnn) (toName alias) (fmap getSymbol symbols) blobLanguage
|
| Just (Syntax.Identifier alias) <- prj aliasF = Just $ ImportDeclaration ((stripQuotes . getSource blobSource) fromAnn) (toName alias) (fmap getSymbol symbols) blobLanguage
|
||||||
| otherwise = Just $ ImportDeclaration ((stripQuotes . getSource) fromAnn) (getSource aliasAnn) (fmap getSymbol symbols) blobLanguage
|
| otherwise = Just $ ImportDeclaration ((stripQuotes . getSource blobSource) fromAnn) (getSource blobSource aliasAnn) (fmap getSymbol symbols) blobLanguage
|
||||||
where
|
where
|
||||||
stripQuotes = T.dropAround (`elem` ['"', '\''])
|
|
||||||
getSource = toText . flip Source.slice blobSource . getField
|
|
||||||
getSymbol = bimap toName toName
|
getSymbol = bimap toName toName
|
||||||
toName = T.decodeUtf8 . friendlyName
|
toName = T.decodeUtf8 . friendlyName
|
||||||
|
|
||||||
instance CustomHasDeclaration (Union fs) Declaration.WildcardImport where
|
instance CustomHasDeclaration (Union fs) Declaration.SideEffectImport where
|
||||||
customToDeclaration Blob{..} _ (Declaration.WildcardImport (Term (In fromAnn _), _) _)
|
customToDeclaration Blob{..} _ (Declaration.SideEffectImport (Term (In fromAnn _), _) _)
|
||||||
= Just $ ImportDeclaration ((stripQuotes . getSource) fromAnn) "" [] blobLanguage
|
= Just $ ImportDeclaration ((stripQuotes . getSource blobSource) fromAnn) "" [] blobLanguage
|
||||||
where
|
|
||||||
stripQuotes = T.dropAround (`elem` ['"', '\''])
|
instance CustomHasDeclaration (Union fs) Ruby.Syntax.Require where
|
||||||
getSource = toText . flip Source.slice blobSource . getField
|
customToDeclaration Blob{..} _ (Ruby.Syntax.Require _ (Term (In fromAnn _), _))
|
||||||
|
= Just $ ImportDeclaration ((stripQuotes . getSource blobSource) fromAnn) "" [] blobLanguage
|
||||||
|
|
||||||
|
instance CustomHasDeclaration (Union fs) Ruby.Syntax.Load where
|
||||||
|
customToDeclaration Blob{..} _ (Ruby.Syntax.Load ((Term (In fromArgs _), _):_))
|
||||||
|
= Just $ ImportDeclaration ((stripQuotes . getSource blobSource) fromArgs) "" [] blobLanguage
|
||||||
|
customToDeclaration Blob{..} _ (Ruby.Syntax.Load _)
|
||||||
|
= Nothing
|
||||||
|
|
||||||
|
getSource :: HasField fields Range => Source -> Record fields -> Text
|
||||||
|
getSource blobSource = toText . flip Source.slice blobSource . getField
|
||||||
|
|
||||||
|
stripQuotes :: Text -> Text
|
||||||
|
stripQuotes = T.dropAround (`elem` ['"', '\''])
|
||||||
|
|
||||||
instance (Syntax.Identifier :< fs, Expression.MemberAccess :< fs) => CustomHasDeclaration (Union fs) Expression.Call where
|
instance (Syntax.Identifier :< fs, Expression.MemberAccess :< fs) => CustomHasDeclaration (Union fs) Expression.Call where
|
||||||
customToDeclaration Blob{..} _ (Expression.Call _ (Term (In fromAnn fromF), _) _ _)
|
customToDeclaration Blob{..} _ (Expression.Call _ (Term (In fromAnn fromF), _) _ _)
|
||||||
@ -184,7 +190,8 @@ type family DeclarationStrategy syntax where
|
|||||||
DeclarationStrategy Declaration.Function = 'Custom
|
DeclarationStrategy Declaration.Function = 'Custom
|
||||||
DeclarationStrategy Declaration.Import = 'Custom
|
DeclarationStrategy Declaration.Import = 'Custom
|
||||||
DeclarationStrategy Declaration.QualifiedImport = 'Custom
|
DeclarationStrategy Declaration.QualifiedImport = 'Custom
|
||||||
DeclarationStrategy Declaration.WildcardImport = 'Custom
|
DeclarationStrategy Declaration.SideEffectImport = 'Custom
|
||||||
|
DeclarationStrategy Ruby.Syntax.Require = 'Custom
|
||||||
DeclarationStrategy Declaration.Method = 'Custom
|
DeclarationStrategy Declaration.Method = 'Custom
|
||||||
DeclarationStrategy Markdown.Heading = 'Custom
|
DeclarationStrategy Markdown.Heading = 'Custom
|
||||||
DeclarationStrategy Expression.Call = 'Custom
|
DeclarationStrategy Expression.Call = 'Custom
|
||||||
|
@ -42,6 +42,10 @@ class (MonadEvaluator term value m, Recursive term) => MonadAnalysis term value
|
|||||||
evaluateModule :: term -> m value
|
evaluateModule :: term -> m value
|
||||||
evaluateModule = evaluateTerm
|
evaluateModule = evaluateTerm
|
||||||
|
|
||||||
|
-- | Isolate the given action with an empty global environment and exports.
|
||||||
|
isolate :: m a -> m a
|
||||||
|
isolate = withGlobalEnv mempty . withExports mempty
|
||||||
|
|
||||||
-- | Evaluate a term to a value using the semantics of the current analysis.
|
-- | Evaluate a term to a value using the semantics of the current analysis.
|
||||||
--
|
--
|
||||||
-- This should always be called when e.g. evaluating the bodies of closures instead of explicitly folding either 'eval' or 'analyzeTerm' over subterms, except in 'MonadAnalysis' instances themselves. On the other hand, top-level evaluation should be performed using 'evaluateModule'.
|
-- This should always be called when e.g. evaluating the bodies of closures instead of explicitly folding either 'eval' or 'analyzeTerm' over subterms, except in 'MonadAnalysis' instances themselves. On the other hand, top-level evaluation should be performed using 'evaluateModule'.
|
||||||
@ -68,19 +72,25 @@ load :: ( MonadAnalysis term value m
|
|||||||
=> ModuleName
|
=> ModuleName
|
||||||
-> m (EnvironmentFor value)
|
-> m (EnvironmentFor value)
|
||||||
load name = askModuleTable >>= maybe notFound evalAndCache . moduleTableLookup name
|
load name = askModuleTable >>= maybe notFound evalAndCache . moduleTableLookup name
|
||||||
where notFound = fail ("cannot load module: " <> show name)
|
where
|
||||||
evalAndCache :: (MonadAnalysis term value m, Ord (LocationFor value)) => [term] -> m (EnvironmentFor value)
|
notFound = fail ("cannot load module: " <> show name)
|
||||||
evalAndCache [] = pure mempty
|
evalAndCache :: (MonadAnalysis term value m, Ord (LocationFor value)) => [term] -> m (EnvironmentFor value)
|
||||||
evalAndCache (x:xs) = do
|
evalAndCache [] = pure mempty
|
||||||
void $ evaluateModule x
|
evalAndCache (x:xs) = do
|
||||||
env <- getGlobalEnv
|
void $ evaluateModule x
|
||||||
exports <- getExports
|
env <- filterEnv <$> getExports <*> getGlobalEnv
|
||||||
-- TODO: If the set of exports is empty because no exports have been
|
modifyModuleTable (moduleTableInsert name env)
|
||||||
-- defined, do we export all terms, or no terms? This behavior varies across
|
(env <>) <$> evalAndCache xs
|
||||||
-- languages. We need better semantics rather than doing it ad-hoc.
|
|
||||||
let env' = if Map.null exports then env else bindExports exports env
|
-- TODO: If the set of exports is empty because no exports have been
|
||||||
modifyModuleTable (moduleTableInsert name env')
|
-- defined, do we export all terms, or no terms? This behavior varies across
|
||||||
(env' <>) <$> evalAndCache xs
|
-- languages. We need better semantics rather than doing it ad-hoc.
|
||||||
|
filterEnv :: (Ord l) => Exports l a -> Environment l a -> Environment l a
|
||||||
|
filterEnv Exports{..} env
|
||||||
|
| Map.null unExports = env
|
||||||
|
| otherwise = Environment $ Map.foldrWithKey maybeInsert mempty unExports
|
||||||
|
where maybeInsert name (alias, address) accum =
|
||||||
|
maybe accum (\v -> Map.insert alias v accum) (address <|> envLookup name env)
|
||||||
|
|
||||||
-- | Lift a 'SubtermAlgebra' for an underlying analysis into a containing analysis. Use this when defining an analysis which can be composed onto other analyses to ensure that a call to 'analyzeTerm' occurs in the inner analysis and not the outer one.
|
-- | Lift a 'SubtermAlgebra' for an underlying analysis into a containing analysis. Use this when defining an analysis which can be composed onto other analyses to ensure that a call to 'analyzeTerm' occurs in the inner analysis and not the outer one.
|
||||||
liftAnalyze :: ( Coercible ( m term value (effects :: [* -> *]) value) (t m term value effects value)
|
liftAnalyze :: ( Coercible ( m term value (effects :: [* -> *]) value) (t m term value effects value)
|
||||||
|
@ -3,6 +3,8 @@ module Control.Abstract.Evaluator
|
|||||||
( MonadEvaluator(..)
|
( MonadEvaluator(..)
|
||||||
, MonadEnvironment(..)
|
, MonadEnvironment(..)
|
||||||
, modifyGlobalEnv
|
, modifyGlobalEnv
|
||||||
|
, modifyExports
|
||||||
|
, addExport
|
||||||
, MonadHeap(..)
|
, MonadHeap(..)
|
||||||
, modifyHeap
|
, modifyHeap
|
||||||
, lookupHeap
|
, lookupHeap
|
||||||
@ -20,7 +22,7 @@ import Data.Abstract.Heap
|
|||||||
import Data.Abstract.ModuleTable
|
import Data.Abstract.ModuleTable
|
||||||
import Data.Abstract.Value
|
import Data.Abstract.Value
|
||||||
import Data.Semigroup.Reducer
|
import Data.Semigroup.Reducer
|
||||||
import Prelude hiding (fail)
|
import Prelude
|
||||||
import Prologue
|
import Prologue
|
||||||
|
|
||||||
-- | A 'Monad' providing the basic essentials for evaluation.
|
-- | A 'Monad' providing the basic essentials for evaluation.
|
||||||
@ -45,14 +47,15 @@ class Monad m => MonadEnvironment value m | m -> value where
|
|||||||
getGlobalEnv :: m (EnvironmentFor value)
|
getGlobalEnv :: m (EnvironmentFor value)
|
||||||
-- | Set the global environment
|
-- | Set the global environment
|
||||||
putGlobalEnv :: EnvironmentFor value -> m ()
|
putGlobalEnv :: EnvironmentFor value -> m ()
|
||||||
|
-- | Sets the global environment for the lifetime of the given action.
|
||||||
withGlobalEnv :: EnvironmentFor value -> m a -> m a
|
withGlobalEnv :: EnvironmentFor value -> m a -> m a
|
||||||
|
|
||||||
-- | Add an export to the global export state.
|
|
||||||
addExport :: Name -> (Name, Maybe (Address (LocationFor value) value)) -> m ()
|
|
||||||
-- | Get the global export state.
|
-- | Get the global export state.
|
||||||
getExports :: m (Map Name (Name, Maybe (Address (LocationFor value) value)))
|
getExports :: m (ExportsFor value)
|
||||||
-- | Sets the exports state to the given map for the lifetime of the given action.
|
-- | Set the global export state.
|
||||||
withExports :: Map Name (Name, Maybe (Address (LocationFor value) value)) -> m a -> m a
|
putExports :: ExportsFor value -> m ()
|
||||||
|
-- | Sets the global export state for the lifetime of the given action.
|
||||||
|
withExports :: ExportsFor value -> m a -> m a
|
||||||
|
|
||||||
-- | Retrieve the local environment.
|
-- | Retrieve the local environment.
|
||||||
askLocalEnv :: m (EnvironmentFor value)
|
askLocalEnv :: m (EnvironmentFor value)
|
||||||
@ -70,11 +73,20 @@ class Monad m => MonadEnvironment value m | m -> value where
|
|||||||
maybe (pure Nothing) (fmap Just . with) addr
|
maybe (pure Nothing) (fmap Just . with) addr
|
||||||
|
|
||||||
-- | Update the global environment.
|
-- | Update the global environment.
|
||||||
modifyGlobalEnv :: MonadEnvironment value m => (EnvironmentFor value -> EnvironmentFor value) -> m ()
|
modifyGlobalEnv :: MonadEnvironment value m => (EnvironmentFor value -> EnvironmentFor value) -> m ()
|
||||||
modifyGlobalEnv f = do
|
modifyGlobalEnv f = do
|
||||||
env <- getGlobalEnv
|
env <- getGlobalEnv
|
||||||
putGlobalEnv $! f env
|
putGlobalEnv $! f env
|
||||||
|
|
||||||
|
-- | Update the global export state.
|
||||||
|
modifyExports :: MonadEnvironment value m => (ExportsFor value -> ExportsFor value) -> m ()
|
||||||
|
modifyExports f = do
|
||||||
|
exports <- getExports
|
||||||
|
putExports $! f exports
|
||||||
|
|
||||||
|
-- | Add an export to the global export state.
|
||||||
|
addExport :: MonadEnvironment value m => Name -> Name -> Maybe (Address (LocationFor value) value) -> m ()
|
||||||
|
addExport name alias = modifyExports . exportInsert name alias
|
||||||
|
|
||||||
-- | A 'Monad' abstracting a heap of values.
|
-- | A 'Monad' abstracting a heap of values.
|
||||||
class Monad m => MonadHeap value m | m -> value where
|
class Monad m => MonadHeap value m | m -> value where
|
||||||
|
@ -80,6 +80,9 @@ class (Monad m, Show value) => MonadValue value m where
|
|||||||
-- | Construct an array of zero or more values.
|
-- | Construct an array of zero or more values.
|
||||||
array :: [value] -> m value
|
array :: [value] -> m value
|
||||||
|
|
||||||
|
-- | Extract a 'ByteString' from a given value.
|
||||||
|
asString :: value -> m ByteString
|
||||||
|
|
||||||
-- | Eliminate boolean values. TODO: s/boolean/truthy
|
-- | Eliminate boolean values. TODO: s/boolean/truthy
|
||||||
ifthenelse :: value -> m a -> m a -> m a
|
ifthenelse :: value -> m a -> m a -> m a
|
||||||
|
|
||||||
@ -142,9 +145,12 @@ instance ( Monad m
|
|||||||
rational = pure . injValue . Value.Rational . Ratio
|
rational = pure . injValue . Value.Rational . Ratio
|
||||||
|
|
||||||
multiple = pure . injValue . Value.Tuple
|
multiple = pure . injValue . Value.Tuple
|
||||||
|
|
||||||
array = pure . injValue . Value.Array
|
array = pure . injValue . Value.Array
|
||||||
|
|
||||||
|
asString v
|
||||||
|
| Just (Value.String n) <- prjValue v = pure n
|
||||||
|
| otherwise = fail ("expected " <> show v <> " to be a string")
|
||||||
|
|
||||||
ifthenelse cond if' else'
|
ifthenelse cond if' else'
|
||||||
| Just (Boolean b) <- prjValue cond = if b then if' else else'
|
| Just (Boolean b) <- prjValue cond = if b then if' else else'
|
||||||
| otherwise = fail ("not defined for non-boolean conditions: " <> show cond)
|
| otherwise = fail ("not defined for non-boolean conditions: " <> show cond)
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
{-# LANGUAGE GeneralizedNewtypeDeriving, MultiParamTypeClasses, StandaloneDeriving #-}
|
{-# LANGUAGE GeneralizedNewtypeDeriving, MultiParamTypeClasses, StandaloneDeriving #-}
|
||||||
module Data.Abstract.Environment where
|
module Data.Abstract.Environment where
|
||||||
|
|
||||||
import Prologue
|
|
||||||
import Data.Abstract.Address
|
import Data.Abstract.Address
|
||||||
import Data.Abstract.FreeVariables
|
import Data.Abstract.FreeVariables
|
||||||
import Data.Abstract.Live
|
import Data.Abstract.Live
|
||||||
import qualified Data.Map as Map
|
|
||||||
import Data.Semigroup.Reducer
|
import Data.Semigroup.Reducer
|
||||||
|
import Prologue
|
||||||
|
import qualified Data.Map as Map
|
||||||
import qualified Data.Set as Set
|
import qualified Data.Set as Set
|
||||||
|
|
||||||
-- | A map of names to addresses that represents the evaluation environment.
|
-- | A map of names to addresses that represents the evaluation environment.
|
||||||
@ -15,6 +15,10 @@ newtype Environment l a = Environment { unEnvironment :: Map.Map Name (Address l
|
|||||||
|
|
||||||
deriving instance Reducer (Name, Address l a) (Environment l a)
|
deriving instance Reducer (Name, Address l a) (Environment l a)
|
||||||
|
|
||||||
|
-- | A map of export names to an alias & address tuple.
|
||||||
|
newtype Exports l a = Exports { unExports :: Map.Map Name (Name, Maybe (Address l a)) }
|
||||||
|
deriving (Eq, Foldable, Functor, Generic1, Monoid, Ord, Semigroup, Show, Traversable)
|
||||||
|
|
||||||
-- | Lookup a 'Name' in the environment.
|
-- | Lookup a 'Name' in the environment.
|
||||||
envLookup :: Name -> Environment l a -> Maybe (Address l a)
|
envLookup :: Name -> Environment l a -> Maybe (Address l a)
|
||||||
envLookup k = Map.lookup k . unEnvironment
|
envLookup k = Map.lookup k . unEnvironment
|
||||||
@ -30,11 +34,8 @@ bindEnv :: Foldable t => t Name -> Environment l a -> Environment l a
|
|||||||
bindEnv names env = foldMap envForName names
|
bindEnv names env = foldMap envForName names
|
||||||
where envForName name = maybe mempty (curry unit name) (envLookup name env)
|
where envForName name = maybe mempty (curry unit name) (envLookup name env)
|
||||||
|
|
||||||
bindExports :: Map Name (Name, Maybe (Address l a)) -> Environment l a -> Environment l a
|
exportInsert :: Name -> Name -> Maybe (Address l a) -> Exports l a -> Exports l a
|
||||||
bindExports aliases env = Environment pairs
|
exportInsert name alias address = Exports . Map.insert name (alias, address) . unExports
|
||||||
where
|
|
||||||
pairs = Map.foldrWithKey (\name (alias, address) accum ->
|
|
||||||
maybe accum (\v -> Map.insert alias v accum) (address <|> envLookup name env)) mempty aliases
|
|
||||||
|
|
||||||
-- | Retrieve the 'Live' set of addresses to which the given free variable names are bound.
|
-- | Retrieve the 'Live' set of addresses to which the given free variable names are bound.
|
||||||
--
|
--
|
||||||
@ -45,8 +46,13 @@ envRoots env = foldMap (maybe mempty liveSingleton . flip envLookup env)
|
|||||||
envAll :: (Ord l) => Environment l a -> Live l a
|
envAll :: (Ord l) => Environment l a -> Live l a
|
||||||
envAll (Environment env) = Live $ Set.fromList (Map.elems env)
|
envAll (Environment env) = Live $ Set.fromList (Map.elems env)
|
||||||
|
|
||||||
|
|
||||||
-- Instances
|
-- Instances
|
||||||
|
|
||||||
instance Eq l => Eq1 (Environment l) where liftEq = genericLiftEq
|
instance Eq l => Eq1 (Environment l) where liftEq = genericLiftEq
|
||||||
instance Ord l => Ord1 (Environment l) where liftCompare = genericLiftCompare
|
instance Ord l => Ord1 (Environment l) where liftCompare = genericLiftCompare
|
||||||
instance Show l => Show1 (Environment l) where liftShowsPrec = genericLiftShowsPrec
|
instance Show l => Show1 (Environment l) where liftShowsPrec = genericLiftShowsPrec
|
||||||
|
|
||||||
|
instance Eq l => Eq1 (Exports l) where liftEq = genericLiftEq
|
||||||
|
instance Ord l => Ord1 (Exports l) where liftCompare = genericLiftCompare
|
||||||
|
instance Show l => Show1 (Exports l) where liftShowsPrec = genericLiftShowsPrec
|
||||||
|
@ -5,16 +5,24 @@ import Prologue
|
|||||||
import Data.Term
|
import Data.Term
|
||||||
import Data.ByteString (intercalate)
|
import Data.ByteString (intercalate)
|
||||||
import qualified Data.List.NonEmpty as NonEmpty
|
import qualified Data.List.NonEmpty as NonEmpty
|
||||||
|
import Data.Abstract.Path
|
||||||
|
|
||||||
-- | The type of variable names.
|
-- | The type of variable names.
|
||||||
type Name = NonEmpty ByteString
|
type Name = NonEmpty ByteString
|
||||||
|
|
||||||
|
-- | Construct a qualified name from a 'ByteString'
|
||||||
name :: ByteString -> Name
|
name :: ByteString -> Name
|
||||||
name x = x :| []
|
name x = x :| []
|
||||||
|
|
||||||
|
-- | Construct a qualified name from a list of 'ByteString's
|
||||||
qualifiedName :: [ByteString] -> Name
|
qualifiedName :: [ByteString] -> Name
|
||||||
qualifiedName = NonEmpty.fromList
|
qualifiedName = NonEmpty.fromList
|
||||||
|
|
||||||
|
-- | Construct a qualified 'Name' from a `/` delimited path.
|
||||||
|
pathToQualifiedName :: ByteString -> Name
|
||||||
|
pathToQualifiedName = qualifiedName . splitOnPathSeparator
|
||||||
|
|
||||||
|
-- | User friendly 'ByteString' of a qualified 'Name'.
|
||||||
friendlyName :: Name -> ByteString
|
friendlyName :: Name -> ByteString
|
||||||
friendlyName xs = intercalate "." (NonEmpty.toList xs)
|
friendlyName xs = intercalate "." (NonEmpty.toList xs)
|
||||||
|
|
||||||
|
24
src/Data/Abstract/Path.hs
Normal file
24
src/Data/Abstract/Path.hs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
module Data.Abstract.Path where
|
||||||
|
|
||||||
|
import Prologue
|
||||||
|
import qualified Data.ByteString.Char8 as BC
|
||||||
|
import qualified Data.ByteString as B
|
||||||
|
import Data.Char (ord)
|
||||||
|
|
||||||
|
-- | Split a 'ByteString' path on `/`, stripping quotes and any `./` prefix.
|
||||||
|
splitOnPathSeparator :: ByteString -> [ByteString]
|
||||||
|
splitOnPathSeparator = splitOnPathSeparator' id
|
||||||
|
|
||||||
|
splitOnPathSeparator' :: (ByteString -> ByteString) -> ByteString -> [ByteString]
|
||||||
|
splitOnPathSeparator' f = BC.split '/' . f . dropRelativePrefix . stripQuotes
|
||||||
|
|
||||||
|
stripQuotes :: ByteString -> ByteString
|
||||||
|
stripQuotes = B.filter (/= fromIntegral (ord '\"'))
|
||||||
|
|
||||||
|
dropRelativePrefix :: ByteString -> ByteString
|
||||||
|
dropRelativePrefix = BC.dropWhile (== '/') . BC.dropWhile (== '.')
|
||||||
|
|
||||||
|
dropExtension :: ByteString -> ByteString
|
||||||
|
dropExtension path = case BC.split '.' path of
|
||||||
|
[] -> path
|
||||||
|
xs -> BC.intercalate "." (Prelude.init xs)
|
@ -134,6 +134,9 @@ instance Show1 Array where liftShowsPrec = genericLiftShowsPrec
|
|||||||
-- | The environment for an abstract value type.
|
-- | The environment for an abstract value type.
|
||||||
type EnvironmentFor v = Environment (LocationFor v) v
|
type EnvironmentFor v = Environment (LocationFor v) v
|
||||||
|
|
||||||
|
-- | The exports for an abstract value type.
|
||||||
|
type ExportsFor v = Exports (LocationFor v) v
|
||||||
|
|
||||||
-- | The 'Heap' for an abstract value type.
|
-- | The 'Heap' for an abstract value type.
|
||||||
type HeapFor value = Heap (LocationFor value) value
|
type HeapFor value = Heap (LocationFor value) value
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ instance Ord1 Identifier where liftCompare = genericLiftCompare
|
|||||||
instance Show1 Identifier where liftShowsPrec = genericLiftShowsPrec
|
instance Show1 Identifier where liftShowsPrec = genericLiftShowsPrec
|
||||||
|
|
||||||
instance Evaluatable Identifier where
|
instance Evaluatable Identifier where
|
||||||
eval (Identifier name) = lookupWith deref name >>= maybe (fail ("free variable: " <> show name)) pure
|
eval (Identifier name) = lookupWith deref name >>= maybe (fail ("free variable: " <> show (friendlyName name))) pure
|
||||||
|
|
||||||
instance FreeVariables1 Identifier where
|
instance FreeVariables1 Identifier where
|
||||||
liftFreeVariables _ (Identifier x) = Set.singleton x
|
liftFreeVariables _ (Identifier x) = Set.singleton x
|
||||||
|
@ -5,6 +5,7 @@ import Data.Abstract.Environment
|
|||||||
import Data.Abstract.Evaluatable
|
import Data.Abstract.Evaluatable
|
||||||
import Diffing.Algorithm
|
import Diffing.Algorithm
|
||||||
import qualified Data.Map as Map
|
import qualified Data.Map as Map
|
||||||
|
import Prelude hiding (fail)
|
||||||
import Prologue
|
import Prologue
|
||||||
|
|
||||||
data Function a = Function { functionContext :: ![a], functionName :: !a, functionParameters :: ![a], functionBody :: !a }
|
data Function a = Function { functionContext :: ![a], functionName :: !a, functionParameters :: ![a], functionBody :: !a }
|
||||||
@ -223,7 +224,7 @@ instance Evaluatable QualifiedExport where
|
|||||||
eval (QualifiedExport exportSymbols) = do
|
eval (QualifiedExport exportSymbols) = do
|
||||||
-- Insert the aliases with no addresses.
|
-- Insert the aliases with no addresses.
|
||||||
for_ exportSymbols $ \(name, alias) ->
|
for_ exportSymbols $ \(name, alias) ->
|
||||||
addExport name (alias, Nothing)
|
addExport name alias Nothing
|
||||||
unit
|
unit
|
||||||
|
|
||||||
|
|
||||||
@ -238,12 +239,15 @@ instance Show1 QualifiedExportFrom where liftShowsPrec = genericLiftShowsPrec
|
|||||||
instance Evaluatable QualifiedExportFrom where
|
instance Evaluatable QualifiedExportFrom where
|
||||||
eval (QualifiedExportFrom from exportSymbols) = do
|
eval (QualifiedExportFrom from exportSymbols) = do
|
||||||
let moduleName = freeVariable (subterm from)
|
let moduleName = freeVariable (subterm from)
|
||||||
importedEnv <- withGlobalEnv mempty (require moduleName)
|
importedEnv <- isolate (require moduleName)
|
||||||
-- Look up addresses in importedEnv and insert the aliases with addresses into the exports.
|
-- Look up addresses in importedEnv and insert the aliases with addresses into the exports.
|
||||||
for_ exportSymbols $ \(name, alias) -> do
|
for_ exportSymbols $ \(name, alias) -> do
|
||||||
let address = Map.lookup name (unEnvironment importedEnv)
|
let address = Map.lookup name (unEnvironment importedEnv)
|
||||||
addExport name (alias, address)
|
maybe (cannotExport moduleName name) (addExport name alias . Just) address
|
||||||
unit
|
unit
|
||||||
|
where
|
||||||
|
cannotExport moduleName name = fail $
|
||||||
|
"module " <> show (friendlyName moduleName) <> " does not export " <> show (friendlyName name)
|
||||||
|
|
||||||
|
|
||||||
newtype DefaultExport a = DefaultExport { defaultExport :: a }
|
newtype DefaultExport a = DefaultExport { defaultExport :: a }
|
||||||
@ -257,6 +261,8 @@ instance Evaluatable DefaultExport where
|
|||||||
|
|
||||||
|
|
||||||
-- | Qualified Import declarations (symbols are qualified in calling environment).
|
-- | Qualified Import declarations (symbols are qualified in calling environment).
|
||||||
|
--
|
||||||
|
-- If the list of symbols is empty copy and qualify everything to the calling environment.
|
||||||
data QualifiedImport a = QualifiedImport { qualifiedImportFrom :: !a, qualifiedImportAlias :: !a, qualifiedImportSymbols :: ![(Name, Name)]}
|
data QualifiedImport a = QualifiedImport { qualifiedImportFrom :: !a, qualifiedImportAlias :: !a, qualifiedImportSymbols :: ![(Name, Name)]}
|
||||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1)
|
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1)
|
||||||
|
|
||||||
@ -267,21 +273,21 @@ instance Show1 QualifiedImport where liftShowsPrec = genericLiftShowsPrec
|
|||||||
instance Evaluatable QualifiedImport where
|
instance Evaluatable QualifiedImport where
|
||||||
eval (QualifiedImport from alias xs) = do
|
eval (QualifiedImport from alias xs) = do
|
||||||
let moduleName = freeVariable (subterm from)
|
let moduleName = freeVariable (subterm from)
|
||||||
importedEnv <- withGlobalEnv mempty (require moduleName)
|
importedEnv <- isolate (require moduleName)
|
||||||
modifyGlobalEnv (flip (Map.foldrWithKey copy) (unEnvironment importedEnv))
|
modifyGlobalEnv (flip (Map.foldrWithKey copy) (unEnvironment importedEnv))
|
||||||
unit
|
unit
|
||||||
where
|
where
|
||||||
prefix = freeVariable (subterm alias)
|
prefix = freeVariable (subterm alias)
|
||||||
symbols = Map.fromList xs
|
symbols = Map.fromList xs
|
||||||
copy = if Map.null symbols then qualifyInsert else directInsert
|
copy = if Map.null symbols then insert else maybeInsert
|
||||||
qualifyInsert k v rest = envInsert (prefix <> k) v rest
|
insert sym = envInsert (prefix <> sym)
|
||||||
directInsert k v rest = maybe rest (\symAlias -> envInsert symAlias v rest) (Map.lookup k symbols)
|
maybeInsert sym v env = maybe env (\symAlias -> insert symAlias v env) (Map.lookup sym symbols)
|
||||||
|
|
||||||
|
|
||||||
-- | Import declarations (symbols are added directly to the calling env).
|
-- | Import declarations (symbols are added directly to the calling environment).
|
||||||
--
|
--
|
||||||
-- If symbols is empty, just import the module for its side effects.
|
-- If the list of symbols is empty copy everything to the calling environment.
|
||||||
data Import a = Import { importFrom :: !a, importSymbols :: ![(Name, Name)] }
|
data Import a = Import { importFrom :: !a, importSymbols :: ![(Name, Name)], importWildcardToken :: !a }
|
||||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1)
|
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1)
|
||||||
|
|
||||||
instance Eq1 Import where liftEq = genericLiftEq
|
instance Eq1 Import where liftEq = genericLiftEq
|
||||||
@ -289,31 +295,28 @@ instance Ord1 Import where liftCompare = genericLiftCompare
|
|||||||
instance Show1 Import where liftShowsPrec = genericLiftShowsPrec
|
instance Show1 Import where liftShowsPrec = genericLiftShowsPrec
|
||||||
|
|
||||||
instance Evaluatable Import where
|
instance Evaluatable Import where
|
||||||
eval (Import from xs) = do
|
eval (Import from xs _) = do
|
||||||
let moduleName = freeVariable (subterm from)
|
let moduleName = freeVariable (subterm from)
|
||||||
importedEnv <- withGlobalEnv mempty (require moduleName)
|
importedEnv <- isolate (require moduleName)
|
||||||
modifyGlobalEnv (flip (Map.foldrWithKey directInsert) (unEnvironment importedEnv))
|
modifyGlobalEnv (flip (Map.foldrWithKey copy) (unEnvironment importedEnv))
|
||||||
unit
|
unit
|
||||||
where
|
where
|
||||||
symbols = Map.fromList xs
|
symbols = Map.fromList xs
|
||||||
directInsert k v rest = maybe rest (\symAlias -> envInsert symAlias v rest) (Map.lookup k symbols)
|
copy = if Map.null symbols then envInsert else maybeInsert
|
||||||
|
maybeInsert k v env = maybe env (\symAlias -> envInsert symAlias v env) (Map.lookup k symbols)
|
||||||
|
|
||||||
|
-- | Side effect only imports (no symbols made available to the calling environment).
|
||||||
-- | A wildcard import (all symbols are added directly to the calling env)
|
data SideEffectImport a = SideEffectImport { sideEffectImportFrom :: !a, sideEffectImportToken :: !a }
|
||||||
--
|
|
||||||
-- Import a module updating the importing environments.
|
|
||||||
data WildcardImport a = WildcardImport { wildcardImportFrom :: !a, wildcardImportToken :: !a }
|
|
||||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1)
|
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1)
|
||||||
|
|
||||||
instance Eq1 WildcardImport where liftEq = genericLiftEq
|
instance Eq1 SideEffectImport where liftEq = genericLiftEq
|
||||||
instance Ord1 WildcardImport where liftCompare = genericLiftCompare
|
instance Ord1 SideEffectImport where liftCompare = genericLiftCompare
|
||||||
instance Show1 WildcardImport where liftShowsPrec = genericLiftShowsPrec
|
instance Show1 SideEffectImport where liftShowsPrec = genericLiftShowsPrec
|
||||||
|
|
||||||
instance Evaluatable WildcardImport where
|
instance Evaluatable SideEffectImport where
|
||||||
eval (WildcardImport from _) = do
|
eval (SideEffectImport from _) = do
|
||||||
let moduleName = freeVariable (subterm from)
|
let moduleName = freeVariable (subterm from)
|
||||||
importedEnv <- withGlobalEnv mempty (require moduleName)
|
void $ isolate (require moduleName)
|
||||||
modifyGlobalEnv (flip (Map.foldrWithKey envInsert) (unEnvironment importedEnv))
|
|
||||||
unit
|
unit
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,9 +8,7 @@ module Language.Go.Assignment
|
|||||||
|
|
||||||
import Assigning.Assignment hiding (Assignment, Error)
|
import Assigning.Assignment hiding (Assignment, Error)
|
||||||
import Data.Abstract.FreeVariables
|
import Data.Abstract.FreeVariables
|
||||||
import qualified Data.ByteString.Char8 as BC
|
import Data.Abstract.Path
|
||||||
import qualified Data.ByteString as B
|
|
||||||
import Data.Char (ord)
|
|
||||||
import Data.Record
|
import Data.Record
|
||||||
import Data.Syntax (contextualize, emptyTerm, parseError, handleError, infixContext, makeTerm, makeTerm', makeTerm'', makeTerm1)
|
import Data.Syntax (contextualize, emptyTerm, parseError, handleError, infixContext, makeTerm, makeTerm', makeTerm'', makeTerm1)
|
||||||
import Language.Go.Grammar as Grammar
|
import Language.Go.Grammar as Grammar
|
||||||
@ -33,7 +31,7 @@ type Syntax =
|
|||||||
, Declaration.Function
|
, Declaration.Function
|
||||||
, Declaration.Import
|
, Declaration.Import
|
||||||
, Declaration.QualifiedImport
|
, Declaration.QualifiedImport
|
||||||
, Declaration.WildcardImport
|
, Declaration.SideEffectImport
|
||||||
, Declaration.Method
|
, Declaration.Method
|
||||||
, Declaration.MethodSignature
|
, Declaration.MethodSignature
|
||||||
, Declaration.Module
|
, Declaration.Module
|
||||||
@ -386,27 +384,27 @@ functionDeclaration = makeTerm <$> (symbol FunctionDeclaration <|> symbol FuncL
|
|||||||
importDeclaration :: Assignment
|
importDeclaration :: Assignment
|
||||||
importDeclaration = makeTerm'' <$> symbol ImportDeclaration <*> children (manyTerm (importSpec <|> importSpecList))
|
importDeclaration = makeTerm'' <$> symbol ImportDeclaration <*> children (manyTerm (importSpec <|> importSpecList))
|
||||||
where
|
where
|
||||||
importSpecList = makeTerm <$> symbol ImportSpecList <*> children (manyTerm (importSpec <|> comment))
|
-- `import . "lib/Math"`
|
||||||
importSpec = makeTerm <$> symbol ImportSpec <*> children sideEffectImport
|
dotImport = inj <$> (makeImport <$> dot <*> importFromPath)
|
||||||
<|> makeTerm <$> symbol ImportSpec <*> children dotImport
|
-- dotImport = inj <$> (flip Declaration.Import <$> (symbol Dot *> source *> pure []) <*> importFromPath)
|
||||||
<|> makeTerm <$> symbol ImportSpec <*> children namedImport
|
-- `import _ "lib/Math"`
|
||||||
<|> makeTerm <$> symbol ImportSpec <*> children plainImport
|
sideEffectImport = inj <$> (flip Declaration.SideEffectImport <$> underscore <*> importFromPath)
|
||||||
|
-- `import m "lib/Math"`
|
||||||
dotImport = flip Declaration.WildcardImport <$> (makeTerm <$> symbol Dot <*> (Syntax.Identifier <$> (name <$> source))) <*> importFromPath
|
namedImport = inj <$> (flip Declaration.QualifiedImport <$> packageIdentifier <*> importFromPath <*> pure [])
|
||||||
sideEffectImport = symbol BlankIdentifier *> source *> (Declaration.Import <$> importFromPath <*> pure [])
|
-- `import "lib/Math"`
|
||||||
namedImport = flip Declaration.QualifiedImport <$> packageIdentifier <*> importFromPath <*> pure []
|
plainImport = inj <$> (symbol InterpretedStringLiteral >>= \loc -> do
|
||||||
plainImport = symbol InterpretedStringLiteral >>= \loc -> do
|
names <- splitOnPathSeparator <$> source
|
||||||
names <- pathToNames <$> source
|
|
||||||
let from = makeTerm loc (Syntax.Identifier (qualifiedName names))
|
let from = makeTerm loc (Syntax.Identifier (qualifiedName names))
|
||||||
let alias = makeTerm loc (Syntax.Identifier (name (last names))) -- Go takes `import "lib/Math"` and uses `Math` as the qualified name (e.g. `Math.Sin()`)
|
let alias = makeTerm loc (Syntax.Identifier (name (last names))) -- Go takes `import "lib/Math"` and uses `Math` as the qualified name (e.g. `Math.Sin()`)
|
||||||
Declaration.QualifiedImport <$> pure from <*> pure alias <*> pure []
|
Declaration.QualifiedImport <$> pure from <*> pure alias <*> pure [])
|
||||||
|
|
||||||
|
makeImport dot path = Declaration.Import path [] dot
|
||||||
|
dot = makeTerm <$> symbol Dot <*> (Literal.TextElement <$> source)
|
||||||
|
underscore = makeTerm <$> symbol BlankIdentifier <*> (Literal.TextElement <$> source)
|
||||||
|
importSpec = makeTerm' <$> symbol ImportSpec <*> children (sideEffectImport <|> dotImport <|> namedImport <|> plainImport)
|
||||||
|
importSpecList = makeTerm <$> symbol ImportSpecList <*> children (manyTerm (importSpec <|> comment))
|
||||||
importFromPath = makeTerm <$> symbol InterpretedStringLiteral <*> (Syntax.Identifier <$> (pathToQualifiedName <$> source))
|
importFromPath = makeTerm <$> symbol InterpretedStringLiteral <*> (Syntax.Identifier <$> (pathToQualifiedName <$> source))
|
||||||
|
|
||||||
pathToQualifiedName = qualifiedName . pathToNames
|
|
||||||
pathToNames = BC.split '/' . (BC.dropWhile (== '/')) . (BC.dropWhile (== '.')) . stripQuotes
|
|
||||||
stripQuotes = B.filter (/= (fromIntegral (ord '\"')))
|
|
||||||
|
|
||||||
indexExpression :: Assignment
|
indexExpression :: Assignment
|
||||||
indexExpression = makeTerm <$> symbol IndexExpression <*> children (Expression.Subscript <$> expression <*> manyTerm expression)
|
indexExpression = makeTerm <$> symbol IndexExpression <*> children (Expression.Subscript <$> expression <*> manyTerm expression)
|
||||||
|
|
||||||
|
@ -37,9 +37,9 @@ type Syntax =
|
|||||||
, Declaration.Comprehension
|
, Declaration.Comprehension
|
||||||
, Declaration.Decorator
|
, Declaration.Decorator
|
||||||
, Declaration.Function
|
, Declaration.Function
|
||||||
|
, Declaration.Import
|
||||||
, Declaration.QualifiedImport
|
, Declaration.QualifiedImport
|
||||||
, Declaration.Variable
|
, Declaration.Variable
|
||||||
, Declaration.WildcardImport
|
|
||||||
, Expression.Arithmetic
|
, Expression.Arithmetic
|
||||||
, Expression.Boolean
|
, Expression.Boolean
|
||||||
, Expression.Bitwise
|
, Expression.Bitwise
|
||||||
@ -386,22 +386,24 @@ comment = makeTerm <$> symbol Comment <*> (Comment.Comment <$> source)
|
|||||||
|
|
||||||
import' :: Assignment
|
import' :: Assignment
|
||||||
import' = makeTerm'' <$> symbol ImportStatement <*> children (manyTerm (aliasedImport <|> plainImport))
|
import' = makeTerm'' <$> symbol ImportStatement <*> children (manyTerm (aliasedImport <|> plainImport))
|
||||||
<|> makeTerm <$> symbol ImportFromStatement <*> children (Declaration.QualifiedImport <$> (identifier <|> emptyTerm) <*> emptyTerm <*> some (aliasImportSymbol <|> importSymbol))
|
<|> makeTerm <$> symbol ImportFromStatement <*> children (Declaration.Import <$> (identifier <|> emptyTerm) <*> (wildcard <|> (some (aliasImportSymbol <|> importSymbol))) <*> emptyTerm)
|
||||||
<|> makeTerm <$> symbol ImportFromStatement <*> children (Declaration.WildcardImport <$> identifier <*> wildcard)
|
|
||||||
where
|
where
|
||||||
|
-- `import a as b`
|
||||||
|
aliasedImport = makeImport <$> symbol AliasedImport <*> children ((,) <$> expression <*> (Just <$> expression))
|
||||||
|
-- `import a`
|
||||||
|
plainImport = makeImport <$> location <*> ((,) <$> identifier <*> pure Nothing)
|
||||||
|
-- `from a import foo `
|
||||||
|
importSymbol = makeNameAliasPair <$> rawIdentifier <*> pure Nothing
|
||||||
|
-- `from a import foo as bar`
|
||||||
|
aliasImportSymbol = symbol AliasedImport *> children (makeNameAliasPair <$> rawIdentifier <*> (Just <$> rawIdentifier))
|
||||||
|
-- `from a import *`
|
||||||
|
wildcard = symbol WildcardImport *> source *> pure []
|
||||||
|
|
||||||
rawIdentifier = (name <$> identifier') <|> (qualifiedName <$> dottedName')
|
rawIdentifier = (name <$> identifier') <|> (qualifiedName <$> dottedName')
|
||||||
dottedName' = symbol DottedName *> children (some identifier')
|
dottedName' = symbol DottedName *> children (some identifier')
|
||||||
identifier' = (symbol Identifier <|> symbol Identifier') *> source
|
identifier' = (symbol Identifier <|> symbol Identifier') *> source
|
||||||
|
|
||||||
makeNameAliasPair from (Just alias) = (from, alias)
|
makeNameAliasPair from (Just alias) = (from, alias)
|
||||||
makeNameAliasPair from Nothing = (from, from)
|
makeNameAliasPair from Nothing = (from, from)
|
||||||
importSymbol = makeNameAliasPair <$> rawIdentifier <*> pure Nothing
|
|
||||||
aliasImportSymbol = symbol AliasedImport *> children (makeNameAliasPair <$> rawIdentifier <*> (Just <$> rawIdentifier))
|
|
||||||
|
|
||||||
wildcard = makeTerm <$> symbol WildcardImport <*> (Syntax.Identifier <$> (name <$> source))
|
|
||||||
|
|
||||||
aliasedImport = makeImport <$> symbol AliasedImport <*> children ((,) <$> expression <*> (Just <$> expression))
|
|
||||||
plainImport = makeImport <$> location <*> ((,) <$> identifier <*> pure Nothing)
|
|
||||||
makeImport loc (from, Just alias) = makeTerm loc (Declaration.QualifiedImport from alias [])
|
makeImport loc (from, Just alias) = makeTerm loc (Declaration.QualifiedImport from alias [])
|
||||||
makeImport loc (from, Nothing) = makeTerm loc (Declaration.QualifiedImport from from [])
|
makeImport loc (from, Nothing) = makeTerm loc (Declaration.QualifiedImport from from [])
|
||||||
|
|
||||||
|
@ -21,13 +21,13 @@ import qualified Data.Syntax.Expression as Expression
|
|||||||
import qualified Data.Syntax.Literal as Literal
|
import qualified Data.Syntax.Literal as Literal
|
||||||
import qualified Data.Syntax.Statement as Statement
|
import qualified Data.Syntax.Statement as Statement
|
||||||
import qualified Data.Term as Term
|
import qualified Data.Term as Term
|
||||||
|
import qualified Language.Ruby.Syntax as Ruby.Syntax
|
||||||
|
|
||||||
-- | The type of Ruby syntax.
|
-- | The type of Ruby syntax.
|
||||||
type Syntax = '[
|
type Syntax = '[
|
||||||
Comment.Comment
|
Comment.Comment
|
||||||
, Declaration.Class
|
, Declaration.Class
|
||||||
, Declaration.Function
|
, Declaration.Function
|
||||||
, Declaration.Import
|
|
||||||
, Declaration.Method
|
, Declaration.Method
|
||||||
, Declaration.Module
|
, Declaration.Module
|
||||||
, Expression.Arithmetic
|
, Expression.Arithmetic
|
||||||
@ -74,6 +74,8 @@ type Syntax = '[
|
|||||||
, Syntax.Error
|
, Syntax.Error
|
||||||
, Syntax.Identifier
|
, Syntax.Identifier
|
||||||
, Syntax.Program
|
, Syntax.Program
|
||||||
|
, Ruby.Syntax.Require
|
||||||
|
, Ruby.Syntax.Load
|
||||||
, []
|
, []
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -295,15 +297,20 @@ pair :: Assignment
|
|||||||
pair = makeTerm <$> symbol Pair <*> children (Literal.KeyValue <$> expression <*> (expression <|> emptyTerm))
|
pair = makeTerm <$> symbol Pair <*> children (Literal.KeyValue <$> expression <*> (expression <|> emptyTerm))
|
||||||
|
|
||||||
methodCall :: Assignment
|
methodCall :: Assignment
|
||||||
methodCall = makeTerm' <$> symbol MethodCall <*> children (require <|> regularCall)
|
methodCall = makeTerm' <$> symbol MethodCall <*> children (require <|> load <|> regularCall)
|
||||||
where
|
where
|
||||||
regularCall = inj <$> (Expression.Call <$> pure [] <*> expression <*> args <*> (block <|> emptyTerm))
|
regularCall = inj <$> (Expression.Call <$> pure [] <*> expression <*> args <*> (block <|> emptyTerm))
|
||||||
require = inj <$> (symbol Identifier *> do
|
require = inj <$> (symbol Identifier *> do
|
||||||
s <- source
|
s <- source
|
||||||
guard (elem s ["autoload", "load", "require", "require_relative"])
|
guard (elem s ["require", "require_relative"])
|
||||||
Declaration.Import <$> args' <*> pure [])
|
Ruby.Syntax.Require (s == "require_relative") <$> nameExpression)
|
||||||
|
load = inj <$> (symbol Identifier *> do
|
||||||
|
s <- source
|
||||||
|
guard (elem s ["load"])
|
||||||
|
Ruby.Syntax.Load <$> loadArgs)
|
||||||
args = (symbol ArgumentList <|> symbol ArgumentListWithParens) *> children (many expression) <|> pure []
|
args = (symbol ArgumentList <|> symbol ArgumentListWithParens) *> children (many expression) <|> pure []
|
||||||
args' = makeTerm'' <$> (symbol ArgumentList <|> symbol ArgumentListWithParens) <*> children (many expression) <|> emptyTerm
|
loadArgs = (symbol ArgumentList <|> symbol ArgumentListWithParens) *> children (some expression)
|
||||||
|
nameExpression = (symbol ArgumentList <|> symbol ArgumentListWithParens) *> children expression
|
||||||
|
|
||||||
call :: Assignment
|
call :: Assignment
|
||||||
call = makeTerm <$> symbol Call <*> children (Expression.MemberAccess <$> expression <*> (expression <|> args))
|
call = makeTerm <$> symbol Call <*> children (Expression.MemberAccess <$> expression <*> (expression <|> args))
|
||||||
|
54
src/Language/Ruby/Syntax.hs
Normal file
54
src/Language/Ruby/Syntax.hs
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
{-# LANGUAGE DeriveAnyClass #-}
|
||||||
|
module Language.Ruby.Syntax where
|
||||||
|
|
||||||
|
import Control.Monad (unless)
|
||||||
|
import Control.Abstract.Value (MonadValue)
|
||||||
|
import Data.Abstract.Environment
|
||||||
|
import Data.Abstract.Evaluatable
|
||||||
|
import Data.Abstract.Path
|
||||||
|
import Data.Abstract.Value (LocationFor)
|
||||||
|
import Diffing.Algorithm
|
||||||
|
import Prelude hiding (fail)
|
||||||
|
import Prologue
|
||||||
|
import qualified Data.Map as Map
|
||||||
|
|
||||||
|
data Require a = Require { requireRelative :: Bool, requirePath :: !a }
|
||||||
|
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1)
|
||||||
|
|
||||||
|
instance Eq1 Require where liftEq = genericLiftEq
|
||||||
|
instance Ord1 Require where liftCompare = genericLiftCompare
|
||||||
|
instance Show1 Require where liftShowsPrec = genericLiftShowsPrec
|
||||||
|
|
||||||
|
instance Evaluatable Require where
|
||||||
|
eval (Require _ x) = do
|
||||||
|
name <- pathToQualifiedName <$> (subtermValue x >>= asString)
|
||||||
|
importedEnv <- isolate (require name)
|
||||||
|
modifyGlobalEnv (flip (Map.foldrWithKey envInsert) (unEnvironment importedEnv))
|
||||||
|
unit
|
||||||
|
|
||||||
|
newtype Load a = Load { loadArgs :: [a] }
|
||||||
|
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1)
|
||||||
|
|
||||||
|
instance Eq1 Load where liftEq = genericLiftEq
|
||||||
|
instance Ord1 Load where liftCompare = genericLiftCompare
|
||||||
|
instance Show1 Load where liftShowsPrec = genericLiftShowsPrec
|
||||||
|
|
||||||
|
instance Evaluatable Load where
|
||||||
|
eval (Load [x]) = do
|
||||||
|
path <- subtermValue x >>= asString
|
||||||
|
doLoad path False
|
||||||
|
eval (Load [x, wrap]) = do
|
||||||
|
path <- subtermValue x >>= asString
|
||||||
|
shouldWrap <- subtermValue wrap >>= toBool
|
||||||
|
doLoad path shouldWrap
|
||||||
|
eval (Load _) = fail "invalid argument supplied to load, path is required"
|
||||||
|
|
||||||
|
doLoad :: (MonadAnalysis term value m, MonadValue value m, Ord (LocationFor value)) => ByteString -> Bool -> m value
|
||||||
|
doLoad path shouldWrap = do
|
||||||
|
let name = pathToQualifiedName path
|
||||||
|
importedEnv <- isolate (load name)
|
||||||
|
unless shouldWrap $ modifyGlobalEnv (flip (Map.foldrWithKey envInsert) (unEnvironment importedEnv))
|
||||||
|
unit
|
||||||
|
where pathToQualifiedName = qualifiedName . splitOnPathSeparator' dropExtension
|
||||||
|
|
||||||
|
-- TODO: autoload
|
@ -9,9 +9,6 @@ module Language.TypeScript.Assignment
|
|||||||
import Assigning.Assignment hiding (Assignment, Error)
|
import Assigning.Assignment hiding (Assignment, Error)
|
||||||
import qualified Assigning.Assignment as Assignment
|
import qualified Assigning.Assignment as Assignment
|
||||||
import Data.Abstract.FreeVariables
|
import Data.Abstract.FreeVariables
|
||||||
import qualified Data.ByteString as B (filter)
|
|
||||||
import qualified Data.ByteString.Char8 as BC
|
|
||||||
import Data.Char (ord)
|
|
||||||
import Data.Record
|
import Data.Record
|
||||||
import Data.Syntax (emptyTerm, handleError, parseError, infixContext, makeTerm, makeTerm', makeTerm'', makeTerm1, contextualize, postContextualize)
|
import Data.Syntax (emptyTerm, handleError, parseError, infixContext, makeTerm, makeTerm', makeTerm'', makeTerm1, contextualize, postContextualize)
|
||||||
import qualified Data.Syntax as Syntax
|
import qualified Data.Syntax as Syntax
|
||||||
@ -39,6 +36,7 @@ type Syntax = '[
|
|||||||
, Declaration.TypeAlias
|
, Declaration.TypeAlias
|
||||||
, Declaration.Import
|
, Declaration.Import
|
||||||
, Declaration.QualifiedImport
|
, Declaration.QualifiedImport
|
||||||
|
, Declaration.SideEffectImport
|
||||||
, Declaration.DefaultExport
|
, Declaration.DefaultExport
|
||||||
, Declaration.QualifiedExport
|
, Declaration.QualifiedExport
|
||||||
, Declaration.QualifiedExportFrom
|
, Declaration.QualifiedExportFrom
|
||||||
@ -642,47 +640,39 @@ statementIdentifier = makeTerm <$> symbol StatementIdentifier <*> (Syntax.Identi
|
|||||||
|
|
||||||
importStatement :: Assignment
|
importStatement :: Assignment
|
||||||
importStatement = makeImportTerm <$> symbol Grammar.ImportStatement <*> children ((,) <$> importClause <*> term fromClause)
|
importStatement = makeImportTerm <$> symbol Grammar.ImportStatement <*> children ((,) <$> importClause <*> term fromClause)
|
||||||
<|> makeImport <$> symbol Grammar.ImportStatement <*> children requireImport
|
<|> makeTerm' <$> symbol Grammar.ImportStatement <*> children (requireImport <|> sideEffectImport)
|
||||||
<|> makeImport <$> symbol Grammar.ImportStatement <*> children bareRequireImport
|
|
||||||
where
|
where
|
||||||
-- Straightforward imports
|
-- `import foo = require "./foo"`
|
||||||
makeImport loc (Just alias, symbols, from) = makeTerm loc (Declaration.QualifiedImport from alias symbols)
|
requireImport = inj <$> (symbol Grammar.ImportRequireClause *> children (flip Declaration.QualifiedImport <$> (term identifier) <*> term fromClause <*> pure []))
|
||||||
makeImport loc (Nothing, symbols, from) = makeTerm loc (Declaration.Import from symbols)
|
-- `import "./foo"`
|
||||||
-- Import a file giving it an alias (e.g. import foo = require "./foo")
|
sideEffectImport = inj <$> (Declaration.SideEffectImport <$> term fromClause <*> emptyTerm)
|
||||||
requireImport = symbol Grammar.ImportRequireClause *> children ((,,) <$> (Just <$> (term identifier)) <*> pure [] <*> term fromClause)
|
-- `import { bar } from "./foo"`
|
||||||
-- Import a file just for it's side effects (e.g. import "./foo")
|
namedImport = (,,,) <$> pure Prelude.False <*> pure Nothing <*> (symbol Grammar.NamedImports *> children (many importSymbol)) <*> emptyTerm
|
||||||
bareRequireImport = (,,) <$> (pure Nothing) <*> pure [] <*> term fromClause
|
-- `import defaultMember from "./foo"`
|
||||||
|
defaultImport = (,,,) <$> pure Prelude.False <*> pure Nothing <*> (pure <$> (makeNameAliasPair <$> rawIdentifier <*> pure Nothing)) <*> emptyTerm
|
||||||
|
-- `import * as name from "./foo"`
|
||||||
|
namespaceImport = symbol Grammar.NamespaceImport *> children ((,,,) <$> pure Prelude.True <*> (Just <$> (term identifier)) <*> pure [] <*> emptyTerm)
|
||||||
|
|
||||||
|
-- Combinations of the above.
|
||||||
|
importClause = symbol Grammar.ImportClause *>
|
||||||
|
children (
|
||||||
|
(pure <$> namedImport)
|
||||||
|
<|> (pure <$> namespaceImport)
|
||||||
|
<|> ((\a b -> [a, b]) <$> defaultImport <*> (namedImport <|> namespaceImport))
|
||||||
|
<|> (pure <$> defaultImport))
|
||||||
|
|
||||||
-- Imports with import clauses
|
makeImportTerm1 loc from (Prelude.True, Just alias, symbols, _) = makeTerm loc (Declaration.QualifiedImport from alias symbols)
|
||||||
makeImportTerm1 loc from (Prelude.True, Just alias, symbols) = makeTerm loc (Declaration.QualifiedImport from alias symbols)
|
makeImportTerm1 loc from (Prelude.True, Nothing, symbols, _) = makeTerm loc (Declaration.QualifiedImport from from symbols)
|
||||||
makeImportTerm1 loc from (Prelude.True, Nothing, symbols) = makeTerm loc (Declaration.QualifiedImport from from symbols)
|
makeImportTerm1 loc from (_, _, symbols, extra) = makeTerm loc (Declaration.Import from symbols extra)
|
||||||
makeImportTerm1 loc from (_, _, symbols) = makeTerm loc (Declaration.Import from symbols)
|
|
||||||
makeImportTerm loc ([x], from) = makeImportTerm1 loc from x
|
makeImportTerm loc ([x], from) = makeImportTerm1 loc from x
|
||||||
makeImportTerm loc (xs, from) = makeTerm loc $ fmap (makeImportTerm1 loc from) xs
|
makeImportTerm loc (xs, from) = makeTerm loc $ fmap (makeImportTerm1 loc from) xs
|
||||||
importClause = symbol Grammar.ImportClause *>
|
importSymbol = symbol Grammar.ImportSpecifier *> children (makeNameAliasPair <$> rawIdentifier <*> ((Just <$> rawIdentifier) <|> (pure Nothing)))
|
||||||
children ( (pure <$> namedImport)
|
|
||||||
<|> (pure <$> namespaceImport)
|
|
||||||
<|> ((\a b -> [a, b]) <$> defaultImport <*> (namedImport <|> namespaceImport))
|
|
||||||
<|> (pure <$> defaultImport)
|
|
||||||
)
|
|
||||||
namedImport = (,,) <$> pure Prelude.False <*> pure Nothing <*> (symbol Grammar.NamedImports *> children (many importSymbol)) -- import { bar } from "./foo"
|
|
||||||
defaultImport = (,,) <$> pure Prelude.False <*> pure Nothing <*> (pure <$> (makeNameAliasPair <$> rawIdentifier <*> pure Nothing)) -- import defaultMember from "./foo"
|
|
||||||
namespaceImport = symbol Grammar.NamespaceImport *> children ((,,) <$> pure Prelude.True <*> (Just <$> (term identifier)) <*> pure []) -- import * as name from "./foo"
|
|
||||||
importSymbol = symbol Grammar.ImportSpecifier *> children (makeNameAliasPair <$> rawIdentifier <*> (Just <$> rawIdentifier))
|
|
||||||
<|> symbol Grammar.ImportSpecifier *> children (makeNameAliasPair <$> rawIdentifier <*> (pure Nothing))
|
|
||||||
rawIdentifier = (symbol Identifier <|> symbol Identifier') *> (name <$> source)
|
rawIdentifier = (symbol Identifier <|> symbol Identifier') *> (name <$> source)
|
||||||
makeNameAliasPair from (Just alias) = (from, alias)
|
makeNameAliasPair from (Just alias) = (from, alias)
|
||||||
makeNameAliasPair from Nothing = (from, from)
|
makeNameAliasPair from Nothing = (from, from)
|
||||||
|
|
||||||
fromClause :: Assignment
|
fromClause :: Assignment
|
||||||
fromClause = makeTerm <$> symbol Grammar.String <*> (Syntax.Identifier <$> (pathToQualifiedName <$> source))
|
fromClause = makeTerm <$> symbol Grammar.String <*> (Syntax.Identifier <$> (pathToQualifiedName <$> source))
|
||||||
where
|
|
||||||
pathToQualifiedName :: ByteString -> Name
|
|
||||||
pathToQualifiedName = qualifiedName . BC.split '/' . (BC.dropWhile (== '/')) . (BC.dropWhile (== '.')) . stripQuotes
|
|
||||||
|
|
||||||
stripQuotes :: ByteString -> ByteString
|
|
||||||
stripQuotes = B.filter (/= (fromIntegral (ord '\"')))
|
|
||||||
|
|
||||||
debuggerStatement :: Assignment
|
debuggerStatement :: Assignment
|
||||||
debuggerStatement = makeTerm <$> symbol Grammar.DebuggerStatement <*> (TypeScript.Syntax.Debugger <$ source)
|
debuggerStatement = makeTerm <$> symbol Grammar.DebuggerStatement <*> (TypeScript.Syntax.Debugger <$ source)
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
{-# LANGUAGE TypeApplications #-}
|
|
||||||
module Analysis.Go.Spec (spec) where
|
module Analysis.Go.Spec (spec) where
|
||||||
|
|
||||||
import Data.Abstract.Value
|
import Data.Abstract.Value
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
{-# LANGUAGE TypeApplications #-}
|
|
||||||
module Analysis.Python.Spec (spec) where
|
module Analysis.Python.Spec (spec) where
|
||||||
|
|
||||||
import Data.Abstract.Value
|
import Data.Abstract.Value
|
||||||
|
35
test/Analysis/Ruby/Spec.hs
Normal file
35
test/Analysis/Ruby/Spec.hs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
module Analysis.Ruby.Spec (spec) where
|
||||||
|
|
||||||
|
import Data.Abstract.Value
|
||||||
|
import Data.Map
|
||||||
|
|
||||||
|
import SpecHelpers
|
||||||
|
|
||||||
|
|
||||||
|
spec :: Spec
|
||||||
|
spec = parallel $ do
|
||||||
|
describe "evalutes Ruby" $ do
|
||||||
|
it "require_relative" $ do
|
||||||
|
env <- evaluate "main.rb"
|
||||||
|
let expectedEnv = Environment $ fromList [ (qualifiedName ["foo"], addr 0) ]
|
||||||
|
env `shouldBe` expectedEnv
|
||||||
|
|
||||||
|
it "load" $ do
|
||||||
|
env <- evaluate "load.rb"
|
||||||
|
let expectedEnv = Environment $ fromList [ (qualifiedName ["foo"], addr 0) ]
|
||||||
|
env `shouldBe` expectedEnv
|
||||||
|
|
||||||
|
it "load wrap" $ do
|
||||||
|
res <- evaluate' "load-wrap.rb"
|
||||||
|
fst res `shouldBe` Left "free variable: \"foo\""
|
||||||
|
snd res `shouldBe` Environment (fromList [ ])
|
||||||
|
|
||||||
|
where
|
||||||
|
addr = Address . Precise
|
||||||
|
fixtures = "test/fixtures/ruby/analysis/"
|
||||||
|
evaluate entry = snd <$> evaluate' entry
|
||||||
|
evaluate' entry = fst . fst . fst . fst <$>
|
||||||
|
evaluateFiles rubyParser
|
||||||
|
[ fixtures <> entry
|
||||||
|
, fixtures <> "foo.rb"
|
||||||
|
]
|
@ -1,4 +1,3 @@
|
|||||||
{-# LANGUAGE TypeApplications #-}
|
|
||||||
module Analysis.TypeScript.Spec (spec) where
|
module Analysis.TypeScript.Spec (spec) where
|
||||||
|
|
||||||
import Data.Abstract.Value
|
import Data.Abstract.Value
|
||||||
@ -31,12 +30,18 @@ spec = parallel $ do
|
|||||||
env <- evaluate "main2.ts"
|
env <- evaluate "main2.ts"
|
||||||
env `shouldBe` Environment (fromList [])
|
env `shouldBe` Environment (fromList [])
|
||||||
|
|
||||||
|
it "fails exporting symbols not defined in the module" $ do
|
||||||
|
env <- fst <$> evaluate' "bad-export.ts"
|
||||||
|
env `shouldBe` Left "module \"foo\" does not export \"pip\""
|
||||||
|
|
||||||
where
|
where
|
||||||
addr = Address . Precise
|
addr = Address . Precise
|
||||||
fixtures = "test/fixtures/typescript/analysis/"
|
fixtures = "test/fixtures/typescript/analysis/"
|
||||||
evaluate entry = snd . fst . fst . fst . fst <$>
|
evaluate entry = snd <$> evaluate' entry
|
||||||
|
evaluate' entry = fst . fst . fst . fst <$>
|
||||||
evaluateFiles typescriptParser
|
evaluateFiles typescriptParser
|
||||||
[ fixtures <> entry
|
[ fixtures <> entry
|
||||||
, fixtures <> "a.ts"
|
, fixtures <> "a.ts"
|
||||||
, fixtures <> "foo.ts"
|
, fixtures <> "foo.ts"
|
||||||
|
, fixtures <> "pip.ts"
|
||||||
]
|
]
|
||||||
|
@ -2,6 +2,7 @@ module Main where
|
|||||||
|
|
||||||
import qualified Analysis.Go.Spec
|
import qualified Analysis.Go.Spec
|
||||||
import qualified Analysis.Python.Spec
|
import qualified Analysis.Python.Spec
|
||||||
|
import qualified Analysis.Ruby.Spec
|
||||||
import qualified Analysis.TypeScript.Spec
|
import qualified Analysis.TypeScript.Spec
|
||||||
import qualified Assigning.Assignment.Spec
|
import qualified Assigning.Assignment.Spec
|
||||||
import qualified Data.Diff.Spec
|
import qualified Data.Diff.Spec
|
||||||
@ -27,6 +28,7 @@ main = hspec $ do
|
|||||||
parallel $ do
|
parallel $ do
|
||||||
describe "Analysis.Go" Analysis.Go.Spec.spec
|
describe "Analysis.Go" Analysis.Go.Spec.spec
|
||||||
describe "Analysis.Python" Analysis.Python.Spec.spec
|
describe "Analysis.Python" Analysis.Python.Spec.spec
|
||||||
|
describe "Analysis.Ruby" Analysis.Ruby.Spec.spec
|
||||||
describe "Analysis.TypeScript" Analysis.TypeScript.Spec.spec
|
describe "Analysis.TypeScript" Analysis.TypeScript.Spec.spec
|
||||||
describe "Assigning.Assignment" Assigning.Assignment.Spec.spec
|
describe "Assigning.Assignment" Assigning.Assignment.Spec.spec
|
||||||
describe "Data.Diff" Data.Diff.Spec.spec
|
describe "Data.Diff" Data.Diff.Spec.spec
|
||||||
|
@ -11,7 +11,7 @@ module SpecHelpers (
|
|||||||
|
|
||||||
import Data.Abstract.Address as X
|
import Data.Abstract.Address as X
|
||||||
import Data.Abstract.Environment as X
|
import Data.Abstract.Environment as X
|
||||||
import Data.Abstract.FreeVariables as X
|
import Data.Abstract.FreeVariables as X hiding (dropExtension)
|
||||||
import Data.Abstract.Heap as X
|
import Data.Abstract.Heap as X
|
||||||
import Data.Abstract.ModuleTable as X
|
import Data.Abstract.ModuleTable as X
|
||||||
import Data.Blob as X
|
import Data.Blob as X
|
||||||
|
@ -7,14 +7,18 @@
|
|||||||
->(Identifier) }
|
->(Identifier) }
|
||||||
{ (Identifier)
|
{ (Identifier)
|
||||||
->(Identifier) })
|
->(Identifier) })
|
||||||
(WildcardImport
|
{+(Import
|
||||||
{ (Identifier)
|
{+(Identifier)+}
|
||||||
->(Identifier) }
|
{+(TextElement)+})+}
|
||||||
(Identifier))
|
{+(QualifiedImport
|
||||||
(QualifiedImport
|
{+(Identifier)+}
|
||||||
{ (Identifier)
|
{+(Identifier)+})+}
|
||||||
->(Identifier) }
|
{-(Import
|
||||||
(Identifier)))
|
{-(Identifier)-}
|
||||||
|
{-(TextElement)-})-}
|
||||||
|
{-(QualifiedImport
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Identifier)-})-})
|
||||||
(Function
|
(Function
|
||||||
(Empty)
|
(Empty)
|
||||||
(Identifier)
|
(Identifier)
|
||||||
|
@ -7,14 +7,18 @@
|
|||||||
->(Identifier) }
|
->(Identifier) }
|
||||||
{ (Identifier)
|
{ (Identifier)
|
||||||
->(Identifier) })
|
->(Identifier) })
|
||||||
(WildcardImport
|
{+(Import
|
||||||
{ (Identifier)
|
{+(Identifier)+}
|
||||||
->(Identifier) }
|
{+(TextElement)+})+}
|
||||||
(Identifier))
|
{+(QualifiedImport
|
||||||
(QualifiedImport
|
{+(Identifier)+}
|
||||||
{ (Identifier)
|
{+(Identifier)+})+}
|
||||||
->(Identifier) }
|
{-(Import
|
||||||
(Identifier)))
|
{-(Identifier)-}
|
||||||
|
{-(TextElement)-})-}
|
||||||
|
{-(QualifiedImport
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Identifier)-})-})
|
||||||
(Function
|
(Function
|
||||||
(Empty)
|
(Empty)
|
||||||
(Identifier)
|
(Identifier)
|
||||||
|
@ -5,9 +5,9 @@
|
|||||||
(QualifiedImport
|
(QualifiedImport
|
||||||
(Identifier)
|
(Identifier)
|
||||||
(Identifier))
|
(Identifier))
|
||||||
(WildcardImport
|
(Import
|
||||||
(Identifier)
|
(Identifier)
|
||||||
(Identifier))
|
(TextElement))
|
||||||
(QualifiedImport
|
(QualifiedImport
|
||||||
(Identifier)
|
(Identifier)
|
||||||
(Identifier)))
|
(Identifier)))
|
||||||
|
@ -5,9 +5,9 @@
|
|||||||
(QualifiedImport
|
(QualifiedImport
|
||||||
(Identifier)
|
(Identifier)
|
||||||
(Identifier))
|
(Identifier))
|
||||||
(WildcardImport
|
(Import
|
||||||
(Identifier)
|
(Identifier)
|
||||||
(Identifier))
|
(TextElement))
|
||||||
(QualifiedImport
|
(QualifiedImport
|
||||||
(Identifier)
|
(Identifier)
|
||||||
(Identifier)))
|
(Identifier)))
|
||||||
|
@ -4,17 +4,17 @@
|
|||||||
{+(QualifiedImport
|
{+(QualifiedImport
|
||||||
{+(Identifier)+}
|
{+(Identifier)+}
|
||||||
{+(Identifier)+})+}
|
{+(Identifier)+})+}
|
||||||
{+(WildcardImport
|
{+(Import
|
||||||
{+(Identifier)+}
|
{+(Identifier)+}
|
||||||
{+(Identifier)+})+}
|
{+(TextElement)+})+}
|
||||||
(QualifiedImport
|
(QualifiedImport
|
||||||
{ (Identifier)
|
{ (Identifier)
|
||||||
->(Identifier) }
|
->(Identifier) }
|
||||||
{ (Identifier)
|
{ (Identifier)
|
||||||
->(Identifier) })
|
->(Identifier) })
|
||||||
{-(WildcardImport
|
{-(Import
|
||||||
{-(Identifier)-}
|
{-(Identifier)-}
|
||||||
{-(Identifier)-})-}
|
{-(TextElement)-})-}
|
||||||
{-(QualifiedImport
|
{-(QualifiedImport
|
||||||
{-(Identifier)-}
|
{-(Identifier)-}
|
||||||
{-(Identifier)-})-}
|
{-(Identifier)-})-}
|
||||||
|
@ -4,17 +4,17 @@
|
|||||||
{+(QualifiedImport
|
{+(QualifiedImport
|
||||||
{+(Identifier)+}
|
{+(Identifier)+}
|
||||||
{+(Identifier)+})+}
|
{+(Identifier)+})+}
|
||||||
{+(WildcardImport
|
{+(Import
|
||||||
{+(Identifier)+}
|
{+(Identifier)+}
|
||||||
{+(Identifier)+})+}
|
{+(TextElement)+})+}
|
||||||
(QualifiedImport
|
(QualifiedImport
|
||||||
{ (Identifier)
|
{ (Identifier)
|
||||||
->(Identifier) }
|
->(Identifier) }
|
||||||
{ (Identifier)
|
{ (Identifier)
|
||||||
->(Identifier) })
|
->(Identifier) })
|
||||||
{-(WildcardImport
|
{-(Import
|
||||||
{-(Identifier)-}
|
{-(Identifier)-}
|
||||||
{-(Identifier)-})-}
|
{-(TextElement)-})-}
|
||||||
{-(QualifiedImport
|
{-(QualifiedImport
|
||||||
{-(Identifier)-}
|
{-(Identifier)-}
|
||||||
{-(Identifier)-})-}
|
{-(Identifier)-})-}
|
||||||
|
@ -4,9 +4,9 @@
|
|||||||
(QualifiedImport
|
(QualifiedImport
|
||||||
(Identifier)
|
(Identifier)
|
||||||
(Identifier))
|
(Identifier))
|
||||||
(WildcardImport
|
(Import
|
||||||
(Identifier)
|
(Identifier)
|
||||||
(Identifier))
|
(TextElement))
|
||||||
(QualifiedImport
|
(QualifiedImport
|
||||||
(Identifier)
|
(Identifier)
|
||||||
(Identifier))
|
(Identifier))
|
||||||
|
@ -4,9 +4,9 @@
|
|||||||
(QualifiedImport
|
(QualifiedImport
|
||||||
(Identifier)
|
(Identifier)
|
||||||
(Identifier))
|
(Identifier))
|
||||||
(WildcardImport
|
(Import
|
||||||
(Identifier)
|
(Identifier)
|
||||||
(Identifier))
|
(TextElement))
|
||||||
(QualifiedImport
|
(QualifiedImport
|
||||||
(Identifier)
|
(Identifier)
|
||||||
(Identifier))
|
(Identifier))
|
||||||
|
104
test/fixtures/javascript/import.diffA-B.txt
vendored
104
test/fixtures/javascript/import.diffA-B.txt
vendored
@ -1,41 +1,65 @@
|
|||||||
(Program
|
(Program
|
||||||
(Import
|
{+(Import
|
||||||
{ (Identifier)
|
{+(Identifier)+}
|
||||||
->(Identifier) })
|
{+(Empty)+})+}
|
||||||
(QualifiedImport
|
{+(QualifiedImport
|
||||||
{ (Identifier)
|
{+(Identifier)+}
|
||||||
->(Identifier) }
|
{+(Identifier)+})+}
|
||||||
{ (Identifier)
|
{+(Import
|
||||||
->(Identifier) })
|
{+(Identifier)+}
|
||||||
{ (Import
|
{+(Empty)+})+}
|
||||||
{-(Identifier)-})
|
{+(Import
|
||||||
->(Import
|
{+(Identifier)+}
|
||||||
{+(Identifier)+}) }
|
{+(Empty)+})+}
|
||||||
{ (Import
|
{+(Import
|
||||||
{-(Identifier)-})
|
{+(Identifier)+}
|
||||||
->(Import
|
{+(Empty)+})+}
|
||||||
{+(Identifier)+}) }
|
{+(
|
||||||
{ (Import
|
{+(Import
|
||||||
{-(Identifier)-})
|
{+(Identifier)+}
|
||||||
->(Import
|
{+(Empty)+})+}
|
||||||
{+(Identifier)+}) }
|
{+(Import
|
||||||
(
|
{+(Identifier)+}
|
||||||
(Import
|
{+(Empty)+})+})+}
|
||||||
{ (Identifier)
|
{+(
|
||||||
->(Identifier) })
|
{+(Import
|
||||||
{ (Import
|
{+(Identifier)+}
|
||||||
{-(Identifier)-})
|
{+(Empty)+})+}
|
||||||
->(Import
|
{+(QualifiedImport
|
||||||
{+(Identifier)+}) })
|
{+(Identifier)+}
|
||||||
(
|
{+(Identifier)+})+})+}
|
||||||
(Import
|
{+(SideEffectImport
|
||||||
{ (Identifier)
|
{+(Identifier)+}
|
||||||
->(Identifier) })
|
{+(Empty)+})+}
|
||||||
(QualifiedImport
|
{-(Import
|
||||||
{ (Identifier)
|
{-(Identifier)-}
|
||||||
->(Identifier) }
|
{-(Empty)-})-}
|
||||||
{ (Identifier)
|
{-(QualifiedImport
|
||||||
->(Identifier) }))
|
{-(Identifier)-}
|
||||||
(Import
|
{-(Identifier)-})-}
|
||||||
{ (Identifier)
|
{-(Import
|
||||||
->(Identifier) }))
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})-}
|
||||||
|
{-(Import
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})-}
|
||||||
|
{-(Import
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})-}
|
||||||
|
{-(
|
||||||
|
{-(Import
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})-}
|
||||||
|
{-(Import
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})-})-}
|
||||||
|
{-(
|
||||||
|
{-(Import
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})-}
|
||||||
|
{-(QualifiedImport
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Identifier)-})-})-}
|
||||||
|
{-(SideEffectImport
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})-})
|
||||||
|
100
test/fixtures/javascript/import.diffB-A.txt
vendored
100
test/fixtures/javascript/import.diffB-A.txt
vendored
@ -1,41 +1,65 @@
|
|||||||
(Program
|
(Program
|
||||||
(Import
|
{+(Import
|
||||||
{ (Identifier)
|
{+(Identifier)+}
|
||||||
->(Identifier) })
|
{+(Empty)+})+}
|
||||||
(QualifiedImport
|
{+(QualifiedImport
|
||||||
{ (Identifier)
|
{+(Identifier)+}
|
||||||
->(Identifier) }
|
{+(Identifier)+})+}
|
||||||
{ (Identifier)
|
|
||||||
->(Identifier) })
|
|
||||||
{ (Import
|
{ (Import
|
||||||
{-(Identifier)-})
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})
|
||||||
->(Import
|
->(Import
|
||||||
{+(Identifier)+}) }
|
{+(Identifier)+}
|
||||||
{ (Import
|
{+(Empty)+}) }
|
||||||
{-(Identifier)-})
|
{+(Import
|
||||||
->(Import
|
{+(Identifier)+}
|
||||||
{+(Identifier)+}) }
|
{+(Empty)+})+}
|
||||||
{ (Import
|
{+(Import
|
||||||
{-(Identifier)-})
|
{+(Identifier)+}
|
||||||
->(Import
|
{+(Empty)+})+}
|
||||||
{+(Identifier)+}) }
|
{+(
|
||||||
(
|
{+(Import
|
||||||
(Import
|
{+(Identifier)+}
|
||||||
{ (Identifier)
|
{+(Empty)+})+}
|
||||||
->(Identifier) })
|
{+(Import
|
||||||
{ (Import
|
{+(Identifier)+}
|
||||||
{-(Identifier)-})
|
{+(Empty)+})+})+}
|
||||||
->(Import
|
{+(
|
||||||
{+(Identifier)+}) })
|
{+(Import
|
||||||
(
|
{+(Identifier)+}
|
||||||
(Import
|
{+(Empty)+})+}
|
||||||
{ (Identifier)
|
{+(QualifiedImport
|
||||||
->(Identifier) })
|
{+(Identifier)+}
|
||||||
(QualifiedImport
|
{+(Identifier)+})+})+}
|
||||||
{ (Identifier)
|
{+(SideEffectImport
|
||||||
->(Identifier) }
|
{+(Identifier)+}
|
||||||
{ (Identifier)
|
{+(Empty)+})+}
|
||||||
->(Identifier) }))
|
{-(QualifiedImport
|
||||||
(Import
|
{-(Identifier)-}
|
||||||
{ (Identifier)
|
{-(Identifier)-})-}
|
||||||
->(Identifier) }))
|
{-(Import
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})-}
|
||||||
|
{-(Import
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})-}
|
||||||
|
{-(Import
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})-}
|
||||||
|
{-(
|
||||||
|
{-(Import
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})-}
|
||||||
|
{-(Import
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})-})-}
|
||||||
|
{-(
|
||||||
|
{-(Import
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})-}
|
||||||
|
{-(QualifiedImport
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Identifier)-})-})-}
|
||||||
|
{-(SideEffectImport
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})-})
|
||||||
|
26
test/fixtures/javascript/import.parseA.txt
vendored
26
test/fixtures/javascript/import.parseA.txt
vendored
@ -1,25 +1,33 @@
|
|||||||
(Program
|
(Program
|
||||||
(Import
|
(Import
|
||||||
(Identifier))
|
(Identifier)
|
||||||
|
(Empty))
|
||||||
(QualifiedImport
|
(QualifiedImport
|
||||||
(Identifier)
|
(Identifier)
|
||||||
(Identifier))
|
(Identifier))
|
||||||
(Import
|
(Import
|
||||||
(Identifier))
|
(Identifier)
|
||||||
|
(Empty))
|
||||||
(Import
|
(Import
|
||||||
(Identifier))
|
(Identifier)
|
||||||
|
(Empty))
|
||||||
(Import
|
(Import
|
||||||
(Identifier))
|
(Identifier)
|
||||||
|
(Empty))
|
||||||
(
|
(
|
||||||
(Import
|
(Import
|
||||||
(Identifier))
|
(Identifier)
|
||||||
|
(Empty))
|
||||||
(Import
|
(Import
|
||||||
(Identifier)))
|
(Identifier)
|
||||||
|
(Empty)))
|
||||||
(
|
(
|
||||||
(Import
|
(Import
|
||||||
(Identifier))
|
(Identifier)
|
||||||
|
(Empty))
|
||||||
(QualifiedImport
|
(QualifiedImport
|
||||||
(Identifier)
|
(Identifier)
|
||||||
(Identifier)))
|
(Identifier)))
|
||||||
(Import
|
(SideEffectImport
|
||||||
(Identifier)))
|
(Identifier)
|
||||||
|
(Empty)))
|
||||||
|
26
test/fixtures/javascript/import.parseB.txt
vendored
26
test/fixtures/javascript/import.parseB.txt
vendored
@ -1,25 +1,33 @@
|
|||||||
(Program
|
(Program
|
||||||
(Import
|
(Import
|
||||||
(Identifier))
|
(Identifier)
|
||||||
|
(Empty))
|
||||||
(QualifiedImport
|
(QualifiedImport
|
||||||
(Identifier)
|
(Identifier)
|
||||||
(Identifier))
|
(Identifier))
|
||||||
(Import
|
(Import
|
||||||
(Identifier))
|
(Identifier)
|
||||||
|
(Empty))
|
||||||
(Import
|
(Import
|
||||||
(Identifier))
|
(Identifier)
|
||||||
|
(Empty))
|
||||||
(Import
|
(Import
|
||||||
(Identifier))
|
(Identifier)
|
||||||
|
(Empty))
|
||||||
(
|
(
|
||||||
(Import
|
(Import
|
||||||
(Identifier))
|
(Identifier)
|
||||||
|
(Empty))
|
||||||
(Import
|
(Import
|
||||||
(Identifier)))
|
(Identifier)
|
||||||
|
(Empty)))
|
||||||
(
|
(
|
||||||
(Import
|
(Import
|
||||||
(Identifier))
|
(Identifier)
|
||||||
|
(Empty))
|
||||||
(QualifiedImport
|
(QualifiedImport
|
||||||
(Identifier)
|
(Identifier)
|
||||||
(Identifier)))
|
(Identifier)))
|
||||||
(Import
|
(SideEffectImport
|
||||||
(Identifier)))
|
(Identifier)
|
||||||
|
(Empty)))
|
||||||
|
@ -1,34 +1,34 @@
|
|||||||
(Program
|
(Program
|
||||||
{+(QualifiedImport
|
{+(Import
|
||||||
{+(Identifier)+}
|
{+(Identifier)+}
|
||||||
{+(Empty)+})+}
|
{+(Empty)+})+}
|
||||||
{+(QualifiedImport
|
{+(Import
|
||||||
{+(Identifier)+}
|
{+(Identifier)+}
|
||||||
{+(Empty)+})+}
|
{+(Empty)+})+}
|
||||||
{+(WildcardImport
|
{ (Import
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})
|
||||||
|
->(Import
|
||||||
{+(Identifier)+}
|
{+(Identifier)+}
|
||||||
{+(Identifier)+})+}
|
{+(Empty)+}) }
|
||||||
{+(QualifiedImport
|
{+(Import
|
||||||
{+(Identifier)+}
|
{+(Identifier)+}
|
||||||
{+(Empty)+})+}
|
{+(Empty)+})+}
|
||||||
{+(QualifiedImport
|
{+(Import
|
||||||
{+(Identifier)+}
|
{+(Identifier)+}
|
||||||
{+(Empty)+})+}
|
{+(Empty)+})+}
|
||||||
{+(QualifiedImport
|
{ (Import
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})
|
||||||
|
->(Import
|
||||||
{+(Empty)+}
|
{+(Empty)+}
|
||||||
{+(Empty)+})+}
|
{+(Empty)+}) }
|
||||||
{-(QualifiedImport
|
{-(Import
|
||||||
{-(Identifier)-}
|
{-(Identifier)-}
|
||||||
{-(Empty)-})-}
|
{-(Empty)-})-}
|
||||||
{-(QualifiedImport
|
{-(Import
|
||||||
{-(Identifier)-}
|
{-(Identifier)-}
|
||||||
{-(Empty)-})-}
|
{-(Empty)-})-}
|
||||||
{-(WildcardImport
|
{-(Import
|
||||||
{-(Identifier)-}
|
|
||||||
{-(Identifier)-})-}
|
|
||||||
{-(QualifiedImport
|
|
||||||
{-(Identifier)-}
|
|
||||||
{-(Empty)-})-}
|
|
||||||
{-(QualifiedImport
|
|
||||||
{-(Empty)-}
|
{-(Empty)-}
|
||||||
{-(Empty)-})-})
|
{-(Empty)-})-})
|
||||||
|
@ -1,34 +1,34 @@
|
|||||||
(Program
|
(Program
|
||||||
{+(QualifiedImport
|
{+(Import
|
||||||
{+(Identifier)+}
|
{+(Identifier)+}
|
||||||
{+(Empty)+})+}
|
{+(Empty)+})+}
|
||||||
{+(QualifiedImport
|
{+(Import
|
||||||
{+(Identifier)+}
|
{+(Identifier)+}
|
||||||
{+(Empty)+})+}
|
{+(Empty)+})+}
|
||||||
{+(WildcardImport
|
{+(Import
|
||||||
{+(Identifier)+}
|
|
||||||
{+(Identifier)+})+}
|
|
||||||
{+(QualifiedImport
|
|
||||||
{+(Identifier)+}
|
{+(Identifier)+}
|
||||||
{+(Empty)+})+}
|
{+(Empty)+})+}
|
||||||
{+(QualifiedImport
|
{+(Import
|
||||||
|
{+(Identifier)+}
|
||||||
|
{+(Empty)+})+}
|
||||||
|
{+(Import
|
||||||
{+(Empty)+}
|
{+(Empty)+}
|
||||||
{+(Empty)+})+}
|
{+(Empty)+})+}
|
||||||
{-(QualifiedImport
|
{-(Import
|
||||||
{-(Identifier)-}
|
{-(Identifier)-}
|
||||||
{-(Empty)-})-}
|
{-(Empty)-})-}
|
||||||
{-(QualifiedImport
|
{-(Import
|
||||||
{-(Identifier)-}
|
{-(Identifier)-}
|
||||||
{-(Empty)-})-}
|
{-(Empty)-})-}
|
||||||
{-(WildcardImport
|
{-(Import
|
||||||
{-(Identifier)-}
|
|
||||||
{-(Identifier)-})-}
|
|
||||||
{-(QualifiedImport
|
|
||||||
{-(Identifier)-}
|
{-(Identifier)-}
|
||||||
{-(Empty)-})-}
|
{-(Empty)-})-}
|
||||||
{-(QualifiedImport
|
{-(Import
|
||||||
{-(Identifier)-}
|
{-(Identifier)-}
|
||||||
{-(Empty)-})-}
|
{-(Empty)-})-}
|
||||||
{-(QualifiedImport
|
{-(Import
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})-}
|
||||||
|
{-(Import
|
||||||
{-(Empty)-}
|
{-(Empty)-}
|
||||||
{-(Empty)-})-})
|
{-(Empty)-})-})
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
(Program
|
(Program
|
||||||
(QualifiedImport
|
(Import
|
||||||
(Identifier)
|
(Identifier)
|
||||||
(Empty))
|
(Empty))
|
||||||
(QualifiedImport
|
(Import
|
||||||
(Identifier)
|
(Identifier)
|
||||||
(Empty))
|
(Empty))
|
||||||
(WildcardImport
|
(Import
|
||||||
(Identifier)
|
|
||||||
(Identifier))
|
|
||||||
(QualifiedImport
|
|
||||||
(Identifier)
|
(Identifier)
|
||||||
(Empty))
|
(Empty))
|
||||||
(QualifiedImport
|
(Import
|
||||||
|
(Identifier)
|
||||||
|
(Empty))
|
||||||
|
(Import
|
||||||
(Empty)
|
(Empty)
|
||||||
(Empty)))
|
(Empty)))
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
(Program
|
(Program
|
||||||
(QualifiedImport
|
(Import
|
||||||
(Identifier)
|
(Identifier)
|
||||||
(Empty))
|
(Empty))
|
||||||
(QualifiedImport
|
(Import
|
||||||
(Identifier)
|
(Identifier)
|
||||||
(Empty))
|
(Empty))
|
||||||
(WildcardImport
|
(Import
|
||||||
(Identifier)
|
|
||||||
(Identifier))
|
|
||||||
(QualifiedImport
|
|
||||||
(Identifier)
|
(Identifier)
|
||||||
(Empty))
|
(Empty))
|
||||||
(QualifiedImport
|
(Import
|
||||||
(Identifier)
|
(Identifier)
|
||||||
(Empty))
|
(Empty))
|
||||||
(QualifiedImport
|
(Import
|
||||||
|
(Identifier)
|
||||||
|
(Empty))
|
||||||
|
(Import
|
||||||
(Empty)
|
(Empty)
|
||||||
(Empty)))
|
(Empty)))
|
||||||
|
3
test/fixtures/ruby/analysis/foo.rb
vendored
Normal file
3
test/fixtures/ruby/analysis/foo.rb
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
def foo(x)
|
||||||
|
return x
|
||||||
|
end
|
3
test/fixtures/ruby/analysis/load-wrap.rb
vendored
Normal file
3
test/fixtures/ruby/analysis/load-wrap.rb
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
load "./foo.rb", true
|
||||||
|
|
||||||
|
foo(1)
|
3
test/fixtures/ruby/analysis/load.rb
vendored
Normal file
3
test/fixtures/ruby/analysis/load.rb
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
load "./foo.rb"
|
||||||
|
|
||||||
|
foo(1)
|
3
test/fixtures/ruby/analysis/main.rb
vendored
Normal file
3
test/fixtures/ruby/analysis/main.rb
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
require_relative "foo"
|
||||||
|
|
||||||
|
foo(1)
|
15
test/fixtures/ruby/require.diffA-B.txt
vendored
15
test/fixtures/ruby/require.diffA-B.txt
vendored
@ -1,12 +1,11 @@
|
|||||||
(Program
|
(Program
|
||||||
(Import
|
(Require
|
||||||
{ (TextElement)
|
{ (TextElement)
|
||||||
->(TextElement) })
|
->(TextElement) })
|
||||||
{+(Import
|
(Call
|
||||||
{+(
|
{ (Identifier)
|
||||||
{+(Symbol)+}
|
->(Identifier) }
|
||||||
{+(TextElement)+})+})+}
|
{+(Symbol)+}
|
||||||
{-(Call
|
{+(TextElement)+}
|
||||||
{-(Identifier)-}
|
{-(Identifier)-}
|
||||||
{-(Identifier)-}
|
(Empty)))
|
||||||
{-(Empty)-})-})
|
|
||||||
|
15
test/fixtures/ruby/require.diffB-A.txt
vendored
15
test/fixtures/ruby/require.diffB-A.txt
vendored
@ -1,12 +1,11 @@
|
|||||||
(Program
|
(Program
|
||||||
(Import
|
(Require
|
||||||
{ (TextElement)
|
{ (TextElement)
|
||||||
->(TextElement) })
|
->(TextElement) })
|
||||||
{+(Call
|
(Call
|
||||||
|
{ (Identifier)
|
||||||
|
->(Identifier) }
|
||||||
{+(Identifier)+}
|
{+(Identifier)+}
|
||||||
{+(Identifier)+}
|
{-(Symbol)-}
|
||||||
{+(Empty)+})+}
|
{-(TextElement)-}
|
||||||
{-(Import
|
(Empty)))
|
||||||
{-(
|
|
||||||
{-(Symbol)-}
|
|
||||||
{-(TextElement)-})-})-})
|
|
||||||
|
2
test/fixtures/ruby/require.parseA.txt
vendored
2
test/fixtures/ruby/require.parseA.txt
vendored
@ -1,5 +1,5 @@
|
|||||||
(Program
|
(Program
|
||||||
(Import
|
(Require
|
||||||
(TextElement))
|
(TextElement))
|
||||||
(Call
|
(Call
|
||||||
(Identifier)
|
(Identifier)
|
||||||
|
11
test/fixtures/ruby/require.parseB.txt
vendored
11
test/fixtures/ruby/require.parseB.txt
vendored
@ -1,7 +1,8 @@
|
|||||||
(Program
|
(Program
|
||||||
(Import
|
(Require
|
||||||
(TextElement))
|
(TextElement))
|
||||||
(Import
|
(Call
|
||||||
(
|
(Identifier)
|
||||||
(Symbol)
|
(Symbol)
|
||||||
(TextElement))))
|
(TextElement)
|
||||||
|
(Empty)))
|
||||||
|
@ -1,24 +1,30 @@
|
|||||||
(Program
|
(Program
|
||||||
(DefaultExport
|
(DefaultExport
|
||||||
{(Class
|
{ (Class
|
||||||
{-(Identifier)-}
|
{-(Identifier)-}
|
||||||
{-([])-})
|
{-([])-})
|
||||||
->
|
->(Function
|
||||||
(Function
|
{+(Empty)+}
|
||||||
|
{+(Empty)+}
|
||||||
|
{+(Identifier)+}
|
||||||
|
{+(RequiredParameter
|
||||||
{+(Empty)+}
|
{+(Empty)+}
|
||||||
{+(Empty)+}
|
{+(Empty)+}
|
||||||
{+(Identifier)+}
|
{+(Annotation
|
||||||
{+(RequiredParameter
|
{+(PredefinedType)+})+}
|
||||||
{+(Empty)+}
|
{+(Assignment
|
||||||
{+(Empty)+}
|
{+(Identifier)+}
|
||||||
{+(Annotation{+(PredefinedType)+})+}
|
{+(Empty)+})+})+}
|
||||||
{+(Assignment{+(Identifier)+}{+(Empty)+})+})+}
|
{+(RequiredParameter
|
||||||
{+(RequiredParameter
|
{+(Empty)+}
|
||||||
{+(Empty)+}
|
{+(Empty)+}
|
||||||
{+(Empty)+}
|
{+(Annotation
|
||||||
{+(Annotation{+(PredefinedType)+})+}
|
{+(PredefinedType)+})+}
|
||||||
{+(Assignment{+(Identifier)+}{+(Empty)+})+})+}
|
{+(Assignment
|
||||||
{+({+(Return
|
{+(Identifier)+}
|
||||||
|
{+(Empty)+})+})+}
|
||||||
|
{+(
|
||||||
|
{+(Return
|
||||||
{+(Hash
|
{+(Hash
|
||||||
{+(ShorthandPropertyIdentifier)+}
|
{+(ShorthandPropertyIdentifier)+}
|
||||||
{+(ShorthandPropertyIdentifier)+})+})+})+})}))
|
{+(ShorthandPropertyIdentifier)+})+})+})+}) }))
|
||||||
|
@ -1,10 +1,30 @@
|
|||||||
(Program
|
(Program
|
||||||
(DefaultExport
|
(DefaultExport
|
||||||
{(Function
|
{ (Function
|
||||||
|
{-(Empty)-}
|
||||||
|
{-(Empty)-}
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(RequiredParameter
|
||||||
{-(Empty)-}
|
{-(Empty)-}
|
||||||
{-(Empty)-}
|
{-(Empty)-}
|
||||||
{-(Identifier)-}
|
{-(Annotation
|
||||||
{-(RequiredParameter{-(Empty)-}{-(Empty)-}{-(Annotation{-(PredefinedType)-})-}{-(Assignment{-(Identifier)-}{-(Empty)-})-})-}
|
{-(PredefinedType)-})-}
|
||||||
{-(RequiredParameter{-(Empty)-}{-(Empty)-}{-(Annotation{-(PredefinedType)-})-}{-(Assignment{-(Identifier)-}{-(Empty)-})-})-}
|
{-(Assignment
|
||||||
{-({-(Return{-(Hash{-(ShorthandPropertyIdentifier)-}{-(ShorthandPropertyIdentifier)-})-})-})-})
|
{-(Identifier)-}
|
||||||
->(Class{+(Identifier)+}{+([])+})}))
|
{-(Empty)-})-})-}
|
||||||
|
{-(RequiredParameter
|
||||||
|
{-(Empty)-}
|
||||||
|
{-(Empty)-}
|
||||||
|
{-(Annotation
|
||||||
|
{-(PredefinedType)-})-}
|
||||||
|
{-(Assignment
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})-})-}
|
||||||
|
{-(
|
||||||
|
{-(Return
|
||||||
|
{-(Hash
|
||||||
|
{-(ShorthandPropertyIdentifier)-}
|
||||||
|
{-(ShorthandPropertyIdentifier)-})-})-})-})
|
||||||
|
->(Class
|
||||||
|
{+(Identifier)+}
|
||||||
|
{+([])+}) }))
|
||||||
|
2
test/fixtures/typescript/analysis/bad-export.ts
vendored
Normal file
2
test/fixtures/typescript/analysis/bad-export.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
export { pip } from "./pip"
|
||||||
|
export { pip } from "./foo"
|
5
test/fixtures/typescript/analysis/pip.ts
vendored
Normal file
5
test/fixtures/typescript/analysis/pip.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export { pip }
|
||||||
|
|
||||||
|
function pip() {
|
||||||
|
return "this is the pip function"
|
||||||
|
}
|
104
test/fixtures/typescript/export.diffA-B.txt
vendored
104
test/fixtures/typescript/export.diffA-B.txt
vendored
@ -1,37 +1,81 @@
|
|||||||
(Program
|
(Program
|
||||||
{(QualifiedExport)->(QualifiedExport)}
|
{ (QualifiedExport)
|
||||||
{(QualifiedExport)->(QualifiedExport)}
|
->(QualifiedExport) }
|
||||||
|
{ (QualifiedExport)
|
||||||
|
->(QualifiedExport) }
|
||||||
(DefaultExport
|
(DefaultExport
|
||||||
(VariableDeclaration
|
(VariableDeclaration
|
||||||
(Assignment(Empty){(Identifier)->(Identifier)}(Empty))
|
(Assignment
|
||||||
(Assignment(Empty){(Identifier)->(Identifier)}(Empty))
|
(Empty)
|
||||||
(Assignment(Empty){(Identifier)->(Identifier)}(Empty))))
|
{ (Identifier)
|
||||||
|
->(Identifier) }
|
||||||
|
(Empty))
|
||||||
|
(Assignment
|
||||||
|
(Empty)
|
||||||
|
{ (Identifier)
|
||||||
|
->(Identifier) }
|
||||||
|
(Empty))
|
||||||
|
(Assignment
|
||||||
|
(Empty)
|
||||||
|
{ (Identifier)
|
||||||
|
->(Identifier) }
|
||||||
|
(Empty))))
|
||||||
(DefaultExport
|
(DefaultExport
|
||||||
(VariableDeclaration
|
(VariableDeclaration
|
||||||
{-(Assignment{-(Empty)-}{-(Identifier)-}{-(Identifier)-})-}
|
{-(Assignment
|
||||||
(Assignment(Empty)(Identifier)(Identifier))
|
{-(Empty)-}
|
||||||
(Assignment(Empty)(Identifier){(Empty)->(Identifier)})
|
{-(Identifier)-}
|
||||||
{+(Assignment{+(Empty)+}{+(Identifier)+}{+(Empty)+})+}
|
{-(Identifier)-})-}
|
||||||
(Assignment(Empty){(Identifier)->(Identifier)}(Empty))))
|
(Assignment
|
||||||
|
(Empty)
|
||||||
|
(Identifier)
|
||||||
|
(Identifier))
|
||||||
|
(Assignment
|
||||||
|
(Empty)
|
||||||
|
(Identifier)
|
||||||
|
{ (Empty)
|
||||||
|
->(Identifier) })
|
||||||
|
{+(Assignment
|
||||||
|
{+(Empty)+}
|
||||||
|
{+(Identifier)+}
|
||||||
|
{+(Empty)+})+}
|
||||||
|
(Assignment
|
||||||
|
(Empty)
|
||||||
|
{ (Identifier)
|
||||||
|
->(Identifier) }
|
||||||
|
(Empty))))
|
||||||
(DefaultExport
|
(DefaultExport
|
||||||
{(Identifier)->(Identifier)})
|
{ (Identifier)
|
||||||
{+(DefaultExport
|
->(Identifier) })
|
||||||
{+(Function{+(Empty)+}{+(Empty)+}{+(Identifier)+}{+([])+})+})+}
|
{+(DefaultExport
|
||||||
|
{+(Function
|
||||||
|
{+(Empty)+}
|
||||||
|
{+(Empty)+}
|
||||||
|
{+(Identifier)+}
|
||||||
|
{+([])+})+})+}
|
||||||
(DefaultExport
|
(DefaultExport
|
||||||
(Function(Empty)(Empty)(Empty)([])))
|
(Function
|
||||||
{+(QualifiedExport)+}
|
(Empty)
|
||||||
{+(DefaultExport
|
(Empty)
|
||||||
{+(TextElement)+})+}
|
(Empty)
|
||||||
{+(QualifiedExportFrom
|
([])))
|
||||||
{+(Identifier)+})+}
|
{+(QualifiedExport)+}
|
||||||
{+(QualifiedExportFrom
|
{+(DefaultExport
|
||||||
{+(Identifier)+})+}
|
{+(TextElement)+})+}
|
||||||
{-(DefaultExport
|
{+(QualifiedExportFrom
|
||||||
{-(Function{-(Empty)-}{-(Empty)-}{-(Identifier)-}{-([])-})-})-}
|
{+(Identifier)+})+}
|
||||||
{-(QualifiedExport)-}
|
{+(QualifiedExportFrom
|
||||||
{-(DefaultExport
|
{+(Identifier)+})+}
|
||||||
{-(TextElement)-})-}
|
{-(DefaultExport
|
||||||
{-(QualifiedExportFrom
|
{-(Function
|
||||||
{-(Identifier)-})-}
|
{-(Empty)-}
|
||||||
{-(QualifiedExportFrom
|
{-(Empty)-}
|
||||||
{-(Identifier)-})-})
|
{-(Identifier)-}
|
||||||
|
{-([])-})-})-}
|
||||||
|
{-(QualifiedExport)-}
|
||||||
|
{-(DefaultExport
|
||||||
|
{-(TextElement)-})-}
|
||||||
|
{-(QualifiedExportFrom
|
||||||
|
{-(Identifier)-})-}
|
||||||
|
{-(QualifiedExportFrom
|
||||||
|
{-(Identifier)-})-})
|
||||||
|
96
test/fixtures/typescript/export.diffB-A.txt
vendored
96
test/fixtures/typescript/export.diffB-A.txt
vendored
@ -1,29 +1,83 @@
|
|||||||
(Program
|
(Program
|
||||||
{(QualifiedExport)->(QualifiedExport)}
|
{ (QualifiedExport)
|
||||||
{(QualifiedExport)->(QualifiedExport)}
|
->(QualifiedExport) }
|
||||||
|
{ (QualifiedExport)
|
||||||
|
->(QualifiedExport) }
|
||||||
(DefaultExport
|
(DefaultExport
|
||||||
(VariableDeclaration
|
(VariableDeclaration
|
||||||
(Assignment(Empty){(Identifier)->(Identifier)}(Empty))
|
(Assignment
|
||||||
(Assignment(Empty){(Identifier)->(Identifier)}(Empty))
|
(Empty)
|
||||||
(Assignment(Empty){(Identifier)->(Identifier)}(Empty))))
|
{ (Identifier)
|
||||||
|
->(Identifier) }
|
||||||
|
(Empty))
|
||||||
|
(Assignment
|
||||||
|
(Empty)
|
||||||
|
{ (Identifier)
|
||||||
|
->(Identifier) }
|
||||||
|
(Empty))
|
||||||
|
(Assignment
|
||||||
|
(Empty)
|
||||||
|
{ (Identifier)
|
||||||
|
->(Identifier) }
|
||||||
|
(Empty))))
|
||||||
(DefaultExport
|
(DefaultExport
|
||||||
(VariableDeclaration
|
(VariableDeclaration
|
||||||
{+(Assignment{+(Empty)+}{+(Identifier)+}{+(Identifier)+})+}
|
{+(Assignment
|
||||||
(Assignment(Empty)(Identifier)(Identifier))
|
{+(Empty)+}
|
||||||
(Assignment(Empty)(Identifier){(Identifier)->(Empty)})
|
{+(Identifier)+}
|
||||||
{+(Assignment{+(Empty)+}{+(Identifier)+}{+(Empty)+})+}
|
{+(Identifier)+})+}
|
||||||
{-(Assignment{-(Empty)-}{-(Identifier)-}{-(Empty)-})-}
|
(Assignment
|
||||||
{-(Assignment{-(Empty)-}{-(Identifier)-}{-(Empty)-})-}))
|
(Empty)
|
||||||
|
(Identifier)
|
||||||
|
(Identifier))
|
||||||
|
(Assignment
|
||||||
|
(Empty)
|
||||||
|
(Identifier)
|
||||||
|
{ (Identifier)
|
||||||
|
->(Empty) })
|
||||||
|
{+(Assignment
|
||||||
|
{+(Empty)+}
|
||||||
|
{+(Identifier)+}
|
||||||
|
{+(Empty)+})+}
|
||||||
|
{-(Assignment
|
||||||
|
{-(Empty)-}
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})-}
|
||||||
|
{-(Assignment
|
||||||
|
{-(Empty)-}
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})-}))
|
||||||
(DefaultExport
|
(DefaultExport
|
||||||
{(Identifier)->(Identifier)})
|
{ (Identifier)
|
||||||
{-(DefaultExport
|
->(Identifier) })
|
||||||
{-(Function{-(Empty)-}{-(Empty)-}{-(Identifier)-}{-([])-})-})-}
|
{-(DefaultExport
|
||||||
|
{-(Function
|
||||||
|
{-(Empty)-}
|
||||||
|
{-(Empty)-}
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-([])-})-})-}
|
||||||
(DefaultExport
|
(DefaultExport
|
||||||
(Function(Empty)(Empty)(Empty)([])))
|
(Function
|
||||||
{+(DefaultExport
|
(Empty)
|
||||||
{+(Function{+(Empty)+}{+(Empty)+}{+(Identifier)+}{+([])+})+})+}
|
(Empty)
|
||||||
{(QualifiedExport)->(QualifiedExport)}
|
(Empty)
|
||||||
|
([])))
|
||||||
|
{+(DefaultExport
|
||||||
|
{+(Function
|
||||||
|
{+(Empty)+}
|
||||||
|
{+(Empty)+}
|
||||||
|
{+(Identifier)+}
|
||||||
|
{+([])+})+})+}
|
||||||
|
{ (QualifiedExport)
|
||||||
|
->(QualifiedExport) }
|
||||||
(DefaultExport
|
(DefaultExport
|
||||||
{(TextElement)->(TextElement)})
|
{ (TextElement)
|
||||||
{(QualifiedExportFrom {-(Identifier)-})->(QualifiedExportFrom {+(Identifier)+})}
|
->(TextElement) })
|
||||||
{(QualifiedExportFrom {-(Identifier)-})->(QualifiedExportFrom {+(Identifier)+})})
|
{ (QualifiedExportFrom
|
||||||
|
{-(Identifier)-})
|
||||||
|
->(QualifiedExportFrom
|
||||||
|
{+(Identifier)+}) }
|
||||||
|
{ (QualifiedExportFrom
|
||||||
|
{-(Identifier)-})
|
||||||
|
->(QualifiedExportFrom
|
||||||
|
{+(Identifier)+}) })
|
||||||
|
61
test/fixtures/typescript/export.parseA.txt
vendored
61
test/fixtures/typescript/export.parseA.txt
vendored
@ -3,19 +3,54 @@
|
|||||||
(QualifiedExport)
|
(QualifiedExport)
|
||||||
(DefaultExport
|
(DefaultExport
|
||||||
(VariableDeclaration
|
(VariableDeclaration
|
||||||
(Assignment(Empty)(Identifier)(Empty))
|
(Assignment
|
||||||
(Assignment(Empty)(Identifier)(Empty))
|
(Empty)
|
||||||
(Assignment(Empty)(Identifier)(Empty))))
|
(Identifier)
|
||||||
|
(Empty))
|
||||||
|
(Assignment
|
||||||
|
(Empty)
|
||||||
|
(Identifier)
|
||||||
|
(Empty))
|
||||||
|
(Assignment
|
||||||
|
(Empty)
|
||||||
|
(Identifier)
|
||||||
|
(Empty))))
|
||||||
(DefaultExport
|
(DefaultExport
|
||||||
(VariableDeclaration
|
(VariableDeclaration
|
||||||
(Assignment(Empty)(Identifier)(Identifier))
|
(Assignment
|
||||||
(Assignment(Empty)(Identifier)(Identifier))
|
(Empty)
|
||||||
(Assignment(Empty)(Identifier)(Empty))
|
(Identifier)
|
||||||
(Assignment(Empty)(Identifier)(Empty))))
|
(Identifier))
|
||||||
(DefaultExport (Identifier))
|
(Assignment
|
||||||
(DefaultExport (Function(Empty)(Empty)(Empty)([])))
|
(Empty)
|
||||||
(DefaultExport (Function(Empty)(Empty)(Identifier)([])))
|
(Identifier)
|
||||||
|
(Identifier))
|
||||||
|
(Assignment
|
||||||
|
(Empty)
|
||||||
|
(Identifier)
|
||||||
|
(Empty))
|
||||||
|
(Assignment
|
||||||
|
(Empty)
|
||||||
|
(Identifier)
|
||||||
|
(Empty))))
|
||||||
|
(DefaultExport
|
||||||
|
(Identifier))
|
||||||
|
(DefaultExport
|
||||||
|
(Function
|
||||||
|
(Empty)
|
||||||
|
(Empty)
|
||||||
|
(Empty)
|
||||||
|
([])))
|
||||||
|
(DefaultExport
|
||||||
|
(Function
|
||||||
|
(Empty)
|
||||||
|
(Empty)
|
||||||
|
(Identifier)
|
||||||
|
([])))
|
||||||
(QualifiedExport)
|
(QualifiedExport)
|
||||||
(DefaultExport (TextElement))
|
(DefaultExport
|
||||||
(QualifiedExportFrom (Identifier))
|
(TextElement))
|
||||||
(QualifiedExportFrom (Identifier)))
|
(QualifiedExportFrom
|
||||||
|
(Identifier))
|
||||||
|
(QualifiedExportFrom
|
||||||
|
(Identifier)))
|
||||||
|
61
test/fixtures/typescript/export.parseB.txt
vendored
61
test/fixtures/typescript/export.parseB.txt
vendored
@ -3,19 +3,54 @@
|
|||||||
(QualifiedExport)
|
(QualifiedExport)
|
||||||
(DefaultExport
|
(DefaultExport
|
||||||
(VariableDeclaration
|
(VariableDeclaration
|
||||||
(Assignment(Empty)(Identifier)(Empty))
|
(Assignment
|
||||||
(Assignment(Empty)(Identifier)(Empty))
|
(Empty)
|
||||||
(Assignment(Empty)(Identifier)(Empty))))
|
(Identifier)
|
||||||
|
(Empty))
|
||||||
|
(Assignment
|
||||||
|
(Empty)
|
||||||
|
(Identifier)
|
||||||
|
(Empty))
|
||||||
|
(Assignment
|
||||||
|
(Empty)
|
||||||
|
(Identifier)
|
||||||
|
(Empty))))
|
||||||
(DefaultExport
|
(DefaultExport
|
||||||
(VariableDeclaration
|
(VariableDeclaration
|
||||||
(Assignment(Empty)(Identifier)(Identifier))
|
(Assignment
|
||||||
(Assignment(Empty)(Identifier)(Identifier))
|
(Empty)
|
||||||
(Assignment(Empty)(Identifier)(Empty))
|
(Identifier)
|
||||||
(Assignment(Empty)(Identifier)(Empty))))
|
(Identifier))
|
||||||
(DefaultExport(Identifier))
|
(Assignment
|
||||||
(DefaultExport(Function(Empty)(Empty)(Identifier)([])))
|
(Empty)
|
||||||
(DefaultExport(Function(Empty)(Empty)(Empty)([])))
|
(Identifier)
|
||||||
|
(Identifier))
|
||||||
|
(Assignment
|
||||||
|
(Empty)
|
||||||
|
(Identifier)
|
||||||
|
(Empty))
|
||||||
|
(Assignment
|
||||||
|
(Empty)
|
||||||
|
(Identifier)
|
||||||
|
(Empty))))
|
||||||
|
(DefaultExport
|
||||||
|
(Identifier))
|
||||||
|
(DefaultExport
|
||||||
|
(Function
|
||||||
|
(Empty)
|
||||||
|
(Empty)
|
||||||
|
(Identifier)
|
||||||
|
([])))
|
||||||
|
(DefaultExport
|
||||||
|
(Function
|
||||||
|
(Empty)
|
||||||
|
(Empty)
|
||||||
|
(Empty)
|
||||||
|
([])))
|
||||||
(QualifiedExport)
|
(QualifiedExport)
|
||||||
(DefaultExport (TextElement))
|
(DefaultExport
|
||||||
(QualifiedExportFrom (Identifier))
|
(TextElement))
|
||||||
(QualifiedExportFrom (Identifier)))
|
(QualifiedExportFrom
|
||||||
|
(Identifier))
|
||||||
|
(QualifiedExportFrom
|
||||||
|
(Identifier)))
|
||||||
|
97
test/fixtures/typescript/import.diffA-B.txt
vendored
97
test/fixtures/typescript/import.diffA-B.txt
vendored
@ -1,45 +1,68 @@
|
|||||||
(Program
|
(Program
|
||||||
(Import
|
|
||||||
{ (Identifier)
|
|
||||||
->(Identifier) })
|
|
||||||
(QualifiedImport
|
|
||||||
{ (Identifier)
|
|
||||||
->(Identifier) }
|
|
||||||
{ (Identifier)
|
|
||||||
->(Identifier) })
|
|
||||||
{ (Import
|
|
||||||
{-(Identifier)-})
|
|
||||||
->(Import
|
|
||||||
{+(Identifier)+}) }
|
|
||||||
{ (Import
|
|
||||||
{-(Identifier)-})
|
|
||||||
->(Import
|
|
||||||
{+(Identifier)+}) }
|
|
||||||
{ (Import
|
|
||||||
{-(Identifier)-})
|
|
||||||
->(Import
|
|
||||||
{+(Identifier)+}) }
|
|
||||||
(
|
|
||||||
(Import
|
|
||||||
{ (Identifier)
|
|
||||||
->(Identifier) })
|
|
||||||
{ (Import
|
|
||||||
{-(Identifier)-})
|
|
||||||
->(Import
|
|
||||||
{+(Identifier)+}) })
|
|
||||||
(
|
|
||||||
(Import
|
|
||||||
{ (Identifier)
|
|
||||||
->(Identifier) })
|
|
||||||
(QualifiedImport
|
|
||||||
{ (Identifier)
|
|
||||||
->(Identifier) }
|
|
||||||
{ (Identifier)
|
|
||||||
->(Identifier) }))
|
|
||||||
{+(Import
|
{+(Import
|
||||||
|
{+(Identifier)+}
|
||||||
|
{+(Empty)+})+}
|
||||||
|
{+(QualifiedImport
|
||||||
|
{+(Identifier)+}
|
||||||
{+(Identifier)+})+}
|
{+(Identifier)+})+}
|
||||||
|
{+(Import
|
||||||
|
{+(Identifier)+}
|
||||||
|
{+(Empty)+})+}
|
||||||
|
{+(Import
|
||||||
|
{+(Identifier)+}
|
||||||
|
{+(Empty)+})+}
|
||||||
|
{+(Import
|
||||||
|
{+(Identifier)+}
|
||||||
|
{+(Empty)+})+}
|
||||||
|
{+(
|
||||||
|
{+(Import
|
||||||
|
{+(Identifier)+}
|
||||||
|
{+(Empty)+})+}
|
||||||
|
{+(Import
|
||||||
|
{+(Identifier)+}
|
||||||
|
{+(Empty)+})+})+}
|
||||||
|
{+(
|
||||||
|
{+(Import
|
||||||
|
{+(Identifier)+}
|
||||||
|
{+(Empty)+})+}
|
||||||
|
{+(QualifiedImport
|
||||||
|
{+(Identifier)+}
|
||||||
|
{+(Identifier)+})+})+}
|
||||||
|
{+(SideEffectImport
|
||||||
|
{+(Identifier)+}
|
||||||
|
{+(Empty)+})+}
|
||||||
{-(Import
|
{-(Import
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})-}
|
||||||
|
{-(QualifiedImport
|
||||||
|
{-(Identifier)-}
|
||||||
{-(Identifier)-})-}
|
{-(Identifier)-})-}
|
||||||
|
{-(Import
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})-}
|
||||||
|
{-(Import
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})-}
|
||||||
|
{-(Import
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})-}
|
||||||
|
{-(
|
||||||
|
{-(Import
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})-}
|
||||||
|
{-(Import
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})-})-}
|
||||||
|
{-(
|
||||||
|
{-(Import
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})-}
|
||||||
|
{-(QualifiedImport
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Identifier)-})-})-}
|
||||||
|
{-(SideEffectImport
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})-}
|
||||||
{-(QualifiedImport
|
{-(QualifiedImport
|
||||||
{-(Identifier)-}
|
{-(Identifier)-}
|
||||||
{-(Identifier)-})-})
|
{-(Identifier)-})-})
|
||||||
|
101
test/fixtures/typescript/import.diffB-A.txt
vendored
101
test/fixtures/typescript/import.diffB-A.txt
vendored
@ -1,45 +1,68 @@
|
|||||||
(Program
|
(Program
|
||||||
(Import
|
|
||||||
{ (Identifier)
|
|
||||||
->(Identifier) })
|
|
||||||
(QualifiedImport
|
|
||||||
{ (Identifier)
|
|
||||||
->(Identifier) }
|
|
||||||
{ (Identifier)
|
|
||||||
->(Identifier) })
|
|
||||||
{ (Import
|
|
||||||
{-(Identifier)-})
|
|
||||||
->(Import
|
|
||||||
{+(Identifier)+}) }
|
|
||||||
{ (Import
|
|
||||||
{-(Identifier)-})
|
|
||||||
->(Import
|
|
||||||
{+(Identifier)+}) }
|
|
||||||
{ (Import
|
|
||||||
{-(Identifier)-})
|
|
||||||
->(Import
|
|
||||||
{+(Identifier)+}) }
|
|
||||||
(
|
|
||||||
(Import
|
|
||||||
{ (Identifier)
|
|
||||||
->(Identifier) })
|
|
||||||
{ (Import
|
|
||||||
{-(Identifier)-})
|
|
||||||
->(Import
|
|
||||||
{+(Identifier)+}) })
|
|
||||||
(
|
|
||||||
(Import
|
|
||||||
{ (Identifier)
|
|
||||||
->(Identifier) })
|
|
||||||
(QualifiedImport
|
|
||||||
{ (Identifier)
|
|
||||||
->(Identifier) }
|
|
||||||
{ (Identifier)
|
|
||||||
->(Identifier) }))
|
|
||||||
{+(Import
|
{+(Import
|
||||||
{+(Identifier)+})+}
|
{+(Identifier)+}
|
||||||
|
{+(Empty)+})+}
|
||||||
{+(QualifiedImport
|
{+(QualifiedImport
|
||||||
{+(Identifier)+}
|
{+(Identifier)+}
|
||||||
{+(Identifier)+})+}
|
{+(Identifier)+})+}
|
||||||
|
{ (Import
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})
|
||||||
|
->(Import
|
||||||
|
{+(Identifier)+}
|
||||||
|
{+(Empty)+}) }
|
||||||
|
{+(Import
|
||||||
|
{+(Identifier)+}
|
||||||
|
{+(Empty)+})+}
|
||||||
|
{+(Import
|
||||||
|
{+(Identifier)+}
|
||||||
|
{+(Empty)+})+}
|
||||||
|
{+(
|
||||||
|
{+(Import
|
||||||
|
{+(Identifier)+}
|
||||||
|
{+(Empty)+})+}
|
||||||
|
{+(Import
|
||||||
|
{+(Identifier)+}
|
||||||
|
{+(Empty)+})+})+}
|
||||||
|
{+(
|
||||||
|
{+(Import
|
||||||
|
{+(Identifier)+}
|
||||||
|
{+(Empty)+})+}
|
||||||
|
{+(QualifiedImport
|
||||||
|
{+(Identifier)+}
|
||||||
|
{+(Identifier)+})+})+}
|
||||||
|
{+(SideEffectImport
|
||||||
|
{+(Identifier)+}
|
||||||
|
{+(Empty)+})+}
|
||||||
|
{+(QualifiedImport
|
||||||
|
{+(Identifier)+}
|
||||||
|
{+(Identifier)+})+}
|
||||||
|
{-(QualifiedImport
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Identifier)-})-}
|
||||||
{-(Import
|
{-(Import
|
||||||
{-(Identifier)-})-})
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})-}
|
||||||
|
{-(Import
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})-}
|
||||||
|
{-(Import
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})-}
|
||||||
|
{-(
|
||||||
|
{-(Import
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})-}
|
||||||
|
{-(Import
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})-})-}
|
||||||
|
{-(
|
||||||
|
{-(Import
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})-}
|
||||||
|
{-(QualifiedImport
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Identifier)-})-})-}
|
||||||
|
{-(SideEffectImport
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Empty)-})-})
|
||||||
|
26
test/fixtures/typescript/import.parseA.txt
vendored
26
test/fixtures/typescript/import.parseA.txt
vendored
@ -1,28 +1,36 @@
|
|||||||
(Program
|
(Program
|
||||||
(Import
|
(Import
|
||||||
(Identifier))
|
(Identifier)
|
||||||
|
(Empty))
|
||||||
(QualifiedImport
|
(QualifiedImport
|
||||||
(Identifier)
|
(Identifier)
|
||||||
(Identifier))
|
(Identifier))
|
||||||
(Import
|
(Import
|
||||||
(Identifier))
|
(Identifier)
|
||||||
|
(Empty))
|
||||||
(Import
|
(Import
|
||||||
(Identifier))
|
(Identifier)
|
||||||
|
(Empty))
|
||||||
(Import
|
(Import
|
||||||
(Identifier))
|
(Identifier)
|
||||||
|
(Empty))
|
||||||
(
|
(
|
||||||
(Import
|
(Import
|
||||||
(Identifier))
|
(Identifier)
|
||||||
|
(Empty))
|
||||||
(Import
|
(Import
|
||||||
(Identifier)))
|
(Identifier)
|
||||||
|
(Empty)))
|
||||||
(
|
(
|
||||||
(Import
|
(Import
|
||||||
(Identifier))
|
(Identifier)
|
||||||
|
(Empty))
|
||||||
(QualifiedImport
|
(QualifiedImport
|
||||||
(Identifier)
|
(Identifier)
|
||||||
(Identifier)))
|
(Identifier)))
|
||||||
(Import
|
(SideEffectImport
|
||||||
(Identifier))
|
(Identifier)
|
||||||
|
(Empty))
|
||||||
(QualifiedImport
|
(QualifiedImport
|
||||||
(Identifier)
|
(Identifier)
|
||||||
(Identifier)))
|
(Identifier)))
|
||||||
|
26
test/fixtures/typescript/import.parseB.txt
vendored
26
test/fixtures/typescript/import.parseB.txt
vendored
@ -1,25 +1,33 @@
|
|||||||
(Program
|
(Program
|
||||||
(Import
|
(Import
|
||||||
(Identifier))
|
(Identifier)
|
||||||
|
(Empty))
|
||||||
(QualifiedImport
|
(QualifiedImport
|
||||||
(Identifier)
|
(Identifier)
|
||||||
(Identifier))
|
(Identifier))
|
||||||
(Import
|
(Import
|
||||||
(Identifier))
|
(Identifier)
|
||||||
|
(Empty))
|
||||||
(Import
|
(Import
|
||||||
(Identifier))
|
(Identifier)
|
||||||
|
(Empty))
|
||||||
(Import
|
(Import
|
||||||
(Identifier))
|
(Identifier)
|
||||||
|
(Empty))
|
||||||
(
|
(
|
||||||
(Import
|
(Import
|
||||||
(Identifier))
|
(Identifier)
|
||||||
|
(Empty))
|
||||||
(Import
|
(Import
|
||||||
(Identifier)))
|
(Identifier)
|
||||||
|
(Empty)))
|
||||||
(
|
(
|
||||||
(Import
|
(Import
|
||||||
(Identifier))
|
(Identifier)
|
||||||
|
(Empty))
|
||||||
(QualifiedImport
|
(QualifiedImport
|
||||||
(Identifier)
|
(Identifier)
|
||||||
(Identifier)))
|
(Identifier)))
|
||||||
(Import
|
(SideEffectImport
|
||||||
(Identifier)))
|
(Identifier)
|
||||||
|
(Empty)))
|
||||||
|
Loading…
Reference in New Issue
Block a user