- * require_once 'PEAR/Exception.php';
- *
- * class Test {
- * function foo() {
- * throw new PEAR_Exception('Error Message', ERROR_CODE);
- * }
- * }
- *
- * function myLogger($pear_exception) {
- * echo $pear_exception->getMessage();
- * }
- * // each time a exception is thrown the 'myLogger' will be called
- * // (its use is completely optional)
- * PEAR_Exception::addObserver('myLogger');
- * $test = new Test;
- * try {
- * $test->foo();
- * } catch (PEAR_Exception $e) {
- * print $e;
- * }
- *
- *
- * @category pear
- * @package PEAR
- * @author Tomas V.V.Cox - * array('name' => $name, 'context' => array(...)) - *- * @return array - */ - public function getErrorData() - { - return array(); - } - - /** - * Returns the exception that caused this exception to be thrown - * @access public - * @return Exception|array The context of the exception - */ - public function getCause() - { - return $this->cause; - } - - /** - * Function must be public to call on caused exceptions - * @param array - */ - public function getCauseMessage(&$causes) - { - $trace = $this->getTraceSafe(); - $cause = array('class' => get_class($this), - 'message' => $this->message, - 'file' => 'unknown', - 'line' => 'unknown'); - if (isset($trace[0])) { - if (isset($trace[0]['file'])) { - $cause['file'] = $trace[0]['file']; - $cause['line'] = $trace[0]['line']; - } - } - $causes[] = $cause; - if ($this->cause instanceof PEAR_Exception) { - $this->cause->getCauseMessage($causes); - } elseif ($this->cause instanceof Exception) { - $causes[] = array('class' => get_class($this->cause), - 'message' => $this->cause->getMessage(), - 'file' => $this->cause->getFile(), - 'line' => $this->cause->getLine()); - } elseif (class_exists('PEAR_Error',false) && $this->cause instanceof PEAR_Error) { - $causes[] = array('class' => get_class($this->cause), - 'message' => $this->cause->getMessage(), - 'file' => 'unknown', - 'line' => 'unknown'); - } elseif (is_array($this->cause)) { - foreach ($this->cause as $cause) { - if ($cause instanceof PEAR_Exception) { - $cause->getCauseMessage($causes); - } elseif ($cause instanceof Exception) { - $causes[] = array('class' => get_class($cause), - 'message' => $cause->getMessage(), - 'file' => $cause->getFile(), - 'line' => $cause->getLine()); - } elseif (class_exists('PEAR_Error',false) && $cause instanceof PEAR_Error) { - $causes[] = array('class' => get_class($cause), - 'message' => $cause->getMessage(), - 'file' => 'unknown', - 'line' => 'unknown'); - } elseif (is_array($cause) && isset($cause['message'])) { - // PEAR_ErrorStack warning - $causes[] = array( - 'class' => $cause['package'], - 'message' => $cause['message'], - 'file' => isset($cause['context']['file']) ? - $cause['context']['file'] : - 'unknown', - 'line' => isset($cause['context']['line']) ? - $cause['context']['line'] : - 'unknown', - ); - } - } - } - } - - public function getTraceSafe() - { - if (!isset($this->_trace)) { - $this->_trace = $this->getTrace(); - if (empty($this->_trace)) { - $backtrace = debug_backtrace(); - $this->_trace = array($backtrace[count($backtrace)-1]); - } - } - - return $this->_trace; - } - - public function getErrorClass() - { - $trace = $this->getTraceSafe(); - - return $trace[0]['class']; - } - - public function getErrorMethod() - { - $trace = $this->getTraceSafe(); - - return $trace[0]['function']; - } - - public function __toString() - { - if (isset($_SERVER['REQUEST_URI'])) { - return $this->toHtml(); - } - - return $this->toText(); - } - - public function toHtml() - { - $trace = $this->getTraceSafe(); - $causes = array(); - $this->getCauseMessage($causes); - $html = '
' - . str_repeat('-', $i) . ' ' . $cause['class'] . ': ' - . htmlspecialchars($cause['message']) . ' in ' . $cause['file'] . ' ' - . 'on line ' . $cause['line'] . '' - . " | ||
Exception trace | ||
# | ' - . 'Function | ' - . 'Location |
' . $k . ' | ' - . ''; - if (!empty($v['class'])) { - $html .= $v['class'] . $v['type']; - } - $html .= $v['function']; - $args = array(); - if (!empty($v['args'])) { - foreach ($v['args'] as $arg) { - if (is_null($arg)) $args[] = 'null'; - elseif (is_array($arg)) $args[] = 'Array'; - elseif (is_object($arg)) $args[] = 'Object('.get_class($arg).')'; - elseif (is_bool($arg)) $args[] = $arg ? 'true' : 'false'; - elseif (is_int($arg) || is_double($arg)) $args[] = $arg; - else { - $arg = (string) $arg; - $str = htmlspecialchars(substr($arg, 0, 16)); - if (strlen($arg) > 16) $str .= '…'; - $args[] = "'" . $str . "'"; - } - } - } - $html .= '(' . implode(', ',$args) . ')' - . ' | ' - . '' . (isset($v['file']) ? $v['file'] : 'unknown') - . ':' . (isset($v['line']) ? $v['line'] : 'unknown') - . ' |
' . ($k+1) . ' | ' - . '{main} | ' - . '
- * require_once 'PHP/LexerGenerator.php';
- * $lex = new PHP_LexerGenerator('/path/to/lexerfile.plex');
+ * $lex = new Smarty_LexerGenerator('/path/to/lexerfile.plex');
*
*
* A file named "/path/to/lexerfile.php" will be created.
@@ -236,7 +228,7 @@
*
*
* Note that this procedure is exceptionally inefficient, and it would be far better
- * to take advantage of PHP_LexerGenerator's top-down precedence and instead code:
+ * to take advantage of Smarty_LexerGenerator's top-down precedence and instead code:
*
*
* /*!lex2php
@@ -248,7 +240,7 @@
* }
* {@*}
*
- * @package PHP_LexerGenerator
+
* @author Gregory Beaver * blah ::= FOO bar. *- * @var PHP_ParserGenerator_Rule + * @var Rule */ public $rp; /** @@ -105,17 +107,17 @@ class PHP_ParserGenerator_Config public $fws; /** * Follow-set forward propagation links. - * @var PHP_ParserGenerator_PropagationLink + * @var PropagationLink */ public $fplp; /** * Follow-set backwards propagation links - * @var PHP_ParserGenerator_PropagationLink + * @var PropagationLink */ public $bplp; /** * State that contains this configuration - * @var PHP_ParserGenerator_State + * @var State */ public $stp; /* enum { @@ -125,43 +127,43 @@ class PHP_ParserGenerator_Config /** * Status during followset and shift computations. * - * One of PHP_ParserGenerator_Config::COMPLETE or - * PHP_ParserGenerator_Config::INCOMPLETE. + * One of Config::COMPLETE or + * Config::INCOMPLETE. * @var int */ public $status; /** * Next configuration in the state. * - * Index of next PHP_ParserGenerator_Config object. + * Index of next Config object. * @var int */ public $next; /** - * Index of the next basis configuration PHP_ParserGenerator_Config object + * Index of the next basis configuration Config object * @var int */ public $bp; /** * Top of the list of configurations for the current state. - * @var PHP_ParserGenerator_Config + * @var Config */ public static $current; /** * Last on the list of configurations for the current state. - * @var PHP_ParserGenerator_Config + * @var Config */ public static $currentend; /** * Top of the list of basis configurations for the current state. - * @var PHP_ParserGenerator_Config + * @var Config */ public static $basis; /** * Last on the list of basis configurations for the current state. - * @var PHP_ParserGenerator_Config + * @var Config */ public static $basisend; @@ -175,20 +177,20 @@ class PHP_ParserGenerator_Config /** * Return a pointer to a new configuration - * @return PHP_ParserGenerator_Config + * @return Config */ private static function newconfig() { - return new PHP_ParserGenerator_Config; + return new Config; } /** * Display the current configuration for the .out file * - * @param PHP_ParserGenerator_Config $cfp - * @see PHP_ParserGenerator_Data::ReportOutput() + * @param Config $cfp + * @see Data::ReportOutput() */ - public static function Configshow(PHP_ParserGenerator_Config $cfp) + public static function Configshow(Config $cfp) { $fp = fopen('php://output', 'w'); while ($cfp) { @@ -272,13 +274,13 @@ public static function Configlist_reset() /** * Add another configuration to the configuration list for this parser state. - * @param PHP_ParserGenerator_Rule the rule + * @param Rule the rule * @param int Index into the right-hand side of the rule where the dot goes - * @return PHP_ParserGenerator_Config + * @return Config */ public static function Configlist_add($rp, $dot) { - $model = new PHP_ParserGenerator_Config; + $model = new Config; $model->rp = $rp; $model->dot = $dot; $cfp = self::Configtable_find($model); @@ -305,13 +307,13 @@ public static function Configlist_add($rp, $dot) * Basis configurations are the root for a configuration. This method also * inserts the configuration into the regular list of configurations for this * reason. - * @param PHP_ParserGenerator_Rule the rule + * @param Rule the rule * @param int Index into the right-hand side of the rule where the dot goes - * @return PHP_ParserGenerator_Config + * @return Config */ public static function Configlist_addbasis($rp, $dot) { - $model = new PHP_ParserGenerator_Config; + $model = new Config; $model->rp = $rp; $model->dot = $dot; $cfp = self::Configtable_find($model); @@ -341,7 +343,7 @@ public static function Configlist_addbasis($rp, $dot) * each configuration, ensuring that each state accounts * for every configuration that could arrive at that state. */ - public static function Configlist_closure(PHP_ParserGenerator_Data $lemp) + public static function Configlist_closure(Data $lemp) { for ($cfp = self::$current; $cfp; $cfp = $cfp->next) { $rp = $cfp->rp; @@ -350,9 +352,9 @@ public static function Configlist_closure(PHP_ParserGenerator_Data $lemp) continue; } $sp = $rp->rhs[$dot]; - if ($sp->type == PHP_ParserGenerator_Symbol::NONTERMINAL) { + if ($sp->type == Symbol::NONTERMINAL) { if ($sp->rule === 0 && $sp !== $lemp->errsym) { - PHP_ParserGenerator::ErrorMsg($lemp->filename, $rp->line, + \SmartyGenerator\ParserGenerator::ErrorMsg($lemp->filename, $rp->line, "Nonterminal \"%s\" has no rules.", $sp->name); $lemp->errorcnt++; } @@ -360,10 +362,10 @@ public static function Configlist_closure(PHP_ParserGenerator_Data $lemp) $newcfp = self::Configlist_add($newrp, 0); for ($i = $dot + 1; $i < $rp->nrhs; $i++) { $xsp = $rp->rhs[$i]; - if ($xsp->type == PHP_ParserGenerator_Symbol::TERMINAL) { + if ($xsp->type == Symbol::TERMINAL) { $newcfp->fws[$xsp->index] = 1; break; - } elseif ($xsp->type == PHP_ParserGenerator_Symbol::MULTITERMINAL) { + } elseif ($xsp->type == Symbol::MULTITERMINAL) { for ($k = 0; $k < $xsp->nsubsym; $k++) { $newcfp->fws[$xsp->subsym[$k]->index] = 1; } @@ -377,7 +379,7 @@ public static function Configlist_closure(PHP_ParserGenerator_Data $lemp) } } if ($i == $rp->nrhs) { - PHP_ParserGenerator_PropagationLink::Plink_add($cfp->fplp, $newcfp); + PropagationLink::Plink_add($cfp->fplp, $newcfp); } } } @@ -392,7 +394,7 @@ public static function Configlist_sort() { $a = 0; //self::Configshow(self::$current); - self::$current = PHP_ParserGenerator::msort(self::$current,'next', array('PHP_ParserGenerator_Config', 'Configcmp')); + self::$current = \SmartyGenerator\ParserGenerator::msort(self::$current,'next', array(Config::class, 'Configcmp')); //self::Configshow(self::$current); self::$currentend = &$a; self::$currentend = 0; @@ -405,7 +407,7 @@ public static function Configlist_sort() public static function Configlist_sortbasis() { $a = 0; - self::$basis = PHP_ParserGenerator::msort(self::$current,'bp', array('PHP_ParserGenerator_Config', 'Configcmp')); + self::$basis = \SmartyGenerator\ParserGenerator::msort(self::$current,'bp', array(Config::class, 'Configcmp')); self::$basisend = &$a; self::$basisend = 0; } @@ -414,7 +416,7 @@ public static function Configlist_sortbasis() * Return a pointer to the head of the configuration list and * reset the list * @see $current - * @return PHP_ParserGenerator_Config + * @return Config */ public static function Configlist_return() { @@ -429,7 +431,7 @@ public static function Configlist_return() * Return a pointer to the head of the basis list and * reset the list * @see $basis - * @return PHP_ParserGenerator_Config + * @return Config */ public static function Configlist_basis() { @@ -442,7 +444,7 @@ public static function Configlist_basis() /** * Free all elements of the given configuration list - * @param PHP_ParserGenerator_Config + * @param Config */ public static function Configlist_eat($cfp) { @@ -487,7 +489,7 @@ public static function Configcmp($a, $b) * Print out information on this configuration. * * @param resource $fp - * @see PHP_ParserGenerator_Data::ReportOutput() + * @see Data::ReportOutput() */ public function ConfigPrint($fp) { @@ -502,7 +504,7 @@ public function ConfigPrint($fp) } $sp = $rp->rhs[$i]; fprintf($fp,' %s', $sp->name); - if ($sp->type == PHP_ParserGenerator_Symbol::MULTITERMINAL) { + if ($sp->type == Symbol::MULTITERMINAL) { for ($j = 1; $j < $sp->nsubsym; $j++) { fprintf($fp, '|%s', $sp->subsym[$j]->name); } @@ -513,7 +515,7 @@ public function ConfigPrint($fp) /** * Hash a configuration for the associative array {@link $x4a} */ - private static function confighash(PHP_ParserGenerator_Config $a) + private static function confighash(Config $a) { $h = 0; $h = $h * 571 + $a->rp->index * 37 + $a->dot; @@ -525,7 +527,7 @@ private static function confighash(PHP_ParserGenerator_Config $a) * Insert a new record into the array. Return TRUE if successful. * Prior data with the same key is NOT overwritten */ - public static function Configtable_insert(PHP_ParserGenerator_Config $data) + public static function Configtable_insert(Config $data) { $h = self::confighash($data); if (isset(self::$x4a[$h])) { @@ -544,7 +546,7 @@ public static function Configtable_insert(PHP_ParserGenerator_Config $data) } /* Insert the new data */ $np = array('data' => $data, 'next' => 0, 'from' => 0); - $np = new PHP_ParserGenerator_StateNode; + $np = new StateNode; $np->data = $data; if (isset(self::$x4a[$h])) { self::$x4a[$h]->from = $np->next; @@ -559,9 +561,9 @@ public static function Configtable_insert(PHP_ParserGenerator_Config $data) /** * Return a pointer to data assigned to the given key. Return NULL * if no such key. - * @return PHP_ParserGenerator_Config|0 + * @return Config|0 */ - public static function Configtable_find(PHP_ParserGenerator_Config $key) + public static function Configtable_find(Config $key) { $h = self::confighash($key); if (!isset(self::$x4a[$h])) { diff --git a/ParserGenerator/Data.php b/src/SmartyGenerator/ParserGenerator/Data.php similarity index 85% rename from ParserGenerator/Data.php rename to src/SmartyGenerator/ParserGenerator/Data.php index 78ec93c..03fc7de 100644 --- a/ParserGenerator/Data.php +++ b/src/SmartyGenerator/ParserGenerator/Data.php @@ -1,6 +1,8 @@ * @copyright 2006 Gregory Beaver * @license http://www.opensource.org/licenses/bsd-license.php New BSD License @@ -50,7 +52,7 @@ * The state vector for the entire parser generator is recorded in * this class. * - * @package PHP_ParserGenerator + * @package \Smarty\ParserGenerator * @author Gregory Beaver