parser add custom type fields
This commit is contained in:
parent
7cbf8aad08
commit
decc909c23
@ -18,11 +18,16 @@ testBooleanField = TestCase $
|
|||||||
testIntField = TestCase $
|
testIntField = TestCase $
|
||||||
assertEqual "expect class with int field" [Class "WithInt" [] [VariableDeclaration "int" "value" Nothing]] $
|
assertEqual "expect class with int field" [Class "WithInt" [] [VariableDeclaration "int" "value" Nothing]] $
|
||||||
parse [CLASS,IDENTIFIER "WithInt",LBRACKET,INT,IDENTIFIER "value",SEMICOLON,RBRACKET]
|
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 [
|
tests = TestList [
|
||||||
testSingleEmptyClass,
|
testSingleEmptyClass,
|
||||||
testTwoEmptyClasses,
|
testTwoEmptyClasses,
|
||||||
testBooleanField,
|
testBooleanField,
|
||||||
testIntField
|
testIntField,
|
||||||
|
testCustomTypeField
|
||||||
]
|
]
|
@ -80,14 +80,14 @@ compilationunit : typedeclarations { $1 }
|
|||||||
typedeclarations : typedeclaration { [$1] }
|
typedeclarations : typedeclaration { [$1] }
|
||||||
| typedeclarations typedeclaration { $1 ++ [$2] }
|
| typedeclarations typedeclaration { $1 ++ [$2] }
|
||||||
|
|
||||||
name : qualifiedname { }
|
name : simplename { $1 }
|
||||||
| simplename { }
|
-- | qualifiedname { }
|
||||||
|
|
||||||
typedeclaration : classdeclaration { $1 }
|
typedeclaration : classdeclaration { $1 }
|
||||||
|
|
||||||
qualifiedname : name DOT IDENTIFIER { }
|
qualifiedname : name DOT IDENTIFIER { }
|
||||||
|
|
||||||
simplename : IDENTIFIER { }
|
simplename : IDENTIFIER { $1 }
|
||||||
|
|
||||||
classdeclaration : CLASS IDENTIFIER classbody { case $3 of (methods, fields) -> Class $2 methods fields }
|
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 }
|
||||||
@ -120,7 +120,7 @@ classtype : classorinterfacetype{ }
|
|||||||
classbodydeclaration : classmemberdeclaration { $1 }
|
classbodydeclaration : classmemberdeclaration { $1 }
|
||||||
-- | constructordeclaration { FieldDecl $ VariableDeclaration "int" "a" Nothing } -- TODO
|
-- | constructordeclaration { FieldDecl $ VariableDeclaration "int" "a" Nothing } -- TODO
|
||||||
|
|
||||||
classorinterfacetype : name{ }
|
classorinterfacetype : name { $1 }
|
||||||
|
|
||||||
classmemberdeclaration : fielddeclaration { $1 }
|
classmemberdeclaration : fielddeclaration { $1 }
|
||||||
-- | methoddeclaration { }
|
-- | methoddeclaration { }
|
||||||
@ -150,7 +150,7 @@ methodheader : type methoddeclarator { }
|
|||||||
| modifiers VOID methoddeclarator { }
|
| modifiers VOID methoddeclarator { }
|
||||||
|
|
||||||
type : primitivetype { $1 }
|
type : primitivetype { $1 }
|
||||||
-- | referencetype { }
|
| referencetype { $1 }
|
||||||
|
|
||||||
variabledeclarators : variabledeclarator { [$1] }
|
variabledeclarators : variabledeclarator { [$1] }
|
||||||
-- | variabledeclarators COMMA variabledeclarator { $1 ++ [$3] }
|
-- | variabledeclarators COMMA variabledeclarator { $1 ++ [$3] }
|
||||||
@ -176,7 +176,7 @@ methoddeclarator : IDENTIFIER LBRACE RBRACE { }
|
|||||||
primitivetype : BOOLEAN { "boolean" }
|
primitivetype : BOOLEAN { "boolean" }
|
||||||
| numerictype { $1 }
|
| numerictype { $1 }
|
||||||
|
|
||||||
referencetype : classorinterfacetype { }
|
referencetype : classorinterfacetype { $1 }
|
||||||
|
|
||||||
|
|
||||||
variabledeclarator : variabledeclaratorid { Declarator $1 Nothing }
|
variabledeclarator : variabledeclaratorid { Declarator $1 Nothing }
|
||||||
|
Loading…
Reference in New Issue
Block a user