mirror of
https://github.com/github/semantic.git
synced 2024-12-22 22:31:36 +03:00
Wildcard imports
This commit is contained in:
parent
ad225f7d89
commit
5e9a9b33a5
@ -272,15 +272,12 @@ instance Eq1 Import where liftEq = genericLiftEq
|
||||
instance Ord1 Import where liftCompare = genericLiftCompare
|
||||
instance Show1 Import where liftShowsPrec = genericLiftShowsPrec
|
||||
|
||||
instance ( Show l
|
||||
, Show t
|
||||
, Semigroup (Cell l (Value l t)) -- lookupOrAlloc
|
||||
instance ( Semigroup (Cell l (Value l t))
|
||||
, Members (Evaluating (Value l t)) es
|
||||
, Addressable l es
|
||||
, Evaluatable es t (Value l t) (Base t)
|
||||
, Recursive t
|
||||
, FreeVariables t
|
||||
-- , HasField fields Range
|
||||
)
|
||||
=> Evaluatable es t (Value l t) Import where
|
||||
eval (Import from alias _) = do
|
||||
@ -294,13 +291,28 @@ instance ( Show l
|
||||
|
||||
-- Restore previous global environment, adding the imported env
|
||||
(name, addr) <- lookupOrAlloc' (qualifiedName (subterm alias)) interface env
|
||||
modify (const (envInsert name addr env)) -- const is important—we are throwing away the modified global env and specifically crafting a new environment.
|
||||
modify (const (envInsert name addr env)) -- const is important. We are throwing away the modified global env and specifically crafting a new one.
|
||||
|
||||
pure interface
|
||||
|
||||
instance Member Fail es => Evaluatable es t Type.Type Import
|
||||
|
||||
|
||||
-- | A wildcard import
|
||||
data WildcardImport a = WildcardImport { wildcardImportFrom :: !a, wildcardImportSymbol :: !a }
|
||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1)
|
||||
|
||||
instance Eq1 WildcardImport where liftEq = genericLiftEq
|
||||
instance Ord1 WildcardImport where liftCompare = genericLiftCompare
|
||||
instance Show1 WildcardImport where liftShowsPrec = genericLiftShowsPrec
|
||||
|
||||
instance ( Members (Evaluating v) es
|
||||
, FreeVariables t
|
||||
)
|
||||
=> Evaluatable es t v WildcardImport where
|
||||
eval (WildcardImport from _) = require @v (qualifiedName (subterm from))
|
||||
|
||||
|
||||
-- | An imported symbol
|
||||
data ImportSymbol a = ImportSymbol { importSymbolName :: !a, importSymbolAlias :: !a }
|
||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1)
|
||||
|
@ -37,6 +37,7 @@ type Syntax =
|
||||
, Declaration.Import
|
||||
, Declaration.ImportSymbol
|
||||
, Declaration.Variable
|
||||
, Declaration.WildcardImport
|
||||
, Expression.Arithmetic
|
||||
, Expression.Boolean
|
||||
, Expression.Bitwise
|
||||
@ -374,11 +375,12 @@ comment = makeTerm <$> symbol Comment <*> (Comment.Comment <$> source)
|
||||
|
||||
import' :: Assignment
|
||||
import' = makeTerm'' <$> symbol ImportStatement <*> children (manyTerm (aliasedImport <|> plainImport))
|
||||
<|> makeTerm <$> symbol ImportFromStatement <*> children (Declaration.Import <$> (dottedName <|> emptyTerm) <*> emptyTerm <*> someTerm (wildCard <|> dottedName <|> aliasedSymbol <|> importSymbol))
|
||||
<|> makeTerm <$> symbol ImportFromStatement <*> children (Declaration.Import <$> (dottedName <|> emptyTerm) <*> emptyTerm <*> someTerm (dottedName <|> aliasedSymbol <|> importSymbol))
|
||||
<|> makeTerm <$> symbol ImportFromStatement <*> children (Declaration.WildcardImport <$> dottedName <*> wildcard)
|
||||
where
|
||||
importSymbol = makeTerm <$> location <*> (Declaration.ImportSymbol <$> expression <*> emptyTerm)
|
||||
aliasedSymbol = makeTerm <$> symbol AliasedImport <*> children (Declaration.ImportSymbol <$> expression <*> expression)
|
||||
wildCard = makeTerm <$> symbol WildcardImport <*> (Syntax.Identifier <$> source)
|
||||
wildcard = makeTerm <$> symbol WildcardImport <*> (Syntax.Identifier <$> source)
|
||||
|
||||
aliasedImport = makeImport <$> symbol AliasedImport <*> children ((,) <$> expression <*> (Just <$> expression))
|
||||
plainImport = makeImport <$> symbol DottedName <*> children ((,) <$> expressions <*> pure Nothing)
|
||||
|
Loading…
Reference in New Issue
Block a user