parser add timesequal, divideequal, moduloequal, minusequal, andequal, xorequal, orequal
This commit is contained in:
parent
9f658397de
commit
a4d41b9ef7
@ -145,8 +145,20 @@ testExpressionPreDecrement = TestCase $
|
|||||||
assertEqual "expect PreIncrement" (UnaryOperation PreDecrement (Reference "a")) $
|
assertEqual "expect PreIncrement" (UnaryOperation PreDecrement (Reference "a")) $
|
||||||
parseExpression [DECREMENT,IDENTIFIER "a"]
|
parseExpression [DECREMENT,IDENTIFIER "a"]
|
||||||
testExpressionAssign = TestCase $
|
testExpressionAssign = TestCase $
|
||||||
assertEqual "expect assign and addition" (StatementExpressionExpression (Assignment (Reference "a") (IntegerLiteral 5))) $
|
assertEqual "expect assign 5 to a" (StatementExpressionExpression (Assignment (Reference "a") (IntegerLiteral 5))) $
|
||||||
parseExpression [IDENTIFIER "a",ASSIGN,INTEGERLITERAL 5]
|
parseExpression [IDENTIFIER "a",ASSIGN,INTEGERLITERAL 5]
|
||||||
|
testExpressionTimesEqual = TestCase $
|
||||||
|
assertEqual "expect assign and multiplication" (StatementExpressionExpression (Assignment (Reference "a") (BinaryOperation Multiplication (Reference "a") (IntegerLiteral 5)))) $
|
||||||
|
parseExpression [IDENTIFIER "a",TIMESEQUAL,INTEGERLITERAL 5]
|
||||||
|
testExpressionDivideEqual = TestCase $
|
||||||
|
assertEqual "expect assign and division" (StatementExpressionExpression (Assignment (Reference "a") (BinaryOperation Division (Reference "a") (IntegerLiteral 5)))) $
|
||||||
|
parseExpression [IDENTIFIER "a",DIVEQUAL,INTEGERLITERAL 5]
|
||||||
|
testExpressionPlusEqual = TestCase $
|
||||||
|
assertEqual "expect assign and addition" (StatementExpressionExpression (Assignment (Reference "a") (BinaryOperation Addition (Reference "a") (IntegerLiteral 5)))) $
|
||||||
|
parseExpression [IDENTIFIER "a",PLUSEQUAL,INTEGERLITERAL 5]
|
||||||
|
testExpressionMinusEqual = TestCase $
|
||||||
|
assertEqual "expect assign and subtraction" (StatementExpressionExpression (Assignment (Reference "a") (BinaryOperation Subtraction (Reference "a") (IntegerLiteral 5)))) $
|
||||||
|
parseExpression [IDENTIFIER "a",MINUSEQUAL,INTEGERLITERAL 5]
|
||||||
|
|
||||||
testStatementIfThen = TestCase $
|
testStatementIfThen = TestCase $
|
||||||
assertEqual "expect empty ifthen" [If (Reference "a") (Block [Block []]) Nothing] $
|
assertEqual "expect empty ifthen" [If (Reference "a") (Block [Block []]) Nothing] $
|
||||||
@ -201,6 +213,11 @@ tests = TestList [
|
|||||||
testExpressionPreIncrement,
|
testExpressionPreIncrement,
|
||||||
testExpressionPreDecrement,
|
testExpressionPreDecrement,
|
||||||
testExpressionAssign,
|
testExpressionAssign,
|
||||||
|
testExpressionTimesEqual,
|
||||||
|
testExpressionTimesEqual,
|
||||||
|
testExpressionDivideEqual,
|
||||||
|
testExpressionPlusEqual,
|
||||||
|
testExpressionMinusEqual,
|
||||||
testStatementIfThen,
|
testStatementIfThen,
|
||||||
testStatementIfThenElse,
|
testStatementIfThenElse,
|
||||||
testStatementWhile
|
testStatementWhile
|
||||||
|
@ -242,7 +242,9 @@ conditionalexpression : conditionalorexpression { $1 }
|
|||||||
-- | conditionalorexpression QUESMARK expression COLON conditionalexpression { }
|
-- | conditionalorexpression QUESMARK expression COLON conditionalexpression { }
|
||||||
|
|
||||||
assignment : lefthandside assignmentoperator assignmentexpression {
|
assignment : lefthandside assignmentoperator assignmentexpression {
|
||||||
Assignment $1 $3
|
case $2 of
|
||||||
|
Nothing -> Assignment $1 $3
|
||||||
|
Just operator -> Assignment $1 (BinaryOperation operator $1 $3)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user