|
4150 - in trunk/Template: src src/parsers/source_to_tst/implementations tes: msg#00324web.ezcomponents.cvs
Author: Raymond Bosman Date: 2006-11-30 14:57:18 +0100 (Thu, 30 Nov 2006) New Revision: 4150 Log: - Assignments not at the top level of the expression are not allowed. Added: trunk/Template/tests/regression_tests/expressions/correct/assignment.in trunk/Template/tests/regression_tests/expressions/correct/assignment.out trunk/Template/tests/regression_tests/expressions/incorrect_assignments/ trunk/Template/tests/regression_tests/expressions/incorrect_assignments/function.in trunk/Template/tests/regression_tests/expressions/incorrect_assignments/function.out trunk/Template/tests/regression_tests/expressions/incorrect_assignments/parenthesis.in trunk/Template/tests/regression_tests/expressions/incorrect_assignments/parenthesis.out trunk/Template/tests/regression_tests/expressions/incorrect_assignments/parenthesis2.in trunk/Template/tests/regression_tests/expressions/incorrect_assignments/parenthesis2.out Modified: trunk/Template/src/error_messages.php trunk/Template/src/parsers/source_to_tst/implementations/expression.php trunk/Template/src/parsers/source_to_tst/implementations/function_call.php Modified: trunk/Template/src/error_messages.php =================================================================== --- trunk/Template/src/error_messages.php 2006-11-30 13:56:44 UTC (rev 4149) +++ trunk/Template/src/error_messages.php 2006-11-30 13:57:18 UTC (rev 4150) @@ -82,7 +82,13 @@ const MSG_TOO_MANY_PARAMETERS = "Function call: '%s' has too many parameters."; const MSG_UNEXPECTED_BLOCK = "Unexpected block {%s} at this position. Some blocks can only be used inside other blocks."; + const MSG_OPERATOR_LHS_IS_MODIFYING_BLOCK = "Unexpected operator. The left side of this expression is not allowed to modify a variable."; + const MSG_OPERATOR_RHS_IS_MODIFYING_BLOCK = "Unexpected operand or expression. An operand or expression that modifies a variable cannot be used in combination with the '%s' operator."; + const MSG_OPERATOR_IS_MODIFYING_BLOCK = "Unexpected operand or expression. The operand or expression modifies a variable, which is not allowed."; + const MSG_PARAMETER_CANNOT_BE_MODIFYING_BLOCK = "The given parameter is not allowed to modify a variable."; + + const MSG_OBJECT_FUNCTION_CALL_NOT_ALLOWED = "Calling a method from an imported object is not allowed."; const MSG_MISSING_CUSTOM_BLOCK_PARAMETER = "Missing the required custom block parameter <%s>."; Modified: trunk/Template/src/parsers/source_to_tst/implementations/expression.php =================================================================== --- trunk/Template/src/parsers/source_to_tst/implementations/expression.php 2006-11-30 13:56:44 UTC (rev 4149) +++ trunk/Template/src/parsers/source_to_tst/implementations/expression.php 2006-11-30 13:57:18 UTC (rev 4150) @@ -187,6 +187,7 @@ $parsedType = false; if ( $this->canParseType( 'Literal', $allowedTypes ) ) { + $this->operatorRhsCheck( $this->currentOperator, $this->lastParser->element, $cursor ); $this->currentOperator = $this->parser->handleOperand( $this->currentOperator, $this->lastParser->element ); $parsedType = "Literal"; } @@ -198,6 +199,7 @@ throw new ezcTemplateParserException( $this->parser->source, $this->startCursor, $this->startCursor, $this->parser->symbolTable->getErrorMessage() ); } + $this->operatorRhsCheck( $this->currentOperator, $this->lastParser->element, $cursor ); $this->currentOperator = $this->parser->handleOperand( $this->currentOperator, $this->lastParser->element ); $this->findNextElement(); @@ -211,11 +213,15 @@ } elseif ( $this->canParseType( 'FunctionCall', $allowedTypes ) ) { + $this->operatorRhsCheck( $this->currentOperator, $this->lastParser->functionCall, $cursor ); + $this->currentOperator = $this->parser->handleOperand( $this->currentOperator, $this->lastParser->functionCall ); $parsedType = "FunctionCall"; } elseif ( $this->allowIdentifier && $this->parseOptionalType( 'Identifier' ) ) { + $this->operatorRhsCheck( $this->currentOperator, $this->lastParser->element, $cursor ); + // Try parsing an identifier since it is allowed $this->currentOperator = $this->parser->handleOperand( $this->currentOperator, $this->lastParser->element ); @@ -240,8 +246,8 @@ throw new ezcTemplateParserException( $this->parser->source, $cursor, $cursor, ezcTemplateSourceToTstErrorMessages::MSG_EXPECT_ROUND_BRACKET_CLOSE ); } + $this->operatorRhsCheck( $this->currentOperator, $this->lastParser->block, $cursor ); $this->currentOperator = $this->parser->handleOperand( $this->currentOperator, $this->lastParser->block ); - $parsedType = "Parenthesis"; } @@ -440,10 +446,11 @@ { if( $cursor->match( "=" ) ) { - //$cursor->advance( 1 ); $function = "ezcTemplateAssignmentOperatorTstNode"; $operator = new $function( $this->parser->source, clone $this->lastCursor, $cursor ); + $this->checkForValidOperator( $this->currentOperator, $operator, $cursor ); + $this->currentOperator = $this->parser->handleOperatorPrecedence( $this->currentOperator, $operator ); $this->parser->reportElementCursor( $operator->startCursor, $operator->endCursor, $operator ); @@ -585,16 +592,43 @@ if( !( $lhs instanceof ezcTemplateVariableTstNode || $lhs instanceof ezcTemplateArrayFetchOperatorTstNode || $lhs instanceof ezcTemplateArrayAppendOperatorTstNode || - $lhs instanceof ezcTemplatePropertyFetchOperatorTstNode ) ) + $lhs instanceof ezcTemplatePropertyFetchOperatorTstNode || + $lhs instanceof ezcTemplateAssignmentOperatorTstNode ) ) { throw new ezcTemplateParserException( $this->parser->source, $cursor, $cursor, ezcTemplateSourceToTstErrorMessages::MSG_UNEXPECTED_ASSIGNMENT ); } + return; } - return true; + if( $lhs instanceof ezcTemplateModifyingBlockTstNode ) + { + throw new ezcTemplateParserException( $this->parser->source, $cursor, $cursor, + ezcTemplateSourceToTstErrorMessages::MSG_OPERATOR_LHS_IS_MODIFYING_BLOCK ); + } + + return; } + + private function operatorRhsCheck( $op, $rhs, $cursor ) + { + if( $rhs instanceof ezcTemplateModifyingBlockTstNode ) + { + if( $op instanceof ezcTemplateOperatorTstNode ) + { + throw new ezcTemplateParserException( $this->parser->source, $cursor, $cursor, + sprintf( ezcTemplateSourceToTstErrorMessages::MSG_OPERATOR_RHS_IS_MODIFYING_BLOCK, $op->symbol )); + } + else + { + throw new ezcTemplateParserException( $this->parser->source, $cursor, $cursor, + ezcTemplateSourceToTstErrorMessages::MSG_OPERATOR_IS_MODIFYING_BLOCK ); + } + } + } + + } ?> Modified: trunk/Template/src/parsers/source_to_tst/implementations/function_call.php =================================================================== --- trunk/Template/src/parsers/source_to_tst/implementations/function_call.php 2006-11-30 13:56:44 UTC (rev 4149) +++ trunk/Template/src/parsers/source_to_tst/implementations/function_call.php 2006-11-30 13:57:18 UTC (rev 4150) @@ -182,6 +182,11 @@ $rootOperator = $rootOperator->getRoot(); } + if ( $rootOperator instanceof ezcTemplateModifyingOperatorTstNode ) + { + throw new ezcTemplateParserException( $this->parser->source, $this->startCursor, $this->currentCursor, sprintf( ezcTemplateSourceToTstErrorMessages::MSG_PARAMETER_CANNOT_BE_MODIFYING_BLOCK, $this->parameterCount ) ); + } + $this->functionCall->appendParameter( $rootOperator ); $this->readingParameter = false; Added: trunk/Template/tests/regression_tests/expressions/correct/assignment.in =================================================================== --- trunk/Template/tests/regression_tests/expressions/correct/assignment.in 2006-11-30 13:56:44 UTC (rev 4149) +++ trunk/Template/tests/regression_tests/expressions/correct/assignment.in 2006-11-30 13:57:18 UTC (rev 4150) @@ -0,0 +1,11 @@ +{var $a, $b, $c} + +{$a = 2} +{$a = $b = 3} +{$a = $b = $c = 4 } +{$c = 5} +{$a = $b = $c } + +{$a} +{$b} +{$c} Property changes on: trunk/Template/tests/regression_tests/expressions/correct/assignment.in ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/Template/tests/regression_tests/expressions/correct/assignment.out =================================================================== --- trunk/Template/tests/regression_tests/expressions/correct/assignment.out 2006-11-30 13:56:44 UTC (rev 4149) +++ trunk/Template/tests/regression_tests/expressions/correct/assignment.out 2006-11-30 13:57:18 UTC (rev 4150) @@ -0,0 +1,5 @@ + + +5 +5 +5 Property changes on: trunk/Template/tests/regression_tests/expressions/correct/assignment.out ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/Template/tests/regression_tests/expressions/incorrect_assignments/function.in =================================================================== --- trunk/Template/tests/regression_tests/expressions/incorrect_assignments/function.in 2006-11-30 13:56:44 UTC (rev 4149) +++ trunk/Template/tests/regression_tests/expressions/incorrect_assignments/function.in 2006-11-30 13:57:18 UTC (rev 4150) @@ -0,0 +1,3 @@ +{var $a} + +{str_len( $a = "bla" )} Property changes on: trunk/Template/tests/regression_tests/expressions/incorrect_assignments/function.in ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/Template/tests/regression_tests/expressions/incorrect_assignments/function.out =================================================================== --- trunk/Template/tests/regression_tests/expressions/incorrect_assignments/function.out 2006-11-30 13:56:44 UTC (rev 4149) +++ trunk/Template/tests/regression_tests/expressions/incorrect_assignments/function.out 2006-11-30 13:57:18 UTC (rev 4150) @@ -0,0 +1,4 @@ +mock:3:22: The given parameter is not allowed to modify a variable. + +{str_len( $a = "bla" )} + ^ Property changes on: trunk/Template/tests/regression_tests/expressions/incorrect_assignments/function.out ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/Template/tests/regression_tests/expressions/incorrect_assignments/parenthesis.in =================================================================== --- trunk/Template/tests/regression_tests/expressions/incorrect_assignments/parenthesis.in 2006-11-30 13:56:44 UTC (rev 4149) +++ trunk/Template/tests/regression_tests/expressions/incorrect_assignments/parenthesis.in 2006-11-30 13:57:18 UTC (rev 4150) @@ -0,0 +1,3 @@ +{var $a} + +{($a = 2) + 2} Property changes on: trunk/Template/tests/regression_tests/expressions/incorrect_assignments/parenthesis.in ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/Template/tests/regression_tests/expressions/incorrect_assignments/parenthesis.out =================================================================== --- trunk/Template/tests/regression_tests/expressions/incorrect_assignments/parenthesis.out 2006-11-30 13:56:44 UTC (rev 4149) +++ trunk/Template/tests/regression_tests/expressions/incorrect_assignments/parenthesis.out 2006-11-30 13:57:18 UTC (rev 4150) @@ -0,0 +1,4 @@ +mock:3:10: Unexpected operand or expression. The operand or expression modifies a variable, which is not allowed. + +{($a = 2) + 2} + ^ Property changes on: trunk/Template/tests/regression_tests/expressions/incorrect_assignments/parenthesis.out ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/Template/tests/regression_tests/expressions/incorrect_assignments/parenthesis2.in =================================================================== --- trunk/Template/tests/regression_tests/expressions/incorrect_assignments/parenthesis2.in 2006-11-30 13:56:44 UTC (rev 4149) +++ trunk/Template/tests/regression_tests/expressions/incorrect_assignments/parenthesis2.in 2006-11-30 13:57:18 UTC (rev 4150) @@ -0,0 +1,2 @@ +{var $a} +{2 + ($a = 2)} Property changes on: trunk/Template/tests/regression_tests/expressions/incorrect_assignments/parenthesis2.in ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/Template/tests/regression_tests/expressions/incorrect_assignments/parenthesis2.out =================================================================== --- trunk/Template/tests/regression_tests/expressions/incorrect_assignments/parenthesis2.out 2006-11-30 13:56:44 UTC (rev 4149) +++ trunk/Template/tests/regression_tests/expressions/incorrect_assignments/parenthesis2.out 2006-11-30 13:57:18 UTC (rev 4150) @@ -0,0 +1,4 @@ +mock:2:14: Unexpected operand or expression. An operand or expression that modifies a variable cannot be used in combination with the '+' operator. + +{2 + ($a = 2)} + ^ Property changes on: trunk/Template/tests/regression_tests/expressions/incorrect_assignments/parenthesis2.out ___________________________________________________________________ Name: svn:eol-style + native |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | 4149 - trunk/Template/src/parsers/tst_to_ast/implementations [eZComponents: Trunk]: 00324, Jan Borsodi |
|---|---|
| Next by Date: | 4151 - trunk/Template/tests/scripts [eZComponents: Trunk]: 00324, Jan Borsodi |
| Previous by Thread: | 4149 - trunk/Template/src/parsers/tst_to_ast/implementations [eZComponents: Trunk]i: 00324, Jan Borsodi |
| Next by Thread: | 4151 - trunk/Template/tests/scripts [eZComponents: Trunk]: 00324, Jan Borsodi |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |