Revision: 406
http://svn.sourceforge.net/wact/?rev=406&view=rev
Author: JeffMoore
Date: 2007-03-28 16:43:14 -0700 (Wed, 28 Mar 2007)
Log Message:
-----------
Removed expression parser. These classes and especially, these test cases are
only going to get in the way. We can restore from svn as required.
Modified Paths:
--------------
trunk/wact/template/compiler/attribute/attribute.test.php
Removed Paths:
-------------
trunk/wact/template/compiler/expression/badbinding.test.php
trunk/wact/template/compiler/expression/badbinding.xcpt.php
trunk/wact/template/compiler/expression/databinding.inc.php
trunk/wact/template/compiler/expression/databinding.test.php
trunk/wact/template/compiler/expression/expression.inc.php
trunk/wact/template/compiler/expression/expression.test.php
trunk/wact/template/compiler/expression/expression.xcpt.php
trunk/wact/template/compiler/expression/formatter.test.php
trunk/wact/template/compiler/expression/formatter.xcpt.php
trunk/wact/template/compiler/expression/invalidformatterspec.test.php
trunk/wact/template/compiler/expression/invalidformatterspec.xcpt.php
trunk/wact/template/compiler/expression/lexer.inc.php
trunk/wact/template/compiler/expression/lexer.test.php
trunk/wact/template/compiler/expression/missingformatter.test.php
trunk/wact/template/compiler/expression/missingformatter.xcpt.php
trunk/wact/template/compiler/expression/missingformatterparameter.test.php
trunk/wact/template/compiler/expression/missingformatterparameter.xcpt.php
trunk/wact/template/compiler/expression/output.inc.php
trunk/wact/template/compiler/expression/toomanyparameters.test.php
trunk/wact/template/compiler/expression/toomanyparameters.xcpt.php
trunk/wact/template/compiler/expression/unresolvedbinding.test.php
trunk/wact/template/compiler/expression/unresolvedbinding.xcpt.php
Modified: trunk/wact/template/compiler/attribute/attribute.test.php
===================================================================
--- trunk/wact/template/compiler/attribute/attribute.test.php 2007-03-28 23:19:56 UTC (rev 405)
+++ trunk/wact/template/compiler/attribute/attribute.test.php 2007-03-28 23:43:14 UTC (rev 406)
@@ -3,19 +3,21 @@
require_once 'wact/template/compiler/attribute/attribute.inc.php';
//require_once 'wact/compiler/codewriter/codewriter.inc.php';
-require_once 'wact/template/compiler/expression/expression.inc.php';
+//require_once 'wact/template/compiler/expression/expression.inc.php';
require_once 'wact/template/compiler/node/template.inc.php';
-Mock::Generate('WactExpressionTemplateAttribute', 'MockExpressionTemplateAttribute');
+//Mock::Generate('WactExpressionTemplateAttribute', 'MockExpressionTemplateAttribute');
Mock::Generate('WactTemplateAttribute', 'MockTemplateAttribute');
Mock::Generate('WactTemplateNode', 'MockTemplateNode');
//Mock::Generate('WactCodeWriter', 'MockCodeWriter');
-Mock::Generate('Expression', 'MockExpression');
+//Mock::Generate('Expression', 'MockExpression');
+/*
Mock::generatePartial(
'WactExpressionTemplateAttribute',
'ExpressionTemplateAttributePartialMock',
array('createExpression'));
+*/
class WactTemplateAttributeTestCase extends WactTestCase {
@@ -77,8 +79,8 @@
class WactExpressionTemplateAttributeTestCase extends WactTestCase {
+/*
function setUp() {
-
$this->expression = new MockExpression($this);
$this->attribute =new ExpressionTemplateAttributePartialMock($this);
@@ -86,24 +88,27 @@
$this->attribute->expectOnce('createExpression');
$this->attribute->__construct('test', 'hello', new MockTemplateNode($this), NULL);
}
-
+*/
+/*
function tearDown() {
unset ( $this->attribute );
parent::tearDown();
}
-
+*/
+/*
function testIsConstant() {
$this->expression->setReturnValue('IsConstant', TRUE);
$this->expression->expectOnce('IsConstant');
$this->assertTrue($this->attribute->isConstant());
}
-
+*/
+/*
function testGetValue() {
$this->expression->setReturnValue('getValue', 'hello');
$this->expression->expectOnce('getValue');
$this->assertEqual($this->attribute->getValue(), 'hello');
}
-
+*/
/*
function testGenerateConstantFragment() {
$this->expression->setReturnValue('IsConstant', TRUE);
@@ -167,6 +172,7 @@
class WactCompoundTemplateAttributeTestCase extends WactTestCase {
+/*
function setUp() {
$this->literal = new MockTemplateAttribute($this);
$this->expression = new MockExpressionTemplateAttribute($this);
@@ -174,7 +180,8 @@
$this->attribute->addAttributeFragment($this->literal);
$this->attribute->addAttributeFragment($this->expression);
}
-
+*/
+/*
function tearDown() {
$this->literal->tally();
$this->expression->tally();
@@ -182,7 +189,8 @@
unset($this->expression);
parent::tearDown();
}
-
+*/
+/*
function testIsConstantAllTrue() {
$this->literal->setReturnValue('IsConstant', TRUE);
$this->literal->expectOnce('IsConstant');
@@ -190,7 +198,8 @@
$this->expression->expectOnce('IsConstant');
$this->assertTrue($this->attribute->isConstant());
}
-
+*/
+/*
function testIsConstantAllFalse() {
$this->literal->setReturnValue('IsConstant', FALSE);
$this->literal->expectOnce('IsConstant');
@@ -198,7 +207,8 @@
$this->expression->expectNever('IsConstant');
$this->assertFalse($this->attribute->isConstant());
}
-
+*/
+/*
function testIsConstantMixed() {
$this->literal->setReturnValue('IsConstant', TRUE);
$this->literal->expectOnce('IsConstant');
@@ -206,7 +216,8 @@
$this->expression->expectOnce('IsConstant');
$this->assertFalse($this->attribute->isConstant());
}
-
+*/
+/*
function testGetValue() {
$this->literal->setReturnValue('getValue', 'Hur');
$this->literal->expectOnce('getValue');
@@ -214,7 +225,7 @@
$this->expression->expectOnce('getValue');
$this->assertEqual($this->attribute->getValue(), 'Hurrah');
}
-
+*/
/*
function testGenerate() {
$this->literal->expectOnce('generateFragment');
Deleted: trunk/wact/template/compiler/expression/badbinding.test.php
===================================================================
--- trunk/wact/template/compiler/expression/badbinding.test.php 2007-03-28 23:19:56 UTC (rev 405)
+++ trunk/wact/template/compiler/expression/badbinding.test.php 2007-03-28 23:43:14 UTC (rev 406)
@@ -1,29 +0,0 @@
-<?php
-
-require_once 'wact/template/compiler/expression/badbinding.xcpt.php';
-
-class WactBadBindingExceptionTestCase extends WactTestCase {
-
- function testException() {
- try {
- $expression = 'testexpression';
- $fileName = 'testfile';
- $lineNo = 123;
- throw new WactBadBindingException($fileName, $lineNo, $expression);
- $this->fail('Expected exception not thrown');
- } catch (WactBadBindingException $e) {
- $this->pass();
-
- $this->assertEqual($e->getFilename(), $fileName);
- $this->assertEqual($e->getLineno(), $lineNo);
- $this->assertEqual($e->getExpression(), $expression);
-
- $this->assertIsIn($expression, $e->getMessage());
- $this->assertIsIn($fileName, $e->getMessage());
- $this->assertIsIn($lineNo, $e->getMessage());
- }
- }
-
-}
-
-?>
Deleted: trunk/wact/template/compiler/expression/badbinding.xcpt.php
===================================================================
--- trunk/wact/template/compiler/expression/badbinding.xcpt.php 2007-03-28 23:19:56 UTC (rev 405)
+++ trunk/wact/template/compiler/expression/badbinding.xcpt.php 2007-03-28 23:43:14 UTC (rev 406)
@@ -1,44 +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
-*/
-if (!class_exists('WactExpressionException', FALSE)) {
- require_once 'wact/template/compiler/expression/expression.xcpt.php';
-}
-
-/**
-* @package Template
-*/
-class WactBadBindingException extends WactExpressionException {
-
- /**
- * Class constructor.
- * @param string file Filename
- * @param string line Line number
- */
- public function __construct($filename, $lineno, $expression) {
- parent::__construct(
- $filename,
- $lineno,
- $expression,
- 'Invalid data binding "{Expression}" in template file "{Filename}" on line {Lineno}'
- );
- }
-}
-
-?>
\ No newline at end of file
Deleted: trunk/wact/template/compiler/expression/databinding.inc.php
===================================================================
--- trunk/wact/template/compiler/expression/databinding.inc.php 2007-03-28 23:19:56 UTC (rev 405)
+++ trunk/wact/template/compiler/expression/databinding.inc.php 2007-03-28 23:43:14 UTC (rev 406)
@@ -1,207 +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 DataBindingExpression {
- /**
- * Name of the element to bind to.
- * @var string
- */
- var $name;
-
- /**
- */
- var $context;
-
- var $path;
- var $DataSourceReferenceVariable;
-
- var $prepared = FALSE;
-
- /**
- * used for error messages
- */
- var $expression;
-
- function __construct($expression, $ComponentContext) {
- $this->expression = $expression;
- $this->context = $ComponentContext;
- }
-
- function autoPrepare() {
- if ($this->prepared) {
- return;
- }
- $originalcontext = $this->context;
- $expression = $this->expression;
- $prefix = substr($expression, 0, 1);
- if ($prefix == "#") {
- $this->context = $this->context->getRootDataSource();
- $expression = substr($expression, 1);
- } else if ($prefix == "^") {
- while ($prefix == "^") {
- $this->context = $this->context->getParentDataSource();
- $expression = substr($expression, 1);
- $prefix = substr($expression, 0, 1);
- }
- }
-
- $pos = strpos($expression, '.');
- if (is_integer($pos)) {
- $path = array();
- while (preg_match('/^(\w+)\.((?s).*)$/', $expression, $match)) {
- $path[] = $match[1];
- $expression = $match[2];
- }
- $this->path = $path;
- }
-
- if (preg_match("/^\w+$/", $expression)) {
- $this->name = $expression;
- } else {
- require_once 'wact/template/compiler/expression/badbinding.xcpt.php';
- throw new WactBadBindingException(
- $originalcontext->getSourceLocation()->file,
- $originalcontext->getSourceLocation()->line,
- $this->expression
- );
- }
-
- /* pre-defined properties will never be found inside a child context */
- if (is_object($this->context)) {
- $this->property = $this->context->getProperty($this->name);
- if (is_object($this->property)) {
- $this->property->activate();
- }
- }
- $this->prepared = TRUE;
- }
-
- function prepare() {
- $this->autoPrepare();
- }
-
- /**
- * Does this expression refer to a constant value (at compile time)?
- * @return Boolean
- */
- function isConstant() {
- $this->autoPrepare();
- if (is_null($this->context)) {
- return TRUE;
- }
- if (is_object($this->property)) {
- return $this->property->isConstant();
- }
- return FALSE;
- }
-
- /**
- * Return the value of this expression
- * @return String
- */
- function getValue() {
- $this->autoPrepare();
- if (is_null($this->context)) {
- return NULL;
- }
- if (is_null($this->property) || !$this->property->isConstant()) {
- require_once 'wact/template/compiler/expression/unresolvedbinding.xcpt.php';
- throw new WactUnresolvedBindingException(
- $this->context->getSourceLocation()->file,
- $this->context->getSourceLocation()->line,
- $this->expression
- );
- } else {
- return $this->property->getValue();
- }
- }
-
- /**
- * Generate setup code for an expression reference
- * @param CodeWriter
- * @return void
- */
- function generatePreStatement($code) {
- $this->autoPrepare();
- if (is_object($this->context)) {
- if (is_object($this->property)) {
- $this->property->generatePreStatement($code);
- }
- if (isset($this->path)) {
- $path = $this->path;
- $key = array_shift($path);
- $this->DataSourceReferenceVariable = $code->getTempVariable();
- $parent_datasource = $this->context->getDataSource();
- $code->writePHP('$' . $this->DataSourceReferenceVariable . '=Template::_dereference(' . $parent_datasource->getDataSourceRefCode() . ',');
- $code->writePHPLIteral($key);
- $code->writePHP(');');
- foreach ($path as $key) {
- $DataSourceReferenceVariable = $code->getTempVariable();
- $code->writePHP('$' . $DataSourceReferenceVariable . '=Template::_dereference($' . $this->DataSourceReferenceVariable . ',');
- $code->writePHPLIteral($key);
- $code->writePHP(');');
- $this->DataSourceReferenceVariable = $DataSourceReferenceVariable;
- }
- }
- }
- }
-
- /**
- * Generate the code to read the data value at run time
- * Must generate only a valid PHP Expression.
- * @param CodeWriter
- * @return void
- */
- function generateExpression($code) {
- $this->autoPrepare();
- if (is_null($this->context)) {
- $code->writePHP('NULL');
- } else {
- if (is_object($this->property)) {
- $this->property->generateExpression($code);
- } else {
- if (isset($this->DataSourceReferenceVariable)) {
- $code->writePHP('$' . $this->DataSourceReferenceVariable . '->get(');
- $code->writePHPLiteral($this->name);
- $code->writePHP(')');
- } else {
- $code->writePHP($this->context->getDataSourceRefCode() . '->get(');
- $code->writePHPLiteral($this->name);
- $code->writePHP(')');
- }
- }
- }
- }
-
- /**
- * Generate tear down code for an expression reference
- * @param CodeWriter
- * @return void
- */
- function generatePostStatement($code) {
- $this->autoPrepare();
- if (is_object($this->context)) {
- if (is_object($this->property)) {
- $this->property->generatePostStatement($code);
- }
- }
- }
-
-}
-
-?>
\ No newline at end of file
Deleted: trunk/wact/template/compiler/expression/databinding.test.php
===================================================================
--- trunk/wact/template/compiler/expression/databinding.test.php 2007-03-28 23:19:56 UTC (rev 405)
+++ trunk/wact/template/compiler/expression/databinding.test.php 2007-03-28 23:43:14 UTC (rev 406)
@@ -1,261 +0,0 @@
-<?php
-
-require_once 'wact/template/compiler/expression/databinding.inc.php';
-
-require_once 'wact/template/compiler/node/template.inc.php';
-require_once 'wact/template/compiler/property/property.inc.php';
-//require_once 'wact/compiler/codewriter/codewriter.inc.php';
-
-Mock::Generate('WactTemplateNode', 'MockTemplateNode');
-Mock::GeneratePartial('WactTemplateNode', 'PartialMockTemplateNode', array('getDataSource', 'getProperty'));
-Mock::Generate('WactTemplateProperty', 'MockTemplateProperty');
-// Mock::Generate('WactCodeWriter', 'MockCodeWriter');
-
-class DataBindingExpressionTestCase extends UnitTestCase {
-
- function testConstruction() {
- $dataspace = new MockTemplateNode($this);
- $dataspace->setReturnValue('getProperty', NULL);
-
- $context = new MockTemplateNode($this);
- $context->setReturnReference('getDataSource', $dataspace);
- $context->expectNever('getRootDataSource');
- $context->expectNever('getParentDataSource');
-
- $DBE = new DataBindingExpression('Test', $context);
- $DBE->prepare();
- $this->assertEqual($DBE->name, 'Test');
-
- $dataspace->tally();
- $context->tally();
- }
-
- function testConstructionRoot() {
- $root = new MockTemplateNode($this);
- $root->setReturnValue('getProperty', NULL);
-
- $context = new MockTemplateNode($this);
- $context->setReturnReference('getRootDataSource', $root);
- $context->expectAtLeastOnce('getRootDataSource');
- $context->expectNever('getDataSource');
- $context->expectNever('getParentDataSource');
-
- $DBE = new DataBindingExpression('#Test', $context);
- $DBE->prepare();
- $this->assertEqual($DBE->name, 'Test');
-
- $context->tally();
- $root->tally();
- }
-
- function testConstructionparent() {
- $parent = new MockTemplateNode($this);
- $parent->setReturnValue('getProperty', NULL);
-
- $context = new MockTemplateNode($this);
- $context->setReturnReference('getParentDataSource', $parent);
- $context->expectAtLeastOnce('getParentDataSource');
- $context->expectNever('getRootDataSource');
- $context->expectNever('getDataSource');
-
- $DBE = new DataBindingExpression('^Test', $context);
- $DBE->prepare();
- $this->assertEqual($DBE->name, 'Test');
-
- $context->tally();
- $parent->tally();
- }
-
- function testBadExpression() {
- $expression = '&$|%';
-
- $dataspace = new MockTemplateNode($this);
- $dataspace->setReturnValue('getProperty', NULL);
-
- $context = new PartialMockTemplateNode($this);
- $context->__construct(NULL, NULL, new WactSourceLocation('file', 123));
- $context->setReturnReference('getDataSource', $dataspace);
-
- $DBE = new DataBindingExpression($expression, $context);
-
- try {
- $DBE->prepare();
- $this->fail('Expected exception not thrown');
- } catch (WactBadBindingException $e) {
- $this->pass();
- $this->assertEqual($e->getExpression(), $expression);
- }
-
- $dataspace->tally();
- $context->tally();
- }
-
- function testGetValueUnresolvedBinding() {
- $expression = 'Test';
-
- $dataspace = new MockTemplateNode($this);
-
- $context = new PartialMockTemplateNode($this);
- $context->__construct(NULL, NULL, new WactSourceLocation('file', 123));
- $context->setReturnReference('getDataSource', $dataspace);
- $context->setReturnValue('getProperty', NULL);
- $context->expectAtLeastOnce('getProperty', array('Test'));
-
- $DBE = new DataBindingExpression('Test', $context);
- $this->assertFalse($DBE->isConstant());
-
- try {
- $DBE->getValue('Test');
- $this->fail('Expected exception not thrown');
- } catch (WactUnresolvedBindingException $e) {
- $this->pass();
- $this->assertEqual($e->getExpression(), $expression);
- }
-
- $dataspace->tally();
- $context->tally();
- }
-
- function testGetValuePropertyValue() {
- $property = new MockTemplateProperty($this);
- $property->expectAtLeastOnce('getValue');
- $property->setReturnValue('IsConstant', TRUE);
- $property->setReturnValue('getValue', 'hello');
-
- $dataspace = new MockTemplateNode($this);
-
- $context = new MockTemplateNode($this);
- $context->setReturnReference('getDataSource', $dataspace);
- $context->setReturnReference('getProperty', $property);
- $context->expectAtLeastOnce('getProperty', array('Test'));
-
- $DBE = new DataBindingExpression('Test', $context);
-
- $this->assertIdentical($DBE->getValue(), 'hello');
-
- $dataspace->tally();
- $property->tally();
- $context->tally();
- }
-
- function testIsConstant() {
- $dataspace = new MockTemplateNode($this);
- $dataspace->setReturnValue('getProperty', NULL);
- $context = new MockTemplateNode($this);
- $context->setReturnReference('getDataSource', $dataspace);
-
- $DBE = new DataBindingExpression('Test', $context);
-
- $this->assertIdentical($DBE->isConstant(), FALSE);
-
- $dataspace->tally();
- $context->tally();
- }
-
- function testIsConstantPropertyValue() {
- $property = new MockTemplateProperty($this);
- $property->expectAtLeastOnce('IsConstant');
- $property->setReturnValue('IsConstant', TRUE);
-
- $dataspace = new MockTemplateNode($this);
-
- $context = new MockTemplateNode($this);
- $context->setReturnReference('getDataSource', $dataspace);
- $context->setReturnReference('getProperty', $property);
- $context->expectAtLeastOnce('getProperty', array('Test'));
-
- $DBE = new DataBindingExpression('Test', $context);
-
- $this->assertIdentical($DBE->isConstant(), TRUE);
-
- $dataspace->tally();
- $property->tally();
- $context->tally();
- }
-
-/*
- function testGeneratePreStatement() {
- $codewriter = new MockCodeWriter($this);
- $property = new MockTemplateProperty($this);
- $property->expectAtLeastOnce('generatePreStatement');
-
- $dataspace = new MockTemplateNode($this);
-
- $context = new MockTemplateNode($this);
- $context->setReturnReference('getDataSource', $dataspace);
- $context->setReturnReference('getProperty', $property);
- $context->expectAtLeastOnce('getProperty', array('Test'));
-
- $DBE = new DataBindingExpression('Test', $context);
- $DBE->generatePreStatement($codewriter);
-
- $dataspace->tally();
- $property->tally();
- $context->tally();
- }
-*/
-/*
- function testGeneratePostStatement() {
- $codewriter = new MockCodeWriter($this);
-
- $property = new MockTemplateProperty($this);
- $property->expectAtLeastOnce('generatePostStatement');
-
- $dataspace = new MockTemplateNode($this);
-
- $context = new MockTemplateNode($this);
- $context->setReturnReference('getDataSource', $dataspace);
- $context->setReturnReference('getProperty', $property);
- $context->expectAtLeastOnce('getProperty', array('Test'));
-
- $DBE = new DataBindingExpression('Test', $context);
- $DBE->generatePostStatement($codewriter);
-
- $dataspace->tally();
- $property->tally();
- $context->tally();
- }
-*/
-/*
- function testGenerateExpressionProperty() {
- $codewriter = new MockCodeWriter($this);
-
- $property = new MockTemplateProperty($this);
- $property->expectAtLeastOnce('generateExpression');
-
- $dataspace = new MockTemplateNode($this);
-
- $context = new MockTemplateNode($this);
- $context->setReturnReference('getDataSource', $dataspace);
- $context->setReturnReference('getProperty', $property);
- $context->expectAtLeastOnce('getProperty', array('Test'));
-
- $DBE = new DataBindingExpression('Test', $context);
- $DBE->generateExpression($codewriter);
-
- $dataspace->tally();
- $property->tally();
- $context->tally();
- }
-*/
-/*
- function testGenerateExpression() {
- $codewriter = new MockCodeWriter($this);
- $codewriter->expectAtLeastOnce('writePHP');
-
- $dataspace = new MockTemplateNode($this);
- $dataspace->setReturnValue('getProperty', NULL);
-
- $context = new MockTemplateNode($this);
- $context->setReturnReference('getDataSource', $dataspace);
-
- $DBE = new DataBindingExpression('Test', $context);
- $DBE->generateExpression($codewriter);
-
- $dataspace->tally();
- $context->tally();
- }
-*/
-}
-
-?>
Deleted: trunk/wact/template/compiler/expression/expression.inc.php
===================================================================
--- trunk/wact/template/compiler/expression/expression.inc.php 2007-03-28 23:19:56 UTC (rev 405)
+++ trunk/wact/template/compiler/expression/expression.inc.php 2007-03-28 23:43:14 UTC (rev 406)
@@ -1,621 +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/expression/lexer.inc.php';
-require_once 'wact/template/compiler/expression/databinding.inc.php';
-
-/**
-* Represents a single Expression found in the template. Responsibly for parsing
-* the expression and building a formatter chain for the expression (if expression
-* contained formatter syntax)
-*/
-class Expression {
-
- /**
- * A list of formatters
- * @var WactTemplateValueFormatter
- */
- var $formatterChain;
-
- /**
- * used for error messages
- * @var string
- */
- var $expression;
-
- /**
- * @param string expression
- * @param object Compiler Component that attribute was found in
- * @param string (optional) default formatter to apply
- */
- function __construct($expression, $ComponentContext, $formatterDictionary, $DefaultFormatter = 'raw') {
- $this->expression = $expression;
- $ApplyDefaultFormatter = TRUE;
- if (preg_match('/^(.*)\s*\|\s*raw$/is', $expression, $match)) {
- $ApplyDefaultFormatter = FALSE;
- $expression = $match[1];
- }
- if ($DefaultFormatter == 'raw') {
- $ApplyDefaultFormatter = FALSE;
- }
-
- $pos = strpos($expression, "|");
- if ($pos === FALSE) {
- $base = $this->createValue($expression, $ComponentContext);
- } else {
- $dbe = trim(substr($expression, 0, $pos));
- $formatters = trim(substr($expression, $pos + 1));
- $base = $this->createFormatterChain(
- $formatters,
- $this->createValue($dbe, $ComponentContext),
- $formatterDictionary,
- $ComponentContext
- );
- }
-
- if ($ApplyDefaultFormatter) {
- $formatterInfo = $formatterDictionary->getFormatterInfo($DefaultFormatter);
- if (is_object($formatterInfo)) {
- $formatterInfo->load();
- $formatter_class = $formatterInfo->formatterClass;
-
- // Don't apply the default formatter if the last formatter in the
- // chain is already that formatter.
- if (strcasecmp(get_class($base), $formatter_class) == 0) {
- $this->formatterChain = $base;
- } else {
- $formatter = new $formatter_class();
- $formatter->sourceLocation = $ComponentContext->getSourceLocation();
- $formatter->registerBase($base);
- $this->formatterChain = $formatter;
- }
- } else {
- require_once 'wact/template/compiler/expression/missingformatter.xcpt.php';
- throw new WactMissingFormatterException(
- $ComponentContext->getSourceLocation()->file,
- $ComponentContext->getSourceLocation()->line,
- $DefaultFormatter
- );
- }
- } else {
- $this->formatterChain = $base;
- }
- }
-
- /**
- * Parses an expression and returns an object representing the expression
- * @param string expression
- * @param object Compiler Component that attribute was found in
- * @return object WactConstantProperty or DataBindingExpression
- */
- function createValue($expression, $ComponentContext) {
- $Parser = new ExpressionValueParser($expression);
-
- switch ( $Parser->ValueType ) {
- // NULL and BOOLEAN values left out on purpose
- case EXPRESSION_VALUE_INT:
- case EXPRESSION_VALUE_FLOAT:
- case EXPRESSION_VALUE_STRING:
- $cp = new WactConstantProperty($Parser->Value);
- return $cp;
- break;
-
- case EXPRESSION_VALUE_DATABINDING:
- default:
- $dbe = new DataBindingExpression($expression, $ComponentContext);
- return $dbe;
- break;
-
- }
-
- }
-
- /**
- * Parses an expression, building a chain of formatters for it
- * @param string expression
- * @param WactTemplateValueFormatter base formatter to start with
- * @param object Compiler Component that attribute was found in
- * @return object formatter with chain of formatters attached
- */
- function createFormatterChain($expr, $Value, $formatterDictionary, $ComponentContext) {
-
- $FFp = new ExpressionFormatterFindingParser($expr);
-
- $Base = $Value;
-
- if ( count($FFp->formatters) == 0 ) {
- return $Value;
- }
-
- foreach ( $FFp->formatters as $formatter_expr ) {
-
- $Fp = new ExpressionFormatterParser($formatter_expr);
-
- if ( is_null($Fp->name) ) {
- require_once 'wact/template/compiler/expression/invalidformatterspec.xcpt.php';
- throw new WactInvalidFormatterSpecException(
- $ComponentContext->getSourceLocation()->file,
- $ComponentContext->getSourceLocation()->llne
- );
- return $Value;
- }
-
- $formatterInfo = $formatterDictionary->getFormatterInfo($Fp->name);
-
- if (!is_object($formatterInfo)) {
- require_once 'wact/template/compiler/expression/missingformatter.xcpt.php';
- throw new WactMissingFormatterException(
- $ComponentContext->getSourceLocation()->file,
- $ComponentContext->getSourceLocation()->line,
- $Fp->name
- );
- return $Value;
- }
-
- $formatterInfo->load();
- $formatter_class = $formatterInfo->formatterClass;
- $formatter = new $formatter_class();
- $formatter->SourceLocation = $ComponentContext->SourceLocation;
-
- if ( !is_null($Fp->Args) ) {
-
- $numArgs = count($Fp->Args);
-
- if ( $numArgs < $formatterInfo->minParameterCount ) {
- require_once 'wact/template/compiler/expression/missingformatterparameter.xcpt.php';
- throw new WactMissingFormatterParameterException(
- $ComponentContext->getSourceLocation()->file,
- $ComponentContext->getSourceLocation()->line,
- $Fp->name
- );
- return $Value;
- }
-
- if ($numArgs > $formatterInfo->maxParameterCount) {
- require_once 'wact/template/compiler/expression/toomanyparameters.xcpt.php';
- throw new WactTooManyParametersException(
- $ComponentContext->getSourceLocation()->file,
- $ComponentContext->getSourceLocation()->line,
- $Fp->name
- );
- return $Value;
- }
-
- foreach ( $Fp->Args as $value_expr ) {
-
- $formatter->registerParameter($this->createValue($value_expr, $ComponentContext));
-
- }
- }
-
- $formatter->registerBase($Base);
-
- $Base = $formatter;
-
- }
-
- return $Base;
-
- }
-
- /**
- * Does this expression refer to a constant value (at compile time)?
- * @return Boolean
- */
- function isConstant() {
- return $this->formatterChain->isConstant();
- }
-
- /**
- * Return the value of this expression
- * @return String
- */
- function getValue() {
- return $this->formatterChain->getValue();
- }
-
- /**
- * Generate setup code for an expression reference
- * @param CodeWriter
- * @return void
- */
- function generatePreStatement($code) {
- $this->formatterChain->generatePreStatement($code);
- }
-
- /**
- * Generate the code to read the data value at run time
- * Must generate only a valid PHP Expression.
- * @param CodeWriter
- * @return void
- */
- function generateExpression($code) {
- $this->formatterChain->generateExpression($code);
- }
-
- /**
- * Generate tear down code for an expression reference
- * @param CodeWriter
- * @return void
- */
- function generatePostStatement($code) {
- $this->formatterChain->generatePostStatement($code);
- }
-
- /**
- * Calls the prepare method on the root of the formatter chain
- * @return void
- */
- function prepare() {
- return $this->formatterChain->prepare();
- }
-
-}
-
-//--------------------------------------------------------------------------------
-/**#@+
- * Value parser constants
- */
-define ('EXPRESSION_VALUE_DATABINDING',0);
-define ('EXPRESSION_VALUE_INT',1);
-define ('EXPRESSION_VALUE_FLOAT',2);
-define ('EXPRESSION_VALUE_STRING',3);
-//--------------------------------------------------------------------------------
-/**
-* Searches expression strings for constant values
-* WARNING: this parser defaults to data binding expressions. That means if it
-* doest recognise a integer, float or string constant, what it calls a data binding
-* expression may not in fact be a data binding expression. It assumes that
-* Expression::createValue asks it a parse a valid value string
-*/
-class ExpressionValueParser {
- /**
- * @var int constant identifying type of value
- */
- var $ValueType = EXPRESSION_VALUE_DATABINDING;
-
- /**
- * @var mixed constant value (string/int/float)
- */
- var $Value;
-
- /**
- * Invokes the Lexer to parse the expression
- * @param string expression to parse
- */
- function __construct($expression) {
- $Lexer = ExpressionValueParser::getLexer();
- $Lexer->parse($expression);
- }
-
- /**
- * Lexer callback - accepts the default data binding
- * expression - called if no constants found
- * @param string parsed expression
- * @param int expression lexer state
- * @return boolean TRUE
- */
- function acceptDatabinding($expression,$state) {
- switch ( $state ) {
- case EXPRESSION_LEXER_UNMATCHED:
- // This doesnt actually get used in Expression::getValue
- $this->Value = $expression;
- break;
- }
- return TRUE;
- }
-
- /**
- * Lexer callback - called for integer constants
- * @param string matched integer
- * @param int expression lexer state
- * @return boolean TRUE
- */
- function acceptInteger($int,$state) {
- switch ( $state ) {
- case EXPRESSION_LEXER_SPECIAL:
- $this->ValueType = EXPRESSION_VALUE_INT;
- $this->Value = intval($int);
- break;
- }
-
- return TRUE;
- }
-
- /**
- * Lexer callback - called for float constants
- * @param string matched float
- * @param int expression lexer state
- * @return boolean TRUE
- */
- function acceptFloat($float,$state) {
- switch ( $state ) {
- case EXPRESSION_LEXER_SPECIAL:
- $this->ValueType = EXPRESSION_VALUE_FLOAT;
- $this->Value = floatval($float);
- break;
- }
- return TRUE;
- }
-
- /**
- * Lexer callback - called for string constants
- * @param string matched string
- * @param int expression lexer state
- * @return boolean TRUE
- */
- function acceptString($string,$state) {
- switch ( $state ) {
- case EXPRESSION_LEXER_SPECIAL:
- $this->ValueType = EXPRESSION_VALUE_STRING;
-
- // Strip the quotes
- // hack but saves introducing further Lexer complexity
- $string = substr($string,1,strlen($string)-2);
-
- $this->Value = $string;
- break;
- }
- return TRUE;
- }
-
- /**
- * Creates the Lexer. Ideally this should be a static instance for
- * performance but Lexer left in strange state after parsing if
- * static
- * @return ExpressionLexer
- */
- function getLexer() {
- $Lexer = new ExpressionLexer($this,'databinding');
-
- $Lexer->addSpecialPattern('^-?\d+$','databinding','integer');
- $Lexer->addSpecialPattern('^-?\d+\.\d+$','databinding','float');
- $Lexer->addSpecialPattern('^".*"$','databinding','doublequote');
- $Lexer->addSpecialPattern('^\'.*\'$','databinding','singlequote');
-
- $Lexer->mapHandler('databinding','acceptDatabinding');
- $Lexer->mapHandler('integer','acceptInteger');
- $Lexer->mapHandler('float','acceptFloat');
- $Lexer->mapHandler('doublequote','acceptString');
- $Lexer->mapHandler('singlequote','acceptString');
-
- return $Lexer;
- }
-}
-
-//--------------------------------------------------------------------------------
-/**
-* Searches expression strings for formatters
-* WARNING: this parser expects the initial variable / value to have been stripped
-* as happens in the Expression constructor
-*/
-class ExpressionFormatterFindingParser {
-
- /**
- * List of values found in expression, marked by formatter delimiter
- * @var array
- */
- var $formatters = array();
-
- /**
- * Current value
- * @var mixed NULL when no value or string as value is built
- */
- var $formatter = NULL;
-
- /**
- * Invokes the Lexer to parse the expression
- * @param string expression to parse
- */
- function __construct($expression) {
- $Lexer = ExpressionFormatterFindingParser::getLexer();
- $Lexer->parse($expression);
-
- // Make sure final value added to values
- if ( !is_null($this->formatter) ) {
- $this->formatters[] = $this->formatter;
- }
- }
-
- /**
- * Lexer callback - called for value strings
- * @param string
- * @param int expression lexer state
- * @return boolean TRUE
- */
- function acceptFormatter($formatter, $state) {
- switch ( $state ) {
- case EXPRESSION_LEXER_UNMATCHED:
- if ( is_null($this->formatter) ) {
- $this->formatter = $formatter;
- } else {
- $this->formatter .= $formatter;
- }
- break;
- case EXPRESSION_LEXER_SPECIAL:
- if ( is_null($this->formatter) ) {
- $this->formatter = $formatter;
- } else {
- $this->formatter .= $formatter;
- }
- break;
- }
- return TRUE;
- }
-
- /**
- * Lexer callback - called every time a formatter delimiter
- * is found. Populates the Values array with the current
- * value
- * @return boolean TRUE
- */
- function addFormatter() {
- if ( !is_null ($this->formatter) ) {
- $this->formatters[] = $this->formatter;
- $this->formatter = NULL;
- }
- return TRUE;
- }
-
- /**
- * Creates the Lexer.
- * @return ExpressionLexer
- */
- function getLexer() {
- $Lexer = new ExpressionLexer($this,'formatter');
-
- $Lexer->addSpecialPattern('\|','formatter','add');
-// $Lexer->addSpecialPattern('".*"','formatter','doublequote');
-// $Lexer->addSpecialPattern('\'.*\'','formatter','singlequote');
- $Lexer->addSpecialPattern('"[^"]*"','formatter','doublequote');
- $Lexer->addSpecialPattern("'[^']*'",'formatter','singlequote');
-
- $Lexer->mapHandler('formatter','acceptFormatter');
- $Lexer->mapHandler('doublequote','acceptFormatter');
- $Lexer->mapHandler('singlequote','acceptFormatter');
- $Lexer->mapHandler('add','addFormatter');
-
- return $Lexer;
- }
-}
-
-/**
-* Parses a single formatter expression
-* WARNING: this parser expects strings parsed by ExpressionFormatterFindingParser
-*/
-class ExpressionFormatterParser {
-
- /**
- * Name of the formatter
- * @var string
- */
- var $name = NULL;
-
- /**
- * List of arguments
- * @var array
- */
- var $Args = NULL;
-
- /**
- * Current argument
- * @var string
- */
- var $arg = NULL;
-
- /**
- * Invokes the Lexer to parse the expression
- * @param string expression to parse
- */
- function __construct($expression) {
- $Lexer = ExpressionFormatterParser::getLexer();
- $Lexer->parse($expression);
-
- // Make sure remaining argument added
- if ( !is_null ($this->Args) && !is_null($this->arg) ) {
- $this->Args[] = $this->arg;
- }
- }
-
- /**
- * Lexer callback - if the : delimiter is found, prepares the Args array
- * @return boolean TRUE
- */
- function initArgs() {
- $this->Args = array();
- return TRUE;
- }
-
- /**
- * Lexer callback - if the , delimiter is found, adds the current arg
- * to the Args array
- * @return boolean TRUE
- */
- function addArg() {
- if ( !is_null($this->Args) && !is_null($this->arg) ) {
- $this->Args[] = $this->arg;
- $this->arg = NULL;
- }
- return TRUE;
- }
-
- /**
- * Lexer callback - accepts a single argument
- * @param string
- * @param int expression lexer state
- * @return boolean TRUE
- */
- function accept($expression,$state) {
-
- switch ( $state ) {
-
- case EXPRESSION_LEXER_UNMATCHED:
- if ( !is_null($this->Args) ) {
- if ( is_null($this->arg) ) {
- $this->arg = $expression;
- } else {
- $this->arg .= $expression;
- }
- } else {
- if ( is_null($this->name) ) {
- $this->name = $expression;
- }
- }
- break;
-
- case EXPRESSION_LEXER_SPECIAL:
- if ( !is_null($this->Args) ) {
- if ( is_null($this->arg) ) {
- $this->arg = $expression;
- } else {
- $this->arg .= $expression;
- }
- }
- break;
- }
-
- return TRUE;
- }
-
- /**
- * Creates the Lexer.
- * @return ExpressionLexer
- */
- function getLexer() {
- $Lexer = new ExpressionLexer($this,'value');
-
- $Lexer->addSpecialPattern(':','value','args');
- $Lexer->addSpecialPattern(',','value','arg');
-
- $Lexer->addSpecialPattern('"[^"]*"','value','doublequote');
- $Lexer->addSpecialPattern("'[^']*'",'value','singlequote');
-
- $Lexer->addPattern('\s','value');
-
- $Lexer->mapHandler('value','accept');
- $Lexer->mapHandler('args','initArgs');
- $Lexer->mapHandler('arg','addArg');
- $Lexer->mapHandler('doublequote','accept');
- $Lexer->mapHandler('singlequote','accept');
-
- return $Lexer;
- }
-
-}
-?>
\ No newline at end of file
Deleted: trunk/wact/template/compiler/expression/expression.test.php
===================================================================
--- trunk/wact/template/compiler/expression/expression.test.php 2007-03-28 23:19:56 UTC (rev 405)
+++ trunk/wact/template/compiler/expression/expression.test.php 2007-03-28 23:43:14 UTC (rev 406)
@@ -1,35 +0,0 @@
-<?php
-
-require_once 'wact/template/compiler/expression/expression.xcpt.php';
-
-class WactExpressionExceptionTester extends WactExpressionException {
- public function __construct($filename, $lineno, $expression, $message) {
- parent::__construct($filename, $lineno, $expression, $message);
- }
-}
-
-class WactExpressionExceptionTestCase extends WactTestCase {
-
- function testException() {
- try {
- $fileName = 'testfile';
- $lineNo = 123;
- $expression = 'testexpression';
- $message = 'testmessage';
-
- throw new WactExpressionExceptionTester($fileName, $lineNo, $expression, $message);
-
- $this->fail('Expected exception not thrown');
- } catch (WactExpressionExceptionTester $e) {
- $this->pass();
-
- $this->assertEqual($e->getFilename(), $fileName);
- $this->assertEqual($e->getLineno(), $lineNo);
- $this->assertEqual($e->getExpression(), $expression);
- $this->assertEqual($e->getMessage(), $message);
- }
- }
-
-}
-
-?>
Deleted: trunk/wact/template/compiler/expression/expression.xcpt.php
===================================================================
--- trunk/wact/template/compiler/expression/expression.xcpt.php 2007-03-28 23:19:56 UTC (rev 405)
+++ trunk/wact/template/compiler/expression/expression.xcpt.php 2007-03-28 23:43:14 UTC (rev 406)
@@ -1,59 +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
-*/
-if (!class_exists('WactLocatedException', FALSE)) {
- require_once 'wact/template/compiler/located.xcpt.php';
-}
-
-/**
-* @package Template
-*/
-abstract class WactExpressionException extends WactLocatedException {
-
- /**
- * @var string
- */
- protected $expression;
-
- /**
- * Class constructor.
- * @param string file Filename
- * @param string line Line number
- */
- public function __construct($filename, $lineno, $expression, $message) {
- $this->expression = $expression;
-
- parent::__construct(
- $filename,
- $lineno,
- $message
- );
- }
-
- /**
- * Returns the data binding expression
- * @return string Data binding expression
- */
- public function getExpression() {
- return $this->expression;
- }
-
-}
-
-?>
\ No newline at end of file
Deleted: trunk/wact/template/compiler/expression/formatter.test.php
===================================================================
--- trunk/wact/template/compiler/expression/formatter.test.php 2007-03-28 23:19:56 UTC (rev 405)
+++ trunk/wact/template/compiler/expression/formatter.test.php 2007-03-28 23:43:14 UTC (rev 406)
@@ -1,35 +0,0 @@
-<?php
-
-require_once 'wact/template/compiler/expression/formatter.xcpt.php';
-
-class WactFormatterExceptionTester extends WactFormatterException {
- public function __construct($filename, $lineno, $formatter, $message) {
- parent::__construct($filename, $lineno, $formatter, $message);
- }
-}
-
-class WactFormatterExceptionTestCase extends WactTestCase {
-
- function testException() {
- try {
- $fileName = 'testfile';
- $lineNo = 123;
- $formatter = 'testformatter';
- $message = 'testmessage';
-
- throw new WactFormatterExceptionTester($fileName, $lineNo, $formatter, $message);
-
- $this->fail('Expected exception not thrown');
- } catch (WactFormatterExceptionTester $e) {
- $this->pass();
-
- $this->assertEqual($e->getFilename(), $fileName);
- $this->assertEqual($e->getLineno(), $lineNo);
- $this->assertEqual($e->getFormatter(), $formatter);
- $this->assertEqual($e->getMessage(), $message);
- }
- }
-
-}
-
-?>
Deleted: trunk/wact/template/compiler/expression/formatter.xcpt.php
===================================================================
--- trunk/wact/template/compiler/expression/formatter.xcpt.php 2007-03-28 23:19:56 UTC (rev 405)
+++ trunk/wact/template/compiler/expression/formatter.xcpt.php 2007-03-28 23:43:14 UTC (rev 406)
@@ -1,56 +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
-*/
-if (!class_exists('WactLocatedException', FALSE)) {
- require_once 'wact/template/compiler/located.xcpt.php';
-}
-
-/**
-* @package Template
-*/
-abstract class WactFormatterException extends WactLocatedException {
-
- protected $formatter;
-
- /**
- * Class constructor.
- * @param string file Filename
- * @param string line Line number
- */
- public function __construct($filename, $lineno, $formatter, $message) {
- $this->formatter = $formatter;
-
- parent::__construct(
- $filename,
- $lineno,
- $message
- );
- }
-
- /**
- * Returns the name of the formatter
- * @return string formatter name
- */
- public function getFormatter() {
- return $this->formatter;
- }
-
-}
-
-?>
\ No newline at end of file
Deleted: trunk/wact/template/compiler/expression/invalidformatterspec.test.php
===================================================================
--- trunk/wact/template/compiler/expression/invalidformatterspec.test.php 2007-03-28 23:19:56 UTC (rev 405)
+++ trunk/wact/template/compiler/expression/invalidformatterspec.test.php 2007-03-28 23:43:14 UTC (rev 406)
@@ -1,33 +0,0 @@
-<?php
-
-require_once 'wact/template/compiler/expression/invalidformatterspec.xcpt.php';
-
-class WactInvalidFormatterSpecExceptionTestCase extends WactTestCase {
-
- function setUp() {
- }
-
- function tearDown() {
- }
-
- function testException() {
- try {
- $fileName = 'testfile';
- $lineNo = 123;
-
- throw new WactInvalidFormatterSpecException($fileName, $lineNo);
- $this->fail('Expected exception not thrown');
- } catch (WactInvalidFormatterSpecException $e) {
- $this->pass();
-
- $this->assertEqual($e->getFilename(), $fileName);
- $this->assertEqual($e->getLineno(), $lineNo);
-
- $this->assertIsIn($fileName, $e->getMessage());
- $this->assertIsIn($lineNo, $e->getMessage());
- }
- }
-
-}
-
-?>
Deleted: trunk/wact/template/compiler/expression/invalidformatterspec.xcpt.php
===================================================================
--- trunk/wact/template/compiler/expression/invalidformatterspec.xcpt.php 2007-03-28 23:19:56 UTC (rev 405)
+++ trunk/wact/template/compiler/expression/invalidformatterspec.xcpt.php 2007-03-28 23:43:14 UTC (rev 406)
@@ -1,43 +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
-*/
-if (!class_exists('WactLocatedException', FALSE)) {
- require_once 'wact/template/compiler/located.xcpt.php';
-}
-
-/**
-* @package Template
-*/
-class WactInvalidFormatterSpecException extends WactLocatedException {
- /**
- * Class constructor.
- * @param string file Filename
- * @param string line Line number
- */
- public function __construct($filename, $lineno) {
- parent::__construct(
- $filename,
- $lineno,
- 'Invalid formatter specification in template file "{Filename}" on line {Lineno}'
- );
- }
-
-}
-
-?>
\ No newline at end of file
Deleted: trunk/wact/template/compiler/expression/lexer.inc.php
===================================================================
--- trunk/wact/template/compiler/expression/lexer.inc.php 2007-03-28 23:19:56 UTC (rev 405)
+++ trunk/wact/template/compiler/expression/lexer.inc.php 2007-03-28 23:43:14 UTC (rev 406)
@@ -1,416 +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
-*/
-
-/**#@+
- * lexer mode constant
- */
-define("EXPRESSION_LEXER_ENTER", 1);
-define("EXPRESSION_LEXER_MATCHED", 2);
-define("EXPRESSION_LEXER_UNMATCHED", 3);
-define("EXPRESSION_LEXER_EXIT", 4);
-define("EXPRESSION_LEXER_SPECIAL", 5);
-/**#@-*/
-
-/**
- * Compounded regular expression. Any of
- * the contained patterns could match and
- * when one does it's label is returned.
- */
-class ExpressionLexerParallelRegex {
- var $_patterns;
- var $_labels;
- var $_regex;
- var $_case;
-
- /**
- * Constructor. Starts with no patterns.
- * @param boolean $case True for case sensitive, false
- * for insensitive.
- */
- function __construct($case) {
- $this->_case = $case;
- $this->_patterns = array();
- $this->_labels = array();
- $this->_regex = null;
- }
-
- /**
- * Adds a pattern with an optional label.
- * @param string $pattern Perl style regex, but ( and )
- * lose the usual meaning.
- * @param string $label Label of regex to be returned
- * on a match.
- */
- function addPattern($pattern, $label = true) {
- $count = count($this->_patterns);
- $this->_patterns[$count] = $pattern;
- $this->_labels[$count] = $label;
- $this->_regex = null;
- }
-
- /**
- * Attempts to match all patterns at once against
- * a string.
- * @param string $subject String to match against.
- * @param string $match First matched portion of
- * subject.
- * @return boolean True on success.
- */
- function match($subject, &$match) {
- if (count($this->_patterns) == 0) {
- return false;
- }
- if (! preg_match($this->_getCompoundedRegex(), $subject, $matches)) {
- $match = "";
- return false;
- }
- $match = $matches[0];
- for ($i = 1; $i < count($matches); $i++) {
- if ($matches[$i]) {
- return $this->_labels[$i - 1];
- }
- }
- return true;
- }
-
- /**
- * Compounds the patterns into a single
- * regular expression separated with the
- * "or" operator. Caches the regex.
- * Will automatically escape (, ) and / tokens.
- * @param array $patterns List of patterns in order.
- */
- function _getCompoundedRegex() {
- if ($this->_regex == null) {
- for ($i = 0; $i < count($this->_patterns); $i++) {
- $this->_patterns[$i] = '(' . str_replace(
- array('/', '(', ')'),
- array('\/', '\(', '\)'),
- $this->_patterns[$i]) . ')';
- }
- $this->_regex = "/" . implode("|", $this->_patterns) . "/" . $this->_getPerlMatchingFlags();
- }
- return $this->_regex;
- }
-
- /**
- * Accessor for perl regex mode flags to use.
- * @return string Perl regex flags.
- */
- function _getPerlMatchingFlags() {
- return ($this->_case ? "msS" : "msSi");
- }
-}
-
-/**
- * States for a stack machine.
- */
-class ExpressionLexerStateStack {
- var $_stack;
-
- /**
- * Constructor. Starts in named state.
- * @param string $start Starting state name.
- */
- function __construct($start) {
- $this->_stack = array($start);
- }
-
- /**
- * Accessor for current state.
- * @return string State.
- */
- function getCurrent() {
- return $this->_stack[count($this->_stack) - 1];
- }
-
- /**
- * Adds a state to the stack and sets it
- * to be the current state.
- * @param string $state New state.
- */
- function enter($state) {
- array_push($this->_stack, $state);
- }
-
- /**
- * Leaves the current state and reverts
- * to the previous one.
- * @return boolean False if we drop off
- * the bottom of the list.
- */
- function leave() {
- if (count($this->_stack) == 1) {
- return false;
- }
- array_pop($this->_stack);
- return true;
- }
-}
-
-/**
- * Accepts text and breaks it into tokens.
- * Some optimisation to make the sure the
- * content is only scanned by the PHP regex
- * parser once. Lexer modes must not start
- * with leading underscores.
- */
-class ExpressionLexer {
- var $_regexes;
- var $_parser;
- var $_mode;
- var $_mode_handlers;
- var $_case;
-
- /**
- * Sets up the lexer in case insensitive matching
- * by default.
- * @param ExpressionParser $parser Handling strategy by
- * reference.
- * @param string $start Starting handler.
- * @param boolean $case True for case sensitive.
- */
- function __construct(&$parser, $start = "accept", $case = false) {
- $this->_case = $case;
- $this->_regexes = array();
- $this->_parser = &$parser;
- $this->_mode = &new ExpressionLexerStateStack($start);
- $this->_mode_handlers = array();
- }
-
- /**
- * Adds a token search pattern for a particular
- * parsing mode. The pattern does not change the
- * current mode.
- * @param string $pattern Perl style regex, but ( and )
- * lose the usual meaning.
- * @param string $mode Should only apply this
- * pattern when dealing with
- * this type of input.
- */
- function addPattern($pattern, $mode = "accept") {
- if (! isset($this->_regexes[$mode])) {
- $this->_regexes[$mode] = new ExpressionLexerParallelRegex($this->_case);
- }
- $this->_regexes[$mode]->addPattern($pattern);
- }
-
- /**
- * Adds a pattern that will enter a new parsing
- * mode. Useful for entering parenthesis, strings,
- * tags, etc.
- * @param string $pattern Perl style regex, but ( and )
- * lose the usual meaning.
- * @param string $mode Should only apply this
- * pattern when dealing with
- * this type of input.
- * @param string $new_mode Change parsing to this new
- * nested mode.
- */
- function addEntryPattern($pattern, $mode, $new_mode) {
- if (! isset($this->_regexes[$mode])) {
- $this->_regexes[$mode] = new ExpressionLexerParallelRegex($this->_case);
- }
- $this->_regexes[$mode]->addPattern($pattern, $new_mode);
- }
-
- /**
- * Adds a pattern that will exit the current mode
- * and re-enter the previous one.
- * @param string $pattern Perl style regex, but ( and )
- * lose the usual meaning.
- * @param string $mode Mode to leave.
- */
- function addExitPattern($pattern, $mode) {
- if (! isset($this->_regexes[$mode])) {
- $this->_regexes[$mode] = new ExpressionLexerParallelRegex($this->_case);
- }
- $this->_regexes[$mode]->addPattern($pattern, "__exit");
- }
-
- /**
- * Adds a pattern that has a special mode. Acts as an entry
- * and exit pattern in one go, effectively calling a special
- * parser handler for this token only.
- * @param string $pattern Perl style regex, but ( and )
- * lose the usual meaning.
- * @param string $mode Should only apply this
- * pattern when dealing with
- * this type of input.
- * @param string $special Use this mode for this one token.
- */
- function addSpecialPattern($pattern, $mode, $special) {
- if (! isset($this->_regexes[$mode])) {
- $this->_regexes[$mode] = new ExpressionLexerParallelRegex($this->_case);
- }
- $this->_regexes[$mode]->addPattern($pattern, "_$special");
- }
-
- /**
- * Adds a mapping from a mode to another handler.
- * @param string $mode Mode to be remapped.
- * @param string $handler New target handler.
- */
- function mapHandler($mode, $handler) {
- $this->_mode_handlers[$mode] = $handler;
- }
-
- /**
- * Splits the page text into tokens. Will fail
- * if the handlers report an error or if no
- * content is consumed. If successful then each
- * unparsed and parsed token invokes a call to the
- * held listener.
- * @param string $raw Raw HTML text.
- * @return boolean True on success, else false.
- */
- function parse($raw) {
- if (! isset($this->_parser)) {
- return false;
- }
- $length = strlen($raw);
- while (is_array($parsed = $this->_reduce($raw))) {
- list($unmatched, $matched, $mode) = $parsed;
- if (! $this->_dispatchTokens($unmatched, $matched, $mode)) {
- return false;
- }
- if (strlen($raw) == $length) {
- return false;
- }
- $length = strlen($raw);
- }
- if (!$parsed) {
- return false;
- }
- return $this->_invokeParser($raw, EXPRESSION_LEXER_UNMATCHED);
- }
-
- /**
- * Sends the matched token and any leading unmatched
- * text to the parser changing the lexer to a new
- * mode if one is listed.
- * @param string $unmatched Unmatched leading portion.
- * @param string $matched Actual token match.
- * @param string $mode Mode after match. A boolean
- * false mode causes no change.
- * @return boolean False if there was any error
- * from the parser.
- */
- function _dispatchTokens($unmatched, $matched, $mode = false) {
- if (! $this->_invokeParser($unmatched, EXPRESSION_LEXER_UNMATCHED)) {
- return false;
- }
- if ($this->_isModeEnd($mode)) {
- if (! $this->_invokeParser($matched, EXPRESSION_LEXER_EXIT)) {
- return false;
- }
- return $this->_mode->leave();
- }
- if ($this->_isSpecialMode($mode)) {
- $this->_mode->enter($this->_decodeSpecial($mode));
- if (! $this->_invokeParser($matched, EXPRESSION_LEXER_SPECIAL)) {
- return false;
- }
- return $this->_mode->leave();
- }
- if (is_string($mode)) {
- $this->_mode->enter($mode);
- return $this->_invokeParser($matched, EXPRESSION_LEXER_ENTER);
- }
- return $this->_invokeParser($matched, EXPRESSION_LEXER_MATCHED);
- }
-
- /**
- * Tests to see if the new mode is actually to leave
- * the current mode and pop an item from the matching
- * mode stack.
- * @param string $mode Mode to test.
- * @return boolean True if this is the exit mode.
- */
- function _isModeEnd($mode) {
- return ($mode === "__exit");
- }
-
- /**
- * Test to see if the mode is one where this mode
- * is entered for this token only and automatically
- * leaves immediately afterwoods.
- * @param string $mode Mode to test.
- * @return boolean True if this is the exit mode.
- */
- function _isSpecialMode($mode) {
- return (strncmp($mode, "_", 1) == 0);
- }
-
- /**
- * Strips the magic underscore marking single token
- * modes.
- * @param string $mode Mode to decode.
- * @return string Underlying mode name.
- */
- function _decodeSpecial($mode) {
- return substr($mode, 1);
- }
-
- /**
- * Calls the parser method named after the current
- * mode. Empty content will be ignored. The lexer
- * has a parser handler for each mode in the lexer.
- * @param string $content Text parsed.
- * @param boolean $is_match Token is recognised rather
- * than unparsed data.
- */
- function _invokeParser($content, $is_match) {
- if (($content === "") || ($content === false)) {
- return true;
- }
- $handler = $this->_mode->getCurrent();
- if (isset($this->_mode_handlers[$handler])) {
- $handler = $this->_mode_handlers[$handler];
- }
- return $this->_parser->$handler($content, $is_match);
- }
-
- /**
- * Tries to match a chunk of text and if successful
- * removes the recognised chunk and any leading
- * unparsed data. Empty strings will not be matched.
- * @param string $raw The subject to parse. This is the
- * content that will be eaten.
- * @return array Three item list of unparsed
- * content followed by the
- * recognised token and finally the
- * action the parser is to take.
- * True if no match, false if there
- * is a parsing error.
- */
- function _reduce(&$raw) {
- if (! isset($this->_regexes[$this->_mode->getCurrent()])) {
- return false;
- }
- if ($raw === "") {
- return true;
- }
- if ($action = $this->_regexes[$this->_mode->getCurrent()]->match($raw, $match)) {
- $unparsed_character_count = strpos($raw, $match);
- $unparsed = substr($raw, 0, $unparsed_character_count);
- $raw = substr($raw, $unparsed_character_count + strlen($match));
- return array($unparsed, $match, $action);
- }
- return true;
- }
-}
-?>
\ No newline at end of file
Deleted: trunk/wact/template/compiler/expression/lexer.test.php
===================================================================
--- trunk/wact/template/compiler/expression/lexer.test.php 2007-03-28 23:19:56 UTC (rev 405)
+++ trunk/wact/template/compiler/expression/lexer.test.php 2007-03-28 23:43:14 UTC (rev 406)
@@ -1,322 +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
-*/
-
-require_once 'wact/template/compiler/expression/lexer.inc.php';
-
-class TestOfExpressionLexerParallelRegex extends UnitTestCase {
-
- function testNoPatterns() {
- $regex =new ExpressionLexerParallelRegex(false);
- $this->assertFalse($regex->match("Hello", $match));
- $this->assertEqual($match, "");
- }
-
- function testNoSubject() {
- $regex =new ExpressionLexerParallelRegex(false);
- $regex->addPattern(".*");
- $this->assertTrue($regex->match("", $match));
- $this->assertEqual($match, "");
- }
-
- function testMatchAll() {
- $regex =new ExpressionLexerParallelRegex(false);
- $regex->addPattern(".*");
- $this->assertTrue($regex->match("Hello", $match));
- $this->assertEqual($match, "Hello");
- }
-
- function testCaseSensitive() {
- $regex =new ExpressionLexerParallelRegex(true);
- $regex->addPattern("abc");
- $this->assertTrue($regex->match("abcdef", $match));
- $this->assertEqual($match, "abc");
- $this->assertTrue($regex->match("AAABCabcdef", $match));
- $this->assertEqual($match, "abc");
- }
-
- function testCaseInsensitive() {
- $regex =new ExpressionLexerParallelRegex(false);
- $regex->addPattern("abc");
- $this->assertTrue($regex->match("abcdef", $match));
- $this->assertEqual($match, "abc");
- $this->assertTrue($regex->match("AAABCabcdef", $match));
- $this->assertEqual($match, "ABC");
- }
-
- function testMatchMultiple() {
- $regex =new ExpressionLexerParallelRegex(true);
- $regex->addPattern("abc");
- $regex->addPattern("ABC");
- $this->assertTrue($regex->match("abcdef", $match));
- $this->assertEqual($match, "abc");
- $this->assertTrue($regex->match("AAABCabcdef", $match));
- $this->assertEqual($match, "ABC");
- $this->assertFalse($regex->match("Hello", $match));
- }
-
- function testPatternLabels() {
- $regex =new ExpressionLexerParallelRegex(false);
- $regex->addPattern("abc", "letter");
- $regex->addPattern("123", "number");
- $this->assertIdentical($regex->match("abcdef", $match), "letter");
- $this->assertEqual($match, "abc");
- $this->assertIdentical($regex->match("0123456789", $match), "number");
- $this->assertEqual($match, "123");
- }
-}
-
-class TestOfExpressionLexerStateStack extends UnitTestCase {
- function TestOfExpressionLexerStateStack() {
- $this->UnitTestCase();
- }
-
- function testStartState() {
- $stack =new ExpressionLexerStateStack("one");
- $this->assertEqual($stack->getCurrent(), "one");
- }
-
- function testExhaustion() {
- $stack =new ExpressionLexerStateStack("one");
- $this->assertFalse($stack->leave());
- }
-
- function testStateMoves() {
- $stack =new ExpressionLexerStateStack("one");
- $stack->enter("two");
- $this->assertEqual($stack->getCurrent(), "two");
- $stack->enter("three");
- $this->assertEqual($stack->getCurrent(), "three");
- $this->assertTrue($stack->leave());
- $this->assertEqual($stack->getCurrent(), "two");
- $stack->enter("third");
- $this->assertEqual($stack->getCurrent(), "third");
- $this->assertTrue($stack->leave());
- $this->assertTrue($stack->leave());
- $this->assertEqual($stack->getCurrent(), "one");
- }
-}
-
-class TestParser {
- function TestParser() {
- }
-
- function accept() {
- }
-
- function a() {
- }
-
- function b() {
- }
-}
-Mock::generate('TestParser');
-
-class TestOfExpressionLexer extends UnitTestCase {
- function TestOfExpressionLexer() {
- $this->UnitTestCase();
- }
-
- function testNoPatterns() {
- $handler =new MockTestParser($this);
- $handler->expectNever("accept");
- $handler->setReturnValue("accept", true);
- $lexer =new ExpressionLexer($handler);
- $this->assertFalse($lexer->parse("abcdef"));
- }
-
- function testEmptyPage() {
- $handler =new MockTestParser($this);
- $handler->expectNever("accept");
- $handler->setReturnValue("accept", true);
- $handler->expectNever("accept");
- $handler->setReturnValue("accept", true);
- $lexer =new ExpressionLexer($handler);
- $lexer->addPattern("a+");
- $this->assertTrue($lexer->parse(""));
- }
-
- function testSinglePattern() {
- $handler =new MockTestParser($this);
- $handler->expectArgumentsAt(0, "accept", array("aaa", LEXER_MATCHED));
- $handler->expectArgumentsAt(1, "accept", array("x", LEXER_UNMATCHED));
- $handler->expectArgumentsAt(2, "accept", array("a", LEXER_MATCHED));
- $handler->expectArgumentsAt(3, "accept", array("yyy", LEXER_UNMATCHED));
- $handler->expectArgumentsAt(4, "accept", array("a", LEXER_MATCHED));
- $handler->expectArgumentsAt(5, "accept", array("x", LEXER_UNMATCHED));
- $handler->expectArgumentsAt(6, "accept", array("aaa", LEXER_MATCHED));
- $handler->expectArgumentsAt(7, "accept", array("z", LEXER_UNMATCHED));
- $handler->expectCallCount("accept", 8);
- $handler->setReturnValue("accept", true);
- $lexer =new ExpressionLexer($handler);
- $lexer->addPattern("a+");
- $this->assertTrue($lexer->parse("aaaxayyyaxaaaz"));
- $handler->tally();
- }
-
- function testMultiplePattern() {
- $handler =new MockTestParser($this);
- $target = array("a", "b", "a", "bb", "x", "b", "a", "xxxxxx", "a", "x");
- for ($i = 0; $i < count($target); $i++) {
- $handler->expectArgumentsAt($i, "accept", array($target[$i], '*'));
- }
- $handler->expectCallCount("accept", count($target));
- $handler->setReturnValue("accept", true);
- $lexer =new ExpressionLexer($handler);
- $lexer->addPattern("a+");
- $lexer->addPattern("b+");
- $this->assertTrue($lexer->parse("ababbxbaxxxxxxax"));
- $handler->tally();
- }
-}
-
-class TestOfExpressionLexerModes extends UnitTestCase {
- function TestOfExpressionLexerModes() {
- $this->UnitTestCase();
- }
-
- function testIsolatedPattern() {
- $handler =new MockTestParser($this);
- $handler->expectArgumentsAt(0, "a", array("a", LEXER_MATCHED));
- $handler->expectArgumentsAt(1, "a", array("b", LEXER_UNMATCHED));
- $handler->expectArgumentsAt(2, "a", array("aa", LEXER_MATCHED));
- $handler->expectArgumentsAt(3, "a", array("bxb", LEXER_UNMATCHED));
- $handler->expectArgumentsAt(4, "a", array("aaa", LEXER_MATCHED));
- $handler->expectArgumentsAt(5, "a", array("x", LEXER_UNMATCHED));
- $handler->expectArgumentsAt(6, "a", array("aaaa", LEXER_MATCHED));
- $handler->expectArgumentsAt(7, "a", array("x", LEXER_UNMATCHED));
- $handler->expectCallCount("a", 8);
- $handler->setReturnValue("a", true);
- $lexer =new ExpressionLexer($handler, "a");
- $lexer->addPattern("a+", "a");
- $lexer->addPattern("b+", "b");
- $this->assertTrue($lexer->parse("abaabxbaaaxaaaax"));
- $handler->tally();
- }
-
- function testModeChange() {
- $handler =new MockTestParser($this);
- $handler->expectArgumentsAt(0, "a", array("a", LEXER_MATCHED));
- $handler->expectArgumentsAt(1, "a", array("b", LEXER_UNMATCHED));
- $handler->expectArgumentsAt(2, "a", array("aa", LEXER_MATCHED));
- $handler->expectArgumentsAt(3, "a", array("b", LEXER_UNMATCHED));
- $handler->expectArgumentsAt(4, "a", array("aaa", LEXER_MATCHED));
- $handler->expectArgumentsAt(0, "b", array(":", LEXER_ENTER));
- $handler->expectArgumentsAt(1, "b", array("a", LEXER_UNMATCHED));
- $handler->expectArgumentsAt(2, "b", array("b", LEXER_MATCHED));
- $handler->expectArgumentsAt(3, "b", array("a", LEXER_UNMATCHED));
- $handler->expectArgumentsAt(4, "b", array("bb", LEXER_MATCHED));
- $handler->expectArgumentsAt(5, "b", array("a", LEXER_UNMATCHED));
- $handler->expectArgumentsAt(6, "b", array("bbb", LEXER_MATCHED));
- $handler->expectArgumentsAt(7, "b", array("a", LEXER_UNMATCHED));
- $handler->expectCallCount("a", 5);
- $handler->expectCallCount("b", 8);
- $handler->setReturnValue("a", true);
- $handler->setReturnValue("b", true);
- $lexer =new ExpressionLexer($handler, "a");
- $lexer->addPattern("a+", "a");
- $lexer->addEntryPattern(":", "a", "b");
- $lexer->addPattern("b+", "b");
- $this->assertTrue($lexer->parse("abaabaaa:ababbabbba"));
- $handler->tally();
- }
-
- function testNesting() {
- $handler =new MockTestParser($this);
- $handler->setReturnValue("a", true);
- $handler->setReturnValue("b", true);
- $handler->expectArgumentsAt(0, "a", array("aa", LEXER_MATCHED));
- $handler->expectArgumentsAt(1, "a", array("b", LEXER_UNMATCHED));
- $handler->expectArgumentsAt(2, "a", array("aa", LEXER_MATCHED));
- $handler->expectArgumentsAt(3, "a", array("b", LEXER_UNMATCHED));
- $handler->expectArgumentsAt(0, "b", array("(", LEXER_ENTER));
- $handler->expectArgumentsAt(1, "b", array("bb", LEXER_MATCHED));
- $handler->expectArgumentsAt(2, "b", array("a", LEXER_UNMATCHED));
- $handler->expectArgumentsAt(3, "b", array("bb", LEXER_MATCHED));
- $handler->expectArgumentsAt(4, "b", array(")", LEXER_EXIT));
- $handler->expectArgumentsAt(4, "a", array("aa", LEXER_MATCHED));
- $handler->expectArgumentsAt(5, "a", array("b", LEXER_UNMATCHED));
- $handler->expectCallCount("a", 6);
- $handler->expectCallCount("b", 5);
- $lexer =new ExpressionLexer($handler, "a");
- $lexer->addPattern("a+", "a");
- $lexer->addEntryPattern("(", "a", "b");
- $lexer->addPattern("b+", "b");
- $lexer->addExitPattern(")", "b");
- $this->assertTrue($lexer->parse("aabaab(bbabb)aab"));
- $handler->tally();
- }
-
- function testSingular() {
- $handler =new MockTestParser($this);
- $handler->setReturnValue("a", true);
- $handler->setReturnValue("b", true);
- $handler->expectArgumentsAt(0, "a", array("aa", LEXER_MATCHED));
- $handler->expectArgumentsAt(1, "a", array("aa", LEXER_MATCHED));
- $handler->expectArgumentsAt(2, "a", array("xx", LEXER_UNMATCHED));
- $handler->expectArgumentsAt(3, "a", array("xx", LEXER_UNMATCHED));
- $handler->expectArgumentsAt(0, "b", array("b", LEXER_SPECIAL));
- $handler->expectArgumentsAt(1, "b", array("bbb", LEXER_SPECIAL));
- $handler->expectCallCount("a", 4);
- $handler->expectCallCount("b", 2);
- $lexer =new ExpressionLexer($handler, "a");
- $lexer->addPattern("a+", "a");
- $lexer->addSpecialPattern("b+", "a", "b");
- $this->assertTrue($lexer->parse("aabaaxxbbbxx"));
- $handler->tally();
- }
-
- function testUnwindTooFar() {
- $handler =new MockTestParser($this);
- $handler->setReturnValue("a", true);
- $handler->expectArgumentsAt(0, "a", array("aa", LEXER_MATCHED));
- $handler->expectArgumentsAt(1, "a", array(")", LEXER_EXIT));
- $handler->expectCallCount("a", 2);
- $lexer =new ExpressionLexer($handler, "a");
- $lexer->addPattern("a+", "a");
- $lexer->addExitPattern(")", "a");
- $this->assertFalse($lexer->parse("aa)aa"));
- $handler->tally();
- }
-}
-
-class TestOfExpressionLexerHandlers extends UnitTestCase {
- function TestOfExpressionLexerHandlers() {
- $this->UnitTestCase();
- }
-
- function testModeMapping() {
- $handler =new MockTestParser($this);
- $handler->setReturnValue("a", true);
- $handler->expectArgumentsAt(0, "a", array("aa", LEXER_MATCHED));
- $handler->expectArgumentsAt(1, "a", array("(", LEXER_ENTER));
- $handler->expectArgumentsAt(2, "a", array("bb", LEXER_MATCHED));
- $handler->expectArgumentsAt(3, "a", array("a", LEXER_UNMATCHED));
- $handler->expectArgumentsAt(4, "a", array("bb", LEXER_MATCHED));
- $handler->expectArgumentsAt(5, "a", array(")", LEXER_EXIT));
- $handler->expectArgumentsAt(6, "a", array("b", LEXER_UNMATCHED));
- $handler->expectCallCount("a", 7);
- $lexer =new ExpressionLexer($handler, "mode_a");
- $lexer->addPattern("a+", "mode_a");
- $lexer->addEntryPattern("(", "mode_a", "mode_b");
- $lexer->addPattern("b+", "mode_b");
- $lexer->addExitPattern(")", "mode_b");
- $lexer->mapHandler("mode_a", "a");
- $lexer->mapHandler("mode_b", "a");
- $this->assertTrue($lexer->parse("aa(bbabb)b"));
- $handler->tally();
- }
-}
-?>
\ No newline at end of file
Deleted: trunk/wact/template/compiler/expression/missingformatter.test.php
===================================================================
--- trunk/wact/template/compiler/expression/missingformatter.test.php 2007-03-28 23:19:56 UTC (rev 405)
+++ trunk/wact/template/compiler/expression/missingformatter.test.php 2007-03-28 23:43:14 UTC (rev 406)
@@ -1,31 +0,0 @@
-<?php
-
-require_once 'wact/template/compiler/expression/missingformatter.xcpt.php';
-
-class WactMissingFormatterExceptionTestCase extends WactTestCase {
-
- function testException() {
- try {
- $fileName = 'testfile';
- $lineNo = 123;
- $formatter = 'testformatter';
-
- throw new WactMissingFormatterException($fileName, $lineNo, $formatter);
-
- $this->fail('Expected exception not thrown');
- } catch (WactMissingFormatterException $e) {
- $this->pass();
-
- $this->assertEqual($e->getFilename(), $fileName);
- $this->assertEqual($e->getLineno(), $lineNo);
- $this->assertEqual($e->getFormatter(), $formatter);
-
- $this->assertIsIn($fileName, $e->getMessage());
- $this->assertIsIn($lineNo, $e->getMessage());
- $this->assertIsIn($formatter, $e->getMessage());
- }
- }
-
-}
-
-?>
Deleted: trunk/wact/template/compiler/expression/missingformatter.xcpt.php
===================================================================
--- trunk/wact/template/compiler/expression/missingformatter.xcpt.php 2007-03-28 23:19:56 UTC (rev 405)
+++ trunk/wact/template/compiler/expression/missingformatter.xcpt.php 2007-03-28 23:43:14 UTC (rev 406)
@@ -1,45 +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
-*/
-if (!class_exists('WactFormatterException', FALSE)) {
- require_once 'wact/template/compiler/expression/formatter.xcpt.php';
-}
-
-/**
-* @package Template
-*/
-class WactMissingFormatterException extends WactFormatterException {
-
- /**
- * Class constructor.
- * @param string file Filename
- * @param string line Line number
- */
- public function __construct($filename, $lineno, $formatter) {
- parent::__construct(
- $filename,
- $lineno,
- $formatter,
- 'Unknown formatter "{formatter}" in template file "{Filename}" on line {Lineno}'
- );
- }
-
-}
-
-?>
\ No newline at end of file
Deleted: trunk/wact/template/compiler/expression/missingformatterparameter.test.php
===================================================================
--- trunk/wact/template/compiler/expression/missingformatterparameter.test.php 2007-03-28 23:19:56 UTC (rev 405)
+++ trunk/wact/template/compiler/expression/missingformatterparameter.test.php 2007-03-28 23:43:14 UTC (rev 406)
@@ -1,31 +0,0 @@
-<?php
-
-require_once 'wact/template/compiler/expression/missingformatterparameter.xcpt.php';
-
-class WactMissingFormatterParameterExceptionTestCase extends WactTestCase {
-
- function testException() {
- try {
- $fileName = 'testfile';
- $lineNo = 123;
- $formatter = 'testformatter';
-
- throw new WactMissingFormatterParameterException($fileName, $lineNo, $formatter);
-
- $this->fail('Expected exception not thrown');
- } catch (WactMissingFormatterParameterException $e) {
- $this->pass();
-
- $this->assertEqual($e->getFilename(), $fileName);
- $this->assertEqual($e->getLineno(), $lineNo);
- $this->assertEqual($e->getFormatter(), $formatter);
-
- $this->assertIsIn($fileName, $e->getMessage());
- $this->assertIsIn($lineNo, $e->getMessage());
- $this->assertIsIn($formatter, $e->getMessage());
- }
- }
-
-}
-
-?>
Deleted: trunk/wact/template/compiler/expression/missingformatterparameter.xcpt.php
===================================================================
--- trunk/wact/template/compiler/expression/missingformatterparameter.xcpt.php 2007-03-28 23:19:56 UTC (rev 405)
+++ trunk/wact/template/compiler/expression/missingformatterparameter.xcpt.php 2007-03-28 23:43:14 UTC (rev 406)
@@ -1,45 +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
-*/
-if (!class_exists('WactFilterException', FALSE)) {
- require_once 'wact/template/compiler/expression/formatter.xcpt.php';
-}
-
-/**
-* @package Template
-*/
-class WactMissingFormatterParameterException extends WactFormatterException {
-
- /**
- * Class constructor.
- * @param string file Filename
- * @param string line Line number
- */
- public function __construct($filename, $lineno, $formatter) {
- parent::__construct(
- $filename,
- $lineno,
- $formatter,
- 'Missing formatter parameter for formatter "{formatter}" in template file "{Filename}" on line {Lineno}'
- );
- }
-
-}
-
-?>
\ No newline at end of file
Deleted: trunk/wact/template/compiler/expression/output.inc.php
===================================================================
--- trunk/wact/template/compiler/expression/output.inc.php 2007-03-28 23:19:56 UTC (rev 405)
+++ trunk/wact/template/compiler/expression/output.inc.php 2007-03-28 23:43:14 UTC (rev 406)
@@ -1,66 +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/node/template.inc.php';
-require_once 'wact/template/compiler/expression/expression.inc.php';
-
-/**
-* Outputs the resultof an expression
-* @see CoreOutputTag
-* @see http://wact.sourceforge.net/index.php/CoreOutputTag
-*/
-class OutputExpression extends WactTemplateNode {
-
- /**
- * @var Expression
- */
- var $expression;
-
- /**
- */
- function __construct($tag, $tagInfo, $sourceLocation, $expression, $formatterDictionary) {
- parent::__construct($tag, $tagInfo, $sourceLocation);
- $this->expression = new Expression($expression, $this, $formatterDictionary, 'html');
- }
-
- /**
- */
- function prepare() {
- $this->expression->prepare();
- parent::prepare();
- }
-
- /**
- * @param CodeWriter
- * @return void
- */
- function generate($code) {
- if ($this->expression->isConstant()) {
- $code->writeHTML($this->expression->getValue());
- } else {
- $this->expression->generatePreStatement($code);
- $code->writePHP('echo ');
- $this->expression->generateExpression($code);
- $code->writePHP(';');
- $this->expression->generatePostStatement($code);
- }
- }
-
-}
-?>
\ No newline at end of file
Deleted: trunk/wact/template/compiler/expression/toomanyparameters.test.php
===================================================================
--- trunk/wact/template/compiler/expression/toomanyparameters.test.php 2007-03-28 23:19:56 UTC (rev 405)
+++ trunk/wact/template/compiler/expression/toomanyparameters.test.php 2007-03-28 23:43:14 UTC (rev 406)
@@ -1,31 +0,0 @@
-<?php
-
-require_once 'wact/template/compiler/expression/toomanyparameters.xcpt.php';
-
-class WactTooManyParametersExceptionTestCase extends WactTestCase {
-
- function testException() {
- try {
- $fileName = 'testfile';
- $lineNo = 123;
- $formatter = 'testformatter';
-
- throw new WactTooManyParametersException($fileName, $lineNo, $formatter);
-
- $this->fail('Expected exception not thrown');
- } catch (WactTooManyParametersException $e) {
- $this->pass();
-
- $this->assertEqual($e->getFilename(), $fileName);
- $this->assertEqual($e->getLineno(), $lineNo);
- $this->assertEqual($e->getFormatter(), $formatter);
-
- $this->assertIsIn($fileName, $e->getMessage());
- $this->assertIsIn($lineNo, $e->getMessage());
- $this->assertIsIn($formatter, $e->getMessage());
- }
- }
-
-}
-
-?>
Deleted: trunk/wact/template/compiler/expression/toomanyparameters.xcpt.php
===================================================================
--- trunk/wact/template/compiler/expression/toomanyparameters.xcpt.php 2007-03-28 23:19:56 UTC (rev 405)
+++ trunk/wact/template/compiler/expression/toomanyparameters.xcpt.php 2007-03-28 23:43:14 UTC (rev 406)
@@ -1,45 +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
-*/
-if (!class_exists('WactFormatterException', FALSE)) {
- require_once 'wact/template/compiler/expression/formatter.xcpt.php';
-}
-
-/**
-* @package Template
-*/
-class WactTooManyParametersException extends WactFormatterException {
-
- /**
- * Class constructor.
- * @param string file Filename
- * @param string line Line number
- */
- public function __construct($filename, $lineno, $formatter) {
- parent::__construct(
- $filename,
- $lineno,
- $formatter,
- 'Too many parameters for formatter "{formatter}" in template file "{Filename}" on line {Lineno}'
- );
- }
-
-}
-
-?>
\ No newline at end of file
Deleted: trunk/wact/template/compiler/expression/unresolvedbinding.test.php
===================================================================
--- trunk/wact/template/compiler/expression/unresolvedbinding.test.php 2007-03-28 23:19:56 UTC (rev 405)
+++ trunk/wact/template/compiler/expression/unresolvedbinding.test.php 2007-03-28 23:43:14 UTC (rev 406)
@@ -1,31 +0,0 @@
-<?php
-
-require_once 'wact/template/compiler/expression/unresolvedbinding.xcpt.php';
-
-class WactUnresolvedBindingExceptionTestCase extends WactTestCase {
-
- function testException() {
- try {
- $fileName = 'testfile';
- $lineNo = 123;
- $expression = 'testexpression';
- $message = 'testmessage';
- throw new WactUnresolvedBindingException($fileName, $lineNo, $expression);
-
- $this->fail('Expected exception not thrown');
- } catch (WactUnresolvedBindingException $e) {
- $this->pass();
-
- $this->assertEqual($e->getFilename(), $fileName);
- $this->assertEqual($e->getLineno(), $lineNo);
- $this->assertEqual($e->getExpression(), $expression);
-
- $this->assertIsIn($fileName, $e->getMessage());
- $this->assertIsIn($lineNo, $e->getMessage());
- $this->assertIsIn($expression, $e->getMessage());
- }
- }
-
-}
-
-?>
Deleted: trunk/wact/template/compiler/expression/unresolvedbinding.xcpt.php
===================================================================
--- trunk/wact/template/compiler/expression/unresolvedbinding.xcpt.php 2007-03-28 23:19:56 UTC (rev 405)
+++ trunk/wact/template/compiler/expression/unresolvedbinding.xcpt.php 2007-03-28 23:43:14 UTC (rev 406)
@@ -1,44 +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
-*/
-if (!class_exists('WactExpressionException', FALSE)) {
- require_once 'wact/template/compiler/expression/expression.xcpt.php';
-}
-
-/**
-* @package Template
-*/
-class WactUnresolvedBindingException extends WactExpressionException {
-
- /**
- * Class constructor.
- * @param string file Filename
- * @param string line Line number
- */
- public function __construct($filename, $lineno, $expression) {
- parent::__construct(
- $filename,
- $lineno,
- $expression,
- 'Cannot resolve data binding "{Expression}" (attribute must resolve to a constant value) in template file "{Filename}" on line {Lineno}'
- );
- }
-}
-
-?>
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|