Thread: [Wact-cvs] SF.net SVN: wact: [450] trunk/wact/template/compiler (Page 2)
Status: Pre-Alpha
Brought to you by:
jeffmoore
From: <nor...@us...> - 2007-04-21 20:42:05
|
Revision: 450 http://svn.sourceforge.net/wact/?rev=450&view=rev Author: norbertmocsnik Date: 2007-04-21 13:42:00 -0700 (Sat, 21 Apr 2007) Log Message: ----------- Merged WactNodeBuilder back into WactTreeBuilder (and WactComponentParsingState). Modified Paths: -------------- trunk/wact/template/compiler/compiler.inc.php trunk/wact/template/compiler/parser/source.inc.php trunk/wact/template/compiler/parser/state.inc.php trunk/wact/template/compiler/parser/state.test.php trunk/wact/template/compiler/parser/treebuilder.inc.php trunk/wact/template/compiler/parser/treebuilder.test.php Removed Paths: ------------- trunk/wact/template/compiler/parser/nodebuilder.inc.php trunk/wact/template/compiler/parser/nodebuilder.test.php Modified: trunk/wact/template/compiler/compiler.inc.php =================================================================== --- trunk/wact/template/compiler/compiler.inc.php 2007-04-21 02:21:11 UTC (rev 449) +++ trunk/wact/template/compiler/compiler.inc.php 2007-04-21 20:42:00 UTC (rev 450) @@ -18,7 +18,6 @@ require_once 'wact/template/compiler/node/root.inc.php'; require_once 'wact/template/compiler/parser/treebuilder.inc.php'; -require_once 'wact/template/compiler/parser/nodebuilder.inc.php'; require_once 'wact/template/compiler/parser/state.inc.php'; require_once 'wact/template/compiler/node/text.inc.php'; require_once 'wact/template/compiler/parser/source.inc.php'; Deleted: trunk/wact/template/compiler/parser/nodebuilder.inc.php =================================================================== --- trunk/wact/template/compiler/parser/nodebuilder.inc.php 2007-04-21 02:21:11 UTC (rev 449) +++ trunk/wact/template/compiler/parser/nodebuilder.inc.php 2007-04-21 20:42:00 UTC (rev 450) @@ -1,217 +0,0 @@ -<?php -/** -* Web Application Component Toolkit -* -* @link http://www.phpwact.org/ -* -* @author Wact Development Team -* @link http://www.phpwact.org/team -* -* @copyright Copyright 2006, Jeff Moore -* @license http://opensource.org/licenses/mit-license.php MIT -* -* @package Template -* @version 0.9 -*/ - -/* -* File level includes -*/ -require_once 'wact/template/compiler/attribute/attribute.inc.php'; -require_once 'wact/template/compiler/attribute/expression.inc.php'; -require_once 'wact/template/compiler/attribute/compound.inc.php'; - -require_once 'wact/template/compiler/expression/output.inc.php'; -require_once 'wact/template/compiler/expression/parser.inc.php'; - -/** -* Responsible for building nodes of the component tree. -* WactTreeBuilder is responsible for the tree structure. -*/ -class WactNodeBuilder { - - /** - * Used to locate position within document - */ - private $locator; - - /** - */ - private $formatterDictionary; - - /** - */ - private $propertyDictionary; - - /** - * Constructs WactTreeBuilder, setting up expression parsers - */ - function __construct($propDict, $formatterDict) { - $this->formatterDictionary = $formatterDict; - $this->propertyDictionary = $propDict; - } - - /** - * Sets the Document Locator - * @param DocumentLocator - * @return void - */ - function setDocumentLocator($locator) { - $this->locator = $locator; - } - - /** - * Builds a component, adding attributes - * @param WactTagInfo - * @param string XML tag name of component - * @param array attributes for tag - * @param boolean whether the tag has contents - * @return WactTemplateNode - */ - function buildComponent($tagInfo, $tag, $attrs) { - - $class = $tagInfo->tagClass; - $sourceLocation = new WactSourceLocation( - $this->locator->getPublicId(), - $this->locator->getLineNumber()); - - $component = new $class($tag, $tagInfo, $sourceLocation); - - foreach ( $attrs as $name => $value ) { - $listener = new WactAttributeFragmentListener($component, $name); - $parser = new WactExpressionParser(); - $parser->parseFragments($listener, $value); - } - - return $component; - } - - /** - * Builds content node(s), adding it (them) to the component tree. - * A single piece of content may actually be a mix of terminal nodes - * (WactTextTemplateNodes and Expressions) - * @param WactTreeBuilder - * @param string content of tag - * @return void - */ - function addContent($treeBuilder, $text) { - $listener = new WactContentFragmentListener($treeBuilder, $this->locator); - $parser = new WactExpressionParser(); - $parser->parseFragments($listener, $text, 'WactHtmlEscapeExpressionNode'); - } - - /** - * Builds XML processing instructions and adds them to the component tree. - * PHP instructions are ignored. - * @param WactTreeBuilder - * @param string target processor - * @param string instruction - * @return void - */ - function addProcessingInstruction($treeBuilder, $target, $instruction) { - // we can optimize here by not loading PHP node until we need it - // It will probably be rarely used in templates. - require_once 'wact/template/compiler/node/php.inc.php'; - - // Pass through any PI's except PHP PI's - $invalid_targets = array('php','PHP','=',''); - if ( !in_array($target, $invalid_targets) ) { - $php = 'echo "<?'.$target.' '; // Whitespace assumption - $php.= str_replace('"','\"',$instruction); - $php.= '?>\n";'; // Newline assumption - $treeBuilder->addNode(new WactPhpTemplateNode(NULL, NULL, NULL, $php)); - } - } - -} - - -class WactContentFragmentListener implements WactExpressionFragmentObserver { - - protected $treeBuilder; - - protected $locator; - - function __construct($treeBuilder, $locator) { - $this->treeBuilder = $treeBuilder; - $this->locator = $locator; - } - - function addLiteral($text) { - $this->treeBuilder->addTextNode($text); - } - - function addExpression(WactTemplateExpressionNode $expr) { - - $location = new WactSourceLocation( - $this->locator->getPublicId(), - $this->locator->getLineNumber()); - - $output = new WactExpressionOutputTemplateNode ( - NULL, NULL, - $location, - $expr); - - $this->treeBuilder->addNode($output); - - } - - function beginFragments() { - } - - function addLiteralFragment($text) { - $this->treeBuilder->addTextNode($text); - } - - function addExpressionFragment(WactTemplateExpressionNode $expr) { - $this->addExpression($expr); - } - - function endFragments() { - } - -} - -class WactAttributeFragmentListener implements WactExpressionFragmentObserver{ - - protected $component; - protected $name; - protected $compound; - - function __construct($component, $name) { - $this->component = $component; - $this->name = $name; - } - - function addExpression(WactTemplateExpressionNode $expr) { - $attribute = new WactExpressionTemplateAttribute( - $name, $match[WACT_EXPPARSER_EXPRESSION], $component, $this->formatterDictionary); - } - - function addLiteral($text) { - $attribute = new WactTemplateAttribute($this->name, $text); - $this->component->addChildAttribute($attribute); - } - - function beginFragments() { - $this->compound = new WactCompoundTemplateAttribute($name); - } - - function addLiteralFragment($text) { - $attribute = new WactTemplateLiteralAttributeFragment($text); - $this->compound->addAttributeFragment($attribute); - } - - function addExpressionFragment(WactTemplateExpressionNode $expr) { - $attribute = new WactExpressionAttributeFragment($expr); - $this->compound->addAttributeFragment($attribute); - } - - function endFragments() { - $this->component->addChildAttribute($this->compound); - } - -} - - -?> \ No newline at end of file Deleted: trunk/wact/template/compiler/parser/nodebuilder.test.php =================================================================== --- trunk/wact/template/compiler/parser/nodebuilder.test.php 2007-04-21 02:21:11 UTC (rev 449) +++ trunk/wact/template/compiler/parser/nodebuilder.test.php 2007-04-21 20:42:00 UTC (rev 450) @@ -1,131 +0,0 @@ -<?php - -require_once 'wact/template/compiler/parser/nodebuilder.inc.php'; -require_once 'wact/template/compiler/parser/treebuilder.inc.php'; -require_once 'wact/xml/sax/html.inc.php'; -require_once 'wact/template/compiler/tag/dictionary.inc.php'; -require_once 'wact/template/compiler/property/dictionary.inc.php'; -require_once 'wact/template/compiler/formatter/dictionary.inc.php'; -require_once 'wact/template/compiler/node/template.inc.php'; - - -Mock::generate('WactTemplateNode','MockTemplateNode'); -Mock::generate('WactHtmlSaxReader','MockHTMLParser'); -Mock::generate('WactPropertyDictionary','MockPropertyDictionary'); -Mock::generate('WactFormatterDictionary','MockFormatterDictionary'); -Mock::generate('WactTreeBuilder', 'MockTreeBuilder'); - -class MyMockComponent { - var $tag; - function MyMockComponent($tag, $tagInfo, $sourceLocation) { - $this->tag = $tag; - } - function getTag() { - return $this->tag; - } - - function removeAttribute() { - } - - function checkNestingLevel() { - } - - function getServerId(){ - } - - function addchildattribute(){ - } -} - -class WactNodeBuilderTestCase extends UnitTestCase { - - var $nodeBuilder; - var $propertyDictionary; - var $formatterDictionary; - var $locator; - - function setUp() { - $this->propertyDictionary = new MockPropertyDictionary($this); - - $this->propertyDictionary->setReturnValue('getPropertyList', array()); - - $this->formatterDictionary = new MockFormatterDictionary($this); - $this->nodeBuilder = new WactNodeBuilder($this->propertyDictionary, $this->formatterDictionary); - $this->locator = new MockHTMLParser($this); - $this->nodeBuilder->setDocumentLocator($this->locator); - } - - function tearDown() { - unset ( $this->nodeBuilder ); - unset ( $this->locator ); - } - - function testBuildComponent() { - $tag = 'test'; - $info = new WactTagInfo($tag, 'MyMockComponent'); - - $node = $this->nodeBuilder->buildComponent($info, $tag, array('foo'=>'bar')); - - $this->assertIsA($node, $info->tagClass); - $this->assertEqual($node->getTag(), $tag); - } -/* - function testCreateTagComponent() { - $tag = 'test'; - $info = new WactTagInfo($tag, 'MyMockComponent'); - - $this->locator->expectOnce('getLineNumber'); - $this->locator->expectOnce('getPublicId'); - - $node = $this->nodeBuilder->createComponent($info, $tag); - - $this->assertIsA($node, $info->tagClass); - $this->assertEqual($node->getTag(), $tag); - $this->locator->tally(); - } - - function testAddAttributes() { - $node = new MockTemplateNode($this); - $node->expectOnce('addChildAttribute'); - - $this->nodeBuilder->addAttributesToComponent($node, array('foo' => 'test')); - - $node->tally(); - } - -*/ - function testAddContent() { - $fi = new WactFormatterInfo('html', 'WactTemplateValueFormatter'); - $fi->file = 'wact/template/compiler/formatter/formatter.inc.php'; - - $this->formatterDictionary->setReturnValue('getFormatterInfo', $fi); - - $treeBuilder = new MockTreeBuilder($this); - $treeBuilder->expectOnce('addTextNode'); - $treeBuilder->expectOnce('addNode'); - - $this->nodeBuilder->addContent($treeBuilder, '{$1}test'); - - $treeBuilder->tally(); - } - - function testAddProcessingInstruction() { - $treeBuilder = new MockTreeBuilder($this); - $treeBuilder->expectOnce('addNode'); - - $this->nodeBuilder->addProcessingInstruction($treeBuilder, 'xml', 'version="1.0"'); - - $treeBuilder->tally(); - } - - function testIgnoredAddProcessingInstruction() { - $treeBuilder = new MockTreeBuilder($this); - $treeBuilder->expectNever('addNode'); - - $this->nodeBuilder->addProcessingInstruction($treeBuilder, 'php','ignore'); - - $treeBuilder->tally(); - } - -} -?> \ No newline at end of file Modified: trunk/wact/template/compiler/parser/source.inc.php =================================================================== --- trunk/wact/template/compiler/parser/source.inc.php 2007-04-21 02:21:11 UTC (rev 449) +++ trunk/wact/template/compiler/parser/source.inc.php 2007-04-21 20:42:00 UTC (rev 450) @@ -125,13 +125,11 @@ $propertyDictionary = $dictionaries->getPropertyDictionary(); $formatterDictionary = $dictionaries->getFormatterDictionary(); - $nodeBuilder = new WactNodeBuilder($propertyDictionary, $formatterDictionary); - $tagCountBeforeParse = $this->treeBuilder->getExpectedTagCount(); $this->treeBuilder->setCursor($componentRoot); - $this->componentParsingState = new WactComponentParsingState($this, $this->treeBuilder, $nodeBuilder, $tagDictionary); + $this->componentParsingState = new WactComponentParsingState($this, $this->treeBuilder, $tagDictionary); $this->literalParsingState = new WactLiteralParsingState($this, $this->treeBuilder); $this->changeToComponentParsingState(); Modified: trunk/wact/template/compiler/parser/state.inc.php =================================================================== --- trunk/wact/template/compiler/parser/state.inc.php 2007-04-21 02:21:11 UTC (rev 449) +++ trunk/wact/template/compiler/parser/state.inc.php 2007-04-21 20:42:00 UTC (rev 450) @@ -107,31 +107,16 @@ * @var WactTagDictionary */ private $tagDictionary; - + /** - * Instance of Node Builder - * @var NodeBuilder - */ - private $nodeBuilder; - - /** * @param WactSourceParser */ - function __construct($parser, $treeBuilder, $nodeBuilder, $tagDictionary) { + function __construct($parser, $treeBuilder, $tagDictionary) { parent::__construct($parser, $treeBuilder); $this->tagDictionary = $tagDictionary; - $this->nodeBuilder = $nodeBuilder; } /** - * @param Locator - */ - function setDocumentLocator($locator) { - parent::setDocumentLocator($locator); - $this->nodeBuilder->setDocumentLocator($locator); - } - - /** * Builds an attribute string based on passed array of attributes * @param array * @return string @@ -161,7 +146,7 @@ * @param array tag attributes */ function startElement($tag, $attrs) { - + $lower_attributes = $this->checkAttributes($tag, $attrs); $tagInfo = $this->tagDictionary->findComponent($tag, $lower_attributes, FALSE, $this->treeBuilder->getCursor()); @@ -172,12 +157,12 @@ if ( $tagInfo->endTag != WactTagInfo::ENDTAG_FORBIDDEN ) { $this->treeBuilder->pushExpectedTag($tag, PARSER_TAG_IS_COMPONENT); } - - $component = $this->nodeBuilder->buildComponent($tagInfo, $tag, $attrs); + + $component = $this->treeBuilder->buildComponent($tagInfo, $tag, $attrs); if ( $this->treeBuilder->pushNode($component) == WactTemplateNode::FORBID_PARSING) { $this->parser->changeToLiteralParsingState($tag); } - + // Cleanup for components that have no closing tag if ( $tagInfo->endTag == WactTagInfo::ENDTAG_FORBIDDEN ) { $this->treeBuilder->popNode(WactTemplateNode::CLOSING_NONE); @@ -186,7 +171,7 @@ } else { $this->treeBuilder->pushExpectedTag($tag, PARSER_TAG_IS_PLAIN); - $this->nodeBuilder->addContent($this->treeBuilder, + $this->treeBuilder->addContent($this->treeBuilder, '<' . $tag . $this->getAttributeString($attrs) . '>'); } } @@ -207,7 +192,7 @@ ); } } - + if ($this->treeBuilder->popExpectedTag($tag) == PARSER_TAG_IS_COMPONENT) { $this->treeBuilder->popNode(WactTemplateNode::CLOSING_TAG); } else { @@ -221,31 +206,33 @@ * @param array tag attributes */ function emptyElement($tag, $attrs) { - + $lower_attributes = $this->checkAttributes($tag, $attrs); $tagInfo = $this->tagDictionary->findComponent($tag, $lower_attributes, TRUE, $this->treeBuilder->getCursor()); if (is_object($tagInfo)) { $tagInfo->load(); - $component = $this->nodeBuilder->buildComponent($tagInfo, $tag, $attrs); - + $component = $this->treeBuilder->buildComponent($tagInfo, $tag, $attrs); + if ( $this->treeBuilder->pushNode($component) == WactTemplateNode::FORBID_PARSING) { - $this->parser->changeToLiteralParsingState($tag); + $this->parser->changeToLiteralParsingState($tag); } - + // Cleanup for components that have no closing tag if ( $tagInfo->endTag == WactTagInfo::ENDTAG_FORBIDDEN ) { $this->parser->changeToComponentParsingState(); } $this->treeBuilder->popNode(WactTemplateNode::CLOSING_SELF); - } else { - $this->nodeBuilder->addContent($this->treeBuilder, + } else { + $this->treeBuilder->addContent($this->treeBuilder, '<' . $tag . $this->getAttributeString($attrs) . ' />'); } } + + /** * Transforms attributes so keys are lowercase, and checks for * illegal DBEs @@ -266,13 +253,13 @@ } return $lower_attributes; } - + /** * Handle tag content * @param string tag content */ function characters($text) { - $this->nodeBuilder->addContent($this->treeBuilder, $text); + $this->treeBuilder->addContent($this->treeBuilder, $text); } /** @@ -280,7 +267,7 @@ * @param string tag content */ function cdata($text) { - $this->nodeBuilder->addContent($this->treeBuilder, '<![CDATA[' . $text . ']]>'); + $this->treeBuilder->addContent($this->treeBuilder, '<![CDATA[' . $text . ']]>'); } /** @@ -289,7 +276,7 @@ * @param string instruction */ function processingInstruction($target, $instruction) { - $this->nodeBuilder->addProcessingInstruction($this->treeBuilder, $target, $instruction); + $this->addProcessingInstruction($this->treeBuilder, $target, $instruction); } /** @@ -298,7 +285,7 @@ */ function jasp($text) { // Name of method is not good in this case - $this->nodeBuilder->addContent($this->treeBuilder, '<%' . $text . '%>'); + $this->treeBuilder->addContent($this->treeBuilder, '<%' . $text . '%>'); } /** @@ -306,7 +293,7 @@ * @param string content of escape */ function escape($text) { - $this->nodeBuilder->addContent($this->treeBuilder, '<!' . $text . '>'); + $this->treeBuilder->addContent($this->treeBuilder, '<!' . $text . '>'); } /** @@ -314,7 +301,7 @@ * @param string content of doctype */ function doctype($text) { - $this->nodeBuilder->addContent($this->treeBuilder, '<!' . $text . '>'); + $this->treeBuilder->addContent($this->treeBuilder, '<!' . $text . '>'); } /** @@ -323,7 +310,7 @@ */ function comment($text) { // Name of method is not good in this case - $this->nodeBuilder->addContent($this->treeBuilder, '<!--' . $text . '-->'); + $this->treeBuilder->addContent($this->treeBuilder, '<!--' . $text . '-->'); } /** @@ -332,7 +319,7 @@ */ function unexpectedEOF($text) { // Ignore the error and treat the rest of the file like data - $this->nodeBuilder->addContent($this->treeBuilder, $text); + $this->treeBuilder->addContent($this->treeBuilder, $text); } /** @@ -341,9 +328,32 @@ */ function invalidEntitySyntax($text) { // Ignore the error and treat the rest of the file like data - $this->nodeBuilder->addContent($this->treeBuilder, $text); + $this->treeBuilder->addContent($this->treeBuilder, $text); } + /** + * Builds XML processing instructions and adds them to the component tree. + * PHP instructions are ignored. + * @param WactTreeBuilder + * @param string target processor + * @param string instruction + * @return void + */ + function addProcessingInstruction($treeBuilder, $target, $instruction) { + // we can optimize here by not loading PHP node until we need it + // It will probably be rarely used in templates. + require_once 'wact/template/compiler/node/php.inc.php'; + + // Pass through any PI's except PHP PI's + $invalid_targets = array('php','PHP','=',''); + if ( !in_array($target, $invalid_targets) ) { + $php = 'echo "<?'.$target.' '; // Whitespace assumption + $php.= str_replace('"','\"',$instruction); + $php.= '?>\n";'; // Newline assumption + $treeBuilder->addNode(new WactPhpTemplateNode(NULL, NULL, NULL, $php)); + } + } + } /** Modified: trunk/wact/template/compiler/parser/state.test.php =================================================================== --- trunk/wact/template/compiler/parser/state.test.php 2007-04-21 02:21:11 UTC (rev 449) +++ trunk/wact/template/compiler/parser/state.test.php 2007-04-21 20:42:00 UTC (rev 450) @@ -2,7 +2,6 @@ require_once 'wact/template/compiler/parser/state.inc.php'; require_once 'wact/template/compiler/parser/source.inc.php'; -require_once 'wact/template/compiler/parser/nodebuilder.inc.php'; require_once 'wact/template/compiler/parser/treebuilder.inc.php'; require_once 'wact/template/compiler/node/view.inc.php'; require_once 'wact/template/compiler/tag/dictionary.inc.php'; @@ -10,7 +9,6 @@ Mock::generate('WactViewTemplateNode','MockViewTemplateNode'); Mock::generate('WactSourceParser','MockSourceParser'); -Mock::generate('WactNodeBuilder', 'MockNodeBuilder'); Mock::generate('WactTreeBuilder','MockTreeBuilder'); Mock::generate('WactTagDictionary','MockTagDictionary'); Mock::generate('WactHtmlSaxReader','MockHTMLParser'); @@ -52,26 +50,23 @@ class WactComponentParsingStateTestCase extends WactBaseParsingStateTestCase { protected $component; - protected $nodeBuilder; protected $tagDictionary; function setUp() { parent::setUp(); - + $this->component = new MockViewTemplateNode($this); - - $this->nodeBuilder = new MockNodeBuilder($this); - $this->nodeBuilder->setReturnReference('buildComponent', $this->component); - + $this->treeBuilder->component = $this->component; + $this->treeBuilder->setReturnReference('buildComponent', $this->component); $this->treeBuilder->setReturnReference('getCursor', $this->component); - + $this->tagDictionary = new MockTagDictionary($this); - $this->state = new WactComponentParsingState($this->parser, $this->treeBuilder, $this->nodeBuilder, $this->tagDictionary); + $this->state = new WactComponentParsingState($this->parser, $this->treeBuilder, $this->tagDictionary); $this->state->setDocumentLocator($this->locator); } - + function tearDown() { unset($this->component); unset($this->state); @@ -85,16 +80,16 @@ function testStartElementIsPlain() { $tag = 'test'; $attrs = array('foo'=>'bar'); - + $this->tagDictionary->setReturnValue('findComponent', NULL); - + $this->treeBuilder->expectOnce('pushExpectedTag', array($tag, PARSER_TAG_IS_PLAIN)); - + $this->state->startElement($tag, $attrs); - + $this->treeBuilder->tally(); } - + function testStartElementIsComponent() { $tag = 'test'; $attrs = array('foo'=>'bar'); @@ -105,12 +100,11 @@ $this->component->setReturnValue('preParse', WactTemplateNode::REQUIRE_PARSING); - $this->nodeBuilder->expectOnce('buildComponent', array('*', $tag, $attrs)); + $this->treeBuilder->expectOnce('buildComponent', array('*', $tag, $attrs)); $this->treeBuilder->expectOnce('pushExpectedTag', array($tag, PARSER_TAG_IS_COMPONENT)); - + $this->state->startElement($tag, $attrs); - $this->nodeBuilder->tally(); $this->treeBuilder->tally(); } @@ -158,7 +152,7 @@ $attrs = array('runat'=>'{$hello}'); $this->component->tag = $tag; - + try { $this->state->startElement($tag, $attrs); $this->fail('Expected exception not thrown'); @@ -168,7 +162,7 @@ } function testEndElementIsComponent() { $tag = 'test'; - + $this->treeBuilder->expectOnce('popExpectedTag', array($tag)); $this->treeBuilder->setReturnValue('popExpectedTag', PARSER_TAG_IS_COMPONENT); $this->treeBuilder->expectOnce('popNode', array(WactTemplateNode::CLOSING_TAG)); @@ -180,7 +174,7 @@ function testEndElementisPlain() { $tag = 'test'; - + $this->treeBuilder->expectOnce('popExpectedTag', array($tag)); $this->treeBuilder->setReturnValue('popExpectedTag', PARSER_TAG_IS_PLAIN); $this->treeBuilder->expectNever('popNode'); @@ -194,13 +188,13 @@ function testEndElementNoMatch() { $component = new WactTemplateNode('bar', NULL, new WactSourceLocation('file', 123)); - + $this->treeBuilder = new WactTreeBuilder(); $this->treeBuilder->setCursor($component); $this->treeBuilder->setDocumentLocator($this->locator); $this->treeBuilder->pushExpectedTag('foo', PARSER_TAG_IS_COMPONENT); - $this->state = new WactComponentParsingState($this->parser, $this->treeBuilder, $this->nodeBuilder, $this->tagDictionary); + $this->state = new WactComponentParsingState($this->parser, $this->treeBuilder, $this->tagDictionary); $this->state->setDocumentLocator($this->locator); try { @@ -236,15 +230,15 @@ function testEmptyElement() { $tag = 'test'; $attrs = array('foo'=>'bar'); - + $this->tagDictionary->setReturnValue('findComponent', NULL); - + $this->treeBuilder->expectNever('pushExpectedTag'); - + $this->state->emptyElement($tag, $attrs); $this->treeBuilder->tally(); } - + function testEmptyElementIsComponent() { $tag = 'test'; $attrs = array('foo'=>'bar'); @@ -255,13 +249,12 @@ $this->component->setReturnValue('preParse', WactTemplateNode::REQUIRE_PARSING); - $this->nodeBuilder->expectOnce('buildComponent', array('*', $tag, $attrs)); + $this->treeBuilder->expectOnce('buildComponent', array('*', $tag, $attrs)); $this->treeBuilder->expectOnce('pushNode'); $this->treeBuilder->expectNever('pushExpectedTag'); - + $this->state->emptyElement($tag, $attrs); - $this->nodeBuilder->tally(); $this->treeBuilder->tally(); } @@ -303,13 +296,13 @@ $this->treeBuilder->tally(); $this->parser->tally(); } - + function testEmptyElementIllegalAttributeName() { $tag = 'test'; $attrs = array('runat'=>'{$hello}'); $this->component->tag = $tag; - + try { $this->state->emptyElement($tag, $attrs); $this->fail('Expected exception not thrown'); @@ -317,71 +310,80 @@ $this->pass(); } } - + function testCharacters() { $text = 'test'; - $this->nodeBuilder->expectOnce('addContent', array('*', $text)); + $this->treeBuilder->expectOnce('addContent', array('*', $text)); $this->state->characters($text); - $this->nodeBuilder->tally(); } function testCdata() { $text = 'test'; - $this->nodeBuilder->expectOnce('addContent', array('*', '<![CDATA[' . $text . ']]>')); + $this->treeBuilder->expectOnce('addContent', array('*', '<![CDATA[' . $text . ']]>')); $this->state->cdata($text); - $this->nodeBuilder->tally(); } + /* function testProcessingInstruction() { $target = 'test'; $instruction = 'doit'; - $this->nodeBuilder->expectOnce('addProcessingInstruction', array('*', $target, $instruction)); + $this->state->expectOnce('addProcessingInstruction', array('*', $target, $instruction)); $this->state->processingInstruction($target, $instruction); - $this->nodeBuilder->tally(); } + */ function testJasp() { $text = 'test'; - $this->nodeBuilder->expectOnce('addContent', array('*', '<%' . $text . '%>')); + $this->treeBuilder->expectOnce('addContent', array('*', '<%' . $text . '%>')); $this->state->jasp($text); - $this->nodeBuilder->tally(); } function testComment() { $text = 'test'; - $this->nodeBuilder->expectOnce('addContent', array('*', '<!--' . $text . '-->')); + $this->treeBuilder->expectOnce('addContent', array('*', '<!--' . $text . '-->')); $this->state->comment($text); - $this->nodeBuilder->tally(); } function testEscape() { $text = 'test'; - $this->nodeBuilder->expectOnce('addContent', array('*', '<!' . $text . '>')); + $this->treeBuilder->expectOnce('addContent', array('*', '<!' . $text . '>')); $this->state->escape($text); - $this->nodeBuilder->tally(); } function testDoctype() { $text = 'test'; - $this->nodeBuilder->expectOnce('addContent', array('*', '<!' . $text . '>')); + $this->treeBuilder->expectOnce('addContent', array('*', '<!' . $text . '>')); $this->state->doctype($text); - $this->nodeBuilder->tally(); } function testUnexpectedEOF() { $text = 'test'; - $this->nodeBuilder->expectOnce('addContent', array('*', $text)); + $this->treeBuilder->expectOnce('addContent', array('*', $text)); $this->state->unexpectedEOF($text); - $this->nodeBuilder->tally(); } function testInvalidEntitySyntax() { $text = 'test'; - $this->nodeBuilder->expectOnce('addContent', array('*', $text)); + $this->treeBuilder->expectOnce('addContent', array('*', $text)); $this->state->invalidEntitySyntax($text); - $this->nodeBuilder->tally(); } + function testAddProcessingInstruction() { + $this->treeBuilder->expectOnce('addNode'); + + $this->state->addProcessingInstruction($this->treeBuilder, 'xml', 'version="1.0"'); + + $this->treeBuilder->tally(); + } + + function testIgnoredAddProcessingInstruction() { + $this->treeBuilder->expectNever('addNode'); + + $this->state->addProcessingInstruction($this->treeBuilder, 'php','ignore'); + + $this->treeBuilder->tally(); + } + } class WactLiteralParsingStateTestCase extends WactBaseParsingStateTestCase { @@ -391,7 +393,7 @@ $this->state = new WactLiteralParsingState($this->parser, $this->treeBuilder); $this->state->setDocumentLocator($this->locator); } - + function tearDown() { unset($this->state); } Modified: trunk/wact/template/compiler/parser/treebuilder.inc.php =================================================================== --- trunk/wact/template/compiler/parser/treebuilder.inc.php 2007-04-21 02:21:11 UTC (rev 449) +++ trunk/wact/template/compiler/parser/treebuilder.inc.php 2007-04-21 20:42:00 UTC (rev 450) @@ -14,6 +14,99 @@ * @version 0.9 */ +/* +* File level includes +*/ +require_once 'wact/template/compiler/expression/parser.inc.php'; +require_once 'wact/template/compiler/expression/output.inc.php'; + +class WactContentFragmentListener implements WactExpressionFragmentObserver { + + protected $treeBuilder; + + protected $locator; + + function __construct($treeBuilder, $locator) { + $this->treeBuilder = $treeBuilder; + $this->locator = $locator; + } + + function addLiteral($text) { + $this->treeBuilder->addTextNode($text); + } + + function addExpression(WactTemplateExpressionNode $expr) { + + $location = new WactSourceLocation( + $this->locator->getPublicId(), + $this->locator->getLineNumber()); + + $output = new WactExpressionOutputTemplateNode ( + NULL, NULL, + $location, + $expr); + + $this->treeBuilder->addNode($output); + + } + + function beginFragments() { + } + + function addLiteralFragment($text) { + $this->treeBuilder->addTextNode($text); + } + + function addExpressionFragment(WactTemplateExpressionNode $expr) { + $this->addExpression($expr); + } + + function endFragments() { + } + +} + +class WactAttributeFragmentListener implements WactExpressionFragmentObserver{ + + protected $component; + protected $name; + protected $compound; + + function __construct($component, $name) { + $this->component = $component; + $this->name = $name; + } + + function addExpression(WactTemplateExpressionNode $expr) { + $attribute = new WactExpressionTemplateAttribute( + $name, $match[WACT_EXPPARSER_EXPRESSION], $component, $this->formatterDictionary); + } + + function addLiteral($text) { + $attribute = new WactTemplateAttribute($this->name, $text); + $this->component->addChildAttribute($attribute); + } + + function beginFragments() { + $this->compound = new WactCompoundTemplateAttribute($name); + } + + function addLiteralFragment($text) { + $attribute = new WactTemplateLiteralAttributeFragment($text); + $this->compound->addAttributeFragment($attribute); + } + + function addExpressionFragment(WactTemplateExpressionNode $expr) { + $attribute = new WactExpressionAttributeFragment($expr); + $this->compound->addAttributeFragment($attribute); + } + + function endFragments() { + $this->component->addChildAttribute($this->compound); + } + +} + /** * Acts on the WactRootTemplateNode in response to events within the WactSourceParser * @@ -252,7 +345,46 @@ return $item ? $item[0] : false; } + /** + * Builds a component, adding attributes + * @param WactTagInfo + * @param string XML tag name of component + * @param array attributes for tag + * @param boolean whether the tag has contents + * @return WactTemplateNode + */ + function buildComponent($tagInfo, $tag, $attrs) { + $class = $tagInfo->tagClass; + $sourceLocation = new WactSourceLocation( + $this->locator->getPublicId(), + $this->locator->getLineNumber()); + + $component = new $class($tag, $tagInfo, $sourceLocation); + + foreach ( $attrs as $name => $value ) { + $listener = new WactAttributeFragmentListener($component, $name); + $parser = new WactExpressionParser(); + $parser->parseFragments($listener, $value); + } + + return $component; + } + + /** + * Builds content node(s), adding it (them) to the component tree. + * A single piece of content may actually be a mix of terminal nodes + * (WactTextTemplateNodes and Expressions) + * @param WactTreeBuilder + * @param string content of tag + * @return void + */ + function addContent($treeBuilder, $text) { + $listener = new WactContentFragmentListener($treeBuilder, $this->locator); + $parser = new WactExpressionParser(); + $parser->parseFragments($listener, $text, 'WactHtmlEscapeExpressionNode'); + } + /** * Checks that each immediate child of the current component has a unique ID * amongst its siblings. Modified: trunk/wact/template/compiler/parser/treebuilder.test.php =================================================================== --- trunk/wact/template/compiler/parser/treebuilder.test.php 2007-04-21 02:21:11 UTC (rev 449) +++ trunk/wact/template/compiler/parser/treebuilder.test.php 2007-04-21 20:42:00 UTC (rev 450) @@ -1,14 +1,42 @@ <?php require_once 'wact/template/compiler/parser/treebuilder.inc.php'; -require_once 'wact/template/compiler/parser/nodebuilder.inc.php'; require_once 'wact/template/compiler/node/template.inc.php'; require_once 'wact/template/compiler/node/text.inc.php'; +require_once 'wact/template/compiler/tag/dictionary.inc.php'; +require_once 'wact/template/compiler/property/dictionary.inc.php'; +require_once 'wact/template/compiler/formatter/dictionary.inc.php'; require_once 'wact/xml/sax/html.inc.php'; Mock::generate('WactTemplateNode','MockTemplateNode'); Mock::generate('WactHtmlSaxReader','MockHTMLParser'); +Mock::generate('WactPropertyDictionary','MockPropertyDictionary'); +Mock::generate('WactFormatterDictionary','MockFormatterDictionary'); +Mock::generate('WactTreeBuilder', 'MockTreeBuilder'); +class MyMockComponent { + var $tag; + + function MyMockComponent($tag, $tagInfo, $sourceLocation) { + $this->tag = $tag; + } + function getTag() { + return $this->tag; + } + + function removeAttribute() { + } + + function checkNestingLevel() { + } + + function getServerId(){ + } + + function addchildattribute(){ + } +} + class WactTreeBuilderTestCase extends UnitTestCase { var $component; @@ -18,6 +46,11 @@ $this->treeBuilder = new WactTreeBuilder(); $this->treeBuilder->setCursor($this->component); $this->treeBuilder->setDocumentLocator(new MockHTMLParser($this)); + + $this->propertyDictionary = new MockPropertyDictionary($this); + $this->propertyDictionary->setReturnValue('getPropertyList', array()); + + $this->formatterDictionary = new MockFormatterDictionary($this); } function tearDown() { @@ -27,12 +60,12 @@ function testPushNode() { $newComponent = new MockTemplateNode($this); - + $this->component->expectOnce('addChild'); $newComponent->expectOnce('preParse'); - + $this->treeBuilder->pushNode($newComponent); - + $this->assertReference($newComponent, $this->treeBuilder->getCursor()); $this->component->tally(); $newComponent->tally(); @@ -40,45 +73,45 @@ function testAddNode() { $newComponent = new MockTemplateNode($this); - + $this->component->expectOnce('addChild'); $newComponent->expectOnce('preParse'); - + $this->treeBuilder->addNode($newComponent); - + $this->assertReference($this->component, $this->treeBuilder->getCursor()); $this->component->tally(); } - + function testAddTextNode() { $this->component->expectOnce('addChild'); - + $this->treeBuilder->addTextNode('text'); - + $this->assertReference($this->component, $this->treeBuilder->getCursor()); $this->component->tally(); } - + function testPopNode() { $parentComponent = new MockTemplateNode($this); $grandParentComponent = new MockTemplateNode($this); $parentComponent->parent = $grandParentComponent; $this->component->parent = $parentComponent; - + $this->component->setReturnValue('getChildren', array()); $this->component->expect('close', array(WactTemplateNode::CLOSING_TAG)); - + $this->treeBuilder->popNode(WactTemplateNode::CLOSING_TAG); $treeBuilderCursor = $this->treeBuilder->getCursor(); - + $this->assertReference($parentComponent, $treeBuilderCursor); $this->assertReference($grandParentComponent,$treeBuilderCursor->parent); } - + function testPushAndPopExpectedTag() { $this->treeBuilder->pushExpectedTag('tag1', 'tag1info'); $this->treeBuilder->pushExpectedTag('tag2', 'tag2info'); - + $this->assertEqual($this->treeBuilder->popExpectedTag('tag2'), 'tag2info'); try { @@ -90,7 +123,7 @@ $this->assertEqual($e->getExpectedTag(), 'tag1'); } } - + function testPushCursor() { // This test is essentially a test of the functionality that enables the // core:wrap implementation. @@ -101,41 +134,41 @@ // (4) When the parser pops the tag at which the cursor was pushed // the cursor returns where it was before step (2) // (5) New components added should appear under this orig point. - + $root = new WactTemplateNode('testtag', NULL, new WactSourceLocation('file', 123)); $insertionPoint = new WactTemplateNode('testtag', NULL, new WactSourceLocation('file', 123)); $childOne = new WactTemplateNode('testtag', NULL, new WactSourceLocation('file', 123)); $childTwo = new WactTemplateNode('testtag', NULL, new WactSourceLocation('file', 123)); - + // set up an open tag at root $this->treeBuilder->setCursor($root); $this->treeBuilder->pushExpectedTag('tag'); - - // add some content to the tree + + // add some content to the tree $this->treeBuilder->pushNode($insertionPoint); $this->treeBuilder->popNode(WactTemplateNode::CLOSING_TAG); - + // make sure the tree is: Root --child--> InsertionPoint with cursor // at Root and open 'tag' $this->assertReference($this->treeBuilder->getCursor(), $root); $this->assertReference($insertionPoint->parent, $root); $this->assertEqual($this->treeBuilder->getExpectedTag(), 'tag'); - + // push InsertionPoint as cursor, and add another node to the tree $this->treeBuilder->pushCursor($insertionPoint); $this->treeBuilder->pushNode($childOne); $this->treeBuilder->popNode(WactTemplateNode::CLOSING_TAG); - + // make sure cursor is at InsertionPoint, and new node is child of InsertionPoint $this->assertReference($this->treeBuilder->getCursor(), $insertionPoint); $this->assertReference($childOne->parent, $insertionPoint); - + // now the parser gets '</tag>', and then more content // so we pop 'tag' (should restore orig cursor), and add a new node $this->treeBuilder->popExpectedTag('tag'); $this->treeBuilder->pushNode($childTwo); $this->treeBuilder->popNode(WactTemplateNode::CLOSING_TAG); - + // the new node should be a child of Root, not InsertionPoint $this->assertReference($this->treeBuilder->getCursor(), $root); $this->assertReference($childTwo->parent, $root); @@ -143,31 +176,31 @@ function testPushAndPopExpectedTagsWithPushCursor() { $newCursor = new MockTemplateNode($this); - + $this->treeBuilder->pushExpectedTag('tag1', 'tag1info'); - + // push a new cursor $this->treeBuilder->pushCursor($newCursor); $this->assertReference($this->treeBuilder->getCursor(), $newCursor); - + $this->treeBuilder->pushExpectedTag('tag2', 'tag2info'); - + $this->assertEqual($this->treeBuilder->getExpectedTagCount(), 3); $this->assertEqual($this->treeBuilder->getExpectedTag(), 'tag2'); $this->assertEqual($this->treeBuilder->popExpectedTag('tag2'), 'tag2info'); $this->assertEqual($this->treeBuilder->getExpectedTagCount(), 2); - + // getting expected tag should skip the cursor $this->assertEqual($this->treeBuilder->getExpectedTag(), 'tag1'); - + // popping the next tag should restore the cursor to the original $this->assertEqual($this->treeBuilder->popExpectedTag('tag1'), 'tag1info'); $this->assertReference($this->treeBuilder->getCursor(), $this->component); $this->assertEqual($this->treeBuilder->getExpectedTagCount(), 0); } - + function testCheckServerIds() { $root = new WactTemplateNode('testtag', NULL, new WactSourceLocation('file', 123)); $childOne = new MockTemplateNode($this); @@ -218,20 +251,20 @@ $this->assertEqual($e->getServerId(), 'dup'); } } - + function testDuplicateIdIsLegalInDifferentBranch() { $root = new WactTemplateNode('testtag', NULL, new WactSourceLocation('file', 123)); - + $branch = new WactTemplateNode('testtag', NULL, new WactSourceLocation('file', 123)); $childOne = new MockTemplateNode($this); $childOne->setReturnValue('getChildren', array()); $branch->addChild($childOne); $root->addChild($branch); - + $childTwo = new MockTemplateNode($this); $childTwo->setReturnValue('getChildren', array()); $root->addChild($childTwo); - + $childOne->setReturnValue('getServerId', 'dup'); $childTwo->setReturnValue('getServerId', 'dup'); @@ -239,5 +272,54 @@ $this->treeBuilder->checkServerIds(); } + function testBuildComponent() { + $tag = 'test'; + $info = new WactTagInfo($tag, 'MyMockComponent'); + + $node = $this->treeBuilder->buildComponent($info, $tag, array('foo'=>'bar')); + + $this->assertIsA($node, $info->tagClass); + $this->assertEqual($node->getTag(), $tag); + } +/* + function testCreateTagComponent() { + $tag = 'test'; + $info = new WactTagInfo($tag, 'MyMockComponent'); + + $this->locator->expectOnce('getLineNumber'); + $this->locator->expectOnce('getPublicId'); + + $node = $this->treeBuilder->createComponent($info, $tag); + + $this->assertIsA($node, $info->tagClass); + $this->assertEqual($node->getTag(), $tag); + $this->locator->tally(); + } + + function testAddAttributes() { + $node = new MockTemplateNode($this); + $node->expectOnce('addChildAttribute'); + + $this->nodeBuilder->addAttributesToComponent($node, array('foo' => 'test')); + + $node->tally(); + } + +*/ + function testAddContent() { + $fi = new WactFormatterInfo('html', 'WactTemplateValueFormatter'); + $fi->file = 'wact/template/compiler/formatter/formatter.inc.php'; + + $this->formatterDictionary->setReturnValue('getFormatterInfo', $fi); + + $treeBuilder = new MockTreeBuilder($this); + $treeBuilder->expectOnce('addTextNode'); + $treeBuilder->expectOnce('addNode'); + + $this->treeBuilder->addContent($treeBuilder, '{$1}test'); + + $treeBuilder->tally(); + } + } ?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nor...@us...> - 2007-06-22 17:28:20
|
Revision: 516 http://svn.sourceforge.net/wact/?rev=516&view=rev Author: norbertmocsnik Date: 2007-06-22 10:28:18 -0700 (Fri, 22 Jun 2007) Log Message: ----------- Moved WactSourceLocation one level up in the directory tree (the directory will be removed). Modified Paths: -------------- trunk/wact/template/compiler/node/template.inc.php trunk/wact/template/compiler/node/template.test.php Added Paths: ----------- trunk/wact/template/compiler/location.inc.php Removed Paths: ------------- trunk/wact/template/compiler/common/location.inc.php Deleted: trunk/wact/template/compiler/common/location.inc.php =================================================================== --- trunk/wact/template/compiler/common/location.inc.php 2007-05-29 13:55:20 UTC (rev 515) +++ trunk/wact/template/compiler/common/location.inc.php 2007-06-22 17:28:18 UTC (rev 516) @@ -1,39 +0,0 @@ -<?php -/** -* Web Application Component Toolkit -* -* @link http://www.phpwact.org/ -* -* @author Wact Development Team -* @link http://www.phpwact.org/team -* -* @copyright Copyright 2006, Jeff Moore -* @license http://opensource.org/licenses/mit-license.php MIT -* -* @package Template -* @version 0.9 -*/ - -class WactSourceLocation { - - /** - * Used to identify the source template file, when generating compile time - * error messages. - * @var string source template filename - */ - var $file; - - /** - * Used to indentify the line number where a compile time error occurred. - * @var int line number - */ - var $line; - - function __construct($file, $line) { - $this->file = $file; - $this->line = $line; - } - -} - -?> \ No newline at end of file Copied: trunk/wact/template/compiler/location.inc.php (from rev 515, trunk/wact/template/compiler/common/location.inc.php) =================================================================== --- trunk/wact/template/compiler/location.inc.php (rev 0) +++ trunk/wact/template/compiler/location.inc.php 2007-06-22 17:28:18 UTC (rev 516) @@ -0,0 +1,39 @@ +<?php +/** +* Web Application Component Toolkit +* +* @link http://www.phpwact.org/ +* +* @author Wact Development Team +* @link http://www.phpwact.org/team +* +* @copyright Copyright 2006, Jeff Moore +* @license http://opensource.org/licenses/mit-license.php MIT +* +* @package Template +* @version 0.9 +*/ + +class WactSourceLocation { + + /** + * Used to identify the source template file, when generating compile time + * error messages. + * @var string source template filename + */ + var $file; + + /** + * Used to indentify the line number where a compile time error occurred. + * @var int line number + */ + var $line; + + function __construct($file, $line) { + $this->file = $file; + $this->line = $line; + } + +} + +?> \ No newline at end of file Modified: trunk/wact/template/compiler/node/template.inc.php =================================================================== --- trunk/wact/template/compiler/node/template.inc.php 2007-05-29 13:55:20 UTC (rev 515) +++ trunk/wact/template/compiler/node/template.inc.php 2007-06-22 17:28:18 UTC (rev 516) @@ -19,7 +19,7 @@ */ require_once 'wact/template/compiler/attribute/attribute.inc.php'; require_once 'wact/template/compiler/attribute/dictionary.inc.php'; -require_once 'wact/template/compiler/common/location.inc.php'; +require_once 'wact/template/compiler/location.inc.php'; /** * Base class for compile time components. Compile time component methods are Modified: trunk/wact/template/compiler/node/template.test.php =================================================================== --- trunk/wact/template/compiler/node/template.test.php 2007-05-29 13:55:20 UTC (rev 515) +++ trunk/wact/template/compiler/node/template.test.php 2007-06-22 17:28:18 UTC (rev 516) @@ -1,7 +1,7 @@ <?php require_once 'wact/template/compiler/node/template.inc.php'; -require_once 'wact/template/compiler/common/location.inc.php'; +require_once 'wact/template/compiler/location.inc.php'; //require_once 'wact/compiler/codewriter/codewriter.inc.php'; Mock::generate('WactTemplateNode', 'MockTemplateNode'); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nor...@us...> - 2007-06-22 22:09:05
|
Revision: 521 http://svn.sourceforge.net/wact/?rev=521&view=rev Author: norbertmocsnik Date: 2007-06-22 15:09:01 -0700 (Fri, 22 Jun 2007) Log Message: ----------- Removed the old dictionary implementations. Removed Paths: ------------- trunk/wact/template/compiler/common/ trunk/wact/template/compiler/dictionary.new.php Deleted: trunk/wact/template/compiler/dictionary.new.php =================================================================== --- trunk/wact/template/compiler/dictionary.new.php 2007-06-22 22:08:40 UTC (rev 520) +++ trunk/wact/template/compiler/dictionary.new.php 2007-06-22 22:09:01 UTC (rev 521) @@ -1,202 +0,0 @@ -<?php -/** -* Web Application Component Toolkit -* -* @link http://www.phpwact.org/ -* -* @author Wact Development Team -* @link http://www.phpwact.org/team -* -* @copyright Copyright 2006, Jeff Moore -* @license http://opensource.org/licenses/mit-license.php MIT -* -* @package View -* @version 0.9 -*/ - -/** -* File level includes -*/ -require_once 'wact/template/compiler/tag/extractor.inc.php'; -require_once 'wact/template/compiler/tag/dictionary.inc.php'; -require_once 'wact/template/compiler/property/extractor.inc.php'; -require_once 'wact/template/compiler/property/dictionary.inc.php'; -require_once 'wact/template/compiler/formatter/extractor.inc.php'; -require_once 'wact/template/compiler/formatter/dictionary.inc.php'; -require_once 'wact/compiler/annotation/parser.inc.php'; - -/** -* @todo implement caching (source organizer + expiration policies?) -*/ - -/** -* -*/ -class WactDefaultTemplateDictionary extends WactTemplateDictionary { - /** - * @todo implement recursive scanning - */ - public function __construct() { - $builder = new WactTemplateDictionaryBuilder(); - $builder->addPath(realpath(dirname(__FILE__) . '/../../plugins/template/core')); - $builder->addPath(realpath(dirname(__FILE__) . '/../../plugins/template/front')); - $builder->addPath(realpath(dirname(__FILE__) . '/../../plugins/template/html')); - $builder->addPath(realpath(dirname(__FILE__) . '/../../plugins/template/form')); - - parent::__construct($builder); - } -} - -/** -* -*/ -class WactTemplateDictionary { - /** - * @var WactTagDictionary - */ - protected $tagDictionary = null; - - /** - * @var WactPropertyDictionary - */ - protected $propertyDictionary = null; - - /** - * @var WactFormatterDictionary - */ - protected $formatterDictionary = null; - - /** - * @var WactTemplateDictionaryBuilder - */ - protected $builder; - - /** - * @param WactTemplateDictionaryBuilder $builder - */ - public function __construct($builder) { - $this->builder = $builder; - } - - /** - * @return WactTagDictionary - */ - public function getTagDictionary() { - if (is_null($this->tagDictionary)) { - $this->tagDictionary = $this->builder->buildTagDictionary(); - } - - return $this->tagDictionary; - } - - /** - * @return WactPropertyDictionary - */ - public function getPropertyDictionary() { - if (is_null($this->propertyDictionary)) { - $this->propertyDictionary = $this->builder->buildPropertyDictionary(); - } - - return $this->propertyDictionary; - } - - /** - * @return WactFormatterDictionary - */ - public function getFormatterDictionary() { - if (is_null($this->formatterDictionary)) { - $this->formatterDictionary = $this->builder->buildFormatterDictionary(); - } - - return $this->formatterDictionary; - } -} - -/** -* -*/ -class WactTemplateDictionaryBuilder { - /** - * @var array - */ - protected $paths = array(); - - /** - * @param string $path - */ - public function addPath($path) { - if (!in_array($path, $this->paths)) { - $this->paths[] = $path; - } - } - - /** - * @param string $extension - * @return array - */ - protected function getFiles($extension) { - $files = array(); - $size = strlen($extension); - - foreach($this->paths as $path) { - if (is_dir($path)) { - if ($dir = opendir($path)) { - while (($file = readdir($dir)) !== false) { - if (substr($file, -$size, $size) == $extension) { - $files[] = $path . '/' . $file; - } - } - closedir($dir); - } - } - } - - return $files; - } - - /** - * @param string $extension - * @param WactTagInfoExtractor|WactPropertyInfoExtractor|WactFormatterInfoExtractor $extractor - */ - protected function buildDictionary($extension, $extractor) { - $parser = new WactClassAnnotationParser(); - - $files = $this->getFiles($extension); - foreach ($files as $file) { - $extractor->setCurrentFile($file); - $parser->process($extractor, file_get_contents($file)); - } - } - - /** - * @return WactTagDictionary - */ - public function buildTagDictionary() { - $dictionary = new WactTagDictionary(); - $this->buildDictionary('.tag.php', new WactTagInfoExtractor($dictionary)); - - return $dictionary; - } - - /** - * @return WactPropertyDictionary - */ - public function buildPropertyDictionary() { - $dictionary = new WactPropertyDictionary(); - $this->buildDictionary('.prop.php', new WactPropertyInfoExtractor($dictionary)); - - return $dictionary; - } - - /** - * @return WactFormatterDictionary - */ - public function buildFormatterDictionary() { - $dictionary = new WactFormatterDictionary(); - $this->buildDictionary('.format.php', new WactFormatterInfoExtractor($dictionary)); - - return $dictionary; - } -} - -?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Jef...@us...> - 2007-10-21 02:27:06
|
Revision: 587 http://wact.svn.sourceforge.net/wact/?rev=587&view=rev Author: JeffMoore Date: 2007-10-20 19:27:01 -0700 (Sat, 20 Oct 2007) Log Message: ----------- Split WactCompilingContext to separate file. Modified Paths: -------------- trunk/wact/template/compiler/compiler.inc.php Added Paths: ----------- trunk/wact/template/compiler/context.inc.php Modified: trunk/wact/template/compiler/compiler.inc.php =================================================================== --- trunk/wact/template/compiler/compiler.inc.php 2007-10-21 01:34:50 UTC (rev 586) +++ trunk/wact/template/compiler/compiler.inc.php 2007-10-21 02:27:01 UTC (rev 587) @@ -17,6 +17,8 @@ /** * File level includes */ +require_once 'wact/template/compiler/context.inc.php'; + require_once 'wact/compiler/codewriter/codewriter.inc.php'; require_once 'wact/template/compiler/node/root.inc.php'; @@ -33,18 +35,6 @@ require_once 'wact/template/compiler/formatter/extractor.inc.php'; require_once 'wact/template/compiler/formatter/dictionary.inc.php'; -interface WactTemplateCompilingContext { - - public function getConfig(); - public function getSourceOrganizer(); - public function getTemplateLoader(); - - public function findComponent($tag, $attrs, $isEmpty, $component); - public function findFormatter($name); - public function findProperties($name); - -} - /** */ class WactTemplateCompiler implements WactTemplateCompilingContext { Added: trunk/wact/template/compiler/context.inc.php =================================================================== --- trunk/wact/template/compiler/context.inc.php (rev 0) +++ trunk/wact/template/compiler/context.inc.php 2007-10-21 02:27:01 UTC (rev 587) @@ -0,0 +1,32 @@ +<?php +/** +* Web Application Component Toolkit +* +* @link http://www.phpwact.org/ +* +* @author Wact Development Team +* @link http://www.phpwact.org/team +* +* @copyright Copyright 2006, Jeff Moore +* @license http://opensource.org/licenses/mit-license.php MIT +* +* @package Template +* @version 0.9 +*/ + +/** +*/ +interface WactTemplateCompilingContext { + + public function getConfig(); + public function getSourceOrganizer(); + public function getTemplateLoader(); + + public function findComponent($tag, $attrs, $isEmpty, $component); + public function getTagInfo($tag); + public function findFormatter($name); + public function findProperties($name); + +} + +?> \ No newline at end of file Property changes on: trunk/wact/template/compiler/context.inc.php ___________________________________________________________________ Name: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Jef...@us...> - 2007-10-24 01:12:08
|
Revision: 612 http://wact.svn.sourceforge.net/wact/?rev=612&view=rev Author: JeffMoore Date: 2007-10-23 18:12:04 -0700 (Tue, 23 Oct 2007) Log Message: ----------- Changed the order of the generation phases so constructors are generated first. Modified Paths: -------------- trunk/wact/template/compiler/compiler.inc.php trunk/wact/template/compiler/node/dataview.inc.php trunk/wact/template/compiler/node/inline.inc.php trunk/wact/template/compiler/node/view.inc.php Modified: trunk/wact/template/compiler/compiler.inc.php =================================================================== --- trunk/wact/template/compiler/compiler.inc.php 2007-10-23 15:43:19 UTC (rev 611) +++ trunk/wact/template/compiler/compiler.inc.php 2007-10-24 01:12:04 UTC (rev 612) @@ -112,10 +112,10 @@ $tree->prepare(); + $tree->renderConstructor($code); + $tree->generatePaintMethod($code); - $tree->renderConstructor($code); - return $code->getCode(); } Modified: trunk/wact/template/compiler/node/dataview.inc.php =================================================================== --- trunk/wact/template/compiler/node/dataview.inc.php 2007-10-23 15:43:19 UTC (rev 611) +++ trunk/wact/template/compiler/node/dataview.inc.php 2007-10-24 01:12:04 UTC (rev 612) @@ -39,11 +39,7 @@ // method of doing this that cleans up this code. (eventually.) // Don't use this as an example. - if (!empty($this->parentViewFile)) { - $code->registerInclude($this->parentViewFile); - } - - $oldScope = $code->createClass($this->getViewClass(), $this->parentViewClass); + $oldScope = $code->switchToClassScope($this->getViewClass()); $code->createMethod('paint'); $name = $this->getAttribute('from'); Modified: trunk/wact/template/compiler/node/inline.inc.php =================================================================== --- trunk/wact/template/compiler/node/inline.inc.php 2007-10-23 15:43:19 UTC (rev 611) +++ trunk/wact/template/compiler/node/inline.inc.php 2007-10-24 01:12:04 UTC (rev 612) @@ -88,11 +88,7 @@ * @param WactCodeWriter $code */ function generatePaintMethod($code) { - if (!empty($this->parentViewFile)) { - $code->registerInclude($this->parentViewFile); - } - - $oldScope = $code->createClass($this->getViewClass(), $this->parentViewClass); + $oldScope = $code->switchToClassScope($this->getViewClass()); $code->createMethod('paint'); // render children Modified: trunk/wact/template/compiler/node/view.inc.php =================================================================== --- trunk/wact/template/compiler/node/view.inc.php 2007-10-23 15:43:19 UTC (rev 611) +++ trunk/wact/template/compiler/node/view.inc.php 2007-10-24 01:12:04 UTC (rev 612) @@ -46,22 +46,6 @@ /** * @param WactCodeWriter $code */ - function generatePaintMethod($code) { - if (!empty($this->parentViewFile)) { - $code->registerInclude($this->parentViewFile); - } - - $oldScope = $code->createClass($this->getViewClass(), $this->parentViewClass); - - // render Children - parent::generatePaintMethod($code); - - $code->setScope($oldScope); - } - - /** - * @param WactCodeWriter $code - */ function generatePaintInline($code) { // generate this code into our parent's scope $code->writePHP('$this->children[\'' . $this->getServerId() . '\']->render();'); @@ -89,7 +73,12 @@ $code->writePHP(', \'' . $this->getServerId() . '\');' . "\n"); // use var_export } - $oldScope = $code->switchToClassScope($this->getViewClass()); + $oldScope = $code->createClass($this->getViewClass(), $this->parentViewClass); + + if (!empty($this->parentViewFile)) { + $code->registerInclude($this->parentViewFile); + } + $code->createMethod('__construct'); $this->generateConstructor($code); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Jef...@us...> - 2007-10-26 01:20:14
|
Revision: 622 http://wact.svn.sourceforge.net/wact/?rev=622&view=rev Author: JeffMoore Date: 2007-10-25 18:20:09 -0700 (Thu, 25 Oct 2007) Log Message: ----------- Added test cases for raw formatter. Modified Paths: -------------- trunk/wact/template/compiler/expression/parser.inc.php trunk/wact/template/compiler/expression/parser.test.php trunk/wact/template/compiler/parser/treebuilder.inc.php Modified: trunk/wact/template/compiler/expression/parser.inc.php =================================================================== --- trunk/wact/template/compiler/expression/parser.inc.php 2007-10-25 14:09:32 UTC (rev 621) +++ trunk/wact/template/compiler/expression/parser.inc.php 2007-10-26 01:20:09 UTC (rev 622) @@ -50,14 +50,27 @@ */ class WactExpressionParser { + /** + */ + protected $compilingContext; + + /** + */ protected $text; + + /** + */ protected $position; + + /** + */ protected $length; /** * Construct this parser */ - function __construct() { + function __construct($context) { + $this->compilingContext = $context; } /** @@ -123,7 +136,7 @@ } if ($token == '-') { - return new WactUnaryMInusExpressionNode($this->parseDereferenced()); + return new WactUnaryMinusExpressionNode($this->parseDereferenced()); } else if ($token == '(') { $expr = $this->parseExpression(); if ($this->getToken('/\G\s*(\))/u')) { @@ -295,6 +308,12 @@ } /** + * expression := logical { '|' name logical* }* + */ + protected function parseFormated() { + } + + /** * expression := logical */ protected function parseExpression() { @@ -333,7 +352,7 @@ $expression = $this->parseExpression(); - if ($this->getToken('/\G\s*(\!)/u') && $defaultRoot) { + if (!$this->getToken('/\G\s*(\!raw)/u') && $defaultRoot) { $expression = new $defaultRoot($expression); } Modified: trunk/wact/template/compiler/expression/parser.test.php =================================================================== --- trunk/wact/template/compiler/expression/parser.test.php 2007-10-25 14:09:32 UTC (rev 621) +++ trunk/wact/template/compiler/expression/parser.test.php 2007-10-26 01:20:09 UTC (rev 622) @@ -11,7 +11,7 @@ function setUp() { $this->observer = new MockExpressionObserver($this); - $this->parser = new WactExpressionParser(); + $this->parser = new WactExpressionParser(NULL); } function tearDown() { @@ -97,15 +97,30 @@ $this->observer->tally(); } + function testExpressionRootIsDefault() { + $this->observer->expectOnce('addExpression', array(new IsAExpectation('WactHtmlEscapeExpressionNode'))); + + $this->parser->parseFragments($this->observer, '{$1}', 'WactHtmlEscapeExpressionNode'); + + $this->observer->tally(); + } + + function testRawFormatterOverridesDefaultRoot() { + $this->observer->expectOnce('addExpression', array(new NotAExpectation('WactHtmlEscapeExpressionNode'))); + + $this->parser->parseFragments($this->observer, '{$1!raw}', 'WactHtmlEscapeExpressionNode'); + + $this->observer->tally(); + } + } - class WactConstantExpressionEvaluationTestCase extends UnitTestCase { protected $observer; function setUp() { - $this->parser = new WactExpressionParser(); + $this->parser = new WactExpressionParser(NULL); } function tearDown() { Modified: trunk/wact/template/compiler/parser/treebuilder.inc.php =================================================================== --- trunk/wact/template/compiler/parser/treebuilder.inc.php 2007-10-25 14:09:32 UTC (rev 621) +++ trunk/wact/template/compiler/parser/treebuilder.inc.php 2007-10-26 01:20:09 UTC (rev 622) @@ -361,7 +361,7 @@ foreach ( $attrs as $name => $value ) { $listener = new WactAttributeFragmentListener($component, $name); - $parser = new WactExpressionParser(); + $parser = new WactExpressionParser($this->compilingContext); $parser->parseFragments($listener, $value); } @@ -377,7 +377,7 @@ */ function addContent($text) { $listener = new WactContentFragmentListener($this, $this->locator); - $parser = new WactExpressionParser(); + $parser = new WactExpressionParser($this->compilingContext); $parser->parseFragments($listener, $text, 'WactHtmlEscapeExpressionNode'); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |