diff --git a/src/Language/Java/Assignment.hs b/src/Language/Java/Assignment.hs index f29e211ad..b75f325ab 100644 --- a/src/Language/Java/Assignment.hs +++ b/src/Language/Java/Assignment.hs @@ -53,6 +53,7 @@ type Syntax = , Java.Syntax.Module , Java.Syntax.New , Java.Syntax.Package + , Java.Syntax.SpreadParameter , Java.Syntax.Synchronized , Java.Syntax.TypeParameter , Java.Syntax.TypeWithModifiers @@ -307,7 +308,7 @@ enum = makeTerm <$> symbol Grammar.EnumDeclaration <*> children (Java.Syntax.Enu enumBodyDeclarations = symbol EnumBodyDeclarations *> children (manyTerm expression) return' :: Assignment -return' = makeTerm <$> symbol ReturnStatement <*> (Statement.Return <$> children expression) +return' = makeTerm <$> symbol ReturnStatement <*> (Statement.Return <$> children (expression <|> emptyTerm)) -- method expressions dims :: Assignment.Assignment [] Grammar [Term] @@ -516,7 +517,7 @@ throws :: Assignment.Assignment [] Grammar [Term] throws = symbol Throws *> children (symbol ExceptionTypeList *> children(manyTerm type')) formalParameters :: Assignment.Assignment [] Grammar [Term] -formalParameters = manyTerm parameter +formalParameters = manyTerm (parameter <|> spreadParameter) where parameter = makeTerm <$> symbol FormalParameter <*> children (makeAnnotation <$> manyTerm modifier <*> type' <* symbol VariableDeclaratorId <*> children identifier) makeAnnotation [] type' variableName = Type.Annotation variableName type' @@ -527,3 +528,10 @@ castExpression = makeTerm <$> symbol CastExpression <*> children (flip Type.Anno fieldAccess :: Assignment 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) diff --git a/src/Language/Java/Syntax.hs b/src/Language/Java/Syntax.hs index b1617c9de..8ffac8839 100644 --- a/src/Language/Java/Syntax.hs +++ b/src/Language/Java/Syntax.hs @@ -167,3 +167,13 @@ instance Show1 WildcardBounds where liftShowsPrec = genericLiftShowsPrec -- TODO: Implement Eval instance for TypeWithModifiers 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