diff --git a/Test/TestParser.hs b/Test/TestParser.hs index 35f25ab..b979794 100644 --- a/Test/TestParser.hs +++ b/Test/TestParser.hs @@ -27,6 +27,9 @@ testMultipleDeclarationSameLine = TestCase $ testMultipleDeclarations = TestCase $ assertEqual "expect class with int and char field" [Class "Multiple" [] [VariableDeclaration "int" "value" Nothing, VariableDeclaration "char" "letter" Nothing]] $ parse [CLASS,IDENTIFIER "Multiple",LBRACKET,INT,IDENTIFIER "value",SEMICOLON,CHAR,IDENTIFIER "letter",SEMICOLON,RBRACKET] +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] tests = TestList [ @@ -35,5 +38,6 @@ tests = TestList [ testBooleanField, testIntField, testCustomTypeField, - testMultipleDeclarations + testMultipleDeclarations, + testWithModifier ] \ No newline at end of file diff --git a/src/Parser/JavaParser.y b/src/Parser/JavaParser.y index 69fe9f2..8d772eb 100644 --- a/src/Parser/JavaParser.y +++ b/src/Parser/JavaParser.y @@ -90,7 +90,7 @@ qualifiedname : name DOT IDENTIFIER { } simplename : IDENTIFIER { $1 } classdeclaration : CLASS IDENTIFIER classbody { case $3 of (methods, fields) -> Class $2 methods fields } - -- | modifiers CLASS IDENTIFIER classbody { case $4 of (methods, fields) -> Class $3 methods fields } + | modifiers CLASS IDENTIFIER classbody { case $4 of (methods, fields) -> Class $3 methods fields } classbody : LBRACKET RBRACKET { ([], []) } | LBRACKET classbodydeclarations RBRACKET { $2 } @@ -129,7 +129,7 @@ constructordeclaration : constructordeclarator constructorbody { } | modifiers constructordeclarator constructorbody { } fielddeclaration : type variabledeclarators SEMICOLON { FieldDecls $ map (convertDeclarator $1) $2 } - -- | modifiers type variabledeclarators SEMICOLON {} + | modifiers type variabledeclarators SEMICOLON { FieldDecls $ map (convertDeclarator $2) $3 } methoddeclaration : methodheader methodbody { } @@ -365,9 +365,6 @@ data MethodOrFieldDeclaration = MethodDecl MethodDeclaration data Declarator = Declarator Identifier (Maybe Expression) --- convertDeclaratorList :: [DataType] -> MethodOrFieldDeclaration --- convertDeclaratorList = FieldDecls $ map - convertDeclarator :: DataType -> Declarator -> VariableDeclaration convertDeclarator dataType (Declarator id assigment) = VariableDeclaration dataType id assigment