parser add return

This commit is contained in:
Marvin Schlegel 2024-05-08 15:52:44 +02:00
parent 8de0309107
commit f82776e636
2 changed files with 8 additions and 4 deletions

View File

@ -80,6 +80,9 @@ testLocalBoolWithInitialization = TestCase $
testFieldNullWithInitialization = TestCase $ testFieldNullWithInitialization = TestCase $
assertEqual "expect Class with initialized field" [Class "WithInitField" [] [VariableDeclaration "Object" "bar" $ Just NullLiteral]] $ assertEqual "expect Class with initialized field" [Class "WithInitField" [] [VariableDeclaration "Object" "bar" $ Just NullLiteral]] $
parse [CLASS,IDENTIFIER "WithInitField",LBRACKET,IDENTIFIER "Object",IDENTIFIER "bar",ASSIGN,NULLLITERAL,SEMICOLON,RBRACKET] parse [CLASS,IDENTIFIER "WithInitField",LBRACKET,IDENTIFIER "Object",IDENTIFIER "bar",ASSIGN,NULLLITERAL,SEMICOLON,RBRACKET]
testReturnVoid = TestCase $
assertEqual "expect block with return nothing" (Block [Return Nothing]) $
parseBlock [LBRACKET,RETURN,SEMICOLON,RBRACKET]
tests = TestList [ tests = TestList [
testSingleEmptyClass, testSingleEmptyClass,
@ -104,5 +107,6 @@ tests = TestList [
testExpressionIntLiteral, testExpressionIntLiteral,
testFieldWithInitialization, testFieldWithInitialization,
testLocalBoolWithInitialization, testLocalBoolWithInitialization,
testFieldNullWithInitialization testFieldNullWithInitialization,
testReturnVoid
] ]

View File

@ -217,7 +217,7 @@ localvariabledeclaration : type variabledeclarators { map LocalVariableDeclarati
statementwithouttrailingsubstatement : block { [$1] } statementwithouttrailingsubstatement : block { [$1] }
| emptystatement { [] } | emptystatement { [] }
-- | expressionstatement { } -- | expressionstatement { }
-- | returnstatement { } | returnstatement { [$1] }
ifthenstatement : IF LBRACE expression RBRACE statement { } ifthenstatement : IF LBRACE expression RBRACE statement { }
@ -232,8 +232,8 @@ emptystatement : SEMICOLON { Block [] }
expressionstatement : statementexpression SEMICOLON { } expressionstatement : statementexpression SEMICOLON { }
returnstatement : RETURN SEMICOLON { } returnstatement : RETURN SEMICOLON { Return Nothing }
| RETURN expression SEMICOLON { } | RETURN expression SEMICOLON { Return $ Just $2 }
statementnoshortif : statementwithouttrailingsubstatement { } statementnoshortif : statementwithouttrailingsubstatement { }
| ifthenelsestatementnoshortif { } | ifthenelsestatementnoshortif { }