parser add empty methods

This commit is contained in:
Marvin Schlegel 2024-05-06 23:34:03 +02:00
parent 5e90f0d0ee
commit f57f360abf
2 changed files with 17 additions and 13 deletions

View File

@ -30,6 +30,9 @@ 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 $
assertEqual "expect class with method" [Class "WithMethod" [MethodDeclaration "int" "foo" [] (Block [])] []] $
parse [CLASS,IDENTIFIER "WithMethod",LBRACKET,INT,IDENTIFIER "foo",LBRACE,RBRACE,SEMICOLON,RBRACKET]
tests = TestList [
@ -39,5 +42,6 @@ tests = TestList [
testIntField,
testCustomTypeField,
testMultipleDeclarations,
testWithModifier
testWithModifier,
testMethod
]

View File

@ -123,7 +123,7 @@ classbodydeclaration : classmemberdeclaration { $1 }
classorinterfacetype : name { $1 }
classmemberdeclaration : fielddeclaration { $1 }
-- | methoddeclaration { }
| methoddeclaration { $1 }
constructordeclaration : constructordeclarator constructorbody { }
| modifiers constructordeclarator constructorbody { }
@ -131,10 +131,10 @@ constructordeclaration : constructordeclarator constructorbody { }
fielddeclaration : type variabledeclarators SEMICOLON { FieldDecls $ map (convertDeclarator $1) $2 }
| modifiers type variabledeclarators SEMICOLON { FieldDecls $ map (convertDeclarator $2) $3 }
methoddeclaration : methodheader methodbody { }
methoddeclaration : methodheader methodbody { case $1 of (returnType, (name, parameters)) -> MethodDecl (MethodDeclaration returnType name parameters $2) }
block : LBRACKET RBRACKET { }
| LBRACKET blockstatements RBRACKET { }
block : LBRACKET RBRACKET { Block [] }
-- | LBRACKET blockstatements RBRACKET { }
constructordeclarator : simplename LBRACE RBRACE { }
| simplename LBRACE formalparameterlist RBRACE { }
@ -144,10 +144,10 @@ constructorbody : LBRACKET RBRACKET { }
| LBRACKET blockstatements RBRACKET { }
| LBRACKET explicitconstructorinvocation blockstatements RBRACKET { }
methodheader : type methoddeclarator { }
| modifiers type methoddeclarator { }
| VOID methoddeclarator { }
| modifiers VOID methoddeclarator { }
methodheader : type methoddeclarator { ($1, $2) }
-- | modifiers type methoddeclarator { }
-- | VOID methoddeclarator { }
-- | modifiers VOID methoddeclarator { }
type : primitivetype { $1 }
| referencetype { $1 }
@ -155,8 +155,8 @@ type : primitivetype { $1 }
variabledeclarators : variabledeclarator { [$1] }
| variabledeclarators COMMA variabledeclarator { $1 ++ [$3] }
methodbody : block { }
| SEMICOLON { }
methodbody : block { $1 }
| SEMICOLON { Block [] }
blockstatements : blockstatement { }
| blockstatements blockstatement { }
@ -170,8 +170,8 @@ explicitconstructorinvocation : THIS LBRACE RBRACE SEMICOLON { }
classtypelist : classtype { }
| classtypelist COMMA classtype { }
methoddeclarator : IDENTIFIER LBRACE RBRACE { }
| IDENTIFIER LBRACE formalparameterlist RBRACE { }
methoddeclarator : IDENTIFIER LBRACE RBRACE { ($1, []) }
-- | IDENTIFIER LBRACE formalparameterlist RBRACE { }
primitivetype : BOOLEAN { "boolean" }
| numerictype { $1 }