mirror of
https://github.com/github/semantic.git
synced 2024-12-23 14:54:16 +03:00
Add anonymous functions
This commit is contained in:
parent
0f627bcc50
commit
5352559835
@ -61,6 +61,13 @@ type Syntax = '[
|
|||||||
, Syntax.ClassInterfaceClause
|
, Syntax.ClassInterfaceClause
|
||||||
, Declaration.Class
|
, Declaration.Class
|
||||||
, Syntax.ClassBaseClause
|
, Syntax.ClassBaseClause
|
||||||
|
, Syntax.ScalarType
|
||||||
|
, Syntax.BaseTypeDeclaration
|
||||||
|
, Syntax.TypeDeclaration
|
||||||
|
, Syntax.ReturnType
|
||||||
|
, Syntax.UseClause
|
||||||
|
, Type.Annotation
|
||||||
|
, Declaration.Function
|
||||||
, Expression.New
|
, Expression.New
|
||||||
, [] ]
|
, [] ]
|
||||||
|
|
||||||
@ -142,13 +149,52 @@ primaryExpression = choice [
|
|||||||
literal,
|
literal,
|
||||||
-- arrayCreationExpression,
|
-- arrayCreationExpression,
|
||||||
-- intrinsic,
|
-- intrinsic,
|
||||||
-- anonymousFunctionCreationExpression,
|
anonymousFunctionCreationExpression,
|
||||||
objectCreationExpression,
|
objectCreationExpression,
|
||||||
updateExpression,
|
updateExpression,
|
||||||
shellCommandExpression,
|
shellCommandExpression,
|
||||||
expression
|
expression
|
||||||
]
|
]
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
parameters :: Assignment.Assignment [] Grammar [Term]
|
||||||
|
parameters = manyTerm (simpleParameter <|> variadicParameter)
|
||||||
|
|
||||||
|
simpleParameter :: Assignment
|
||||||
|
simpleParameter = makeTerm <$> symbol SimpleParameter <*> children (makeAnnotation <$> (typeDeclaration <|> emptyTerm) <*> (makeAssignment <$> location <*> variableName <*> (defaultArgumentSpecifier <|> emptyTerm)))
|
||||||
|
where
|
||||||
|
makeAnnotation typeDecl assignment = Type.Annotation assignment typeDecl
|
||||||
|
makeAssignment loc name argument = makeTerm loc (Statement.Assignment [] name argument)
|
||||||
|
|
||||||
|
defaultArgumentSpecifier :: Assignment
|
||||||
|
defaultArgumentSpecifier = symbol DefaultArgumentSpecifier *> children expression
|
||||||
|
|
||||||
|
|
||||||
|
variadicParameter :: Assignment
|
||||||
|
variadicParameter = makeTerm <$> symbol VariadicParameter <*> children (makeTypeAnnotation <$> (typeDeclaration <|> emptyTerm) <*> variableName)
|
||||||
|
where makeTypeAnnotation ty variableName = (Type.Annotation variableName ty)
|
||||||
|
|
||||||
|
functionUseClause :: Assignment
|
||||||
|
functionUseClause = makeTerm <$> symbol AnonymousFunctionUseClause <*> children (Syntax.UseClause <$> someTerm variableName)
|
||||||
|
|
||||||
|
returnType :: Assignment
|
||||||
|
returnType = makeTerm <$> symbol ReturnType <*> children (Syntax.ReturnType <$> (typeDeclaration <|> emptyTerm))
|
||||||
|
|
||||||
|
typeDeclaration :: Assignment
|
||||||
|
typeDeclaration = makeTerm <$> symbol TypeDeclaration <*> children (Syntax.TypeDeclaration <$> baseTypeDeclaration)
|
||||||
|
|
||||||
|
baseTypeDeclaration :: Assignment
|
||||||
|
baseTypeDeclaration = makeTerm <$> symbol BaseTypeDeclaration <*> children (Syntax.BaseTypeDeclaration <$> (scalarType <|> qualifiedName <|> emptyTerm))
|
||||||
|
|
||||||
|
scalarType :: Assignment
|
||||||
|
scalarType = makeTerm <$> symbol ScalarType <*> (Syntax.ScalarType <$> source)
|
||||||
|
|
||||||
|
compoundStatement :: Assignment
|
||||||
|
compoundStatement = makeTerm <$> symbol CompoundStatement <*> children (manyTerm statement)
|
||||||
|
|
||||||
objectCreationExpression :: Assignment
|
objectCreationExpression :: Assignment
|
||||||
objectCreationExpression = (makeTerm <$> symbol ObjectCreationExpression <*> children (fmap Expression.New $ ((:) <$> classTypeDesignator <*> (arguments <|> pure []))))
|
objectCreationExpression = (makeTerm <$> symbol ObjectCreationExpression <*> children (fmap Expression.New $ ((:) <$> classTypeDesignator <*> (arguments <|> pure []))))
|
||||||
|
|
||||||
|
@ -164,3 +164,39 @@ data ClassBaseClause a = ClassBaseClause a
|
|||||||
instance Eq1 ClassBaseClause where liftEq = genericLiftEq
|
instance Eq1 ClassBaseClause where liftEq = genericLiftEq
|
||||||
instance Ord1 ClassBaseClause where liftCompare = genericLiftCompare
|
instance Ord1 ClassBaseClause where liftCompare = genericLiftCompare
|
||||||
instance Show1 ClassBaseClause where liftShowsPrec = genericLiftShowsPrec
|
instance Show1 ClassBaseClause where liftShowsPrec = genericLiftShowsPrec
|
||||||
|
|
||||||
|
|
||||||
|
data UseClause a = UseClause [a]
|
||||||
|
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable)
|
||||||
|
|
||||||
|
instance Eq1 UseClause where liftEq = genericLiftEq
|
||||||
|
instance Ord1 UseClause where liftCompare = genericLiftCompare
|
||||||
|
instance Show1 UseClause where liftShowsPrec = genericLiftShowsPrec
|
||||||
|
|
||||||
|
data ReturnType a = ReturnType a
|
||||||
|
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable)
|
||||||
|
|
||||||
|
instance Eq1 ReturnType where liftEq = genericLiftEq
|
||||||
|
instance Ord1 ReturnType where liftCompare = genericLiftCompare
|
||||||
|
instance Show1 ReturnType where liftShowsPrec = genericLiftShowsPrec
|
||||||
|
|
||||||
|
data TypeDeclaration a = TypeDeclaration a
|
||||||
|
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable)
|
||||||
|
|
||||||
|
instance Eq1 TypeDeclaration where liftEq = genericLiftEq
|
||||||
|
instance Ord1 TypeDeclaration where liftCompare = genericLiftCompare
|
||||||
|
instance Show1 TypeDeclaration where liftShowsPrec = genericLiftShowsPrec
|
||||||
|
|
||||||
|
data BaseTypeDeclaration a = BaseTypeDeclaration a
|
||||||
|
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable)
|
||||||
|
|
||||||
|
instance Eq1 BaseTypeDeclaration where liftEq = genericLiftEq
|
||||||
|
instance Ord1 BaseTypeDeclaration where liftCompare = genericLiftCompare
|
||||||
|
instance Show1 BaseTypeDeclaration where liftShowsPrec = genericLiftShowsPrec
|
||||||
|
|
||||||
|
data ScalarType a = ScalarType ByteString
|
||||||
|
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable)
|
||||||
|
|
||||||
|
instance Eq1 ScalarType where liftEq = genericLiftEq
|
||||||
|
instance Ord1 ScalarType where liftCompare = genericLiftCompare
|
||||||
|
instance Show1 ScalarType where liftShowsPrec = genericLiftShowsPrec
|
||||||
|
Loading…
Reference in New Issue
Block a user