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 $
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]
testReturnVoid = TestCase $
assertEqual "expect block with return nothing" (Block [Return Nothing]) $
parseBlock [LBRACKET,RETURN,SEMICOLON,RBRACKET]
tests = TestList [
testSingleEmptyClass,
@ -104,5 +107,6 @@ tests = TestList [
testExpressionIntLiteral,
testFieldWithInitialization,
testLocalBoolWithInitialization,
testFieldNullWithInitialization
testFieldNullWithInitialization,
testReturnVoid
]

View File

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