mirror of
https://github.com/github/semantic.git
synced 2024-12-20 21:31:48 +03:00
Refactor to specialize syntax across different languages
This commit is contained in:
parent
7b5137fdee
commit
d04909bb1b
@ -153,18 +153,6 @@ instance Evaluatable Class where
|
||||
klass name supers classEnv
|
||||
v <$ modifyEnv (Env.insert name addr)
|
||||
|
||||
data Namespace a = Namespace { namespaceIdentifier :: !a, namespaceStatements :: ![a] }
|
||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1)
|
||||
|
||||
instance Eq1 Namespace where liftEq = genericLiftEq
|
||||
instance Ord1 Namespace where liftCompare = genericLiftCompare
|
||||
instance Show1 Namespace where liftShowsPrec = genericLiftShowsPrec
|
||||
|
||||
instance Evaluatable Namespace where
|
||||
eval (Namespace iden xs) = letrec' name $ \addr ->
|
||||
eval xs <* makeNamespace name addr
|
||||
where name = freeVariable (subterm iden)
|
||||
|
||||
-- | A decorator in Python
|
||||
data Decorator a = Decorator { decoratorIdentifier :: !a, decoratorParamaters :: ![a], decoratorBody :: !a }
|
||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1)
|
||||
|
@ -29,7 +29,6 @@ type Syntax = '[
|
||||
, Declaration.Class
|
||||
, Declaration.Function
|
||||
, Declaration.Method
|
||||
, Declaration.Namespace
|
||||
, Expression.Arithmetic
|
||||
, Expression.Bitwise
|
||||
, Expression.Boolean
|
||||
@ -77,6 +76,7 @@ type Syntax = '[
|
||||
, Syntax.Program
|
||||
, Ruby.Syntax.Require
|
||||
, Ruby.Syntax.Load
|
||||
, Ruby.Syntax.Module
|
||||
, []
|
||||
]
|
||||
|
||||
@ -207,7 +207,7 @@ singletonClass :: Assignment
|
||||
singletonClass = makeTerm <$> symbol SingletonClass <*> children (Declaration.Class <$> pure [] <*> expression <*> pure [] <*> expressions)
|
||||
|
||||
module' :: Assignment
|
||||
module' = makeTerm <$> symbol Module <*> children (Declaration.Namespace <$> expression <*> many expression)
|
||||
module' = makeTerm <$> symbol Module <*> children (Ruby.Syntax.Module <$> expression <*> many expression)
|
||||
|
||||
scopeResolution :: Assignment
|
||||
scopeResolution = makeTerm <$> symbol ScopeResolution <*> children (Expression.ScopeResolution <$> many expression)
|
||||
|
@ -61,3 +61,16 @@ doLoad path shouldWrap = do
|
||||
toName = qualifiedName . splitOnPathSeparator . dropExtension . dropRelativePrefix . stripQuotes
|
||||
|
||||
-- TODO: autoload
|
||||
|
||||
|
||||
data Module a = Module { moduleIdentifier :: !a, moduleStatements :: ![a] }
|
||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1)
|
||||
|
||||
instance Eq1 Module where liftEq = genericLiftEq
|
||||
instance Ord1 Module where liftCompare = genericLiftCompare
|
||||
instance Show1 Module where liftShowsPrec = genericLiftShowsPrec
|
||||
|
||||
instance Evaluatable Module where
|
||||
eval (Module iden xs) = letrec' name $ \addr ->
|
||||
eval xs <* makeNamespace name addr
|
||||
where name = freeVariable (subterm iden)
|
||||
|
@ -41,7 +41,6 @@ type Syntax = '[
|
||||
, Declaration.DefaultExport
|
||||
, Declaration.QualifiedExport
|
||||
, Declaration.QualifiedExportFrom
|
||||
, Declaration.Namespace
|
||||
, Expression.Arithmetic
|
||||
, Expression.Bitwise
|
||||
, Expression.Boolean
|
||||
@ -124,6 +123,8 @@ type Syntax = '[
|
||||
, TypeScript.Syntax.LiteralType
|
||||
, TypeScript.Syntax.Union
|
||||
, TypeScript.Syntax.Intersection
|
||||
, TypeScript.Syntax.Module
|
||||
, TypeScript.Syntax.InternalModule
|
||||
, TypeScript.Syntax.FunctionType
|
||||
, TypeScript.Syntax.Tuple
|
||||
, TypeScript.Syntax.Constructor
|
||||
@ -756,10 +757,10 @@ optionalParameter = makeOptionalParam <$> symbol Grammar.OptionalParameter <*> c
|
||||
where makeOptionalParam loc (modifier, readonly, subject, annotation, initializer) = makeTerm loc (TypeScript.Syntax.OptionalParameter [modifier, readonly, annotation] (makeTerm loc (Statement.Assignment [] subject initializer)))
|
||||
|
||||
internalModule :: Assignment
|
||||
internalModule = makeTerm <$> symbol Grammar.InternalModule <*> children (Declaration.Namespace <$> term (string <|> identifier <|> nestedIdentifier) <*> statements)
|
||||
internalModule = makeTerm <$> symbol Grammar.InternalModule <*> children (TypeScript.Syntax.InternalModule <$> term (string <|> identifier <|> nestedIdentifier) <*> statements)
|
||||
|
||||
module' :: Assignment
|
||||
module' = makeTerm <$> symbol Module <*> children (Declaration.Namespace <$> term (string <|> identifier <|> nestedIdentifier) <*> (statements <|> pure []))
|
||||
module' = makeTerm <$> symbol Module <*> children (TypeScript.Syntax.Module <$> term (string <|> identifier <|> nestedIdentifier) <*> (statements <|> pure []))
|
||||
|
||||
|
||||
statements :: Assignment.Assignment [] Grammar [Term]
|
||||
|
@ -388,6 +388,31 @@ instance Ord1 Update where liftCompare = genericLiftCompare
|
||||
instance Show1 Update where liftShowsPrec = genericLiftShowsPrec
|
||||
instance Evaluatable Update
|
||||
|
||||
data Module a = Module { moduleIdentifier :: !a, moduleStatements :: ![a] }
|
||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1)
|
||||
|
||||
instance Eq1 Module where liftEq = genericLiftEq
|
||||
instance Ord1 Module where liftCompare = genericLiftCompare
|
||||
instance Show1 Module where liftShowsPrec = genericLiftShowsPrec
|
||||
|
||||
instance Evaluatable Module where
|
||||
eval (Module iden xs) = letrec' name $ \addr ->
|
||||
eval xs <* makeNamespace name addr
|
||||
where name = freeVariable (subterm iden)
|
||||
|
||||
data InternalModule a = InternalModule { internalModuleIdentifier :: !a, internalModuleStatements :: ![a] }
|
||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1)
|
||||
|
||||
instance Eq1 InternalModule where liftEq = genericLiftEq
|
||||
instance Ord1 InternalModule where liftCompare = genericLiftCompare
|
||||
instance Show1 InternalModule where liftShowsPrec = genericLiftShowsPrec
|
||||
|
||||
instance Evaluatable InternalModule where
|
||||
eval (InternalModule iden xs) = letrec' name $ \addr ->
|
||||
eval xs <* makeNamespace name addr
|
||||
where name = freeVariable (subterm iden)
|
||||
|
||||
|
||||
data ImportAlias a = ImportAlias { _importAliasSubject :: !a, _importAlias :: !a }
|
||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user