1
1
mirror of https://github.com/github/semantic.git synced 2024-12-27 00:44:57 +03:00

assign spread parameter

This commit is contained in:
Ayman Nadeem 2018-06-05 12:01:34 -07:00
parent ccfe2d1a23
commit be050a7115
2 changed files with 20 additions and 2 deletions

View File

@ -53,6 +53,7 @@ type Syntax =
, Java.Syntax.Module , Java.Syntax.Module
, Java.Syntax.New , Java.Syntax.New
, Java.Syntax.Package , Java.Syntax.Package
, Java.Syntax.SpreadParameter
, Java.Syntax.Synchronized , Java.Syntax.Synchronized
, Java.Syntax.TypeParameter , Java.Syntax.TypeParameter
, Java.Syntax.TypeWithModifiers , Java.Syntax.TypeWithModifiers
@ -307,7 +308,7 @@ enum = makeTerm <$> symbol Grammar.EnumDeclaration <*> children (Java.Syntax.Enu
enumBodyDeclarations = symbol EnumBodyDeclarations *> children (manyTerm expression) enumBodyDeclarations = symbol EnumBodyDeclarations *> children (manyTerm expression)
return' :: Assignment return' :: Assignment
return' = makeTerm <$> symbol ReturnStatement <*> (Statement.Return <$> children expression) return' = makeTerm <$> symbol ReturnStatement <*> (Statement.Return <$> children (expression <|> emptyTerm))
-- method expressions -- method expressions
dims :: Assignment.Assignment [] Grammar [Term] dims :: Assignment.Assignment [] Grammar [Term]
@ -516,7 +517,7 @@ throws :: Assignment.Assignment [] Grammar [Term]
throws = symbol Throws *> children (symbol ExceptionTypeList *> children(manyTerm type')) throws = symbol Throws *> children (symbol ExceptionTypeList *> children(manyTerm type'))
formalParameters :: Assignment.Assignment [] Grammar [Term] formalParameters :: Assignment.Assignment [] Grammar [Term]
formalParameters = manyTerm parameter formalParameters = manyTerm (parameter <|> spreadParameter)
where where
parameter = makeTerm <$> symbol FormalParameter <*> children (makeAnnotation <$> manyTerm modifier <*> type' <* symbol VariableDeclaratorId <*> children identifier) parameter = makeTerm <$> symbol FormalParameter <*> children (makeAnnotation <$> manyTerm modifier <*> type' <* symbol VariableDeclaratorId <*> children identifier)
makeAnnotation [] type' variableName = Type.Annotation variableName type' makeAnnotation [] type' variableName = Type.Annotation variableName type'
@ -527,3 +528,10 @@ castExpression = makeTerm <$> symbol CastExpression <*> children (flip Type.Anno
fieldAccess :: Assignment fieldAccess :: Assignment
fieldAccess = makeTerm <$> symbol FieldAccess <*> children (Expression.MemberAccess <$> term expression <*> term expression) fieldAccess = makeTerm <$> symbol FieldAccess <*> children (Expression.MemberAccess <$> term expression <*> term expression)
spreadParameter :: Assignment
spreadParameter = makeTerm <$> symbol Grammar.SpreadParameter <*> children (Java.Syntax.SpreadParameter <$> (makeSingleDecl <$> manyTerm modifier <*> type' <*> variableDeclarator))
where
variableDeclarator = symbol VariableDeclarator *> children ((,) <$> variableDeclaratorId <*> optional expression)
makeSingleDecl modifiers type' (target, Nothing) = makeTerm1 (Java.Syntax.Variable modifiers type' target)
makeSingleDecl modifiers type' (target, Just value) = makeTerm1 (Statement.Assignment [] (makeTerm1 (Java.Syntax.Variable modifiers type' target)) value)

View File

@ -167,3 +167,13 @@ instance Show1 WildcardBounds where liftShowsPrec = genericLiftShowsPrec
-- TODO: Implement Eval instance for TypeWithModifiers -- TODO: Implement Eval instance for TypeWithModifiers
instance Evaluatable WildcardBounds instance Evaluatable WildcardBounds
newtype SpreadParameter a = SpreadParameter { spreadParameterVariableDeclarator :: a}
deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Mergeable, Ord, Show, ToJSONFields1, Traversable)
instance Eq1 SpreadParameter where liftEq = genericLiftEq
instance Ord1 SpreadParameter where liftCompare = genericLiftCompare
instance Show1 SpreadParameter where liftShowsPrec = genericLiftShowsPrec
-- TODO: Implement Eval instance for SpreadParameter
instance Evaluatable SpreadParameter