logo       

4115 - in trunk/Template: src/parsers/source_to_tst/implementations src/par: msg#00288

web.ezcomponents.cvs

Subject: 4115 - in trunk/Template: src/parsers/source_to_tst/implementations src/parsers/tst_to_ast/implementations src/syntax_trees/tst/nodes tests/regression_tests/blocks/incorrect tests/regression_tests/foreach/incorrect [eZComponents: Trunk]

Author: Raymond Bosman
Date: 2006-11-28 17:39:40 +0100 (Tue, 28 Nov 2006)
New Revision: 4115

Log:
- Changed the error message for {delimiter} outside a foreach and while.
- {delimiter} can also be used inside a {while}

Modified:
trunk/Template/src/parsers/source_to_tst/implementations/program.php

trunk/Template/src/parsers/tst_to_ast/implementations/tst_to_ast_transformer.php
trunk/Template/src/syntax_trees/tst/nodes/block.php
trunk/Template/src/syntax_trees/tst/nodes/delimiter.php

trunk/Template/tests/regression_tests/blocks/incorrect/non_matching_block_0025.out

trunk/Template/tests/regression_tests/blocks/incorrect/non_matching_block_0026.out

trunk/Template/tests/regression_tests/blocks/incorrect/non_matching_block_0027.out

trunk/Template/tests/regression_tests/blocks/incorrect/non_matching_block_0028.out

trunk/Template/tests/regression_tests/blocks/incorrect/non_matching_block_0029.out

trunk/Template/tests/regression_tests/blocks/incorrect/non_matching_block_0030.out

trunk/Template/tests/regression_tests/blocks/incorrect/non_matching_block_0031.out

trunk/Template/tests/regression_tests/blocks/incorrect/non_matching_block_0032.out

trunk/Template/tests/regression_tests/foreach/incorrect/delimiter_outside_foreach.out

Modified: trunk/Template/src/parsers/source_to_tst/implementations/program.php
===================================================================
--- trunk/Template/src/parsers/source_to_tst/implementations/program.php
2006-11-28 15:22:53 UTC (rev 4114)
+++ trunk/Template/src/parsers/source_to_tst/implementations/program.php
2006-11-28 16:39:40 UTC (rev 4115)
@@ -194,19 +194,19 @@
// This method throws an exception if the node cannot be
attached.
$element->canAttachToParent( $this->lastBlock );

- $this->lastBlock->handleElement( $element );
+ $this->lastBlock->handleElement( $element );

- if ( $element instanceof ezcTemplateBlockTstNode &&
$element->isNestingBlock)
- {
+ if ( $element instanceof ezcTemplateBlockTstNode &&
$element->isNestingBlock)
+ {

- // No special handling required so we check if the
element
- // is a nesting block and should start a new nesting
level
+ // No special handling required so we check if the element
+ // is a nesting block and should start a new nesting level

- $element->parentBlock = $this->lastBlock;
- $this->lastBlock = $element;
+ $element->parentBlock = $this->lastBlock;
+ $this->lastBlock = $element;

- $this->parser->symbolTable->increaseScope();
- }
+ $this->parser->symbolTable->increaseScope();
+ }
}
}
}

Modified:
trunk/Template/src/parsers/tst_to_ast/implementations/tst_to_ast_transformer.php
===================================================================
---
trunk/Template/src/parsers/tst_to_ast/implementations/tst_to_ast_transformer.php
2006-11-28 15:22:53 UTC (rev 4114)
+++
trunk/Template/src/parsers/tst_to_ast/implementations/tst_to_ast_transformer.php
2006-11-28 16:39:40 UTC (rev 4115)
@@ -729,21 +729,49 @@

