parser implement multiple declarations
This commit is contained in:
parent
decc909c23
commit
301b87c9ac
@ -21,7 +21,12 @@ testIntField = TestCase $
|
|||||||
testCustomTypeField = TestCase $
|
testCustomTypeField = TestCase $
|
||||||
assertEqual "expect class with foo field" [Class "WithFoo" [] [VariableDeclaration "Foo" "value" Nothing]] $
|
assertEqual "expect class with foo field" [Class "WithFoo" [] [VariableDeclaration "Foo" "value" Nothing]] $
|
||||||
parse [CLASS,IDENTIFIER "WithFoo",LBRACKET,IDENTIFIER "Foo",IDENTIFIER "value",SEMICOLON,RBRACKET]
|
parse [CLASS,IDENTIFIER "WithFoo",LBRACKET,IDENTIFIER "Foo",IDENTIFIER "value",SEMICOLON,RBRACKET]
|
||||||
|
testMultipleDeclarationSameLine = TestCase $
|
||||||
|
assertEqual "expect class with two int fields" [Class "TwoInts" [] [VariableDeclaration "int" "num1" Nothing, VariableDeclaration "int" "num2" Nothing]] $
|
||||||
|
parse [CLASS,IDENTIFIER "TwoInts",LBRACKET,INT,IDENTIFIER "num1",COMMA,IDENTIFIER "num2",SEMICOLON,RBRACKET]
|
||||||
|
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]
|
||||||
|
|
||||||
|
|
||||||
tests = TestList [
|
tests = TestList [
|
||||||
@ -29,5 +34,6 @@ tests = TestList [
|
|||||||
testTwoEmptyClasses,
|
testTwoEmptyClasses,
|
||||||
testBooleanField,
|
testBooleanField,
|
||||||
testIntField,
|
testIntField,
|
||||||
testCustomTypeField
|
testCustomTypeField,
|
||||||
|
testMultipleDeclarations
|
||||||
]
|
]
|
@ -103,11 +103,11 @@ classbodydeclarations : classbodydeclaration {
|
|||||||
MethodDecl method -> ([method], [])
|
MethodDecl method -> ([method], [])
|
||||||
FieldDecls fields -> ([], fields)
|
FieldDecls fields -> ([], fields)
|
||||||
}
|
}
|
||||||
-- | classbodydeclarations classbodydeclaration {
|
| classbodydeclarations classbodydeclaration {
|
||||||
-- case ($1, $2) of
|
case ($1, $2) of
|
||||||
-- ((methods, fields), MethodDecl method) -> ((methods ++ [method]), fields)
|
((methods, fields), MethodDecl method) -> ((methods ++ [method]), fields)
|
||||||
-- ((methods, fields), FieldDecl field) -> (methods, (fields ++ [field]))
|
((methods, fields), FieldDecls newFields) -> (methods, (fields ++ newFields))
|
||||||
-- }
|
}
|
||||||
|
|
||||||
modifier : PUBLIC { }
|
modifier : PUBLIC { }
|
||||||
| PROTECTED { }
|
| PROTECTED { }
|
||||||
@ -153,7 +153,7 @@ type : primitivetype { $1 }
|
|||||||
| referencetype { $1 }
|
| referencetype { $1 }
|
||||||
|
|
||||||
variabledeclarators : variabledeclarator { [$1] }
|
variabledeclarators : variabledeclarator { [$1] }
|
||||||
-- | variabledeclarators COMMA variabledeclarator { $1 ++ [$3] }
|
| variabledeclarators COMMA variabledeclarator { $1 ++ [$3] }
|
||||||
|
|
||||||
methodbody : block { }
|
methodbody : block { }
|
||||||
| SEMICOLON { }
|
| SEMICOLON { }
|
||||||
|
Loading…
Reference in New Issue
Block a user