parser implement methods with params
This commit is contained in:
parent
3130f7f7d4
commit
f183b8b183
@ -40,6 +40,15 @@ testEmptyPrivateMethod = TestCase $
|
||||
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]
|
||||
testEmptyMethodWithParam = TestCase $
|
||||
assertEqual "expect class with method with param" [Class "WithParam" [MethodDeclaration "void" "foo" [ParameterDeclaration "int" "param"] (Block [])] []] $
|
||||
parse [CLASS,IDENTIFIER "WithParam",LBRACKET,VOID,IDENTIFIER "foo",LBRACE,INT,IDENTIFIER "param",RBRACE,SEMICOLON,RBRACKET]
|
||||
testEmptyMethodWithParams = TestCase $
|
||||
assertEqual "expect class with multiple params" [Class "WithParams" [MethodDeclaration "void" "foo" [ParameterDeclaration "int" "p1",ParameterDeclaration "Custom" "p2"] (Block [])] []] $
|
||||
parse [CLASS,IDENTIFIER "WithParams",LBRACKET,VOID,IDENTIFIER "foo",LBRACE,INT,IDENTIFIER "p1",COMMA,IDENTIFIER "Custom",IDENTIFIER "p2",RBRACE,SEMICOLON,RBRACKET]
|
||||
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]
|
||||
|
||||
|
||||
tests = TestList [
|
||||
@ -52,5 +61,8 @@ tests = TestList [
|
||||
testWithModifier,
|
||||
testEmptyMethod,
|
||||
testEmptyPrivateMethod,
|
||||
testEmptyVoidMethod
|
||||
testEmptyVoidMethod,
|
||||
testEmptyMethodWithParam,
|
||||
testEmptyMethodWithParams,
|
||||
testClassWithMethodAndField
|
||||
]
|
@ -161,8 +161,8 @@ methodbody : block { $1 }
|
||||
blockstatements : blockstatement { }
|
||||
| blockstatements blockstatement { }
|
||||
|
||||
formalparameterlist : formalparameter { }
|
||||
| formalparameterlist COMMA formalparameter{ }
|
||||
formalparameterlist : formalparameter { [$1] }
|
||||
| formalparameterlist COMMA formalparameter { $1 ++ [$3] }
|
||||
|
||||
explicitconstructorinvocation : THIS LBRACE RBRACE SEMICOLON { }
|
||||
| THIS LBRACE argumentlist RBRACE SEMICOLON { }
|
||||
@ -171,7 +171,7 @@ classtypelist : classtype { }
|
||||
| classtypelist COMMA classtype { }
|
||||
|
||||
methoddeclarator : IDENTIFIER LBRACE RBRACE { ($1, []) }
|
||||
-- | IDENTIFIER LBRACE formalparameterlist RBRACE { }
|
||||
| IDENTIFIER LBRACE formalparameterlist RBRACE { ($1, $3) }
|
||||
|
||||
primitivetype : BOOLEAN { "boolean" }
|
||||
| numerictype { $1 }
|
||||
@ -185,7 +185,7 @@ variabledeclarator : variabledeclaratorid { Declarator $1 Nothing }
|
||||
blockstatement : localvariabledeclarationstatement { }
|
||||
| statement { }
|
||||
|
||||
formalparameter : type variabledeclaratorid { }
|
||||
formalparameter : type variabledeclaratorid { ParameterDeclaration $1 $2 }
|
||||
|
||||
argumentlist : expression { }
|
||||
| argumentlist COMMA expression { }
|
||||
|
Loading…
Reference in New Issue
Block a user