diff --git a/Test/TestParser.hs b/Test/TestParser.hs index d85b9f5..ba54821 100644 --- a/Test/TestParser.hs +++ b/Test/TestParser.hs @@ -50,7 +50,7 @@ testClassWithMethodAndField = TestCase $ assertEqual "expect class with method and field" [Class "WithMethodAndField" [MethodDeclaration "void" "foo" [] (Block []), MethodDeclaration "int" "bar" [] (Block [])] [VariableDeclaration "int" "value" Nothing]] $ parse [CLASS,IDENTIFIER "WithMethodAndField",LBRACKET,VOID,IDENTIFIER "foo",LBRACE,RBRACE,LBRACKET,RBRACKET,INT,IDENTIFIER "value",SEMICOLON,INT,IDENTIFIER "bar",LBRACE,RBRACE,SEMICOLON,RBRACKET] testClassWithConstructor = TestCase $ - assertEqual "expect class with constructor" [Class "WithConstructor" [MethodDeclaration "WithConstructor" "" [] (Block [])] []] $ + assertEqual "expect class with constructor" [Class "WithConstructor" [MethodDeclaration "void" "" [] (Block [])] []] $ parse [CLASS,IDENTIFIER "WithConstructor",LBRACKET,IDENTIFIER "WithConstructor",LBRACE,RBRACE,LBRACKET,RBRACKET,RBRACKET] diff --git a/src/Parser/JavaParser.y b/src/Parser/JavaParser.y index 53828ea..e51afb4 100644 --- a/src/Parser/JavaParser.y +++ b/src/Parser/JavaParser.y @@ -127,8 +127,8 @@ classorinterfacetype : name { $1 } classmemberdeclaration : fielddeclaration { $1 } | methoddeclaration { $1 } -constructordeclaration : constructordeclarator constructorbody { case $1 of (classname, parameters) -> MethodDecl $ MethodDeclaration classname "" parameters $2 } - | modifiers constructordeclarator constructorbody { case $2 of (classname, parameters) -> MethodDecl $ MethodDeclaration classname "" parameters $3 } +constructordeclaration : constructordeclarator constructorbody { case $1 of (classname, parameters) -> MethodDecl $ MethodDeclaration "void" "" parameters $2 } + | modifiers constructordeclarator constructorbody { case $2 of (classname, parameters) -> MethodDecl $ MethodDeclaration "void" "" parameters $3 } fielddeclaration : type variabledeclarators SEMICOLON { FieldDecls $ map (convertDeclarator $1) $2 } | modifiers type variabledeclarators SEMICOLON { FieldDecls $ map (convertDeclarator $2) $3 }