public function visitWhileLoopTstNode( ezcTemplateWhileLoopTstNode $type )
{
- if ( $type->name == "do" )
+ $delimVar = new ezcTemplateVariableAstNode(
$this->getUniqueVariableName( "delim" ) );
+ $delimOut = new ezcTemplateVariableAstNode(
$this->getUniqueVariableName( "delimOut" ) );
+ array_unshift( $this->delimiterStack, array("counter" => $delimVar,
"output" => $delimOut, "found" => false) );
+
+ $astNode = array();
+ $body = $this->createBody( $type->elements );
+
+ $i = 0;
+ if ( $this->delimiterStack[0]["found"] )
{
- $astNode = new ezcTemplateDoWhileAstNode();
+ // Assign the delimiter variable to 0 (above foreach).
+ // $_ezcTemplate_delimiterCounter = 0
+ $astNode[$i++] = new ezcTemplateGenericStatementAstNode( new
ezcTemplateAssignmentOperatorAstNode(
+ $this->delimiterStack[0]["counter"], new
ezcTemplateLiteralAstNode( 0 ) ) );
+
+ // Assign delimiter output to "" (above foreach)
+ // $_ezcTemplate_delimiterOut = ""
+ $astNode[$i++] = new ezcTemplateGenericStatementAstNode( new
ezcTemplateAssignmentOperatorAstNode(
+ $this->delimiterStack[0]["output"], new
ezcTemplateLiteralAstNode( "" ) ) );
+
+ array_unshift( $body->statements, new
ezcTemplateGenericStatementAstNode( new ezcTemplateAssignmentOperatorAstNode(
$this->delimiterStack[0]["output"], new ezcTemplateLiteralAstNode( "" ) ) ) );
+
+ $inc = new ezcTemplateIncrementOperatorAstNode( true );
+ $inc->appendParameter( $this->delimiterStack[0]["counter"] );
+
+ array_unshift( $body->statements, new
ezcTemplateGenericStatementAstNode( $inc ) );
+
+ // output delimiter output (in foreach).
+ // $_ezcTemplate_output .= $_ezcTemplate_delimiterOut;
+ array_unshift( $body->statements, new
ezcTemplateGenericStatementAstNode( new
ezcTemplateConcatAssignmentOperatorAstNode(
+ $this->outputVariable->getAst() ,
$this->delimiterStack[0]["output"] ) ) );
+
}
- else
- {
- $astNode = new ezcTemplateWhileAstNode();
- }

+ $astNode[$i] = new ezcTemplateWhileAstNode();
+
$cb = new ezcTemplateConditionBodyAstNode();
$cb->condition = $type->condition->accept( $this );
- $cb->body = $this->createBody( $type->elements );
+ $cb->body = $body;

- $astNode->conditionBody = $cb;
+ $astNode[$i]->conditionBody = $cb;

+
return $astNode;
}


Modified: trunk/Template/src/syntax_trees/tst/nodes/block.php
===================================================================
--- trunk/Template/src/syntax_trees/tst/nodes/block.php 2006-11-28 15:22:53 UTC
(rev 4114)
+++ trunk/Template/src/syntax_trees/tst/nodes/block.php 2006-11-28 16:39:40 UTC
(rev 4115)
@@ -239,11 +239,6 @@
throw new Exception( "Detected invalid recursion creation in
parser element " . get_class( $this ) );
}

- if ( $element instanceof ezcTemplateDelimiterTstNode )
- {
- throw new ezcTemplateParserException( $element->source,
$element->startCursor, $element->startCursor,
ezcTemplateSourceToTstErrorMessages::MSG_EXPECT_DELIMITER_INSIDE_FOREACH );
- }
-
if ( $element instanceof ezcTemplateLoopTstNode )
{
throw new ezcTemplateParserException( $element->source,
$element->startCursor, $element->startCursor,
ezcTemplateSourceToTstErrorMessages::MSG_UNEXPECTED_BREAK_OR_CONTINUE );

Modified: trunk/Template/src/syntax_trees/tst/nodes/delimiter.php
===================================================================
--- trunk/Template/src/syntax_trees/tst/nodes/delimiter.php 2006-11-28
15:22:53 UTC (rev 4114)
+++ trunk/Template/src/syntax_trees/tst/nodes/delimiter.php 2006-11-28
16:39:40 UTC (rev 4115)
@@ -48,5 +48,26 @@
parent::handleElement( $element );
}

+ public function canAttachToParent( $parentElement )
+ {
+ // Process the lot.
+ // Must at least have one parent with foreach or while.
+
+ $p = $parentElement;
+
+ while( !$p instanceof ezcTemplateProgramTstNode )
+ {
+ if( $p instanceof ezcTemplateForeachLoopTstNode || $p instanceof
ezcTemplateWhileLoopTstNode )
+ {
+ return; // Perfect, we are inside a loop.
+ }
+
+ $p = $p->parentBlock;
+ }
+
+
+ throw new ezcTemplateParserException( $this->source,
$this->startCursor, $this->startCursor,
+ "{" . $this->name . "} can only be a child of an {foreach} or a
{while} block." );
+ }
}
?>

Modified:
trunk/Template/tests/regression_tests/blocks/incorrect/non_matching_block_0025.out
===================================================================
---
trunk/Template/tests/regression_tests/blocks/incorrect/non_matching_block_0025.out
2006-11-28 15:22:53 UTC (rev 4114)
+++
trunk/Template/tests/regression_tests/blocks/incorrect/non_matching_block_0025.out
2006-11-28 16:39:40 UTC (rev 4115)
@@ -1,4 +1,4 @@
-mock:3:11: Delimiter can only be used inside a foreach block.
+mock:3:11: {delimiter} can only be a child of an {foreach} or a {while} block.

{delimiter}
^

Modified:
trunk/Template/tests/regression_tests/blocks/incorrect/non_matching_block_0026.out
===================================================================
---
trunk/Template/tests/regression_tests/blocks/incorrect/non_matching_block_0026.out
2006-11-28 15:22:53 UTC (rev 4114)
+++
trunk/Template/tests/regression_tests/blocks/incorrect/non_matching_block_0026.out
2006-11-28 16:39:40 UTC (rev 4115)
@@ -1,4 +1,4 @@
-mock:3:11: Delimiter can only be used inside a foreach block.
+mock:3:11: {delimiter} can only be a child of an {foreach} or a {while} block.

