From e3fa3efd952e14cfe51c702ebde07b655b869d20 Mon Sep 17 00:00:00 2001 From: Marvin Schlegel Date: Mon, 6 May 2024 23:51:33 +0200 Subject: [PATCH] add void methods --- Test/TestParser.hs | 13 +++++++++++-- src/Parser/JavaParser.y | 8 ++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Test/TestParser.hs b/Test/TestParser.hs index 4e0694b..85b899b 100644 --- a/Test/TestParser.hs +++ b/Test/TestParser.hs @@ -30,9 +30,16 @@ testMultipleDeclarations = TestCase $ testWithModifier = TestCase $ assertEqual "expect class with int field" [Class "WithInt" [] [VariableDeclaration "int" "value" Nothing]] $ parse [ABSTRACT,CLASS,IDENTIFIER "WithInt",LBRACKET,PUBLIC,INT,IDENTIFIER "value",SEMICOLON,RBRACKET] -testMethod = TestCase $ + +testEmptyMethod = TestCase $ assertEqual "expect class with method" [Class "WithMethod" [MethodDeclaration "int" "foo" [] (Block [])] []] $ parse [CLASS,IDENTIFIER "WithMethod",LBRACKET,INT,IDENTIFIER "foo",LBRACE,RBRACE,SEMICOLON,RBRACKET] +testEmptyPrivateMethod = TestCase $ + assertEqual "expect class with method" [Class "WithMethod" [MethodDeclaration "int" "foo" [] (Block [])] []] $ + parse [CLASS,IDENTIFIER "WithMethod",LBRACKET,PRIVATE,INT,IDENTIFIER "foo",LBRACE,RBRACE,LBRACKET,RBRACKET,RBRACKET] +testEmptyVoidMethod = TestCase $ + assertEqual "expect class with method" [Class "WithMethod" [MethodDeclaration "void" "foo" [] (Block [])] []] $ + parse [CLASS,IDENTIFIER "WithMethod",LBRACKET,VOID,IDENTIFIER "foo",LBRACE,RBRACE,LBRACKET,RBRACKET,RBRACKET] tests = TestList [ @@ -43,5 +50,7 @@ tests = TestList [ testCustomTypeField, testMultipleDeclarations, testWithModifier, - testMethod + testEmptyMethod, + testEmptyPrivateMethod, + testEmptyVoidMethod ] \ No newline at end of file diff --git a/src/Parser/JavaParser.y b/src/Parser/JavaParser.y index d48b7e2..ec3788c 100644 --- a/src/Parser/JavaParser.y +++ b/src/Parser/JavaParser.y @@ -144,10 +144,10 @@ constructorbody : LBRACKET RBRACKET { } | LBRACKET blockstatements RBRACKET { } | LBRACKET explicitconstructorinvocation blockstatements RBRACKET { } -methodheader : type methoddeclarator { ($1, $2) } - -- | modifiers type methoddeclarator { } - -- | VOID methoddeclarator { } - -- | modifiers VOID methoddeclarator { } +methodheader : type methoddeclarator { ($1, $2) } + | modifiers type methoddeclarator { ($2, $3) } + | VOID methoddeclarator { ("void", $2) } + | modifiers VOID methoddeclarator { ("void", $3)} type : primitivetype { $1 } | referencetype { $1 }