1
1
mirror of https://github.com/github/semantic.git synced 2024-12-23 14:54:16 +03:00

Add traits and constructors/destructors

This commit is contained in:
joshvera 2018-01-10 17:49:17 -05:00
parent 844ca0551d
commit fb1440f4d3
2 changed files with 68 additions and 11 deletions

View File

@ -87,6 +87,15 @@ type Syntax = '[
, Syntax.NamespaceUseClause
, Syntax.NamespaceUseDeclaration
, Syntax.Namespace
, Syntax.AliasAs
, Syntax.InsteadOf
, Syntax.TraitUseSpecification
, Syntax.TraitUseClause
, Syntax.ClassModifier
, Syntax.Static
, Syntax.DestructorDeclaration
, Syntax.ConstructorDeclaration
, Syntax.TraitDeclaration
, [] ]
type Term = Term.Term (Data.Union.Union Syntax) (Record Location)
@ -172,7 +181,7 @@ augmentedAssignmentExpression = makeTerm' <$> symbol AugmentedAssignmentExpressi
, assign Expression.BAnd <$ symbol AnonAmpersandEqual
, assign Expression.BXOr <$ symbol AnonCaretEqual
, assign Expression.BOr <$ symbol AnonPipeEqual ])
where assign :: f :< Syntax => (Term -> Term -> f Term) -> Term -> Term -> Data.Union.Union Syntax Term
where
assign c l r = inj (Statement.Assignment [] l (makeTerm1 (c l r)))
binaryExpression :: Assignment
@ -312,7 +321,8 @@ printIntrinsic = makeTerm <$> symbol PrintIntrinsic <*> children (Syntax.PrintIn
anonymousFunctionCreationExpression :: Assignment
anonymousFunctionCreationExpression = makeTerm <$> symbol AnonymousFunctionCreationExpression <*> children (makeFunction <$> emptyTerm <*> parameters <*> functionUseClause <*> returnType <*> compoundStatement)
where makeFunction identifier parameters functionUseClause returnType statement = Declaration.Function [functionUseClause, returnType] identifier parameters statement
where
makeFunction identifier parameters functionUseClause returnType statement = Declaration.Function [functionUseClause, returnType] identifier parameters statement
parameters :: Assignment.Assignment [] Grammar [Term]
parameters = manyTerm (simpleParameter <|> variadicParameter)
@ -357,12 +367,12 @@ objectCreationExpression = (makeTerm <$> symbol ObjectCreationExpression <*> chi
classMemberDeclaration :: Assignment
classMemberDeclaration = choice [
classConstDeclaration
classConstDeclaration,
-- propertyDeclaration,
-- methodDeclaration,
-- constructorDeclaration,
-- destructorDeclaration,
-- traitUseClause
constructorDeclaration,
destructorDeclaration,
traitUseClause
]
classBaseClause :: Assignment
@ -442,13 +452,32 @@ traitDeclaration = makeTerm <$> symbol TraitDeclaration <*> children (Syntax.Tra
traitMemberDeclaration :: Assignment
traitMemberDeclaration = choice [
propertyDeclaration,
methodDeclaration,
-- propertyDeclaration,
-- methodDeclaration,
constructorDeclaration,
destructorDeclaration,
(makeTerm <$> location <*> someTerm traitUseClause)
makeTerm <$> location <*> someTerm traitUseClause
]
constructorDeclaration :: Assignment
constructorDeclaration = makeTerm <$> symbol ConstructorDeclaration <*> children (Syntax.ConstructorDeclaration <$> someTerm methodModifier <*> parameters <*> compoundStatement)
destructorDeclaration :: Assignment
destructorDeclaration = makeTerm <$> symbol DestructorDeclaration <*> children (Syntax.DestructorDeclaration <$> someTerm methodModifier <*> compoundStatement)
methodModifier :: Assignment
methodModifier = choice [
visibilityModifier,
classModifier,
staticModifier
]
staticModifier :: Assignment
staticModifier = makeTerm <$> symbol StaticModifier <*> (Syntax.Static <$> source)
classModifier :: Assignment
classModifier = makeTerm <$> symbol ClassModifier <*> (Syntax.ClassModifier <$> source)
traitUseClause :: Assignment
traitUseClause = makeTerm <$> symbol TraitUseClause <*> children (Syntax.TraitUseClause <$> someTerm qualifiedName <*> traitUseSpecification)
@ -469,7 +498,7 @@ namespaceDefinition = makeTerm <$> symbol NamespaceDefinition <*> children (Synt
namespaceUseDeclaration :: Assignment
namespaceUseDeclaration = makeTerm <$> symbol NamespaceUseDeclaration <*> children (Syntax.NamespaceUseDeclaration <$>
(((++) <$> (pure <$> (namespaceFunctionOrConst <|> emptyTerm)) <*> someTerm namespaceUseClause) <|> ((\a b cs -> a : b : cs) <$> namespaceFunctionOrConst <*> namespaceName <*> someTerm namespaceUseGroupClause1) <|> ((\a b -> a : b) <$> namespaceName <*> someTerm namespaceUseGroupClause2)))
(((++) <$> (pure <$> (namespaceFunctionOrConst <|> emptyTerm)) <*> someTerm namespaceUseClause) <|> ((\a b cs -> a : b : cs) <$> namespaceFunctionOrConst <*> namespaceName <*> someTerm namespaceUseGroupClause1) <|> ((:) <$> namespaceName <*> someTerm namespaceUseGroupClause2)))
namespaceUseClause :: Assignment
namespaceUseClause = makeTerm <$> symbol NamespaceUseClause <*> children (fmap Syntax.NamespaceUseClause $ (\a b -> [a, b]) <$> namespaceName <*> (namespaceAliasingClause <|> emptyTerm))

View File

@ -305,3 +305,31 @@ data TraitUseClause a = TraitUseClause [a] a
instance Eq1 TraitUseClause where liftEq = genericLiftEq
instance Ord1 TraitUseClause where liftCompare = genericLiftCompare
instance Show1 TraitUseClause where liftShowsPrec = genericLiftShowsPrec
data DestructorDeclaration a = DestructorDeclaration [a] a
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable)
instance Eq1 DestructorDeclaration where liftEq = genericLiftEq
instance Ord1 DestructorDeclaration where liftCompare = genericLiftCompare
instance Show1 DestructorDeclaration where liftShowsPrec = genericLiftShowsPrec
newtype Static a = Static ByteString
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable)
instance Eq1 Static where liftEq = genericLiftEq
instance Ord1 Static where liftCompare = genericLiftCompare
instance Show1 Static where liftShowsPrec = genericLiftShowsPrec
newtype ClassModifier a = ClassModifier ByteString
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable)
instance Eq1 ClassModifier where liftEq = genericLiftEq
instance Ord1 ClassModifier where liftCompare = genericLiftCompare
instance Show1 ClassModifier where liftShowsPrec = genericLiftShowsPrec
data ConstructorDeclaration a = ConstructorDeclaration [a] [a] a
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable)
instance Eq1 ConstructorDeclaration where liftEq = genericLiftEq
instance Ord1 ConstructorDeclaration where liftCompare = genericLiftCompare
instance Show1 ConstructorDeclaration where liftShowsPrec = genericLiftShowsPrec