{delimiter}
^

Modified:
trunk/Template/tests/regression_tests/blocks/incorrect/non_matching_block_0027.out
===================================================================
---
trunk/Template/tests/regression_tests/blocks/incorrect/non_matching_block_0027.out
2006-11-28 15:22:53 UTC (rev 4114)
+++
trunk/Template/tests/regression_tests/blocks/incorrect/non_matching_block_0027.out
2006-11-28 16:39:40 UTC (rev 4115)
@@ -1,4 +1,4 @@
-mock:3:11: Delimiter can only be used inside a foreach block.
+mock:3:11: {delimiter} can only be a child of an {foreach} or a {while} block.

{delimiter}
^

Modified:
trunk/Template/tests/regression_tests/blocks/incorrect/non_matching_block_0028.out
===================================================================
---
trunk/Template/tests/regression_tests/blocks/incorrect/non_matching_block_0028.out
2006-11-28 15:22:53 UTC (rev 4114)
+++
trunk/Template/tests/regression_tests/blocks/incorrect/non_matching_block_0028.out
2006-11-28 16:39:40 UTC (rev 4115)
@@ -1,4 +1,4 @@
-mock:3:11: Delimiter can only be used inside a foreach block.
+mock:3:11: {delimiter} can only be a child of an {foreach} or a {while} block.

{delimiter}
^

Modified:
trunk/Template/tests/regression_tests/blocks/incorrect/non_matching_block_0029.out
===================================================================
---
trunk/Template/tests/regression_tests/blocks/incorrect/non_matching_block_0029.out
2006-11-28 15:22:53 UTC (rev 4114)
+++
trunk/Template/tests/regression_tests/blocks/incorrect/non_matching_block_0029.out
2006-11-28 16:39:40 UTC (rev 4115)
@@ -1,4 +1,4 @@
-mock:3:11: Delimiter can only be used inside a foreach block.
+mock:3:11: {delimiter} can only be a child of an {foreach} or a {while} block.

{delimiter}
^

Modified:
trunk/Template/tests/regression_tests/blocks/incorrect/non_matching_block_0030.out
===================================================================
---
trunk/Template/tests/regression_tests/blocks/incorrect/non_matching_block_0030.out
2006-11-28 15:22:53 UTC (rev 4114)
+++
trunk/Template/tests/regression_tests/blocks/incorrect/non_matching_block_0030.out
2006-11-28 16:39:40 UTC (rev 4115)
@@ -1,4 +1,4 @@
-mock:3:11: Delimiter can only be used inside a foreach block.
+mock:3:11: {delimiter} can only be a child of an {foreach} or a {while} block.

{delimiter}
^

Modified:
trunk/Template/tests/regression_tests/blocks/incorrect/non_matching_block_0031.out
===================================================================
---
trunk/Template/tests/regression_tests/blocks/incorrect/non_matching_block_0031.out
2006-11-28 15:22:53 UTC (rev 4114)
+++
trunk/Template/tests/regression_tests/blocks/incorrect/non_matching_block_0031.out
2006-11-28 16:39:40 UTC (rev 4115)
@@ -1,4 +1,4 @@
-mock:3:11: Delimiter can only be used inside a foreach block.
+mock:3:11: {delimiter} can only be a child of an {foreach} or a {while} block.

{delimiter}
^

Modified:
trunk/Template/tests/regression_tests/blocks/incorrect/non_matching_block_0032.out
===================================================================
---
trunk/Template/tests/regression_tests/blocks/incorrect/non_matching_block_0032.out
2006-11-28 15:22:53 UTC (rev 4114)
+++
trunk/Template/tests/regression_tests/blocks/incorrect/non_matching_block_0032.out
2006-11-28 16:39:40 UTC (rev 4115)
@@ -1,4 +1,4 @@
-mock:3:11: Delimiter can only be used inside a foreach block.
+mock:3:11: {delimiter} can only be a child of an {foreach} or a {while} block.

{delimiter}
^

Modified:
trunk/Template/tests/regression_tests/foreach/incorrect/delimiter_outside_foreach.out
===================================================================
---
trunk/Template/tests/regression_tests/foreach/incorrect/delimiter_outside_foreach.out
2006-11-28 15:22:53 UTC (rev 4114)
+++
trunk/Template/tests/regression_tests/foreach/incorrect/delimiter_outside_foreach.out
2006-11-28 16:39:40 UTC (rev 4115)
@@ -1,4 +1,4 @@
-mock:1:11: Delimiter can only be used inside a foreach block.
+mock:1:11: {delimiter} can only be a child of an {foreach} or a {while} block.

{delimiter modulo 2}
^



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise