diff --git a/Test/TestParser.hs b/Test/TestParser.hs index ce3f2cc..3fd30f0 100644 --- a/Test/TestParser.hs +++ b/Test/TestParser.hs @@ -18,11 +18,16 @@ testBooleanField = TestCase $ testIntField = TestCase $ assertEqual "expect class with int field" [Class "WithInt" [] [VariableDeclaration "int" "value" Nothing]] $ parse [CLASS,IDENTIFIER "WithInt",LBRACKET,INT,IDENTIFIER "value",SEMICOLON,RBRACKET] +testCustomTypeField = TestCase $ + assertEqual "expect class with foo field" [Class "WithFoo" [] [VariableDeclaration "Foo" "value" Nothing]] $ + parse [CLASS,IDENTIFIER "WithFoo",LBRACKET,IDENTIFIER "Foo",IDENTIFIER "value",SEMICOLON,RBRACKET] + tests = TestList [ testSingleEmptyClass, testTwoEmptyClasses, testBooleanField, - testIntField + testIntField, + testCustomTypeField ] \ No newline at end of file diff --git a/src/Parser/JavaParser.y b/src/Parser/JavaParser.y index bfe74b2..bcfec2f 100644 --- a/src/Parser/JavaParser.y +++ b/src/Parser/JavaParser.y @@ -80,14 +80,14 @@ compilationunit : typedeclarations { $1 } typedeclarations : typedeclaration { [$1] } | typedeclarations typedeclaration { $1 ++ [$2] } -name : qualifiedname { } - | simplename { } +name : simplename { $1 } + -- | qualifiedname { } typedeclaration : classdeclaration { $1 } qualifiedname : name DOT IDENTIFIER { } -simplename : 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 } @@ -120,7 +120,7 @@ classtype : classorinterfacetype{ } classbodydeclaration : classmemberdeclaration { $1 } -- | constructordeclaration { FieldDecl $ VariableDeclaration "int" "a" Nothing } -- TODO -classorinterfacetype : name{ } +classorinterfacetype : name { $1 } classmemberdeclaration : fielddeclaration { $1 } -- | methoddeclaration { } @@ -150,7 +150,7 @@ methodheader : type methoddeclarator { } | modifiers VOID methoddeclarator { } type : primitivetype { $1 } - -- | referencetype { } + | referencetype { $1 } variabledeclarators : variabledeclarator { [$1] } -- | variabledeclarators COMMA variabledeclarator { $1 ++ [$3] } @@ -176,7 +176,7 @@ methoddeclarator : IDENTIFIER LBRACE RBRACE { } primitivetype : BOOLEAN { "boolean" } | numerictype { $1 } -referencetype : classorinterfacetype { } +referencetype : classorinterfacetype { $1 } variabledeclarator : variabledeclaratorid { Declarator $1 Nothing }