parser add this and braced expressions
This commit is contained in:
parent
a4d41b9ef7
commit
b11adcf907
@ -159,6 +159,16 @@ testExpressionPlusEqual = TestCase $
|
||||
testExpressionMinusEqual = TestCase $
|
||||
assertEqual "expect assign and subtraction" (StatementExpressionExpression (Assignment (Reference "a") (BinaryOperation Subtraction (Reference "a") (IntegerLiteral 5)))) $
|
||||
parseExpression [IDENTIFIER "a",MINUSEQUAL,INTEGERLITERAL 5]
|
||||
testExpressionThis = TestCase $
|
||||
assertEqual "expect this" (Reference "this") $
|
||||
parseExpression [THIS]
|
||||
testExpressionBraced = TestCase $
|
||||
assertEqual "expect braced expresssion" (BinaryOperation Multiplication (Reference "b") (BinaryOperation Addition (Reference "a") (IntegerLiteral 3))) $
|
||||
parseExpression [IDENTIFIER "b",TIMES,LBRACE,IDENTIFIER "a",PLUS,INTEGERLITERAL 3,RBRACE]
|
||||
|
||||
testExpressionPrecedence = TestCase $
|
||||
assertEqual "expect times to be inner expression" (BinaryOperation Addition (BinaryOperation Multiplication (Reference "b") (Reference "a")) (IntegerLiteral 3)) $
|
||||
parseExpression [IDENTIFIER "b",TIMES,IDENTIFIER "a",PLUS,INTEGERLITERAL 3]
|
||||
|
||||
testStatementIfThen = TestCase $
|
||||
assertEqual "expect empty ifthen" [If (Reference "a") (Block [Block []]) Nothing] $
|
||||
@ -218,6 +228,9 @@ tests = TestList [
|
||||
testExpressionDivideEqual,
|
||||
testExpressionPlusEqual,
|
||||
testExpressionMinusEqual,
|
||||
testExpressionBraced,
|
||||
testExpressionThis,
|
||||
testExpressionPrecedence,
|
||||
testStatementIfThen,
|
||||
testStatementIfThenElse,
|
||||
testStatementWhile
|
||||
|
@ -316,8 +316,8 @@ inclusiveorexpression : exclusiveorexpression { $1 }
|
||||
| inclusiveorexpression OR exclusiveorexpression { BinaryOperation Or $1 $3 }
|
||||
|
||||
primarynonewarray : literal { $1 }
|
||||
-- | THIS { }
|
||||
-- | LBRACE expression RBRACE { }
|
||||
| THIS { Reference "this" }
|
||||
| LBRACE expression RBRACE { $2 }
|
||||
-- | classinstancecreationexpression { }
|
||||
-- | fieldaccess { }
|
||||
-- | methodinvocation { }
|
||||
|
Loading…
Reference in New Issue
Block a user