diff --git a/.gitignore b/.gitignore index 92874f6..f216044 100644 --- a/.gitignore +++ b/.gitignore @@ -1,218 +1,3 @@ -################# -## Eclipse -################# - -*.pydevproject -.project -.metadata -bin/ -tmp/ -*.tmp -*.bak -*.swp -*~.nib -local.properties -.classpath -.settings/ -.loadpath - -# External tool builders -.externalToolBuilders/ - -# Locally stored "Eclipse launch configurations" -*.launch - -# CDT-specific -.cproject - -# PDT-specific -.buildpath - - -################# -## Visual Studio -################# - -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. - -# User-specific files -*.suo -*.user -*.sln.docstates - -# Build results - -[Dd]ebug/ -[Rr]elease/ -x64/ -build/ -[Bb]in/ -[Oo]bj/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -*_i.c -*_p.c -*.ilk -*.meta -*.obj -*.pch -*.pdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*.log -*.vspscc -*.vssscc -.builds -*.pidb -*.log -*.scc - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opensdf -*.sdf -*.cachefile - -# Visual Studio profiler -*.psess -*.vsp -*.vspx - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# NCrunch -*.ncrunch* -.*crunch*.local.xml - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.Publish.xml -*.pubxml - -# NuGet Packages Directory -## TODO: If you have NuGet Package Restore enabled, uncomment the next line -#packages/ - -# Windows Azure Build Output -csx -*.build.csdef - -# Windows Store app package directory -AppPackages/ - -# Others -sql/ -*.Cache -ClientBin/ -[Ss]tyle[Cc]op.* -~$* -*~ -*.dbmdl -*.[Pp]ublish.xml -*.pfx -*.publishsettings - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file to a newer -# Visual Studio version. Backup files are not needed, because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm - -# SQL Server files -App_Data/*.mdf -App_Data/*.ldf - -############# -## Windows detritus -############# - -# Windows image file caches -Thumbs.db -ehthumbs.db - -# Folder config file -Desktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Mac crap -.DS_Store - - -############# -## Python -############# - -*.py[co] - -# Packages -*.egg -*.egg-info -dist/ -build/ -eggs/ -parts/ -var/ -sdist/ -develop-eggs/ -.installed.cfg - -# Installer logs -pip-log.txt - -# Unit test / coverage reports -.coverage -.tox - -#Translations -*.mo - -#Mr Developer -.mr.developer.cfg - .idea/ - +/composer.lock +vendor/* diff --git a/Create_Config_Parser.php b/Create_Config_Parser.php deleted file mode 100644 index bbb933e..0000000 --- a/Create_Config_Parser.php +++ /dev/null @@ -1,28 +0,0 @@ -
Fatal error: Missing lexer / parser definition folder \'lexer\' in distribution
'; - exit(1); -} -copy("{$smartyPath}smarty_internal_configfilelexer.php", "{$lexerPath}smarty_internal_configfilelexer.php.bak"); -copy("{$smartyPath}smarty_internal_configfileparser.php", "{$lexerPath}smarty_internal_configfileparser.php.bak"); - -// Create Lexer -require_once './LexerGenerator.php'; -$lex = new PHP_LexerGenerator("{$lexerPath}smarty_internal_configfilelexer.plex"); -unset($lex); - -// Create Parser -require_once './ParserGenerator.php'; -$parser = new PHP_ParserGenerator(); -$parser->main("{$lexerPath}smarty_internal_configfileparser.y"); -unset($parser); - -$content = file_get_contents("{$lexerPath}smarty_internal_configfileparser.php"); -$content = preg_replace(array('#/\*\s*\d+\s*\*/#', "#'lhs'#", "#'rhs'#"), array('', 0, 1), $content); -file_put_contents("{$lexerPath}smarty_internal_configfileparser.php", $content); - -copy("{$lexerPath}smarty_internal_configfilelexer.php", "{$smartyPath}smarty_internal_configfilelexer.php"); -copy("{$lexerPath}smarty_internal_configfileparser.php", "{$smartyPath}smarty_internal_configfileparser.php"); - diff --git a/Create_Template_Parser.php b/Create_Template_Parser.php deleted file mode 100644 index bbbbf12..0000000 --- a/Create_Template_Parser.php +++ /dev/null @@ -1,30 +0,0 @@ -
Fatal error: Missing lexer / parser definition folder \'lexer\' in distribution
'; - exit(1); -} - -copy("{$smartyPath}smarty_internal_templatelexer.php", "{$lexerPath}smarty_internal_templatelexer.php.bak"); -copy("{$smartyPath}smarty_internal_templateparser.php", "{$lexerPath}smarty_internal_templateparser.php.bak"); -// Create Lexer -require_once './LexerGenerator.php'; -$lex = new PHP_LexerGenerator("{$lexerPath}smarty_internal_templatelexer.plex"); -unset($lex); - -// Create Parser -require_once './ParserGenerator.php'; -$parser = new PHP_ParserGenerator(); -$parser->main("{$lexerPath}smarty_internal_templateparser.y"); -unset($parser); - -$content = file_get_contents("{$lexerPath}smarty_internal_templateparser.php"); -$content = preg_replace(array('#/\*\s*\d+\s*\*/#', "#'lhs'#", "#'rhs'#"), array('', 0, 1), $content); -file_put_contents("{$lexerPath}smarty_internal_templateparser.php", $content); - -copy("{$lexerPath}smarty_internal_templatelexer.php", "{$smartyPath}smarty_internal_templatelexer.php"); -copy("{$lexerPath}smarty_internal_templateparser.php", "{$smartyPath}smarty_internal_templateparser.php"); diff --git a/Exception.php b/Exception.php deleted file mode 100644 index b315cff..0000000 --- a/Exception.php +++ /dev/null @@ -1,400 +0,0 @@ - - * @author Hans Lellelid - * @author Bertrand Mansion - * @author Greg Beaver - * @copyright 1997-2008 The PHP Group - * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Exception.php,v 1.29 2008/01/03 20:26:35 cellog Exp $ - * @link http://pear.php.net/package/PEAR - * @since File available since Release 1.3.3 - */ - -/** - * Base PEAR_Exception Class - * - * 1) Features: - * - * - Nestable exceptions (throw new PEAR_Exception($msg, $prev_exception)) - * - Definable triggers, shot when exceptions occur - * - Pretty and informative error messages - * - Added more context info available (like class, method or cause) - * - cause can be a PEAR_Exception or an array of mixed - * PEAR_Exceptions/PEAR_ErrorStack warnings - * - callbacks for specific exception classes and their children - * - * 2) Ideas: - * - * - Maybe a way to define a 'template' for the output - * - * 3) Inherited properties from PHP Exception Class: - * - * protected $message - * protected $code - * protected $line - * protected $file - * private $trace - * - * 4) Inherited methods from PHP Exception Class: - * - * __clone - * __construct - * getMessage - * getCode - * getFile - * getLine - * getTraceSafe - * getTraceSafeAsString - * __toString - * - * 5) Usage example - * - * - * 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 - * @author Hans Lellelid - * @author Bertrand Mansion - * @author Greg Beaver - * @copyright 1997-2008 The PHP Group - * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version Release: 1.7.2 - * @link http://pear.php.net/package/PEAR - * @since Class available since Release 1.3.3 - * - */ -class PEAR_Exception extends Exception -{ - const OBSERVER_PRINT = -2; - const OBSERVER_TRIGGER = -4; - const OBSERVER_DIE = -8; - protected $cause; - private static $_observers = array(); - private static $_uniqueid = 0; - private $_trace; - - /** - * Supported signatures: - * - PEAR_Exception(string $message); - * - PEAR_Exception(string $message, int $code); - * - PEAR_Exception(string $message, Exception $cause); - * - PEAR_Exception(string $message, Exception $cause, int $code); - * - PEAR_Exception(string $message, PEAR_Error $cause); - * - PEAR_Exception(string $message, PEAR_Error $cause, int $code); - * - PEAR_Exception(string $message, array $causes); - * - PEAR_Exception(string $message, array $causes, int $code); - * @param string exception message - * @param int|Exception|PEAR_Error|array|null exception cause - * @param int|null exception code or null - */ - public function __construct($message, $p2 = null, $p3 = null) - { - if (is_int($p2)) { - $code = $p2; - $this->cause = null; - } elseif (is_object($p2) || is_array($p2)) { - // using is_object allows both Exception and PEAR_Error - if (is_object($p2) && !($p2 instanceof Exception)) { - if (!class_exists('PEAR_Error',false) || !($p2 instanceof PEAR_Error)) { - throw new PEAR_Exception('exception cause must be Exception, ' . - 'array, or PEAR_Error'); - } - } - $code = $p3; - if (is_array($p2) && isset($p2['message'])) { - // fix potential problem of passing in a single warning - $p2 = array($p2); - } - $this->cause = $p2; - } else { - $code = null; - $this->cause = null; - } - parent::__construct($message, $code); - $this->signal(); - } - - /** - * @param mixed $callback - A valid php callback, see php func is_callable() - * - A PEAR_Exception::OBSERVER_* constant - * - An array(const PEAR_Exception::OBSERVER_*, - * mixed $options) - * @param string $label The name of the observer. Use this if you want - * to remove it later with removeObserver() - */ - public static function addObserver($callback, $label = 'default') - { - self::$_observers[$label] = $callback; - } - - public static function removeObserver($label = 'default') - { - unset(self::$_observers[$label]); - } - - /** - * @return int unique identifier for an observer - */ - public static function getUniqueId() - { - return self::$_uniqueid++; - } - - private function signal() - { - foreach (self::$_observers as $func) { - if (is_callable($func)) { - call_user_func($func, $this); - continue; - } - settype($func, 'array'); - switch ($func[0]) { - case self::OBSERVER_PRINT : - $f = (isset($func[1])) ? $func[1] : '%s'; - printf($f, $this->getMessage()); - break; - case self::OBSERVER_TRIGGER : - $f = (isset($func[1])) ? $func[1] : E_USER_NOTICE; - trigger_error($this->getMessage(), $f); - break; - case self::OBSERVER_DIE : - $f = (isset($func[1])) ? $func[1] : '%s'; - die(printf($f, $this->getMessage())); - break; - default: - trigger_error('invalid observer type', E_USER_WARNING); - } - } - } - - /** - * Return specific error information that can be used for more detailed - * error messages or translation. - * - * This method may be overridden in child exception classes in order - * to add functionality not present in PEAR_Exception and is a placeholder - * to define API - * - * The returned array must be an associative array of parameter => value like so: - *
-     * 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 = '' . "\n"; - foreach ($causes as $i => $cause) { - $html .= '\n"; - } - $html .= '' . "\n" - . '' - . '' - . '' . "\n"; - - foreach ($trace as $k => $v) { - $html .= '' - . '' - . '' . "\n"; - } - $html .= '' - . '' - . '' . "\n" - . '
' - . str_repeat('-', $i) . ' ' . $cause['class'] . ': ' - . htmlspecialchars($cause['message']) . ' in ' . $cause['file'] . ' ' - . 'on line ' . $cause['line'] . '' - . "
Exception trace
#FunctionLocation
' . $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} 
'; - - return $html; - } - - public function toText() - { - $causes = array(); - $this->getCauseMessage($causes); - $causeMsg = ''; - foreach ($causes as $i => $cause) { - $causeMsg .= str_repeat(' ', $i) . $cause['class'] . ': ' - . $cause['message'] . ' in ' . $cause['file'] - . ' on line ' . $cause['line'] . "\n"; - } - - return $causeMsg . $this->getTraceAsString(); - } -} diff --git a/LexerGenerator/cli.php b/LexerGenerator/cli.php deleted file mode 100644 index 1523331..0000000 --- a/LexerGenerator/cli.php +++ /dev/null @@ -1,3 +0,0 @@ -main(); diff --git a/README.md b/README.md index b177a8c..ac69803 100644 --- a/README.md +++ b/README.md @@ -1,36 +1,6 @@ -# Smarty 3 template engine -## Lexer/Parser generator repository +# Smarty Lexer/Parser generator -The "smarty/smarty-lexer" package is used to generate the lexer and parser class files. +The "smarty/smarty-lexer" package is used to generate the lexer and parser class files for the [Smarty](https://github.com/smarty-php/smarty) project. +Since Smarty v3.1.35, the correct smarty/smarty-lexer is automatically configured using composer. -**For Smarty versions >= 3.1.22 require "smarty/smarty-lexer": "~3.1" to get the latest version of the package** - - -**For Smarty versions <= 3.1.21 The "smarty/smarty-lexer" version must be identical with the target Smarty version** - -Use for example - - "require": { - "smarty/smarty-lexer": "3.1.18" - } - -in your composer.json file to get the generator for Smarty 3.1.18. - - - -To generate the template lexer and parser run: `php Create_Template_Parser.php` - -It will create -* `smarty_internal_templatelexer.php` from `smarty_internal_templatelexer.plex` -* `smarty_internal_templateparser.php` from `smarty_internal_templateparser.y` - -To generate the config file lexer and parser run: `php Create_Config_Parser.php` - -It will create -* `smarty_internal_configfilelexer.php` from `smarty_internal_configfilelexer.plex` -* `smarty_internal_configfileparser.php` from `smarty_internal_configfileparser.y` - -If the "smarty/smarty" package was installed by composer the generated lexer and parser files will be copied -automatically into the distribution. - \ No newline at end of file diff --git a/Lempar.php b/Resources/Lempar.lt similarity index 96% rename from Lempar.php rename to Resources/Lempar.lt index a78ac3f..685eee8 100644 --- a/Lempar.php +++ b/Resources/Lempar.lt @@ -1,14 +1,4 @@ yystack[$this->yyidx]->stateno, self::$yyRuleInfo[$yyruleno]['lhs']); if (isset(self::$yyExpectedTokens[$nextstate])) { - $expected = array_merge($expected, self::$yyExpectedTokens[$nextstate]); + $expected = array_merge($expected, self::$yyExpectedTokens[$nextstate]); if (isset($res4[$nextstate][$token])) { if ($res4[$nextstate][$token]) { $this->yyidx = $yyidx; @@ -155,7 +145,7 @@ public function yy_get_expected_tokens($token) if ($nextstate < self::YYNSTATE) { // we need to shift a non-terminal $this->yyidx++; - $x = new ParseyyStackEntry; + $x = (object) ['stateno' => null, 'major' => null, 'minor' => null]; $x->stateno = $nextstate; $x->major = self::$yyRuleInfo[$yyruleno]['lhs']; $this->yystack[$this->yyidx] = $x; @@ -179,8 +169,8 @@ public function yy_get_expected_tokens($token) } break; } while (true); - $this->yyidx = $yyidx; - $this->yystack = $stack; + $this->yyidx = $yyidx; + $this->yystack = $stack; return array_unique($expected); } @@ -238,7 +228,7 @@ public function yy_is_expected_token($token) if ($nextstate < self::YYNSTATE) { // we need to shift a non-terminal $this->yyidx++; - $x = new ParseyyStackEntry; + $x = (object) ['stateno' => null, 'major' => null, 'minor' => null]; $x->stateno = $nextstate; $x->major = self::$yyRuleInfo[$yyruleno]['lhs']; $this->yystack[$this->yyidx] = $x; @@ -346,7 +336,7 @@ public function yy_shift($yyNewState, $yyMajor, $yypMinor) return; } - $yytos = new ParseyyStackEntry; + $yytos = (object) ['stateno' => null, 'major' => null, 'minor' => null]; $yytos->stateno = $yyNewState; $yytos->major = $yyMajor; $yytos->minor = $yypMinor; @@ -401,7 +391,7 @@ public function yy_reduce($yyruleno) if ($yyact < self::YYNSTATE) { if (!$this->yyTraceFILE && $yysize) { $this->yyidx++; - $x = new ParseyyStackEntry; + $x = (object) ['stateno' => null, 'major' => null, 'minor' => null]; $x->stateno = $yyact; $x->major = $yygoto; $x->minor = $yy_lefthand_side; @@ -446,7 +436,7 @@ public function doParse($yymajor, $yytokenvalue) if ($this->yyidx === null || $this->yyidx < 0) { $this->yyidx = 0; $this->yyerrcnt = -1; - $x = new ParseyyStackEntry; + $x = (object) ['stateno' => null, 'major' => null, 'minor' => null]; $x->stateno = 0; $x->major = 0; $this->yystack = array(); diff --git a/composer.json b/composer.json index f23920c..8a46062 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,10 @@ { "name": "Rodney Rehm", "email": "rodney.rehm@medialize.de" + }, + { + "name": "Simon Wisselink", + "homepage": "https://www.iwink.nl/" } ], "support": { @@ -24,13 +28,12 @@ "issues": "http://code.google.com/p/smarty-php/issues/list", "forum": "http://www.smarty.net/forums/" }, + "autoload": { + "psr-4": { + "SmartyGenerator\\": "src/SmartyGenerator/" + } + }, "require": { - "php": ">=5.2" + "php": "^7.1 || ^8.0" }, - "extra": { - "branch-alias": { - "dev-master": "3.1.x-dev" - } - } - } diff --git a/LexerGenerator.php b/src/SmartyGenerator/LexerGenerator.php similarity index 88% rename from LexerGenerator.php rename to src/SmartyGenerator/LexerGenerator.php index 75d479a..80523d8 100644 --- a/LexerGenerator.php +++ b/src/SmartyGenerator/LexerGenerator.php @@ -1,6 +1,7 @@ * @copyright 2006 Gregory Beaver * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @version CVS: $Id: LexerGenerator.php 294970 2010-02-12 03:46:38Z clockwerx $ * @since File available since Release 0.1.0 */ -/** - * The Lexer generation parser - */ -require_once './LexerGenerator/Parser.php'; -/** - * Hand-written lexer for lex2php format files - */ -require_once './LexerGenerator/Lexer.php'; /** * The basic home class for the lexer generator. A lexer scans text and @@ -60,8 +53,7 @@ * * Sample Usage: * - * 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 * @copyright 2006 Gregory Beaver * @license http://www.php.net/license/3_01.txt PHP License 3.01 @@ -256,22 +248,22 @@ * @since Class available since Release 0.1.0 * @example TestLexer.plex Example lexer source * @example TestLexer.php Example lexer generated php code - * @example usage.php Example usage of PHP_LexerGenerator + * @example usage.php Example usage of Smarty_LexerGenerator * @example Lexer.plex File_ChessPGN lexer source (complex) * @example Lexer.php File_ChessPGN lexer generated php code */ -class PHP_LexerGenerator +class LexerGenerator { /** * Plex file lexer. - * @var PHP_LexerGenerator_Lexer + * @var Lexer */ private $_lex; /** * Plex file parser. - * @var PHP_LexerGenerator_Parser + * @var Parser */ private $_parser; @@ -290,8 +282,8 @@ class PHP_LexerGenerator /** * Create a lexer generator and optionally generate a lexer file. * - * @param string Optional plex file {@see PHP_LexerGenerator::create}. - * @param string Optional output file {@see PHP_LexerGenerator::create}. + * @param string Optional plex file {@see Smarty_LexerGenerator::create}. + * @param string Optional output file {@see Smarty_LexerGenerator::create}. */ public function __construct($lexerfile = '', $outfile = '') { @@ -309,7 +301,7 @@ public function __construct($lexerfile = '', $outfile = '') */ public function create($lexerfile, $outfile = '') { - $this->_lex = new PHP_LexerGenerator_Lexer(file_get_contents($lexerfile)); + $this->_lex = new LexerGenerator\Lexer(file_get_contents($lexerfile)); $info = pathinfo($lexerfile); if ($outfile) { $this->outfile = $outfile; @@ -318,7 +310,7 @@ public function create($lexerfile, $outfile = '') substr($info['basename'], 0, strlen($info['basename']) - strlen($info['extension'])) . 'php'; } - $this->_parser = new PHP_LexerGenerator_Parser($this->outfile, $this->_lex); + $this->_parser = new LexerGenerator\Parser($this->outfile, $this->_lex); if ($this -> debug) { $this->_parser->PrintTrace(); } @@ -327,5 +319,4 @@ public function create($lexerfile, $outfile = '') } $this->_parser->doParse(0, 0); } -} -//$a = new PHP_LexerGenerator('/development/File_ChessPGN/ChessPGN/Lexer.plex'); +} \ No newline at end of file diff --git a/LexerGenerator/Exception.php b/src/SmartyGenerator/LexerGenerator/Exception.php similarity index 88% rename from LexerGenerator/Exception.php rename to src/SmartyGenerator/LexerGenerator/Exception.php index 4d51d7d..e2a1f72 100644 --- a/LexerGenerator/Exception.php +++ b/src/SmartyGenerator/LexerGenerator/Exception.php @@ -1,6 +1,8 @@ * @copyright 2006 Gregory Beaver * @license http://www.opensource.org/licenses/bsd-license.php New BSD License */ -require_once './Exception.php'; /** - * @package PHP_LexerGenerator + * @author Gregory Beaver * @copyright 2006 Gregory Beaver * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @version @package_version@ * @since File available since Release 0.1.0 */ -class PHP_LexerGenerator_Exception extends PEAR_Exception {} +class Exception extends \Exception {} diff --git a/LexerGenerator/Lexer.php b/src/SmartyGenerator/LexerGenerator/Lexer.php similarity index 95% rename from LexerGenerator/Lexer.php rename to src/SmartyGenerator/LexerGenerator/Lexer.php index 3dd34a7..284a0ad 100644 --- a/LexerGenerator/Lexer.php +++ b/src/SmartyGenerator/LexerGenerator/Lexer.php @@ -1,6 +1,8 @@ * @copyright 2006 Gregory Beaver * @license http://www.php.net/license/3_01.txt PHP License 3.01 * @version CVS: $Id: Lexer.php 246683 2007-11-22 04:43:52Z instance $ * @since File available since Release 0.1.0 */ -require_once './LexerGenerator/Parser.php'; /** * Token scanner for plex files. * * This scanner detects comments beginning with "/*!lex2php" and * then returns their components (processing instructions, patterns, strings * action code, and regexes) - * @package PHP_LexerGenerator + * @author Gregory Beaver * @copyright 2006 Gregory Beaver * @license http://www.php.net/license/3_01.txt PHP License 3.01 * @version @package_version@ * @since Class available since Release 0.1.0 */ -class PHP_LexerGenerator_Lexer +class Lexer { private $data; private $N; @@ -61,15 +62,15 @@ class PHP_LexerGenerator_Lexer */ public $value; - const CODE = PHP_LexerGenerator_Parser::CODE; - const COMMENTEND = PHP_LexerGenerator_Parser::COMMENTEND; - const COMMENTSTART = PHP_LexerGenerator_Parser::COMMENTSTART; - const PATTERN = PHP_LexerGenerator_Parser::PATTERN; - const PHPCODE = PHP_LexerGenerator_Parser::PHPCODE; - const PI = PHP_LexerGenerator_Parser::PI; - const QUOTE = PHP_LexerGenerator_Parser::QUOTE; - const SINGLEQUOTE = PHP_LexerGenerator_Parser::SINGLEQUOTE; - const SUBPATTERN = PHP_LexerGenerator_Parser::SUBPATTERN; + const CODE = Parser::CODE; + const COMMENTEND = Parser::COMMENTEND; + const COMMENTSTART = Parser::COMMENTSTART; + const PATTERN = Parser::PATTERN; + const PHPCODE = Parser::PHPCODE; + const PI = Parser::PI; + const QUOTE = Parser::QUOTE; + const SINGLEQUOTE = Parser::SINGLEQUOTE; + const SUBPATTERN = Parser::SUBPATTERN; /** * prepare scanning @@ -408,7 +409,7 @@ private function lexRule() if ($next_newline) { $this->N = $next_newline; } else { - $this->N = sizeof($this->data); + $this->N = count($this->data); } $this->line++; } else { diff --git a/LexerGenerator/Parser.php b/src/SmartyGenerator/LexerGenerator/Parser.php similarity index 94% rename from LexerGenerator/Parser.php rename to src/SmartyGenerator/LexerGenerator/Parser.php index 50f9605..33a4cb5 100644 --- a/LexerGenerator/Parser.php +++ b/src/SmartyGenerator/LexerGenerator/Parser.php @@ -1,105 +1,15 @@ string = $s->string; - $this->metadata = $s->metadata; - } else { - $this->string = (string) $s; - if ($m instanceof PHP_LexerGenerator_ParseryyToken) { - $this->metadata = $m->metadata; - } elseif (is_array($m)) { - $this->metadata = $m; - } - } - } +namespace SmartyGenerator\LexerGenerator; - public function __toString() - { - return $this->string; - } - - public function offsetExists($offset) - { - return isset($this->metadata[$offset]); - } - - public function offsetGet($offset) - { - return $this->metadata[$offset]; - } - - public function offsetSet($offset, $value) - { - if ($offset === null) { - if (isset($value[0])) { - $x = ($value instanceof PHP_LexerGenerator_ParseryyToken) ? - $value->metadata : $value; - $this->metadata = array_merge($this->metadata, $x); - - return; - } - $offset = count($this->metadata); - } - if ($value === null) { - return; - } - if ($value instanceof PHP_LexerGenerator_ParseryyToken) { - if ($value->metadata) { - $this->metadata[$offset] = $value->metadata; - } - } elseif ($value) { - $this->metadata[$offset] = $value; - } - } - - public function offsetUnset($offset) - { - unset($this->metadata[$offset]); - } -} - -/** The following structure represents a single element of the - * parser's stack. Information stored includes: - * - * + The state number for the parser at this level of the stack. - * - * + The value of the token stored at this level of the stack. - * (In other words, the "major" token.) - * - * + The semantic value stored at this level of the stack. This is - * the information used by the action routines in the grammar. - * It is sometimes called the "minor" token. - */ -class PHP_LexerGenerator_ParseryyStackEntry -{ - public $stateno; /* The state-number */ - public $major; /* The major token value. This is the code - ** number for the token at this stack level */ - public $minor; /* The user-supplied minor token value. This - ** is the value of the token */ -}; +/* Driver template for the ParserrGenerator parser generator. (PHP port of LEMON) +*/; // code external to the class is included here #line 3 "Parser.y" /* ?> * @copyright 2006 Gregory Beaver * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @version CVS: $Id: Parser.php 246683 2007-11-22 04:43:52Z instance $ * @since File available since Release 0.1.0 */ -/** - * For regular expression validation - */ -require_once './LexerGenerator/Regex/Lexer.php'; -require_once './LexerGenerator/Regex/Parser.php'; -require_once './LexerGenerator/Exception.php'; /** * Token parser for plex files. * - * This parser converts tokens pulled from {@link PHP_LexerGenerator_Lexer} + * This parser converts tokens pulled from {@link Lexer} * into abstract patterns and rules, then creates the output file - * @package PHP_LexerGenerator + * @author Gregory Beaver * @copyright 2006 Gregory Beaver * @license http://www.php.net/license/3_01.txt PHP License 3.01 @@ -166,7 +70,7 @@ class PHP_LexerGenerator_ParseryyStackEntry // declare_class is output here #line 2 "Parser.y" -class PHP_LexerGenerator_Parser#line 171 "Parser.php" +class Parser #line 171 "Parser.php" { /* First off, code is included which follows the "include_class" declaration ** in the input file. */ @@ -208,8 +112,8 @@ public function __construct($outfile, $lex) throw new Exception('unable to open lexer output file "' . $outfile . '"'); } $this->lex = $lex; - $this->_regexLexer = new PHP_LexerGenerator_Regex_Lexer(''); - $this->_regexParser = new PHP_LexerGenerator_Regex_Parser($this->_regexLexer); + $this->_regexLexer = new Regex\Lexer(''); + $this->_regexParser = new Regex\Parser($this->_regexLexer); } public function doLongestMatch($rules, $statename, $ruleindex) @@ -523,9 +427,9 @@ public function _validatePattern($pattern, $update = false) $this->_regexLexer->token, $this->_regexLexer->value); } $this->_regexParser->doParse(0, 0); - } catch (PHP_LexerGenerator_Exception $e) { + } catch (Exception $e) { $this->error($e->getMessage()); - throw new PHP_LexerGenerator_Exception('Invalid pattern "' . $pattern . '"'); + throw new Exception('Invalid pattern "' . $pattern . '"'); } return $this->_regexParser->result; @@ -768,7 +672,7 @@ public function _validatePattern($pattern, $update = false) * @param resource * @param string */ - public static function Trace($TraceFILE, $zTracePrompt) + public function Trace($TraceFILE, $zTracePrompt) { if (!$TraceFILE) { $zTracePrompt = 0; @@ -782,7 +686,7 @@ public static function Trace($TraceFILE, $zTracePrompt) /** * Output debug information to output (php://output stream) */ - public static function PrintTrace() + public function PrintTrace() { $this->yyTraceFILE = fopen('php://output', 'w'); $this->yyTracePrompt = ''; @@ -915,7 +819,7 @@ public static function yy_destructor($yymajor, $yypminor) * is popped from the stack, then call it. * * Return the major token number for the symbol popped. - * @param PHP_LexerGenerator_ParseryyParser + * @param ParseryyParser * @return int */ public function yy_pop_parser_stack() @@ -942,9 +846,6 @@ public function yy_pop_parser_stack() */ public function __destruct() { - while ($this->yyidx >= 0) { - $this->yy_pop_parser_stack(); - } if (is_resource($this->yyTraceFILE)) { fclose($this->yyTraceFILE); } @@ -996,7 +897,7 @@ public function yy_get_expected_tokens($token) if ($nextstate < self::YYNSTATE) { // we need to shift a non-terminal $this->yyidx++; - $x = new PHP_LexerGenerator_ParseryyStackEntry; + $x = new ParseryyStackEntry; $x->stateno = $nextstate; $x->major = self::$yyRuleInfo[$yyruleno]['lhs']; $this->yystack[$this->yyidx] = $x; @@ -1072,7 +973,7 @@ public function yy_is_expected_token($token) if ($nextstate < self::YYNSTATE) { // we need to shift a non-terminal $this->yyidx++; - $x = new PHP_LexerGenerator_ParseryyStackEntry; + $x = new ParseryyStackEntry; $x->stateno = $nextstate; $x->major = self::$yyRuleInfo[$yyruleno]['lhs']; $this->yystack[$this->yyidx] = $x; @@ -1206,7 +1107,7 @@ public function yy_shift($yyNewState, $yyMajor, $yypMinor) return; } - $yytos = new PHP_LexerGenerator_ParseryyStackEntry; + $yytos = new ParseryyStackEntry; $yytos->stateno = $yyNewState; $yytos->major = $yyMajor; $yytos->minor = $yypMinor; @@ -1869,7 +1770,7 @@ public function yy_reduce($yyruleno) //int $yygoto; /* The next state */ //int $yyact; /* The next action */ //mixed $yygotominor; /* The LHS of the rule reduced */ - //PHP_LexerGenerator_ParseryyStackEntry $yymsp; /* The top of the parser's stack */ + //ParseryyStackEntry $yymsp; /* The top of the parser's stack */ //int $yysize; /* Amount to pop the stack */ if ($this->yyTraceFILE && $yyruleno >= 0 && $yyruleno < count(self::$yyRuleName)) { @@ -1900,7 +1801,7 @@ public function yy_reduce($yyruleno) ** That gives a significant speed improvement. */ if (!$this->yyTraceFILE && $yysize) { $this->yyidx++; - $x = new PHP_LexerGenerator_ParseryyStackEntry; + $x = new ParseryyStackEntry; $x->stateno = $yyact; $x->major = $yygoto; $x->minor = $yy_lefthand_side; @@ -1991,7 +1892,7 @@ public function doParse($yymajor, $yytokenvalue) /* if ($yymajor == 0) return; // not sure why this was here... */ $this->yyidx = 0; $this->yyerrcnt = -1; - $x = new PHP_LexerGenerator_ParseryyStackEntry; + $x = new ParseryyStackEntry; $x->stateno = 0; $x->major = 0; $this->yystack = array(); diff --git a/LexerGenerator/Parser.y b/src/SmartyGenerator/LexerGenerator/Parser.y similarity index 97% rename from LexerGenerator/Parser.y rename to src/SmartyGenerator/LexerGenerator/Parser.y index cfa96d6..45ec04c 100644 --- a/LexerGenerator/Parser.y +++ b/src/SmartyGenerator/LexerGenerator/Parser.y @@ -1,9 +1,9 @@ -%name PHP_LexerGenerator_Parser -%declare_class {class PHP_LexerGenerator_Parser} +%name Smarty\LexerGenerator\Parser +%declare_class {class Smarty\LexerGenerator\Parser} %include { /* ?> * @copyright 2006 Gregory Beaver * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @version CVS: $Id: Parser.y 246683 2007-11-22 04:43:52Z instance $ * @since File available since Release 0.1.0 */ -/** - * For regular expression validation - */ -require_once 'PHP/LexerGenerator/Regex/Lexer.php'; -require_once 'PHP/LexerGenerator/Regex/Parser.php'; -require_once 'PHP/LexerGenerator/Exception.php'; /** * Token parser for plex files. * - * This parser converts tokens pulled from {@link PHP_LexerGenerator_Lexer} + * This parser converts tokens pulled from {@link Smarty\LexerGenerator\Lexer} * into abstract patterns and rules, then creates the output file - * @package PHP_LexerGenerator + * @author Gregory Beaver * @copyright 2006 Gregory Beaver * @license http://www.php.net/license/3_01.txt PHP License 3.01 @@ -116,8 +110,8 @@ require_once 'PHP/LexerGenerator/Exception.php'; throw new Exception('unable to open lexer output file "' . $outfile . '"'); } $this->lex = $lex; - $this->_regexLexer = new PHP_LexerGenerator_Regex_Lexer(''); - $this->_regexParser = new PHP_LexerGenerator_Regex_Parser($this->_regexLexer); + $this->_regexLexer = new Smarty\LexerGenerator\Regex\Lexer(''); + $this->_regexParser = new Smarty\LexerGenerator\Regex\Parser($this->_regexLexer); } function doLongestMatch($rules, $statename, $ruleindex) @@ -425,9 +419,9 @@ require_once 'PHP/LexerGenerator/Exception.php'; $this->_regexLexer->token, $this->_regexLexer->value); } $this->_regexParser->doParse(0, 0); - } catch (PHP_LexerGenerator_Exception $e) { + } catch (Smarty\LexerGenerator\Exception $e) { $this->error($e->getMessage()); - throw new PHP_LexerGenerator_Exception('Invalid pattern "' . $pattern . '"'); + throw new Smarty\LexerGenerator\Exception('Invalid pattern "' . $pattern . '"'); } return $this->_regexParser->result; } diff --git a/src/SmartyGenerator/LexerGenerator/ParseryyStackEntry.php b/src/SmartyGenerator/LexerGenerator/ParseryyStackEntry.php new file mode 100644 index 0000000..fa35a9d --- /dev/null +++ b/src/SmartyGenerator/LexerGenerator/ParseryyStackEntry.php @@ -0,0 +1,24 @@ +string = $s->string; + $this->metadata = $s->metadata; + } else { + $this->string = (string)$s; + if ($m instanceof ParseryyToken) { + $this->metadata = $m->metadata; + } elseif (is_array($m)) { + $this->metadata = $m; + } + } + } + + public function __toString() { + return $this->string; + } + + public function offsetExists($offset) { + return isset($this->metadata[$offset]); + } + + public function offsetGet($offset) { + return $this->metadata[$offset]; + } + + public function offsetSet($offset, $value) { + if ($offset === null) { + if (isset($value[0])) { + $x = ($value instanceof ParseryyToken) ? + $value->metadata : $value; + $this->metadata = array_merge($this->metadata, $x); + + return; + } + $offset = count($this->metadata); + } + if ($value === null) { + return; + } + if ($value instanceof ParseryyToken) { + if ($value->metadata) { + $this->metadata[$offset] = $value->metadata; + } + } elseif ($value) { + $this->metadata[$offset] = $value; + } + } + + public function offsetUnset($offset) { + unset($this->metadata[$offset]); + } +} \ No newline at end of file diff --git a/LexerGenerator/Regex/Lexer.php b/src/SmartyGenerator/LexerGenerator/Regex/Lexer.php similarity index 95% rename from LexerGenerator/Regex/Lexer.php rename to src/SmartyGenerator/LexerGenerator/Regex/Lexer.php index 18d57a3..68a3143 100644 --- a/LexerGenerator/Regex/Lexer.php +++ b/src/SmartyGenerator/LexerGenerator/Regex/Lexer.php @@ -1,34 +1,35 @@ string = $s->string; - $this->metadata = $s->metadata; - } else { - $this->string = (string) $s; - if ($m instanceof PHP_LexerGenerator_Regex_yyToken) { - $this->metadata = $m->metadata; - } elseif (is_array($m)) { - $this->metadata = $m; - } - } - } - - public function __toString() - { - return $this->_string; - } - - public function offsetExists($offset) - { - return isset($this->metadata[$offset]); - } - - public function offsetGet($offset) - { - return $this->metadata[$offset]; - } +namespace SmartyGenerator\LexerGenerator\Regex; - public function offsetSet($offset, $value) - { - if ($offset === null) { - if (isset($value[0])) { - $x = ($value instanceof PHP_LexerGenerator_Regex_yyToken) ? - $value->metadata : $value; - $this->metadata = array_merge($this->metadata, $x); +/* Driver template for the PHP_rGenerator parser generator. (PHP port of LEMON) +*/ - return; - } - $offset = count($this->metadata); - } - if ($value === null) { - return; - } - if ($value instanceof PHP_LexerGenerator_Regex_yyToken) { - if ($value->metadata) { - $this->metadata[$offset] = $value->metadata; - } - } elseif ($value) { - $this->metadata[$offset] = $value; - } - } - public function offsetUnset($offset) - { - unset($this->metadata[$offset]); - } -} -/** The following structure represents a single element of the - * parser's stack. Information stored includes: - * - * + The state number for the parser at this level of the stack. - * - * + The value of the token stored at this level of the stack. - * (In other words, the "major" token.) - * - * + The semantic value stored at this level of the stack. This is - * the information used by the action routines in the grammar. - * It is sometimes called the "minor" token. - */ -class PHP_LexerGenerator_Regex_yyStackEntry -{ - public $stateno; /* The state-number */ - public $major; /* The major token value. This is the code - ** number for the token at this stack level */ - public $minor; /* The user-supplied minor token value. This - ** is the value of the token */ -}; // code external to the class is included here #line 2 "Parser.y" -require_once './LexerGenerator/Exception.php'; #line 102 "Parser.php" // declare_class is output here #line 5 "Parser.y" -class PHP_LexerGenerator_Regex_Parser#line 107 "Parser.php" +use SmartyGenerator\LexerGenerator\ParseryyToken; + +class Parser #line 107 "Parser.php" { /* First off, code is included which follows the "include_class" declaration ** in the input file. */ @@ -115,7 +29,7 @@ class PHP_LexerGenerator_Regex_Parser#line 107 "Parser.php" public $result; public function __construct($lex) { - $this->result = new PHP_LexerGenerator_ParseryyToken(''); + $this->result = new ParseryyToken(''); $this->_lex = $lex; $this->_subpatterns = 0; $this->_patternIndex = 1; @@ -126,7 +40,7 @@ public function reset($patternIndex, $updatePattern = false) $this->_updatePattern = $updatePattern; $this->_patternIndex = $patternIndex; $this->_subpatterns = 0; - $this->result = new PHP_LexerGenerator_ParseryyToken(''); + $this->result = new ParseryyToken(''); } #line 134 "Parser.php" @@ -521,7 +435,7 @@ public function reset($patternIndex, $updatePattern = false) * @param resource * @param string */ - public static function Trace($TraceFILE, $zTracePrompt) + public function Trace($TraceFILE, $zTracePrompt) { if (!$TraceFILE) { $zTracePrompt = 0; @@ -730,7 +644,7 @@ public static function yy_destructor($yymajor, $yypminor) * is popped from the stack, then call it. * * Return the major token number for the symbol popped. - * @param PHP_LexerGenerator_Regex_yyParser + * @param yyParser * @return int */ public function yy_pop_parser_stack() @@ -757,9 +671,6 @@ public function yy_pop_parser_stack() */ public function __destruct() { - while ($this->yyidx >= 0) { - $this->yy_pop_parser_stack(); - } if (is_resource(self::$yyTraceFILE)) { fclose(self::$yyTraceFILE); } @@ -811,7 +722,7 @@ public function yy_get_expected_tokens($token) if ($nextstate < self::YYNSTATE) { // we need to shift a non-terminal $this->yyidx++; - $x = new PHP_LexerGenerator_Regex_yyStackEntry; + $x = new yyStackEntry; $x->stateno = $nextstate; $x->major = self::$yyRuleInfo[$yyruleno]['lhs']; $this->yystack[$this->yyidx] = $x; @@ -887,7 +798,7 @@ public function yy_is_expected_token($token) if ($nextstate < self::YYNSTATE) { // we need to shift a non-terminal $this->yyidx++; - $x = new PHP_LexerGenerator_Regex_yyStackEntry; + $x = new yyStackEntry; $x->stateno = $nextstate; $x->major = self::$yyRuleInfo[$yyruleno]['lhs']; $this->yystack[$this->yyidx] = $x; @@ -1021,7 +932,7 @@ public function yy_shift($yyNewState, $yyMajor, $yypMinor) return; } - $yytos = new PHP_LexerGenerator_Regex_yyStackEntry; + $yytos = new yyStackEntry; $yytos->stateno = $yyNewState; $yytos->major = $yyMajor; $yytos->minor = $yypMinor; @@ -1264,21 +1175,21 @@ public function yy_r0() #line 56 "Parser.y" public function yy_r1() { - throw new PHP_LexerGenerator_Exception('Cannot include start match "' . + throw new \SmartyGenerator\LexerGenerator\Exception('Cannot include start match "' . $this->yystack[$this->yyidx + -2]->minor . '" or end match "' . $this->yystack[$this->yyidx + 0]->minor . '"'); } #line 1265 "Parser.php" #line 60 "Parser.y" public function yy_r2() { - throw new PHP_LexerGenerator_Exception('Cannot include start match "' . + throw new \SmartyGenerator\LexerGenerator\Exception('Cannot include start match "' . B . '"'); } #line 1271 "Parser.php" #line 64 "Parser.y" public function yy_r3() { - throw new PHP_LexerGenerator_Exception('Cannot include end match "' . $this->yystack[$this->yyidx + 0]->minor . '"'); + throw new \SmartyGenerator\LexerGenerator\Exception('Cannot include end match "' . $this->yystack[$this->yyidx + 0]->minor . '"'); } #line 1276 "Parser.php" #line 67 "Parser.y" @@ -1287,77 +1198,77 @@ public function yy_r4(){$this->_retvalue = $this->yystack[$this->yyidx + 0]->min #line 68 "Parser.y" public function yy_r5() { - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken($this->yystack[$this->yyidx + -2]->minor->string . '|' . $this->yystack[$this->yyidx + 0]->minor->string, array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken($this->yystack[$this->yyidx + -2]->minor->string . '|' . $this->yystack[$this->yyidx + 0]->minor->string, array( 'pattern' => $this->yystack[$this->yyidx + -2]->minor['pattern'] . '|' . $this->yystack[$this->yyidx + 0]->minor['pattern'])); } #line 1285 "Parser.php" #line 84 "Parser.y" public function yy_r17() { - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken($this->yystack[$this->yyidx + -1]->minor->string . $this->yystack[$this->yyidx + 0]->minor->string, array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken($this->yystack[$this->yyidx + -1]->minor->string . $this->yystack[$this->yyidx + 0]->minor->string, array( 'pattern' => $this->yystack[$this->yyidx + -1]->minor['pattern'] . $this->yystack[$this->yyidx + 0]->minor['pattern'])); } #line 1291 "Parser.php" #line 123 "Parser.y" public function yy_r28() { - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken('[' . $this->yystack[$this->yyidx + -1]->minor->string . ']', array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken('[' . $this->yystack[$this->yyidx + -1]->minor->string . ']', array( 'pattern' => '[' . $this->yystack[$this->yyidx + -1]->minor['pattern'] . ']')); } #line 1297 "Parser.php" #line 127 "Parser.y" public function yy_r29() { - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken('[^' . $this->yystack[$this->yyidx + -1]->minor->string . ']', array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken('[^' . $this->yystack[$this->yyidx + -1]->minor->string . ']', array( 'pattern' => '[^' . $this->yystack[$this->yyidx + -1]->minor['pattern'] . ']')); } #line 1303 "Parser.php" #line 131 "Parser.y" public function yy_r30() { - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken('[' . $this->yystack[$this->yyidx + -2]->minor->string . ']' . $this->yystack[$this->yyidx + 0]->minor, array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken('[' . $this->yystack[$this->yyidx + -2]->minor->string . ']' . $this->yystack[$this->yyidx + 0]->minor, array( 'pattern' => '[' . $this->yystack[$this->yyidx + -2]->minor['pattern'] . ']' . $this->yystack[$this->yyidx + 0]->minor)); } #line 1309 "Parser.php" #line 135 "Parser.y" public function yy_r31() { - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken('[^' . $this->yystack[$this->yyidx + -2]->minor->string . ']' . $this->yystack[$this->yyidx + 0]->minor, array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken('[^' . $this->yystack[$this->yyidx + -2]->minor->string . ']' . $this->yystack[$this->yyidx + 0]->minor, array( 'pattern' => '[^' . $this->yystack[$this->yyidx + -2]->minor['pattern'] . ']' . $this->yystack[$this->yyidx + 0]->minor)); } #line 1315 "Parser.php" #line 140 "Parser.y" public function yy_r32() { - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken($this->yystack[$this->yyidx + 0]->minor, array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken($this->yystack[$this->yyidx + 0]->minor, array( 'pattern' => $this->yystack[$this->yyidx + 0]->minor)); } #line 1321 "Parser.php" #line 144 "Parser.y" public function yy_r33() { - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken('\\\\' . $this->yystack[$this->yyidx + 0]->minor, array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken('\\\\' . $this->yystack[$this->yyidx + 0]->minor, array( 'pattern' => $this->yystack[$this->yyidx + 0]->minor)); } #line 1327 "Parser.php" #line 148 "Parser.y" public function yy_r34() { - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken('\\\\' . $this->yystack[$this->yyidx + -2]->minor . '-' . $this->yystack[$this->yyidx + 0]->minor, array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken('\\\\' . $this->yystack[$this->yyidx + -2]->minor . '-' . $this->yystack[$this->yyidx + 0]->minor, array( 'pattern' => $this->yystack[$this->yyidx + -2]->minor . '-' . $this->yystack[$this->yyidx + 0]->minor)); } #line 1333 "Parser.php" #line 152 "Parser.y" public function yy_r35() { - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken($this->yystack[$this->yyidx + -2]->minor . '-' . $this->yystack[$this->yyidx + 0]->minor, array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken($this->yystack[$this->yyidx + -2]->minor . '-' . $this->yystack[$this->yyidx + 0]->minor, array( 'pattern' => $this->yystack[$this->yyidx + -2]->minor . '-' . $this->yystack[$this->yyidx + 0]->minor)); } #line 1339 "Parser.php" #line 156 "Parser.y" public function yy_r36() { - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken($this->yystack[$this->yyidx + -2]->minor . '-\\\\' . $this->yystack[$this->yyidx + 0]->minor, array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken($this->yystack[$this->yyidx + -2]->minor . '-\\\\' . $this->yystack[$this->yyidx + 0]->minor, array( 'pattern' => $this->yystack[$this->yyidx + -2]->minor . '-' . $this->yystack[$this->yyidx + 0]->minor)); } #line 1345 "Parser.php" @@ -1365,12 +1276,12 @@ public function yy_r36() public function yy_r37() { if (((int) substr($this->yystack[$this->yyidx + 0]->minor, 1)) > $this->_subpatterns) { - throw new PHP_LexerGenerator_Exception('Back-reference refers to non-existent ' . + throw new \SmartyGenerator\LexerGenerator\Exception('Back-reference refers to non-existent ' . 'sub-pattern ' . substr($this->yystack[$this->yyidx + 0]->minor, 1)); } $this->yystack[$this->yyidx + 0]->minor = substr($this->yystack[$this->yyidx + 0]->minor, 1); // adjust back-reference for containing () - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken('\\\\' . ($this->yystack[$this->yyidx + 0]->minor + $this->_patternIndex), array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken('\\\\' . ($this->yystack[$this->yyidx + 0]->minor + $this->_patternIndex), array( 'pattern' => '\\' . ($this->_updatePattern ? ($this->yystack[$this->yyidx + 0]->minor + $this->_patternIndex) : $this->yystack[$this->yyidx + 0]->minor))); } #line 1357 "Parser.php" @@ -1378,60 +1289,60 @@ public function yy_r37() public function yy_r38() { if (((int) substr($this->yystack[$this->yyidx + 0]->minor, 1)) > $this->_subpatterns) { - throw new PHP_LexerGenerator_Exception($this->yystack[$this->yyidx + 0]->minor . ' will be interpreted as an invalid' . + throw new \SmartyGenerator\LexerGenerator\Exception($this->yystack[$this->yyidx + 0]->minor . ' will be interpreted as an invalid' . ' back-reference, use "\\0' . substr($this->yystack[$this->yyidx + 0]->minor, 1) . ' for octal'); } $this->yystack[$this->yyidx + 0]->minor = substr($this->yystack[$this->yyidx + 0]->minor, 1); - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken('\\\\' . ($this->yystack[$this->yyidx + 0]->minor + $this->_patternIndex), array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken('\\\\' . ($this->yystack[$this->yyidx + 0]->minor + $this->_patternIndex), array( 'pattern' => '\\' . ($this->_updatePattern ? ($this->yystack[$this->yyidx + 0]->minor + $this->_patternIndex) : $this->yystack[$this->yyidx + 0]->minor))); } #line 1368 "Parser.php" #line 179 "Parser.y" public function yy_r39() { - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken($this->yystack[$this->yyidx + -1]->minor->string . '\\' . $this->yystack[$this->yyidx + 0]->minor, array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken($this->yystack[$this->yyidx + -1]->minor->string . '\\' . $this->yystack[$this->yyidx + 0]->minor, array( 'pattern' => $this->yystack[$this->yyidx + -1]->minor['pattern'] . $this->yystack[$this->yyidx + 0]->minor)); } #line 1374 "Parser.php" #line 183 "Parser.y" public function yy_r40() { - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken($this->yystack[$this->yyidx + -1]->minor->string . '\\\\' . $this->yystack[$this->yyidx + 0]->minor, array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken($this->yystack[$this->yyidx + -1]->minor->string . '\\\\' . $this->yystack[$this->yyidx + 0]->minor, array( 'pattern' => $this->yystack[$this->yyidx + -1]->minor['pattern'] . $this->yystack[$this->yyidx + 0]->minor)); } #line 1380 "Parser.php" #line 187 "Parser.y" public function yy_r41() { - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken($this->yystack[$this->yyidx + -1]->minor->string . $this->yystack[$this->yyidx + 0]->minor, array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken($this->yystack[$this->yyidx + -1]->minor->string . $this->yystack[$this->yyidx + 0]->minor, array( 'pattern' => $this->yystack[$this->yyidx + -1]->minor['pattern'] . $this->yystack[$this->yyidx + 0]->minor)); } #line 1386 "Parser.php" #line 191 "Parser.y" public function yy_r42() { - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken($this->yystack[$this->yyidx + -3]->minor->string . '\\\\' . $this->yystack[$this->yyidx + -2]->minor . '-\\' . $this->yystack[$this->yyidx + 0]->minor, array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken($this->yystack[$this->yyidx + -3]->minor->string . '\\\\' . $this->yystack[$this->yyidx + -2]->minor . '-\\' . $this->yystack[$this->yyidx + 0]->minor, array( 'pattern' => $this->yystack[$this->yyidx + -3]->minor['pattern'] . $this->yystack[$this->yyidx + -2]->minor . '-' . $this->yystack[$this->yyidx + 0]->minor)); } #line 1392 "Parser.php" #line 195 "Parser.y" public function yy_r43() { - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken($this->yystack[$this->yyidx + -3]->minor->string . '\\\\' . $this->yystack[$this->yyidx + -2]->minor . '-' . $this->yystack[$this->yyidx + 0]->minor, array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken($this->yystack[$this->yyidx + -3]->minor->string . '\\\\' . $this->yystack[$this->yyidx + -2]->minor . '-' . $this->yystack[$this->yyidx + 0]->minor, array( 'pattern' => $this->yystack[$this->yyidx + -3]->minor['pattern'] . $this->yystack[$this->yyidx + -2]->minor . '-' . $this->yystack[$this->yyidx + 0]->minor)); } #line 1398 "Parser.php" #line 199 "Parser.y" public function yy_r44() { - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken($this->yystack[$this->yyidx + -3]->minor->string . $this->yystack[$this->yyidx + -2]->minor . '-\\\\' . $this->yystack[$this->yyidx + 0]->minor, array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken($this->yystack[$this->yyidx + -3]->minor->string . $this->yystack[$this->yyidx + -2]->minor . '-\\\\' . $this->yystack[$this->yyidx + 0]->minor, array( 'pattern' => $this->yystack[$this->yyidx + -3]->minor['pattern'] . $this->yystack[$this->yyidx + -2]->minor . '-' . $this->yystack[$this->yyidx + 0]->minor)); } #line 1404 "Parser.php" #line 203 "Parser.y" public function yy_r45() { - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken($this->yystack[$this->yyidx + -3]->minor->string . $this->yystack[$this->yyidx + -2]->minor . '-' . $this->yystack[$this->yyidx + 0]->minor, array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken($this->yystack[$this->yyidx + -3]->minor->string . $this->yystack[$this->yyidx + -2]->minor . '-' . $this->yystack[$this->yyidx + 0]->minor, array( 'pattern' => $this->yystack[$this->yyidx + -3]->minor['pattern'] . $this->yystack[$this->yyidx + -2]->minor . '-' . $this->yystack[$this->yyidx + 0]->minor)); } #line 1410 "Parser.php" @@ -1439,11 +1350,11 @@ public function yy_r45() public function yy_r46() { if (((int) substr($this->yystack[$this->yyidx + 0]->minor, 1)) > $this->_subpatterns) { - throw new PHP_LexerGenerator_Exception('Back-reference refers to non-existent ' . + throw new \SmartyGenerator\LexerGenerator\Exception('Back-reference refers to non-existent ' . 'sub-pattern ' . substr($this->yystack[$this->yyidx + 0]->minor, 1)); } $this->yystack[$this->yyidx + 0]->minor = substr($this->yystack[$this->yyidx + 0]->minor, 1); - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken($this->yystack[$this->yyidx + -1]->minor->string . '\\\\' . ($this->yystack[$this->yyidx + 0]->minor + $this->_patternIndex), array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken($this->yystack[$this->yyidx + -1]->minor->string . '\\\\' . ($this->yystack[$this->yyidx + 0]->minor + $this->_patternIndex), array( 'pattern' => $this->yystack[$this->yyidx + -1]->minor['pattern'] . '\\' . ($this->_updatePattern ? ($this->yystack[$this->yyidx + 0]->minor + $this->_patternIndex) : $this->yystack[$this->yyidx + 0]->minor))); } #line 1421 "Parser.php" @@ -1451,39 +1362,39 @@ public function yy_r46() public function yy_r47() { if (((int) substr($this->yystack[$this->yyidx + 0]->minor, 1)) > $this->_subpatterns) { - throw new PHP_LexerGenerator_Exception($this->yystack[$this->yyidx + 0]->minor . ' will be interpreted as an invalid' . + throw new \SmartyGenerator\LexerGenerator\Exception($this->yystack[$this->yyidx + 0]->minor . ' will be interpreted as an invalid' . ' back-reference, use "\\0' . substr($this->yystack[$this->yyidx + 0]->minor, 1) . ' for octal'); } $this->yystack[$this->yyidx + 0]->minor = substr($this->yystack[$this->yyidx + 0]->minor, 1); - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken($this->yystack[$this->yyidx + -1]->minor->string . '\\\\' . ($this->yystack[$this->yyidx + 0]->minor + $this->_patternIndex), array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken($this->yystack[$this->yyidx + -1]->minor->string . '\\\\' . ($this->yystack[$this->yyidx + 0]->minor + $this->_patternIndex), array( 'pattern' => $this->yystack[$this->yyidx + -1]->minor['pattern'] . '\\' . ($this->_updatePattern ? ($this->yystack[$this->yyidx + 0]->minor + $this->_patternIndex) : $this->yystack[$this->yyidx + 0]->minor))); } #line 1432 "Parser.php" #line 230 "Parser.y" public function yy_r49() { - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken($this->yystack[$this->yyidx + -1]->minor . $this->yystack[$this->yyidx + 0]->minor, array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken($this->yystack[$this->yyidx + -1]->minor . $this->yystack[$this->yyidx + 0]->minor, array( 'pattern' => $this->yystack[$this->yyidx + -1]->minor . $this->yystack[$this->yyidx + 0]->minor)); } #line 1438 "Parser.php" #line 242 "Parser.y" public function yy_r52() { - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken('\\' . $this->yystack[$this->yyidx + 0]->minor, array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken('\\' . $this->yystack[$this->yyidx + 0]->minor, array( 'pattern' => $this->yystack[$this->yyidx + 0]->minor)); } #line 1444 "Parser.php" #line 246 "Parser.y" public function yy_r53() { - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken('\\' . $this->yystack[$this->yyidx + -1]->minor . $this->yystack[$this->yyidx + 0]->minor, array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken('\\' . $this->yystack[$this->yyidx + -1]->minor . $this->yystack[$this->yyidx + 0]->minor, array( 'pattern' => $this->yystack[$this->yyidx + -1]->minor . $this->yystack[$this->yyidx + 0]->minor)); } #line 1450 "Parser.php" #line 254 "Parser.y" public function yy_r55() { - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken('\\\\' . $this->yystack[$this->yyidx + -1]->minor . $this->yystack[$this->yyidx + 0]->minor, array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken('\\\\' . $this->yystack[$this->yyidx + -1]->minor . $this->yystack[$this->yyidx + 0]->minor, array( 'pattern' => $this->yystack[$this->yyidx + -1]->minor . $this->yystack[$this->yyidx + 0]->minor)); } #line 1456 "Parser.php" @@ -1491,12 +1402,12 @@ public function yy_r55() public function yy_r57() { if (((int) substr($this->yystack[$this->yyidx + -1]->minor, 1)) > $this->_subpatterns) { - throw new PHP_LexerGenerator_Exception('Back-reference refers to non-existent ' . + throw new \SmartyGenerator\LexerGenerator\Exception('Back-reference refers to non-existent ' . 'sub-pattern ' . substr($this->yystack[$this->yyidx + -1]->minor, 1)); } $this->yystack[$this->yyidx + -1]->minor = substr($this->yystack[$this->yyidx + -1]->minor, 1); // adjust back-reference for containing () - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken('\\\\' . ($this->yystack[$this->yyidx + -1]->minor + $this->_patternIndex) . $this->yystack[$this->yyidx + 0]->minor, array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken('\\\\' . ($this->yystack[$this->yyidx + -1]->minor + $this->_patternIndex) . $this->yystack[$this->yyidx + 0]->minor, array( 'pattern' => '\\' . ($this->_updatePattern ? ($this->yystack[$this->yyidx + -1]->minor + $this->_patternIndex) : $this->yystack[$this->yyidx + -1]->minor) . $this->yystack[$this->yyidx + 0]->minor)); } #line 1468 "Parser.php" @@ -1504,32 +1415,32 @@ public function yy_r57() public function yy_r59() { if (((int) substr($this->yystack[$this->yyidx + -1]->minor, 1)) > $this->_subpatterns) { - throw new PHP_LexerGenerator_Exception($this->yystack[$this->yyidx + -1]->minor . ' will be interpreted as an invalid' . + throw new \SmartyGenerator\LexerGenerator\Exception($this->yystack[$this->yyidx + -1]->minor . ' will be interpreted as an invalid' . ' back-reference, use "\\0' . substr($this->yystack[$this->yyidx + -1]->minor, 1) . ' for octal'); } $this->yystack[$this->yyidx + -1]->minor = substr($this->yystack[$this->yyidx + -1]->minor, 1); - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken('\\\\' . ($this->yystack[$this->yyidx + -1]->minor + $this->_patternIndex) . $this->yystack[$this->yyidx + 0]->minor, array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken('\\\\' . ($this->yystack[$this->yyidx + -1]->minor + $this->_patternIndex) . $this->yystack[$this->yyidx + 0]->minor, array( 'pattern' => '\\' . ($this->_updatePattern ? ($this->yystack[$this->yyidx + -1]->minor + $this->_patternIndex) : $this->yystack[$this->yyidx + -1]->minor) . $this->yystack[$this->yyidx + 0]->minor)); } #line 1479 "Parser.php" #line 300 "Parser.y" public function yy_r61() { - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken($this->yystack[$this->yyidx + -2]->minor->string . $this->yystack[$this->yyidx + -1]->minor . $this->yystack[$this->yyidx + 0]->minor, array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken($this->yystack[$this->yyidx + -2]->minor->string . $this->yystack[$this->yyidx + -1]->minor . $this->yystack[$this->yyidx + 0]->minor, array( 'pattern' => $this->yystack[$this->yyidx + -2]->minor['pattern'] . $this->yystack[$this->yyidx + -1]->minor . $this->yystack[$this->yyidx + 0]->minor)); } #line 1485 "Parser.php" #line 316 "Parser.y" public function yy_r65() { - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken($this->yystack[$this->yyidx + -2]->minor->string . '\\' . $this->yystack[$this->yyidx + -1]->minor . $this->yystack[$this->yyidx + 0]->minor, array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken($this->yystack[$this->yyidx + -2]->minor->string . '\\' . $this->yystack[$this->yyidx + -1]->minor . $this->yystack[$this->yyidx + 0]->minor, array( 'pattern' => $this->yystack[$this->yyidx + -2]->minor['pattern'] . $this->yystack[$this->yyidx + -1]->minor . $this->yystack[$this->yyidx + 0]->minor)); } #line 1491 "Parser.php" #line 324 "Parser.y" public function yy_r67() { - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken($this->yystack[$this->yyidx + -2]->minor->string . '\\\\' . $this->yystack[$this->yyidx + -1]->minor . $this->yystack[$this->yyidx + 0]->minor, array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken($this->yystack[$this->yyidx + -2]->minor->string . '\\\\' . $this->yystack[$this->yyidx + -1]->minor . $this->yystack[$this->yyidx + 0]->minor, array( 'pattern' => $this->yystack[$this->yyidx + -2]->minor['pattern'] . $this->yystack[$this->yyidx + -1]->minor . $this->yystack[$this->yyidx + 0]->minor)); } #line 1497 "Parser.php" @@ -1537,11 +1448,11 @@ public function yy_r67() public function yy_r69() { if (((int) substr($this->yystack[$this->yyidx + -1]->minor, 1)) > $this->_subpatterns) { - throw new PHP_LexerGenerator_Exception('Back-reference refers to non-existent ' . + throw new \SmartyGenerator\LexerGenerator\Exception('Back-reference refers to non-existent ' . 'sub-pattern ' . substr($this->yystack[$this->yyidx + -1]->minor, 1)); } $this->yystack[$this->yyidx + -1]->minor = substr($this->yystack[$this->yyidx + -1]->minor, 1); - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken($this->yystack[$this->yyidx + -2]->minor->string . '\\\\' . ($this->yystack[$this->yyidx + -1]->minor + $this->_patternIndex) . $this->yystack[$this->yyidx + 0]->minor, array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken($this->yystack[$this->yyidx + -2]->minor->string . '\\\\' . ($this->yystack[$this->yyidx + -1]->minor + $this->_patternIndex) . $this->yystack[$this->yyidx + 0]->minor, array( 'pattern' => $this->yystack[$this->yyidx + -2]->minor['pattern'] . '\\' . ($this->_updatePattern ? ($this->yystack[$this->yyidx + -1]->minor + $this->_patternIndex) : $this->yystack[$this->yyidx + -1]->minor) . $this->yystack[$this->yyidx + 0]->minor)); } #line 1508 "Parser.php" @@ -1549,39 +1460,39 @@ public function yy_r69() public function yy_r71() { if (((int) substr($this->yystack[$this->yyidx + -1]->minor, 1)) > $this->_subpatterns) { - throw new PHP_LexerGenerator_Exception($this->yystack[$this->yyidx + -1]->minor . ' will be interpreted as an invalid' . + throw new \SmartyGenerator\LexerGenerator\Exception($this->yystack[$this->yyidx + -1]->minor . ' will be interpreted as an invalid' . ' back-reference, use "\\0' . substr($this->yystack[$this->yyidx + -1]->minor, 1) . ' for octal'); } $this->yystack[$this->yyidx + -1]->minor = substr($this->yystack[$this->yyidx + -1]->minor, 1); - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken($this->yystack[$this->yyidx + -2]->minor->string . '\\\\' . ($this->yystack[$this->yyidx + -1]->minor + $this->_patternIndex) . $this->yystack[$this->yyidx + 0]->minor, array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken($this->yystack[$this->yyidx + -2]->minor->string . '\\\\' . ($this->yystack[$this->yyidx + -1]->minor + $this->_patternIndex) . $this->yystack[$this->yyidx + 0]->minor, array( 'pattern' => $this->yystack[$this->yyidx + -2]->minor['pattern'] . '\\' . ($this->_updatePattern ? ($this->yystack[$this->yyidx + -1]->minor + $this->_patternIndex) : $this->yystack[$this->yyidx + -1]->minor) . $this->yystack[$this->yyidx + 0]->minor)); } #line 1519 "Parser.php" #line 365 "Parser.y" public function yy_r72() { - throw new PHP_LexerGenerator_Exception('Error: cannot set preg options directly with "' . + throw new \SmartyGenerator\LexerGenerator\Exception('Error: cannot set preg options directly with "' . $this->yystack[$this->yyidx + -2]->minor . $this->yystack[$this->yyidx + -1]->minor . $this->yystack[$this->yyidx + 0]->minor . '"'); } #line 1525 "Parser.php" #line 369 "Parser.y" public function yy_r73() { - throw new PHP_LexerGenerator_Exception('Error: cannot set preg options directly with "' . + throw new \SmartyGenerator\LexerGenerator\Exception('Error: cannot set preg options directly with "' . $this->yystack[$this->yyidx + -4]->minor . $this->yystack[$this->yyidx + -3]->minor . $this->yystack[$this->yyidx + -2]->minor . $this->yystack[$this->yyidx + -1]->minor['pattern'] . $this->yystack[$this->yyidx + 0]->minor . '"'); } #line 1531 "Parser.php" #line 374 "Parser.y" public function yy_r74() { - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken('(?:' . $this->yystack[$this->yyidx + -1]->minor->string . ')', array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken('(?:' . $this->yystack[$this->yyidx + -1]->minor->string . ')', array( 'pattern' => '(?:' . $this->yystack[$this->yyidx + -1]->minor['pattern'] . ')')); } #line 1537 "Parser.php" #line 378 "Parser.y" public function yy_r75() { - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken('(?:' . $this->yystack[$this->yyidx + -2]->minor->string . ')' . $this->yystack[$this->yyidx + 0]->minor, array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken('(?:' . $this->yystack[$this->yyidx + -2]->minor->string . ')' . $this->yystack[$this->yyidx + 0]->minor, array( 'pattern' => '(?:' . $this->yystack[$this->yyidx + -2]->minor['pattern'] . ')' . $this->yystack[$this->yyidx + 0]->minor)); } #line 1543 "Parser.php" @@ -1590,15 +1501,15 @@ public function yy_r76() { if ($this->yystack[$this->yyidx + -4]->minor != 'R') { if (!preg_match('/[1-9][0-9]*/', $this->yystack[$this->yyidx + -4]->minor)) { - throw new PHP_LexerGenerator_Exception('Invalid sub-pattern conditional: "(?(' . $this->yystack[$this->yyidx + -4]->minor . ')"'); + throw new \SmartyGenerator\LexerGenerator\Exception('Invalid sub-pattern conditional: "(?(' . $this->yystack[$this->yyidx + -4]->minor . ')"'); } if ($this->yystack[$this->yyidx + -4]->minor > $this->_subpatterns) { - throw new PHP_LexerGenerator_Exception('sub-pattern conditional . "' . $this->yystack[$this->yyidx + -4]->minor . '" refers to non-existent sub-pattern'); + throw new \SmartyGenerator\LexerGenerator\Exception('sub-pattern conditional . "' . $this->yystack[$this->yyidx + -4]->minor . '" refers to non-existent sub-pattern'); } } else { - throw new PHP_LexerGenerator_Exception('Recursive conditional (?(' . $this->yystack[$this->yyidx + -4]->minor . ')" cannot work in this lexer'); + throw new \SmartyGenerator\LexerGenerator\Exception('Recursive conditional (?(' . $this->yystack[$this->yyidx + -4]->minor . ')" cannot work in this lexer'); } - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken('(?(' . $this->yystack[$this->yyidx + -4]->minor . ')' . $this->yystack[$this->yyidx + -2]->minor->string . ')' . $this->yystack[$this->yyidx + 0]->minor, array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken('(?(' . $this->yystack[$this->yyidx + -4]->minor . ')' . $this->yystack[$this->yyidx + -2]->minor->string . ')' . $this->yystack[$this->yyidx + 0]->minor, array( 'pattern' => '(?(' . $this->yystack[$this->yyidx + -4]->minor . ')' . $this->yystack[$this->yyidx + -2]->minor['pattern'] . ')' . $this->yystack[$this->yyidx + 0]->minor)); } #line 1559 "Parser.php" @@ -1607,78 +1518,78 @@ public function yy_r77() { if ($this->yystack[$this->yyidx + -3]->minor != 'R') { if (!preg_match('/[1-9][0-9]*/', $this->yystack[$this->yyidx + -3]->minor)) { - throw new PHP_LexerGenerator_Exception('Invalid sub-pattern conditional: "(?(' . $this->yystack[$this->yyidx + -3]->minor . ')"'); + throw new \SmartyGenerator\LexerGenerator\Exception('Invalid sub-pattern conditional: "(?(' . $this->yystack[$this->yyidx + -3]->minor . ')"'); } if ($this->yystack[$this->yyidx + -3]->minor > $this->_subpatterns) { - throw new PHP_LexerGenerator_Exception('sub-pattern conditional . "' . $this->yystack[$this->yyidx + -3]->minor . '" refers to non-existent sub-pattern'); + throw new \SmartyGenerator\LexerGenerator\Exception('sub-pattern conditional . "' . $this->yystack[$this->yyidx + -3]->minor . '" refers to non-existent sub-pattern'); } } else { - throw new PHP_LexerGenerator_Exception('Recursive conditional (?(' . $this->yystack[$this->yyidx + -3]->minor . ')" cannot work in this lexer'); + throw new \SmartyGenerator\LexerGenerator\Exception('Recursive conditional (?(' . $this->yystack[$this->yyidx + -3]->minor . ')" cannot work in this lexer'); } - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken('(?(' . $this->yystack[$this->yyidx + -3]->minor . ')' . $this->yystack[$this->yyidx + -1]->minor->string . ')', array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken('(?(' . $this->yystack[$this->yyidx + -3]->minor . ')' . $this->yystack[$this->yyidx + -1]->minor->string . ')', array( 'pattern' => '(?(' . $this->yystack[$this->yyidx + -3]->minor . ')' . $this->yystack[$this->yyidx + -1]->minor['pattern'] . ')')); } #line 1575 "Parser.php" #line 411 "Parser.y" public function yy_r78() { - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken('(?' . $this->yystack[$this->yyidx + -2]->minor->string . $this->yystack[$this->yyidx + -1]->minor->string . ')', array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken('(?' . $this->yystack[$this->yyidx + -2]->minor->string . $this->yystack[$this->yyidx + -1]->minor->string . ')', array( 'pattern' => '(?' . $this->yystack[$this->yyidx + -2]->minor['pattern'] . $this->yystack[$this->yyidx + -1]->minor['pattern'] . ')')); } #line 1581 "Parser.php" #line 415 "Parser.y" public function yy_r79() { - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken('(?' . $this->yystack[$this->yyidx + -3]->minor->string . $this->yystack[$this->yyidx + -2]->minor->string . ')' . $this->yystack[$this->yyidx + 0]->minor, array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken('(?' . $this->yystack[$this->yyidx + -3]->minor->string . $this->yystack[$this->yyidx + -2]->minor->string . ')' . $this->yystack[$this->yyidx + 0]->minor, array( 'pattern' => '(?' . $this->yystack[$this->yyidx + -3]->minor['pattern'] . $this->yystack[$this->yyidx + -2]->minor['pattern'] . ')' . $this->yystack[$this->yyidx + 0]->minor)); } #line 1587 "Parser.php" #line 419 "Parser.y" public function yy_r80() { - throw new PHP_LexerGenerator_Exception('Look-behind assertions cannot be used: "(?<=' . + throw new \SmartyGenerator\LexerGenerator\Exception('Look-behind assertions cannot be used: "(?<=' . $this->yystack[$this->yyidx + -1]->minor['pattern'] . ')'); } #line 1593 "Parser.php" #line 423 "Parser.y" public function yy_r81() { - throw new PHP_LexerGenerator_Exception('Look-behind assertions cannot be used: "(?<=' . + throw new \SmartyGenerator\LexerGenerator\Exception('Look-behind assertions cannot be used: "(?<=' . $this->yystack[$this->yyidx + -2]->minor['pattern'] . ')'); } #line 1599 "Parser.php" #line 428 "Parser.y" public function yy_r82() { - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken('(?=' . $this->yystack[$this->yyidx + -1]->minor->string . ')', array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken('(?=' . $this->yystack[$this->yyidx + -1]->minor->string . ')', array( 'pattern'=> '(?=' . $this->yystack[$this->yyidx + -1]->minor['pattern'] . ')')); } #line 1605 "Parser.php" #line 432 "Parser.y" public function yy_r83() { - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken('(?!' . $this->yystack[$this->yyidx + -1]->minor->string . ')', array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken('(?!' . $this->yystack[$this->yyidx + -1]->minor->string . ')', array( 'pattern' => '(?!' . $this->yystack[$this->yyidx + -1]->minor['pattern'] . ')')); } #line 1611 "Parser.php" #line 441 "Parser.y" public function yy_r85() { - throw new PHP_LexerGenerator_Exception('Look-behind assertions cannot be used: "(?yystack[$this->yyidx + -1]->minor['pattern'] . ')'); } #line 1617 "Parser.php" #line 446 "Parser.y" public function yy_r86() { - throw new PHP_LexerGenerator_Exception('Cannot use named sub-patterns: "(' . + throw new \SmartyGenerator\LexerGenerator\Exception('Cannot use named sub-patterns: "(' . $this->yystack[$this->yyidx + -2]->minor['pattern'] . ')'); } #line 1623 "Parser.php" #line 450 "Parser.y" public function yy_r87() { - throw new PHP_LexerGenerator_Exception('Cannot use named sub-patterns: "(' . + throw new \SmartyGenerator\LexerGenerator\Exception('Cannot use named sub-patterns: "(' . $this->yystack[$this->yyidx + -3]->minor['pattern'] . ')'); } #line 1629 "Parser.php" @@ -1686,7 +1597,7 @@ public function yy_r87() public function yy_r88() { $this->_subpatterns++; - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken('(' . $this->yystack[$this->yyidx + -1]->minor->string . ')', array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken('(' . $this->yystack[$this->yyidx + -1]->minor->string . ')', array( 'pattern' => '(' . $this->yystack[$this->yyidx + -1]->minor['pattern'] . ')')); } #line 1636 "Parser.php" @@ -1694,21 +1605,21 @@ public function yy_r88() public function yy_r89() { $this->_subpatterns++; - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken('(' . $this->yystack[$this->yyidx + -2]->minor->string . ')' . $this->yystack[$this->yyidx + 0]->minor, array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken('(' . $this->yystack[$this->yyidx + -2]->minor->string . ')' . $this->yystack[$this->yyidx + 0]->minor, array( 'pattern' => '(' . $this->yystack[$this->yyidx + -2]->minor['pattern'] . ')' . $this->yystack[$this->yyidx + 0]->minor)); } #line 1643 "Parser.php" #line 465 "Parser.y" public function yy_r90() { - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken('(?>' . $this->yystack[$this->yyidx + -1]->minor->string . ')', array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken('(?>' . $this->yystack[$this->yyidx + -1]->minor->string . ')', array( 'pattern' => '(?>' . $this->yystack[$this->yyidx + -1]->minor['pattern'] . ')')); } #line 1649 "Parser.php" #line 470 "Parser.y" public function yy_r91() { - $this->_retvalue = new PHP_LexerGenerator_ParseryyToken('(' . $this->yystack[$this->yyidx + -1]->minor->string . ')', array( + $this->_retvalue = new \SmartyGenerator\LexerGenerator\ParseryyToken('(' . $this->yystack[$this->yyidx + -1]->minor->string . ')', array( 'pattern' => '(' . $this->yystack[$this->yyidx + -1]->minor['pattern'] . ')')); } #line 1655 "Parser.php" @@ -1758,7 +1669,7 @@ public function yy_reduce($yyruleno) //int $yygoto; /* The next state */ //int $yyact; /* The next action */ //mixed $yygotominor; /* The LHS of the rule reduced */ - //PHP_LexerGenerator_Regex_yyStackEntry $yymsp; /* The top of the parser's stack */ + //yyStackEntry $yymsp; /* The top of the parser's stack */ //int $yysize; /* Amount to pop the stack */ if (self::$yyTraceFILE && $yyruleno >= 0 && $yyruleno < count(self::$yyRuleName)) { @@ -1789,7 +1700,7 @@ public function yy_reduce($yyruleno) ** That gives a significant speed improvement. */ if (!self::$yyTraceFILE && $yysize) { $this->yyidx++; - $x = new PHP_LexerGenerator_Regex_yyStackEntry; + $x = new yyStackEntry; $x->stateno = $yyact; $x->major = $yygoto; $x->minor = $yy_lefthand_side; @@ -1882,7 +1793,7 @@ public function doParse($yymajor, $yytokenvalue) /* if ($yymajor == 0) return; // not sure why this was here... */ $this->yyidx = 0; $this->yyerrcnt = -1; - $x = new PHP_LexerGenerator_Regex_yyStackEntry; + $x = new yyStackEntry; $x->stateno = 0; $x->major = 0; $this->yystack = array(); diff --git a/src/SmartyGenerator/LexerGenerator/Regex/yyStackEntry.php b/src/SmartyGenerator/LexerGenerator/Regex/yyStackEntry.php new file mode 100644 index 0000000..1a61909 --- /dev/null +++ b/src/SmartyGenerator/LexerGenerator/Regex/yyStackEntry.php @@ -0,0 +1,23 @@ +string = $s->string; + $this->metadata = $s->metadata; + } else { + $this->string = (string) $s; + if ($m instanceof yyToken) { + $this->metadata = $m->metadata; + } elseif (is_array($m)) { + $this->metadata = $m; + } + } + } + + public function __toString() + { + return $this->_string; + } + + public function offsetExists($offset) + { + return isset($this->metadata[$offset]); + } + + public function offsetGet($offset) + { + return $this->metadata[$offset]; + } + + public function offsetSet($offset, $value) + { + if ($offset === null) { + if (isset($value[0])) { + $x = ($value instanceof yyToken) ? + $value->metadata : $value; + $this->metadata = array_merge($this->metadata, $x); + + return; + } + $offset = count($this->metadata); + } + if ($value === null) { + return; + } + if ($value instanceof yyToken) { + if ($value->metadata) { + $this->metadata[$offset] = $value->metadata; + } + } elseif ($value) { + $this->metadata[$offset] = $value; + } + } + + public function offsetUnset($offset) + { + unset($this->metadata[$offset]); + } +} \ No newline at end of file diff --git a/ParserGenerator.php b/src/SmartyGenerator/ParserGenerator.php similarity index 93% rename from ParserGenerator.php rename to src/SmartyGenerator/ParserGenerator.php index bdcf222..5424df7 100644 --- a/ParserGenerator.php +++ b/src/SmartyGenerator/ParserGenerator.php @@ -1,6 +1,7 @@ * @copyright 2006 Gregory Beaver * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @version CVS: $Id: ParserGenerator.php,v 1.2 2006/12/16 04:01:58 cellog Exp $ * @since File available since Release 0.1.0 */ -/**#@+ - * Basic components of the parser generator - */ -require_once './ParserGenerator/Action.php'; -require_once './ParserGenerator/ActionTable.php'; -require_once './ParserGenerator/Config.php'; -require_once './ParserGenerator/Data.php'; -require_once './ParserGenerator/Symbol.php'; -require_once './ParserGenerator/Rule.php'; -require_once './ParserGenerator/Parser.php'; -require_once './ParserGenerator/PropagationLink.php'; -require_once './ParserGenerator/State.php'; -/**#@-*/ + /** * The basic home class for the parser generator * - * @package PHP_ParserGenerator + * @package \Smarty\ParserGenerator * @author Gregory Beaver * @copyright 2006 Gregory Beaver * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @version 0.1.5 * @since Class available since Release 0.1.0 - * @example Lempar.php - * @example examples/Parser.y Sample parser file format (PHP_LexerGenerator's parser) - * @example examples/Parser.php Sample parser file format PHP code (PHP_LexerGenerator's parser) + * @example Resources/Lempar.lt + * @example examples/Parser.y Sample parser file format (Smarty_LexerGenerator's parser) + * @example examples/Parser.php Sample parser file format PHP code (Smarty_LexerGenerator's parser) */ -class PHP_ParserGenerator +class ParserGenerator { /** * Set this to 1 to turn on debugging of Lemon's parsing of @@ -175,6 +164,10 @@ public function handleflags($i, $argv) return 0; } + public function setQuiet() { + $this->quiet = 1; + } + /** * Process a command line switch which has an argument. * @param int @@ -412,13 +405,13 @@ private function handle_D_option($z) */ /* The main program. Parse the command line and do it... */ - public function main($filename = null) + public function main($filename = null, $fileout = null) { - $lem = new PHP_ParserGenerator_Data; + $lem = new ParserGenerator\Data; if (!isset($filename)) { $this->OptInit($_SERVER['argv']); if ($this->version) { - echo "Lemon version 1.0/PHP_ParserGenerator port version 0.1.5\n"; + echo "Lemon version 1.0/\Smarty\ParserGenerator port version 0.1.5\n"; exit(0); } if ($this->OptNArgs($_SERVER['argv']) != 1) { @@ -440,6 +433,10 @@ public function main($filename = null) } else { $lem->filenosuffix = $lem->filename; } + if (!isset($fileout)) { + $fileout = $lem->filenosuffix . '.php'; + } + $lem->basisflag = $this->basisflag; $lem->has_fallback = 0; $lem->nconflict = 0; @@ -451,11 +448,11 @@ public function main($filename = null) $lem->tokenprefix = $lem->outname = $lem->extracode = 0; $lem->vardest = 0; $lem->tablesize = 0; - PHP_ParserGenerator_Symbol::Symbol_new("$"); - $lem->errsym = PHP_ParserGenerator_Symbol::Symbol_new("error"); + ParserGenerator\Symbol::Symbol_new("$"); + $lem->errsym = ParserGenerator\Symbol::Symbol_new("error"); /* Parse the input file */ - $parser = new PHP_ParserGenerator_Parser($this); + $parser = new ParserGenerator\Parser($this); $parser->Parse($lem); if ($lem->errorcnt) { exit($lem->errorcnt); @@ -466,13 +463,13 @@ public function main($filename = null) } /* Count and index the symbols of the grammar */ - $lem->nsymbol = PHP_ParserGenerator_Symbol::Symbol_count(); - PHP_ParserGenerator_Symbol::Symbol_new("{default}"); - $lem->symbols = PHP_ParserGenerator_Symbol::Symbol_arrayof(); + $lem->nsymbol = ParserGenerator\Symbol::Symbol_count(); + ParserGenerator\Symbol::Symbol_new("{default}"); + $lem->symbols = ParserGenerator\Symbol::Symbol_arrayof(); for ($i = 0; $i <= $lem->nsymbol; $i++) { $lem->symbols[$i]->index = $i; } - usort($lem->symbols, array('PHP_ParserGenerator_Symbol', 'sortSymbols')); + usort($lem->symbols, array(ParserGenerator\Symbol::class, 'sortSymbols')); for ($i = 0; $i <= $lem->nsymbol; $i++) { $lem->symbols[$i]->index = $i; } @@ -498,7 +495,7 @@ public function main($filename = null) ** links so that the follow-set can be computed later */ $lem->nstate = 0; $lem->FindStates(); - $lem->sorted = PHP_ParserGenerator_State::State_arrayof(); + $lem->sorted = ParserGenerator\State::State_arrayof(); /* Tie up loose ends on the propagation links */ $lem->FindLinks(); @@ -524,7 +521,7 @@ public function main($filename = null) } /* Generate the source code for the parser */ - $lem->ReportTable($this->mhflag); + $lem->ReportTable($this->mhflag, $fileout); /* Produce a header file for use by the scanner. (This step is ** omitted if the "-m" option is used because makeheaders will @@ -746,7 +743,7 @@ public function Reprint() for ($i = 0; $i < $rp->nrhs; $i++) { $sp = $rp->rhs[$i]; printf(" %s", $sp->name); - if ($sp->type == PHP_ParserGenerator_Symbol::MULTITERMINAL) { + if ($sp->type == ParserGenerator\Symbol::MULTITERMINAL) { for ($j = 1; $j < $sp->nsubsym; $j++) { printf("|%s", $sp->subsym[$j]->name); } @@ -766,7 +763,7 @@ public function Reprint() } } } -//$a = new PHP_ParserGenerator; +//$a = new \Smarty\ParserGenerator; //$_SERVER['argv'] = array('lemon', '-s', '/development/lemon/PHP_Parser.y'); //$_SERVER['argv'] = array('lemon', '-s', '/development/File_ChessPGN/ChessPGN/Parser.y'); //$a->main(); diff --git a/ParserGenerator/Action.php b/src/SmartyGenerator/ParserGenerator/Action.php similarity index 80% rename from ParserGenerator/Action.php rename to src/SmartyGenerator/ParserGenerator/Action.php index 205df1b..d4ac50b 100644 --- a/ParserGenerator/Action.php +++ b/src/SmartyGenerator/ParserGenerator/Action.php @@ -1,6 +1,9 @@ * @copyright 2006 Gregory Beaver * @license http://www.opensource.org/licenses/bsd-license.php New BSD License @@ -48,14 +51,14 @@ /** * Every shift or reduce operation is stored as one of the following objects. * - * @package PHP_ParserGenerator + * @package \Smarty\ParserGenerator * @author Gregory Beaver * @copyright 2006 Gregory Beaver * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @version 0.1.5 * @since Class available since Release 0.1.0 */ -class PHP_ParserGenerator_Action +class Action { const SHIFT = 1, ACCEPT = 2, @@ -75,38 +78,39 @@ class PHP_ParserGenerator_Action RD_RESOLVED = 7, /** * Deleted by compression - * @see PHP_ParserGenerator::CompressTables() + * + * @see \SmartyGenerator\ParserGenerator::CompressTables() */ NOT_USED = 8; /** * The look-ahead symbol that triggers this action - * @var PHP_ParserGenerator_Symbol + * @var Smarty\ParserGenerator\Symbol */ public $sp; /* The look-ahead symbol */ /** * This defines the kind of action, and must be one * of the class constants. * - * - {@link PHP_ParserGenerator_Action::SHIFT} - * - {@link PHP_ParserGenerator_Action::ACCEPT} - * - {@link PHP_ParserGenerator_Action::REDUCE} - * - {@link PHP_ParserGenerator_Action::ERROR} - * - {@link PHP_ParserGenerator_Action::CONFLICT} - * - {@link PHP_ParserGenerator_Action::SH_RESOLVED} - * - {@link PHP_ParserGenerator_Action:: RD_RESOLVED} - * - {@link PHP_ParserGenerator_Action::NOT_USED} + * - {@link Smarty\ParserGenerator\Action::SHIFT} + * - {@link Smarty\ParserGenerator\Action::ACCEPT} + * - {@link Smarty\ParserGenerator\Action::REDUCE} + * - {@link Smarty\ParserGenerator\Action::ERROR} + * - {@link Smarty\ParserGenerator\Action::CONFLICT} + * - {@link Smarty\ParserGenerator\Action::SH_RESOLVED} + * - {@link Smarty\ParserGenerator\Action:: RD_RESOLVED} + * - {@link Smarty\ParserGenerator\Action::NOT_USED} */ public $type; /** * The new state, if this is a shift, * the parser rule index, if this is a reduce. * - * @var PHP_ParserGenerator_State|PHP_ParserGenerator_Rule + * @var Smarty\ParserGenerator\State|Smarty\ParserGenerator\Rule */ public $x; /** * The next action for this state. - * @var PHP_ParserGenerator_Action + * @var Smarty\ParserGenerator\Action */ public $next; @@ -115,8 +119,8 @@ class PHP_ParserGenerator_Action * * This is used by {@link Action_sort()} to compare actions */ - public static function actioncmp(PHP_ParserGenerator_Action $ap1, - PHP_ParserGenerator_Action $ap2) + public static function actioncmp(Action $ap1, + Action $ap2) { $rc = $ap1->sp->index - $ap2->sp->index; if ($rc === 0) { @@ -174,16 +178,16 @@ public function display($processed = false) } /** - * create linked list of PHP_ParserGenerator_Actions + * create linked list of Actions * - * @param PHP_ParserGenerator_Action|null - * @param int one of the class constants from PHP_ParserGenerator_Action - * @param PHP_ParserGenerator_Symbol - * @param PHP_ParserGenerator_State|PHP_ParserGenerator_Rule + * @param Action|null + * @param int one of the class constants from Action + * @param Symbol + * @param State|Rule */ - public static function Action_add(&$app, $type, PHP_ParserGenerator_Symbol $sp, $arg) + public static function Action_add(&$app, $type, Symbol $sp, $arg) { - $new = new PHP_ParserGenerator_Action; + $new = new Action; $new->next = $app; $app = $new; $new->type = $type; @@ -195,11 +199,11 @@ public static function Action_add(&$app, $type, PHP_ParserGenerator_Symbol $sp, /** * Sort parser actions - * @see PHP_ParserGenerator_Data::FindActions() + * @see Data::FindActions() */ - public static function Action_sort(PHP_ParserGenerator_Action $ap) + public static function Action_sort(Action $ap) { - $ap = PHP_ParserGenerator::msort($ap, 'next', array('PHP_ParserGenerator_Action', 'actioncmp')); + $ap = \SmartyGenerator\ParserGenerator::msort($ap, 'next', array(Action::class, 'actioncmp')); return $ap; } @@ -207,7 +211,7 @@ public static function Action_sort(PHP_ParserGenerator_Action $ap) /** * Print an action to the given file descriptor. Return FALSE if * nothing was actually printed. - * @see PHP_ParserGenerator_Data::ReportOutput() + * @see Data::ReportOutput() */ public function PrintAction($fp, $indent) { diff --git a/ParserGenerator/ActionTable.php b/src/SmartyGenerator/ParserGenerator/ActionTable.php similarity index 97% rename from ParserGenerator/ActionTable.php rename to src/SmartyGenerator/ParserGenerator/ActionTable.php index f8a18d9..5a5d01e 100644 --- a/ParserGenerator/ActionTable.php +++ b/src/SmartyGenerator/ParserGenerator/ActionTable.php @@ -1,6 +1,8 @@ * @copyright 2006 Gregory Beaver * @license http://www.opensource.org/licenses/bsd-license.php New BSD License @@ -48,14 +50,14 @@ /** * The state of the yy_action table under construction is an instance of * the following structure - * @package PHP_ParserGenerator + * @package \Smarty\ParserGenerator * @author Gregory Beaver * @copyright 2006 Gregory Beaver * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @version 0.1.5 * @since Class available since Release 0.1.0 */ -class PHP_ParserGenerator_ActionTable +class ActionTable { /** * Number of used slots in {@link $aAction} @@ -72,7 +74,7 @@ class PHP_ParserGenerator_ActionTable * 'action' => -1 // Action to take on the given lookahead (action index) * ); * - * @see PHP_ParserGenerator_Data::compute_action() + * @see Data::compute_action() * @var array */ public $aAction = diff --git a/ParserGenerator/Config.php b/src/SmartyGenerator/ParserGenerator/Config.php similarity index 85% rename from ParserGenerator/Config.php rename to src/SmartyGenerator/ParserGenerator/Config.php index 438a4f0..af427e4 100644 --- a/ParserGenerator/Config.php +++ b/src/SmartyGenerator/ParserGenerator/Config.php @@ -1,6 +1,8 @@ * @copyright 2006 Gregory Beaver * @license http://www.opensource.org/licenses/bsd-license.php New BSD License @@ -53,14 +55,14 @@ * symbols which are allowed to immediately follow the end of the rule. * Every configuration is recorded as an instance of the following class. * - * @package PHP_ParserGenerator + * @package \Smarty\ParserGenerator * @author Gregory Beaver * @copyright 2006 Gregory Beaver * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @version 0.1.5 * @since Class available since Release 0.1.0 */ -class PHP_ParserGenerator_Config +class Config { const COMPLETE = 1; const INCOMPLETE = 2; @@ -71,7 +73,7 @@ class PHP_ParserGenerator_Config *
      * 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 * @copyright 2006 Gregory Beaver * @license http://www.opensource.org/licenses/bsd-license.php New BSD License @@ -58,7 +60,7 @@ * @since Class available since Release 0.1.0 */ -class PHP_ParserGenerator_Data +class Data { /** * Used for terminal and non-terminal offsets into the action table @@ -67,12 +69,12 @@ class PHP_ParserGenerator_Data const NO_OFFSET = -2147483647; /** * Table of states sorted by state number - * @var array array of {@link PHP_ParserGenerator_State} objects + * @var array array of {@link State} objects */ public $sorted; /** * List of all rules - * @var PHP_ParserGenerator_Rule + * @var Rule */ public $rule; /** @@ -97,7 +99,7 @@ class PHP_ParserGenerator_Data public $nterminal; /** * Sorted array of pointers to symbols - * @var array array of {@link PHP_ParserGenerator_Symbol} objects + * @var array array of {@link Symbol} objects */ public $symbols = array(); /** @@ -107,7 +109,7 @@ class PHP_ParserGenerator_Data public $errorcnt; /** * The error symbol - * @var PHP_ParserGenerator_Symbol + * @var Symbol */ public $errsym; /** @@ -324,7 +326,7 @@ public function FindRulePrecedences() if ($rp->precsym === 0) { for ($i = 0; $i < $rp->nrhs && $rp->precsym === 0; $i++) { $sp = $rp->rhs[$i]; - if ($sp->type == PHP_ParserGenerator_Symbol::MULTITERMINAL) { + if ($sp->type == Symbol::MULTITERMINAL) { for ($j = 0; $j < $sp->nsubsym; $j++) { if ($sp->subsym[$j]->prec >= 0) { $rp->precsym = $sp->subsym[$j]; @@ -363,7 +365,7 @@ public function FindFirstSets() } for ($i = 0; $i < $rp->nrhs; $i++) { $sp = $rp->rhs[$i]; - if ($sp->type != PHP_ParserGenerator_Symbol::TERMINAL || $sp->lambda === false) { + if ($sp->type != Symbol::TERMINAL || $sp->lambda === false) { break; } } @@ -381,12 +383,12 @@ public function FindFirstSets() $s1 = $rp->lhs; for ($i = 0; $i < $rp->nrhs; $i++) { $s2 = $rp->rhs[$i]; - if ($s2->type == PHP_ParserGenerator_Symbol::TERMINAL) { + if ($s2->type == Symbol::TERMINAL) { //progress += SetAdd(s1->firstset,s2->index); $progress += isset($s1->firstset[$s2->index]) ? 0 : 1; $s1->firstset[$s2->index] = 1; break; - } elseif ($s2->type == PHP_ParserGenerator_Symbol::MULTITERMINAL) { + } elseif ($s2->type == Symbol::MULTITERMINAL) { for ($j = 0; $j < $s2->nsubsym; $j++) { //progress += SetAdd(s1->firstset,s2->subsym[j]->index); $progress += isset($s1->firstset[$s2->subsym[$j]->index]) ? 0 : 1; @@ -420,13 +422,13 @@ public function FindFirstSets() */ public function FindStates() { - PHP_ParserGenerator_Config::Configlist_init(); + Config::Configlist_init(); /* Find the start symbol */ if ($this->start) { - $sp = PHP_ParserGenerator_Symbol::Symbol_find($this->start); + $sp = Symbol::Symbol_find($this->start); if ($sp == 0) { - PHP_ParserGenerator::ErrorMsg($this->filename, 0, + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, 0, "The specified start symbol \"%s\" is not " . "in a nonterminal of the grammar. \"%s\" will be used as the start " . "symbol instead.", $this->start, $this->rule->lhs->name); @@ -442,10 +444,10 @@ public function FindStates() ** start symbol in this case.) */ for ($rp = $this->rule; $rp; $rp = $rp->next) { for ($i = 0; $i < $rp->nrhs; $i++) { - if ($rp->rhs[$i]->type == PHP_ParserGenerator_Symbol::MULTITERMINAL) { + if ($rp->rhs[$i]->type == Symbol::MULTITERMINAL) { foreach ($rp->rhs[$i]->subsym as $subsp) { if ($subsp === $sp) { - PHP_ParserGenerator::ErrorMsg($this->filename, 0, + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, 0, "The start symbol \"%s\" occurs on the " . "right-hand side of a rule. This will result in a parser which " . "does not work properly.", $sp->name); @@ -453,7 +455,7 @@ public function FindStates() } } } elseif ($rp->rhs[$i] === $sp) { - PHP_ParserGenerator::ErrorMsg($this->filename, 0, + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, 0, "The start symbol \"%s\" occurs on the " . "right-hand side of a rule. This will result in a parser which " . "does not work properly.", $sp->name); @@ -466,7 +468,7 @@ public function FindStates() ** is all rules which have the start symbol as their ** left-hand side */ for ($rp = $sp->rule; $rp; $rp = $rp->nextlhs) { - $newcfp = PHP_ParserGenerator_Config::Configlist_addbasis($rp, 0); + $newcfp = Config::Configlist_addbasis($rp, 0); $newcfp->fws[0] = 1; } @@ -481,39 +483,39 @@ public function FindStates() } /** - * @return PHP_ParserGenerator_State + * @return State */ private function getstate() { /* Extract the sorted basis of the new state. The basis was constructed ** by prior calls to "Configlist_addbasis()". */ - PHP_ParserGenerator_Config::Configlist_sortbasis(); - $bp = PHP_ParserGenerator_Config::Configlist_basis(); + Config::Configlist_sortbasis(); + $bp = Config::Configlist_basis(); /* Get a state with the same basis */ - $stp = PHP_ParserGenerator_State::State_find($bp); + $stp = State::State_find($bp); if ($stp) { /* A state with the same basis already exists! Copy all the follow-set ** propagation links from the state under construction into the ** preexisting state, then return a pointer to the preexisting state */ for ($x = $bp, $y = $stp->bp; $x && $y; $x = $x->bp, $y = $y->bp) { - PHP_ParserGenerator_PropagationLink::Plink_copy($y->bplp, $x->bplp); - PHP_ParserGenerator_PropagationLink::Plink_delete($x->fplp); + PropagationLink::Plink_copy($y->bplp, $x->bplp); + PropagationLink::Plink_delete($x->fplp); $x->fplp = $x->bplp = 0; } - $cfp = PHP_ParserGenerator_Config::Configlist_return(); - PHP_ParserGenerator_Config::Configlist_eat($cfp); + $cfp = Config::Configlist_return(); + Config::Configlist_eat($cfp); } else { /* This really is a new state. Construct all the details */ - PHP_ParserGenerator_Config::Configlist_closure($this); /* Compute the configuration closure */ - PHP_ParserGenerator_Config::Configlist_sort(); /* Sort the configuration closure */ - $cfp = PHP_ParserGenerator_Config::Configlist_return(); /* Get a pointer to the config list */ - $stp = new PHP_ParserGenerator_State; /* A new state structure */ + Config::Configlist_closure($this); /* Compute the configuration closure */ + Config::Configlist_sort(); /* Sort the configuration closure */ + $cfp = Config::Configlist_return(); /* Get a pointer to the config list */ + $stp = new State; /* A new state structure */ $stp->bp = $bp; /* Remember the configuration basis */ $stp->cfp = $cfp; /* Remember the configuration closure */ $stp->statenum = $this->nstate++; /* Every state gets a sequence number */ $stp->ap = 0; /* No actions, yet. */ - PHP_ParserGenerator_State::State_insert($stp, $stp->bp); /* Add to the state table */ + State::State_insert($stp, $stp->bp); /* Add to the state table */ // this can't work, recursion is too deep, move it into FindStates() //$this->buildshifts($stp); /* Recursively compute successor states */ return array($stp); @@ -525,10 +527,10 @@ private function getstate() /** * Construct all successor states to the given state. A "successor" * state is any state which can be reached by a shift action. - * @param PHP_ParserGenerator_Data - * @param PHP_ParserGenerator_State The state from which successors are computed + * @param Data + * @param State The state from which successors are computed */ - private function buildshifts(PHP_ParserGenerator_State $stp) + private function buildshifts(State $stp) { // struct config *cfp; /* For looping thru the config closure of "stp" */ // struct config *bcfp; /* For the inner loop on config closure of "stp" */ @@ -541,18 +543,18 @@ private function buildshifts(PHP_ParserGenerator_State $stp) ** state. Initially, all configurations are incomplete */ $cfp = $stp->cfp; for ($cfp = $stp->cfp; $cfp; $cfp = $cfp->next) { - $cfp->status = PHP_ParserGenerator_Config::INCOMPLETE; + $cfp->status = Config::INCOMPLETE; } /* Loop through all configurations of the state "stp" */ for ($cfp = $stp->cfp; $cfp; $cfp = $cfp->next) { - if ($cfp->status == PHP_ParserGenerator_Config::COMPLETE) { + if ($cfp->status == Config::COMPLETE) { continue; /* Already used by inner loop */ } if ($cfp->dot >= $cfp->rp->nrhs) { continue; /* Can't shift this config */ } - PHP_ParserGenerator_Config::Configlist_reset(); /* Reset the new config set */ + Config::Configlist_reset(); /* Reset the new config set */ $sp = $cfp->rp->rhs[$cfp->dot]; /* Symbol after the dot */ /* For every configuration in the state "stp" which has the symbol "sp" @@ -560,19 +562,19 @@ private function buildshifts(PHP_ParserGenerator_State $stp) ** construction but with the dot shifted one symbol to the right. */ $bcfp = $cfp; for ($bcfp = $cfp; $bcfp; $bcfp = $bcfp->next) { - if ($bcfp->status == PHP_ParserGenerator_Config::COMPLETE) { + if ($bcfp->status == Config::COMPLETE) { continue; /* Already used */ } if ($bcfp->dot >= $bcfp->rp->nrhs) { continue; /* Can't shift this one */ } $bsp = $bcfp->rp->rhs[$bcfp->dot]; /* Get symbol after dot */ - if (!PHP_ParserGenerator_Symbol::same_symbol($bsp, $sp)) { + if (!Symbol::same_symbol($bsp, $sp)) { continue; /* Must be same as for "cfp" */ } - $bcfp->status = PHP_ParserGenerator_Config::COMPLETE; /* Mark this config as used */ - $new = PHP_ParserGenerator_Config::Configlist_addbasis($bcfp->rp, $bcfp->dot + 1); - PHP_ParserGenerator_PropagationLink::Plink_add($new->bplp, $bcfp); + $bcfp->status = Config::COMPLETE; /* Mark this config as used */ + $new = Config::Configlist_addbasis($bcfp->rp, $bcfp->dot + 1); + PropagationLink::Plink_add($new->bplp, $bcfp); } /* Get a pointer to the state described by the basis configuration set @@ -585,13 +587,13 @@ private function buildshifts(PHP_ParserGenerator_State $stp) /* The state "newstp" is reached from the state "stp" by a shift action ** on the symbol "sp" */ - if ($sp->type == PHP_ParserGenerator_Symbol::MULTITERMINAL) { + if ($sp->type == Symbol::MULTITERMINAL) { for ($i = 0; $i < $sp->nsubsym; $i++) { - PHP_ParserGenerator_Action::Action_add($stp->ap, PHP_ParserGenerator_Action::SHIFT, $sp->subsym[$i], + Action::Action_add($stp->ap, Action::SHIFT, $sp->subsym[$i], $newstp); } } else { - PHP_ParserGenerator_Action::Action_add($stp->ap, PHP_ParserGenerator_Action::SHIFT, $sp, $newstp); + Action::Action_add($stp->ap, Action::SHIFT, $sp, $newstp); } } } @@ -615,7 +617,7 @@ public function FindLinks() for ($cfp = $stp->data->cfp; $cfp; $cfp = $cfp->next) { for ($plp = $cfp->bplp; $plp; $plp = $plp->next) { $other = $plp->cfp; - PHP_ParserGenerator_PropagationLink::Plink_add($other->fplp, $cfp); + PropagationLink::Plink_add($other->fplp, $cfp); } } } @@ -639,7 +641,7 @@ public function FindActions() if (isset($cfp->fws[$j])) { /* Add a reduce action to the state "stp" which will reduce by the ** rule "cfp->rp" if the lookahead symbol is "$this->symbols[j]" */ - PHP_ParserGenerator_Action::Action_add($stp->ap, PHP_ParserGenerator_Action::REDUCE, + Action::Action_add($stp->ap, Action::REDUCE, $this->symbols[$j], $cfp->rp); } } @@ -648,8 +650,8 @@ public function FindActions() } /* Add the accepting token */ - if ($this->start instanceof PHP_ParserGenerator_Symbol) { - $sp = PHP_ParserGenerator_Symbol::Symbol_find($this->start); + if ($this->start instanceof Symbol) { + $sp = Symbol::Symbol_find($this->start); if ($sp === 0) { $sp = $this->rule->lhs; } @@ -659,7 +661,7 @@ public function FindActions() /* Add to the first state (which is always the starting state of the ** finite state machine) an action to ACCEPT if the lookahead is the ** start nonterminal. */ - PHP_ParserGenerator_Action::Action_add($this->sorted[0]->data->ap, PHP_ParserGenerator_Action::ACCEPT, $sp, 0); + Action::Action_add($this->sorted[0]->data->ap, Action::ACCEPT, $sp, 0); /* Resolve conflicts */ for ($i = 0; $i < $this->nstate; $i++) { @@ -674,7 +676,7 @@ public function FindActions() echo ' Action '; $ap->display(true); } - $stp->ap = PHP_ParserGenerator_Action::Action_sort($stp->ap); + $stp->ap = Action::Action_sort($stp->ap); for ($ap = $stp->ap; $ap !== 0 && $ap->next !== 0; $ap = $ap->next) { for ($nap = $ap->next; $nap !== 0 && $nap->sp === $ap->sp ; $nap = $nap->next) { /* The two actions "ap" and "nap" have the same lookahead. @@ -690,7 +692,7 @@ public function FindActions() } for ($i = 0; $i < $this->nstate; $i++) { for ($ap = $this->sorted[$i]->data->ap; $ap !== 0; $ap = $ap->next) { - if ($ap->type == PHP_ParserGenerator_Action::REDUCE) { + if ($ap->type == Action::REDUCE) { $ap->x->canReduce = true; } } @@ -699,7 +701,7 @@ public function FindActions() if ($rp->canReduce) { continue; } - PHP_ParserGenerator::ErrorMsg($this->filename, $rp->ruleline, "This rule can not be reduced (is not connected to the start symbol).\n"); + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, $rp->ruleline, "This rule can not be reduced (is not connected to the start symbol).\n"); $this->errorcnt++; } } @@ -716,9 +718,9 @@ public function FindActions() * * If either action is a SHIFT, then it must be apx. This * function won't work if apx->type==REDUCE and apy->type==SHIFT. - * @param PHP_ParserGenerator_Action - * @param PHP_ParserGenerator_Action - * @param PHP_ParserGenerator_Symbol|null The error symbol (if defined. NULL otherwise) + * @param Action + * @param Action + * @param Symbol|null The error symbol (if defined. NULL otherwise) */ public function resolve_conflict($apx, $apy, $errsym) { @@ -726,55 +728,55 @@ public function resolve_conflict($apx, $apy, $errsym) if ($apx->sp !== $apy->sp) { throw new Exception('no conflict but resolve_conflict called'); } - if ($apx->type == PHP_ParserGenerator_Action::SHIFT && $apy->type == PHP_ParserGenerator_Action::REDUCE) { + if ($apx->type == Action::SHIFT && $apy->type == Action::REDUCE) { $spx = $apx->sp; $spy = $apy->x->precsym; if ($spy === 0 || $spx->prec < 0 || $spy->prec < 0) { /* Not enough precedence information. */ - $apy->type = PHP_ParserGenerator_Action::CONFLICT; + $apy->type = Action::CONFLICT; $errcnt++; } elseif ($spx->prec > $spy->prec) { /* Lower precedence wins */ - $apy->type = PHP_ParserGenerator_Action::RD_RESOLVED; + $apy->type = Action::RD_RESOLVED; } elseif ($spx->prec < $spy->prec) { - $apx->type = PHP_ParserGenerator_Action::SH_RESOLVED; - } elseif ($spx->prec === $spy->prec && $spx->assoc == PHP_ParserGenerator_Symbol::RIGHT) { + $apx->type = Action::SH_RESOLVED; + } elseif ($spx->prec === $spy->prec && $spx->assoc == Symbol::RIGHT) { /* Use operator */ - $apy->type = PHP_ParserGenerator_Action::RD_RESOLVED; /* associativity */ - } elseif ($spx->prec === $spy->prec && $spx->assoc == PHP_ParserGenerator_Symbol::LEFT) { + $apy->type = Action::RD_RESOLVED; /* associativity */ + } elseif ($spx->prec === $spy->prec && $spx->assoc == Symbol::LEFT) { /* to break tie */ - $apx->type = PHP_ParserGenerator_Action::SH_RESOLVED; + $apx->type = Action::SH_RESOLVED; } else { - if ($spx->prec !== $spy->prec || $spx->assoc !== PHP_ParserGenerator_Symbol::NONE) { - throw new Exception('$spx->prec !== $spy->prec || $spx->assoc !== PHP_ParserGenerator_Symbol::NONE'); + if ($spx->prec !== $spy->prec || $spx->assoc !== Symbol::NONE) { + throw new Exception('$spx->prec !== $spy->prec || $spx->assoc !== Symbol::NONE'); } - $apy->type = PHP_ParserGenerator_Action::CONFLICT; + $apy->type = Action::CONFLICT; $errcnt++; } - } elseif ($apx->type == PHP_ParserGenerator_Action::REDUCE && $apy->type == PHP_ParserGenerator_Action::REDUCE) { + } elseif ($apx->type == Action::REDUCE && $apy->type == Action::REDUCE) { $spx = $apx->x->precsym; $spy = $apy->x->precsym; if ($spx === 0 || $spy === 0 || $spx->prec < 0 || $spy->prec < 0 || $spx->prec === $spy->prec) { - $apy->type = PHP_ParserGenerator_Action::CONFLICT; + $apy->type = Action::CONFLICT; $errcnt++; } elseif ($spx->prec > $spy->prec) { - $apy->type = PHP_ParserGenerator_Action::RD_RESOLVED; + $apy->type = Action::RD_RESOLVED; } elseif ($spx->prec < $spy->prec) { - $apx->type = PHP_ParserGenerator_Action::RD_RESOLVED; + $apx->type = Action::RD_RESOLVED; } } else { - if ($apx->type!== PHP_ParserGenerator_Action::SH_RESOLVED && - $apx->type!== PHP_ParserGenerator_Action::RD_RESOLVED && - $apx->type!== PHP_ParserGenerator_Action::CONFLICT && - $apy->type!== PHP_ParserGenerator_Action::SH_RESOLVED && - $apy->type!== PHP_ParserGenerator_Action::RD_RESOLVED && - $apy->type!== PHP_ParserGenerator_Action::CONFLICT) { - throw new Exception('$apx->type!== PHP_ParserGenerator_Action::SH_RESOLVED && - $apx->type!== PHP_ParserGenerator_Action::RD_RESOLVED && - $apx->type!== PHP_ParserGenerator_Action::CONFLICT && - $apy->type!== PHP_ParserGenerator_Action::SH_RESOLVED && - $apy->type!== PHP_ParserGenerator_Action::RD_RESOLVED && - $apy->type!== PHP_ParserGenerator_Action::CONFLICT'); + if ($apx->type!== Action::SH_RESOLVED && + $apx->type!== Action::RD_RESOLVED && + $apx->type!== Action::CONFLICT && + $apy->type!== Action::SH_RESOLVED && + $apy->type!== Action::RD_RESOLVED && + $apy->type!== Action::CONFLICT) { + throw new Exception('$apx->type!== Action::SH_RESOLVED && + $apx->type!== Action::RD_RESOLVED && + $apx->type!== Action::CONFLICT && + $apy->type!== Action::SH_RESOLVED && + $apy->type!== Action::RD_RESOLVED && + $apy->type!== Action::CONFLICT'); } /* The REDUCE/SHIFT case cannot happen because SHIFTs come before ** REDUCEs on the list. If we reach this point it must be because @@ -799,7 +801,7 @@ public function CompressTables() $rbest = 0; for ($ap = $stp->ap; $ap; $ap = $ap->next) { - if ($ap->type != PHP_ParserGenerator_Action::REDUCE) { + if ($ap->type != Action::REDUCE) { continue; } $rp = $ap->x; @@ -808,7 +810,7 @@ public function CompressTables() } $n = 1; for ($ap2 = $ap->next; $ap2; $ap2 = $ap2->next) { - if ($ap2->type != PHP_ParserGenerator_Action::REDUCE) { + if ($ap2->type != Action::REDUCE) { continue; } $rp2 = $ap2->x; @@ -833,20 +835,20 @@ public function CompressTables() /* Combine matching REDUCE actions into a single default */ for ($ap = $stp->ap; $ap; $ap = $ap->next) { - if ($ap->type == PHP_ParserGenerator_Action::REDUCE && $ap->x === $rbest) { + if ($ap->type == Action::REDUCE && $ap->x === $rbest) { break; } } if ($ap === 0) { throw new Exception('$ap is not an object'); } - $ap->sp = PHP_ParserGenerator_Symbol::Symbol_new("{default}"); + $ap->sp = Symbol::Symbol_new("{default}"); for ($ap = $ap->next; $ap; $ap = $ap->next) { - if ($ap->type == PHP_ParserGenerator_Action::REDUCE && $ap->x === $rbest) { - $ap->type = PHP_ParserGenerator_Action::NOT_USED; + if ($ap->type == Action::REDUCE && $ap->x === $rbest) { + $ap->type = Action::NOT_USED; } } - $stp->ap = PHP_ParserGenerator_Action::Action_sort($stp->ap); + $stp->ap = Action::Action_sort($stp->ap); } } @@ -860,8 +862,8 @@ public function ResortStates() $stp = $this->sorted[$i]->data; $stp->nTknAct = $stp->nNtAct = 0; $stp->iDflt = $this->nstate + $this->nrule; - $stp->iTknOfst = PHP_ParserGenerator_Data::NO_OFFSET; - $stp->iNtOfst = PHP_ParserGenerator_Data::NO_OFFSET; + $stp->iTknOfst = Data::NO_OFFSET; + $stp->iNtOfst = Data::NO_OFFSET; for ($ap = $stp->ap; $ap; $ap = $ap->next) { if ($this->compute_action($ap) >= 0) { if ($ap->sp->index < $this->nterminal) { @@ -877,7 +879,7 @@ public function ResortStates() } $save = $this->sorted[0]; unset($this->sorted[0]); - usort($this->sorted, array('PHP_ParserGenerator_State', 'stateResortCompare')); + usort($this->sorted, array(State::class, 'stateResortCompare')); array_unshift($this->sorted, $save); for ($i = 0; $i < $this->nstate; $i++) { $this->sorted[$i]->statenum = $i; @@ -888,21 +890,21 @@ public function ResortStates() * Given an action, compute the integer value for that action * which is to be put in the action table of the generated machine. * Return negative if no action should be generated. - * @param PHP_ParserGenerator_Action + * @param Action */ public function compute_action($ap) { switch ($ap->type) { - case PHP_ParserGenerator_Action::SHIFT: + case Action::SHIFT: $act = $ap->x->statenum; break; - case PHP_ParserGenerator_Action::REDUCE: + case Action::REDUCE: $act = $ap->x->index + $this->nstate; break; - case PHP_ParserGenerator_Action::ERROR: + case Action::ERROR: $act = $this->nstate + $this->nrule; break; - case PHP_ParserGenerator_Action::ACCEPT: + case Action::ACCEPT: $act = $this->nstate + $this->nrule + 1; break; default: @@ -967,7 +969,7 @@ public function ReportOutput() */ private function tplt_open() { - $templatename = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . "Lempar.php"; + $templatename = dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . "Resources" . DIRECTORY_SEPARATOR . "Lempar.lt"; $buf = $this->filenosuffix . '.lt'; if (file_exists($buf) && is_readable($buf)) { $tpltname = $buf; @@ -1064,7 +1066,7 @@ public function FindFollowSets() { for ($i = 0; $i < $this->nstate; $i++) { for ($cfp = $this->sorted[$i]->data->cfp; $cfp; $cfp = $cfp->next) { - $cfp->status = PHP_ParserGenerator_Config::INCOMPLETE; + $cfp->status = Config::INCOMPLETE; } } @@ -1072,18 +1074,18 @@ public function FindFollowSets() $progress = 0; for ($i = 0; $i < $this->nstate; $i++) { for ($cfp = $this->sorted[$i]->data->cfp; $cfp; $cfp = $cfp->next) { - if ($cfp->status == PHP_ParserGenerator_Config::COMPLETE) { + if ($cfp->status == Config::COMPLETE) { continue; } for ($plp = $cfp->fplp; $plp; $plp = $plp->next) { $a = array_diff_key($cfp->fws, $plp->cfp->fws); if (count($a)) { $plp->cfp->fws += $a; - $plp->cfp->status = PHP_ParserGenerator_Config::INCOMPLETE; + $plp->cfp->status = Config::INCOMPLETE; $progress = 1; } } - $cfp->status = PHP_ParserGenerator_Config::COMPLETE; + $cfp->status = Config::COMPLETE; } } } while ($progress); @@ -1093,7 +1095,7 @@ public function FindFollowSets() * Generate C source code for the parser * @param int Output in makeheaders format if true */ - public function ReportTable($mhflag) + public function ReportTable($mhflag, $fileout) { // FILE *out, *in; // char line[LINESIZE]; @@ -1112,13 +1114,13 @@ public function ReportTable($mhflag) if (!$in) { return; } - $out = fopen($this->filenosuffix . ".php", "wb"); + $out = fopen($fileout, "wb"); if (!$out) { fclose($in); return; } - $this->outname = $this->filenosuffix . ".php"; + $this->outname = $fileout; $lineno = 1; $this->tplt_xfer($this->name, $in, $out, $lineno); @@ -1197,8 +1199,8 @@ public function ReportTable($mhflag) ** sets first is used. */ - usort($ax, array('PHP_ParserGenerator_Data', 'axset_compare')); - $pActtab = new PHP_ParserGenerator_ActionTable; + usort($ax, array(Data::class, 'axset_compare')); + $pActtab = new ActionTable; for ($i = 0; $i < $this->nstate * 2 && $ax[$i]['nAction'] > 0; $i++) { $stp = $ax[$i]['stp']; if ($ax[$i]['isTkn']) { @@ -1298,7 +1300,7 @@ public function ReportTable($mhflag) fprintf($out, " const YY_SHIFT_USE_DFLT = %d;\n", $mnTknOfst - 1); $lineno++; $n = $this->nstate; - while ($n > 0 && $this->sorted[$n - 1]->iTknOfst == PHP_ParserGenerator_Data::NO_OFFSET) { + while ($n > 0 && $this->sorted[$n - 1]->iTknOfst == Data::NO_OFFSET) { $n--; } fprintf($out, " const YY_SHIFT_MAX = %d;\n", $n - 1); @@ -1308,7 +1310,7 @@ public function ReportTable($mhflag) for ($i = $j = 0; $i < $n; $i++) { $stp = $this->sorted[$i]; $ofst = $stp->iTknOfst; - if ($ofst === PHP_ParserGenerator_Data::NO_OFFSET) { + if ($ofst === Data::NO_OFFSET) { $ofst = $mnTknOfst - 1; } // change next line @@ -1332,7 +1334,7 @@ public function ReportTable($mhflag) fprintf($out, " const YY_REDUCE_USE_DFLT = %d;\n", $mnNtOfst - 1); $lineno++; $n = $this->nstate; - while ($n > 0 && $this->sorted[$n - 1]->iNtOfst == PHP_ParserGenerator_Data::NO_OFFSET) { + while ($n > 0 && $this->sorted[$n - 1]->iNtOfst == Data::NO_OFFSET) { $n--; } fprintf($out, " const YY_REDUCE_MAX = %d;\n", $n - 1); @@ -1342,7 +1344,7 @@ public function ReportTable($mhflag) for ($i = $j = 0; $i < $n; $i++) { $stp = $this->sorted[$i]; $ofst = $stp->iNtOfst; - if ($ofst == PHP_ParserGenerator_Data::NO_OFFSET) { + if ($ofst == Data::NO_OFFSET) { $ofst = $mnNtOfst - 1; } // change next line @@ -1370,8 +1372,8 @@ public function ReportTable($mhflag) fwrite($out, " /* $i */ array("); for ($ap = $stp->ap; $ap; $ap = $ap->next) { if ($ap->sp->index < $this->nterminal) { - if ($ap->type == PHP_ParserGenerator_Action::SHIFT || - $ap->type == PHP_ParserGenerator_Action::REDUCE) { + if ($ap->type == Action::SHIFT || + $ap->type == Action::REDUCE) { fwrite($out, $ap->sp->index . ', '); } } @@ -1410,7 +1412,7 @@ public function ReportTable($mhflag) $lineno++; if ($this->stacksize) { if ($this->stacksize <= 0) { - PHP_ParserGenerator::ErrorMsg($this->filename, 0, + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, 0, "Illegal stack size: [%s]. The stack size should be an integer constant.", $this->stacksize); $this->errorcnt++; @@ -1488,7 +1490,7 @@ public function ReportTable($mhflag) for ($j = 0; $j < $rp->nrhs; $j++) { $sp = $rp->rhs[$j]; fwrite($out,' ' . $sp->name); - if ($sp->type == PHP_ParserGenerator_Symbol::MULTITERMINAL) { + if ($sp->type == Symbol::MULTITERMINAL) { for ($k = 1; $k < $sp->nsubsym; $k++) { fwrite($out, '|' . $sp->subsym[$k]->name); } @@ -1507,14 +1509,14 @@ public function ReportTable($mhflag) if ($this->tokendest) { for ($i = 0; $i < $this->nsymbol; $i++) { $sp = $this->symbols[$i]; - if ($sp === 0 || $sp->type != PHP_ParserGenerator_Symbol::TERMINAL) { + if ($sp === 0 || $sp->type != Symbol::TERMINAL) { continue; } fprintf($out, " case %d:\n", $sp->index); $lineno++; } for ($i = 0; $i < $this->nsymbol && - $this->symbols[$i]->type != PHP_ParserGenerator_Symbol::TERMINAL; $i++); + $this->symbols[$i]->type != Symbol::TERMINAL; $i++); if ($i < $this->nsymbol) { $this->emit_destructor_code($out, $this->symbols[$i], $lineno); fprintf($out, " break;\n"); @@ -1525,7 +1527,7 @@ public function ReportTable($mhflag) $dflt_sp = 0; for ($i = 0; $i < $this->nsymbol; $i++) { $sp = $this->symbols[$i]; - if ($sp === 0 || $sp->type == PHP_ParserGenerator_Symbol::TERMINAL || + if ($sp === 0 || $sp->type == Symbol::TERMINAL || $sp->index <= 0 || $sp->destructor != 0) { continue; } @@ -1541,7 +1543,7 @@ public function ReportTable($mhflag) } for ($i = 0; $i < $this->nsymbol; $i++) { $sp = $this->symbols[$i]; - if ($sp === 0 || $sp->type == PHP_ParserGenerator_Symbol::TERMINAL || + if ($sp === 0 || $sp->type == Symbol::TERMINAL || $sp->destructor === 0) { continue; } @@ -1552,7 +1554,7 @@ public function ReportTable($mhflag) for ($j = $i + 1; $j < $this->nsymbol; $j++) { $sp2 = $this->symbols[$j]; - if ($sp2 && $sp2->type != PHP_ParserGenerator_Symbol::TERMINAL && $sp2->destructor + if ($sp2 && $sp2->type != Symbol::TERMINAL && $sp2->destructor && $sp2->dtnum == $sp->dtnum && $sp->destructor == $sp2->destructor) { fprintf($out, " case %d:\n", $sp2->index); @@ -1648,7 +1650,7 @@ public function ReportTable($mhflag) * Generate code which executes when the rule "rp" is reduced. Write * the code to "out". Make sure lineno stays up-to-date. */ - public function emit_code($out, PHP_ParserGenerator_Rule $rp, &$lineno) + public function emit_code($out, Rule $rp, &$lineno) { $linecnt = 0; @@ -1708,7 +1710,7 @@ public function append_str($zText, $n) * the symbols in this string so that the refer to elements of the parser * stack. */ - public function translate_code(PHP_ParserGenerator_Rule $rp) + public function translate_code(Rule $rp) { $lhsused = 0; /* True if the LHS element has been used */ $used = array(); /* True for each RHS element which is used */ @@ -1744,7 +1746,7 @@ public function translate_code(PHP_ParserGenerator_Rule $rp) ($ii - $rp->nrhs + 1) . "]->major", -1); } else { $sp = $rp->rhs[$ii]; - if ($sp->type == PHP_ParserGenerator_Symbol::MULTITERMINAL) { + if ($sp->type == Symbol::MULTITERMINAL) { $dtnum = $sp->subsym[0]->dtnum; } else { $dtnum = $sp->dtnum; @@ -1765,7 +1767,7 @@ public function translate_code(PHP_ParserGenerator_Rule $rp) /* Check to make sure the LHS has been used */ if ($rp->lhsalias && !$lhsused) { - PHP_ParserGenerator::ErrorMsg($this->filename, $rp->ruleline, + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, $rp->ruleline, "Label \"%s\" for \"%s(%s)\" is never used.", $rp->lhsalias, $rp->lhs->name, $rp->lhsalias); $this->errorcnt++; @@ -1775,12 +1777,12 @@ public function translate_code(PHP_ParserGenerator_Rule $rp) ** reduce code */ for ($i = 0; $i < $rp->nrhs; $i++) { if ($rp->rhsalias[$i] && !isset($used[$i])) { - PHP_ParserGenerator::ErrorMsg($this->filename, $rp->ruleline, + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, $rp->ruleline, "Label %s for \"%s(%s)\" is never used.", $rp->rhsalias[$i], $rp->rhs[$i]->name, $rp->rhsalias[$i]); $this->errorcnt++; } elseif ($rp->rhsalias[$i] == 0) { - if ($rp->rhs[$i]->type == PHP_ParserGenerator_Symbol::TERMINAL) { + if ($rp->rhs[$i]->type == Symbol::TERMINAL) { $hasdestructor = $this->tokendest != 0; } else { $hasdestructor = $this->vardest !== 0 || $rp->rhs[$i]->destructor !== 0; @@ -1802,7 +1804,7 @@ public function translate_code(PHP_ParserGenerator_Rule $rp) * The following routine emits code for the destructor for the * symbol sp */ - public function emit_destructor_code($out, PHP_ParserGenerator_Symbol $sp, &$lineno) + public function emit_destructor_code($out, Symbol $sp, &$lineno) // FILE *out; // struct symbol *sp; // struct lemon *lemp; @@ -1811,7 +1813,7 @@ public function emit_destructor_code($out, PHP_ParserGenerator_Symbol $sp, &$lin $cp = 0; $linecnt = 0; - if ($sp->type == PHP_ParserGenerator_Symbol::TERMINAL) { + if ($sp->type == Symbol::TERMINAL) { $cp = $this->tokendest; if ($cp === 0) { return; diff --git a/ParserGenerator/Parser.php b/src/SmartyGenerator/ParserGenerator/Parser.php similarity index 84% rename from ParserGenerator/Parser.php rename to src/SmartyGenerator/ParserGenerator/Parser.php index f4ba5bb..46b8923 100644 --- a/ParserGenerator/Parser.php +++ b/src/SmartyGenerator/ParserGenerator/Parser.php @@ -1,6 +1,8 @@ * @copyright 2006 Gregory Beaver * @license http://www.php.net/license/3_01.txt PHP License 3.01 @@ -24,13 +26,13 @@ /** * The grammar parser for lemon grammar files. * - * @package PHP_ParserGenerator + * @package \Smarty\ParserGenerator * @author Gregory Beaver * @copyright 2006 Gregory Beaver * @license http://www.php.net/license/3_01.txt PHP License 3.01 * @since Class available since Release 0.1.0 */ -class PHP_ParserGenerator_Parser +class Parser { const INITIALIZE = 1; const WAITING_FOR_DECL_OR_RULE = 2; @@ -75,42 +77,42 @@ class PHP_ParserGenerator_Parser public $tokenstart; /** * Global state vector - * @var PHP_ParserGenerator_Data + * @var Data */ public $gp; /** * Parser state (one of the class constants for this class) * - * - PHP_ParserGenerator_Parser::INITIALIZE, - * - PHP_ParserGenerator_Parser::WAITING_FOR_DECL_OR_RULE, - * - PHP_ParserGenerator_Parser::WAITING_FOR_DECL_KEYWORD, - * - PHP_ParserGenerator_Parser::WAITING_FOR_DECL_ARG, - * - PHP_ParserGenerator_Parser::WAITING_FOR_PRECEDENCE_SYMBOL, - * - PHP_ParserGenerator_Parser::WAITING_FOR_ARROW, - * - PHP_ParserGenerator_Parser::IN_RHS, - * - PHP_ParserGenerator_Parser::LHS_ALIAS_1, - * - PHP_ParserGenerator_Parser::LHS_ALIAS_2, - * - PHP_ParserGenerator_Parser::LHS_ALIAS_3, - * - PHP_ParserGenerator_Parser::RHS_ALIAS_1, - * - PHP_ParserGenerator_Parser::RHS_ALIAS_2, - * - PHP_ParserGenerator_Parser::PRECEDENCE_MARK_1, - * - PHP_ParserGenerator_Parser::PRECEDENCE_MARK_2, - * - PHP_ParserGenerator_Parser::RESYNC_AFTER_RULE_ERROR, - * - PHP_ParserGenerator_Parser::RESYNC_AFTER_DECL_ERROR, - * - PHP_ParserGenerator_Parser::WAITING_FOR_DESTRUCTOR_SYMBOL, - * - PHP_ParserGenerator_Parser::WAITING_FOR_DATATYPE_SYMBOL, - * - PHP_ParserGenerator_Parser::WAITING_FOR_FALLBACK_ID + * - Parser::INITIALIZE, + * - Parser::WAITING_FOR_DECL_OR_RULE, + * - Parser::WAITING_FOR_DECL_KEYWORD, + * - Parser::WAITING_FOR_DECL_ARG, + * - Parser::WAITING_FOR_PRECEDENCE_SYMBOL, + * - Parser::WAITING_FOR_ARROW, + * - Parser::IN_RHS, + * - Parser::LHS_ALIAS_1, + * - Parser::LHS_ALIAS_2, + * - Parser::LHS_ALIAS_3, + * - Parser::RHS_ALIAS_1, + * - Parser::RHS_ALIAS_2, + * - Parser::PRECEDENCE_MARK_1, + * - Parser::PRECEDENCE_MARK_2, + * - Parser::RESYNC_AFTER_RULE_ERROR, + * - Parser::RESYNC_AFTER_DECL_ERROR, + * - Parser::WAITING_FOR_DESTRUCTOR_SYMBOL, + * - Parser::WAITING_FOR_DATATYPE_SYMBOL, + * - Parser::WAITING_FOR_FALLBACK_ID * @var int */ public $state; /** * The fallback token - * @var PHP_ParserGenerator_Symbol + * @var Symbol */ public $fallback; /** * Left-hand side of the current rule - * @var PHP_ParserGenerator_Symbol + * @var Symbol */ public $lhs; /** @@ -125,7 +127,7 @@ class PHP_ParserGenerator_Parser public $nrhs; /** * Right-hand side symbols - * @var array array of {@link PHP_ParserGenerator_Symbol} objects + * @var array array of {@link Symbol} objects */ public $rhs = array(); /** @@ -135,7 +137,7 @@ class PHP_ParserGenerator_Parser public $alias = array(); /** * Previous rule parsed - * @var PHP_ParserGenerator_Rule + * @var Rule */ public $prevrule; /** @@ -163,20 +165,20 @@ class PHP_ParserGenerator_Parser public $declassoc; /* Assign this association to decl arguments */ public $preccounter; /* Assign this precedence to decl arguments */ /** - * @var PHP_ParserGenerator_Rule + * @var Rule */ public $firstrule; /* Pointer to first rule in the grammar */ /** - * @var PHP_ParserGenerator_Rule + * @var Rule */ public $lastrule; /* Pointer to the most recently parsed rule */ /** - * @var PHP_ParserGenerator + * @var \SmartyGenerator\ParserGenerator */ private $lemon; - public function __construct(PHP_ParserGenerator $lem) + public function __construct(\SmartyGenerator\ParserGenerator $lem) { $this->lemon = $lem; } @@ -251,9 +253,9 @@ private function preprocess_input(&$z) * It reads in the entire input file (all at once) then tokenizes it. * Each token is passed to the function "parseonetoken" which builds all * the appropriate data structures in the global state vector "gp". - * @param PHP_ParserGenerator_Data + * @param Data */ - public function Parse(PHP_ParserGenerator_Data $gp) + public function Parse(Data $gp) { $startline = 0; @@ -265,7 +267,7 @@ public function Parse(PHP_ParserGenerator_Data $gp) /* Begin by reading the input file */ $filebuf = file_get_contents($this->filename); if (!$filebuf) { - PHP_ParserGenerator::ErrorMsg($this->filename, 0, "Can't open this file for reading."); + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, 0, "Can't open this file for reading."); $gp->errorcnt++; return; @@ -319,7 +321,7 @@ public function Parse(PHP_ParserGenerator_Data $gp) $oldcp = $cp; $test = strpos(substr($filebuf, $cp), '"'); if ($test === false) { - PHP_ParserGenerator::ErrorMsg($this->filename, $startline, + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, $startline, "String starting on this line is not terminated before the end of the file."); $this->errorcnt++; $nextcp = $cp = strlen($filebuf); @@ -373,7 +375,7 @@ public function Parse(PHP_ParserGenerator_Data $gp) } } if ($cp >= strlen($filebuf)) { - PHP_ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, "PHP code starting on this line is not terminated before the end of the file."); $this->errorcnt++; $nextcp = $cp; @@ -417,7 +419,7 @@ public function parseonetoken($token) { $x = $token; $this->a = 0; // for referencing in WAITING_FOR_DECL_KEYWORD - if (PHP_ParserGenerator::DEBUG) { + if (\SmartyGenerator\ParserGenerator::DEBUG) { printf("%s:%d: Token=[%s] state=%d\n", $this->filename, $this->tokenlineno, $token, $this->state); } @@ -432,18 +434,18 @@ public function parseonetoken($token) if ($x[0] == '%') { $this->state = self::WAITING_FOR_DECL_KEYWORD; } elseif (preg_match('/[a-z]/', $x[0])) { - $this->lhs = PHP_ParserGenerator_Symbol::Symbol_new($x); + $this->lhs = Symbol::Symbol_new($x); $this->nrhs = 0; $this->lhsalias = 0; $this->state = self::WAITING_FOR_ARROW; } elseif ($x[0] == '{') { if ($this->prevrule === 0) { - PHP_ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, "There is no prior rule opon which to attach the code fragment which begins on this line."); $this->errorcnt++; } elseif ($this->prevrule->code != 0) { - PHP_ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, "Code fragment beginning on this line is not the first \ to follow the previous rule."); $this->errorcnt++; @@ -454,7 +456,7 @@ public function parseonetoken($token) } elseif ($x[0] == '[') { $this->state = self::PRECEDENCE_MARK_1; } else { - PHP_ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, "Token \"%s\" should be either \"%%\" or a nonterminal name.", $x); $this->errorcnt++; @@ -462,25 +464,25 @@ public function parseonetoken($token) break; case self::PRECEDENCE_MARK_1: if (!preg_match('/[A-Z]/', $x[0])) { - PHP_ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, "The precedence symbol must be a terminal."); $this->errorcnt++; } elseif ($this->prevrule === 0) { - PHP_ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, "There is no prior rule to assign precedence \"[%s]\".", $x); $this->errorcnt++; } elseif ($this->prevrule->precsym != 0) { - PHP_ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, "Precedence mark on this line is not the first to follow the previous rule."); $this->errorcnt++; } else { - $this->prevrule->precsym = PHP_ParserGenerator_Symbol::Symbol_new($x); + $this->prevrule->precsym = Symbol::Symbol_new($x); } $this->state = self::PRECEDENCE_MARK_2; break; case self::PRECEDENCE_MARK_2: if ($x[0] != ']') { - PHP_ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, "Missing \"]\" on precedence mark."); $this->errorcnt++; } @@ -492,7 +494,7 @@ public function parseonetoken($token) } elseif ($x[0] == '(') { $this->state = self::LHS_ALIAS_1; } else { - PHP_ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, "Expected to see a \":\" following the LHS symbol \"%s\".", $this->lhs->name); $this->errorcnt++; @@ -504,7 +506,7 @@ public function parseonetoken($token) $this->lhsalias = $x; $this->state = self::LHS_ALIAS_2; } else { - PHP_ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, "\"%s\" is not a valid alias for the LHS \"%s\"\n", $x, $this->lhs->name); $this->errorcnt++; @@ -515,7 +517,7 @@ public function parseonetoken($token) if ($x[0] == ')') { $this->state = self::LHS_ALIAS_3; } else { - PHP_ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, "Missing \")\" following LHS alias name \"%s\".",$this->lhsalias); $this->errorcnt++; $this->state = self::RESYNC_AFTER_RULE_ERROR; @@ -525,7 +527,7 @@ public function parseonetoken($token) if ($x == '::=') { $this->state = self::IN_RHS; } else { - PHP_ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, "Missing \"->\" following: \"%s(%s)\".", $this->lhs->name, $this->lhsalias); $this->errorcnt++; @@ -534,7 +536,7 @@ public function parseonetoken($token) break; case self::IN_RHS: if ($x[0] == '.') { - $rp = new PHP_ParserGenerator_Rule; + $rp = new Rule; $rp->ruleline = $this->tokenlineno; for ($i = 0; $i < $this->nrhs; $i++) { $rp->rhs[$i] = $this->rhs[$i]; @@ -547,7 +549,7 @@ public function parseonetoken($token) continue; } if (isset($used[$symbol])) { - PHP_ParserGenerator::ErrorMsg($this->filename, + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, "RHS symbol \"%s\" used multiple times.", $symbol); @@ -575,8 +577,8 @@ public function parseonetoken($token) $this->prevrule = $rp; $this->state = self::WAITING_FOR_DECL_OR_RULE; } elseif (preg_match('/[a-zA-Z]/', $x[0])) { - if ($this->nrhs >= PHP_ParserGenerator::MAXRHS) { - PHP_ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, + if ($this->nrhs >= \SmartyGenerator\ParserGenerator::MAXRHS) { + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, "Too many symbols on RHS or rule beginning at \"%s\".", $x); $this->errorcnt++; @@ -584,43 +586,43 @@ public function parseonetoken($token) } else { if (isset($this->rhs[$this->nrhs - 1])) { $msp = $this->rhs[$this->nrhs - 1]; - if ($msp->type == PHP_ParserGenerator_Symbol::MULTITERMINAL) { + if ($msp->type == Symbol::MULTITERMINAL) { $inf = array_reduce($msp->subsym, array($this, '_printmulti'), ''); - PHP_ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, 'WARNING: symbol ' . $x . ' will not' . ' be part of previous multiterminal %s', substr($inf, 0, strlen($inf) - 1) ); } } - $this->rhs[$this->nrhs] = PHP_ParserGenerator_Symbol::Symbol_new($x); + $this->rhs[$this->nrhs] = Symbol::Symbol_new($x); $this->alias[$this->nrhs] = 0; $this->nrhs++; } } elseif (($x[0] == '|' || $x[0] == '/') && $this->nrhs > 0) { $msp = $this->rhs[$this->nrhs - 1]; - if ($msp->type != PHP_ParserGenerator_Symbol::MULTITERMINAL) { + if ($msp->type != Symbol::MULTITERMINAL) { $origsp = $msp; - $msp = new PHP_ParserGenerator_Symbol; - $msp->type = PHP_ParserGenerator_Symbol::MULTITERMINAL; + $msp = new Symbol; + $msp->type = Symbol::MULTITERMINAL; $msp->nsubsym = 1; $msp->subsym = array($origsp); $msp->name = $origsp->name; $this->rhs[$this->nrhs - 1] = $msp; } $msp->nsubsym++; - $msp->subsym[$msp->nsubsym - 1] = PHP_ParserGenerator_Symbol::Symbol_new(substr($x, 1)); + $msp->subsym[$msp->nsubsym - 1] = Symbol::Symbol_new(substr($x, 1)); if (preg_match('/[a-z]/', $x[1]) || preg_match('/[a-z]/', $msp->subsym[0]->name[0])) { - PHP_ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, "Cannot form a compound containing a non-terminal"); $this->errorcnt++; } } elseif ($x[0] == '(' && $this->nrhs > 0) { $this->state = self::RHS_ALIAS_1; } else { - PHP_ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, "Illegal character on RHS of rule: \"%s\".", $x); $this->errorcnt++; $this->state = self::RESYNC_AFTER_RULE_ERROR; @@ -631,7 +633,7 @@ public function parseonetoken($token) $this->alias[$this->nrhs - 1] = $x; $this->state = self::RHS_ALIAS_2; } else { - PHP_ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, "\"%s\" is not a valid alias for the RHS symbol \"%s\"\n", $x, $this->rhs[$this->nrhs - 1]->name); $this->errorcnt++; @@ -642,7 +644,7 @@ public function parseonetoken($token) if ($x[0] == ')') { $this->state = self::IN_RHS; } else { - PHP_ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, "Missing \")\" following LHS alias name \"%s\".", $this->lhsalias); $this->errorcnt++; $this->state = self::RESYNC_AFTER_RULE_ERROR; @@ -698,15 +700,15 @@ public function parseonetoken($token) $this->declargslot = &$this->gp->start; } elseif ('left' == $x) { $this->preccounter++; - $this->declassoc = PHP_ParserGenerator_Symbol::LEFT; + $this->declassoc = Symbol::LEFT; $this->state = self::WAITING_FOR_PRECEDENCE_SYMBOL; } elseif ('right' == $x) { $this->preccounter++; - $this->declassoc = PHP_ParserGenerator_Symbol::RIGHT; + $this->declassoc = Symbol::RIGHT; $this->state = self::WAITING_FOR_PRECEDENCE_SYMBOL; } elseif ('nonassoc' == $x) { $this->preccounter++; - $this->declassoc = PHP_ParserGenerator_Symbol::NONE; + $this->declassoc = Symbol::NONE; $this->state = self::WAITING_FOR_PRECEDENCE_SYMBOL; } elseif ('destructor' == $x) { $this->state = self::WAITING_FOR_DESTRUCTOR_SYMBOL; @@ -716,13 +718,13 @@ public function parseonetoken($token) $this->fallback = 0; $this->state = self::WAITING_FOR_FALLBACK_ID; } else { - PHP_ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, "Unknown declaration keyword: \"%%%s\".", $x); $this->errorcnt++; $this->state = self::RESYNC_AFTER_DECL_ERROR; } } else { - PHP_ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, "Illegal declaration keyword: \"%s\".", $x); $this->errorcnt++; $this->state = self::RESYNC_AFTER_DECL_ERROR; @@ -730,12 +732,12 @@ public function parseonetoken($token) break; case self::WAITING_FOR_DESTRUCTOR_SYMBOL: if (!preg_match('/[A-Za-z]/', $x[0])) { - PHP_ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, "Symbol name missing after %destructor keyword"); $this->errorcnt++; $this->state = self::RESYNC_AFTER_DECL_ERROR; } else { - $sp = PHP_ParserGenerator_Symbol::Symbol_new($x); + $sp = Symbol::Symbol_new($x); $this->declargslot = &$sp->destructor; $this->decllnslot = &$sp->destructorln; $this->state = self::WAITING_FOR_DECL_ARG; @@ -743,12 +745,12 @@ public function parseonetoken($token) break; case self::WAITING_FOR_DATATYPE_SYMBOL: if (!preg_match('/[A-Za-z]/', $x[0])) { - PHP_ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, "Symbol name missing after %destructor keyword"); $this->errorcnt++; $this->state = self::RESYNC_AFTER_DECL_ERROR; } else { - $sp = PHP_ParserGenerator_Symbol::Symbol_new($x); + $sp = Symbol::Symbol_new($x); $this->declargslot = &$sp->datatype; $this->state = self::WAITING_FOR_DECL_ARG; } @@ -757,9 +759,9 @@ public function parseonetoken($token) if ($x[0] == '.') { $this->state = self::WAITING_FOR_DECL_OR_RULE; } elseif (preg_match('/[A-Z]/', $x[0])) { - $sp = PHP_ParserGenerator_Symbol::Symbol_new($x); + $sp = Symbol::Symbol_new($x); if ($sp->prec >= 0) { - PHP_ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, "Symbol \"%s\" has already been given a precedence.", $x); $this->errorcnt++; } else { @@ -767,7 +769,7 @@ public function parseonetoken($token) $sp->assoc = $this->declassoc; } } else { - PHP_ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, "Can't assign a precedence to \"%s\".", $x); $this->errorcnt++; } @@ -775,7 +777,7 @@ public function parseonetoken($token) case self::WAITING_FOR_DECL_ARG: if (preg_match('/[A-Za-z0-9{"]/', $x[0])) { if ($this->declargslot != 0) { - PHP_ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, "The argument \"%s\" to declaration \"%%%s\" is not the first.", $x[0] == '"' ? substr($x, 1) : $x, $this->declkeyword); $this->errorcnt++; @@ -789,7 +791,7 @@ public function parseonetoken($token) $this->state = self::WAITING_FOR_DECL_OR_RULE; } } else { - PHP_ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, "Illegal argument to %%%s: %s",$this->declkeyword, $x); $this->errorcnt++; $this->state = self::RESYNC_AFTER_DECL_ERROR; @@ -799,15 +801,15 @@ public function parseonetoken($token) if ($x[0] == '.') { $this->state = self::WAITING_FOR_DECL_OR_RULE; } elseif (!preg_match('/[A-Z]/', $x[0])) { - PHP_ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, "%%fallback argument \"%s\" should be a token", $x); $this->errorcnt++; } else { - $sp = PHP_ParserGenerator_Symbol::Symbol_new($x); + $sp = Symbol::Symbol_new($x); if ($this->fallback === 0) { $this->fallback = $sp; } elseif (is_object($sp->fallback)) { - PHP_ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, + \SmartyGenerator\ParserGenerator::ErrorMsg($this->filename, $this->tokenlineno, "More than one fallback assigned to token %s", $x); $this->errorcnt++; } else { diff --git a/ParserGenerator/PropagationLink.php b/src/SmartyGenerator/ParserGenerator/PropagationLink.php similarity index 80% rename from ParserGenerator/PropagationLink.php rename to src/SmartyGenerator/ParserGenerator/PropagationLink.php index 21b2d15..51e408c 100644 --- a/ParserGenerator/PropagationLink.php +++ b/src/SmartyGenerator/ParserGenerator/PropagationLink.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 @@ * configuration followset should be propagated to another whenever * the first changes. * - * @package PHP_ParserGenerator + * @package \Smarty\ParserGenerator * @author Gregory Beaver * @copyright 2006 Gregory Beaver * @license http://www.opensource.org/licenses/bsd-license.php New BSD License @@ -58,16 +60,16 @@ * @since Class available since Release 0.1.0 */ -class PHP_ParserGenerator_PropagationLink +class PropagationLink { /** * The configuration that defines this propagation link - * @var PHP_ParserGenerator_Config + * @var Config */ public $cfp; /** * The next propagation link - * @var PHP_ParserGenerator_PropagationLink|0 + * @var PropagationLink|0 */ public $next = 0; @@ -75,14 +77,14 @@ class PHP_ParserGenerator_PropagationLink * Add a propagation link to the current list * * This prepends the configuration passed in to the first parameter - * which is either 0 or a PHP_ParserGenerator_PropagationLink defining + * which is either 0 or a PropagationLink defining * an existing list. - * @param PHP_ParserGenerator_PropagationLink|null - * @param PHP_ParserGenerator_Config + * @param PropagationLink|null + * @param Config */ - public static function Plink_add(&$plpp, PHP_ParserGenerator_Config $cfp) + public static function Plink_add(&$plpp, Config $cfp) { - $new = new PHP_ParserGenerator_PropagationLink; + $new = new PropagationLink; $new->next = $plpp; $plpp = $new; $new->cfp = $cfp; @@ -91,8 +93,8 @@ public static function Plink_add(&$plpp, PHP_ParserGenerator_Config $cfp) /** * Transfer every propagation link on the list "from" to the list "to" */ - public static function Plink_copy(PHP_ParserGenerator_PropagationLink &$to, - PHP_ParserGenerator_PropagationLink $from) + public static function Plink_copy(PropagationLink &$to, + PropagationLink $from) { while ($from) { $nextpl = $from->next; @@ -104,7 +106,7 @@ public static function Plink_copy(PHP_ParserGenerator_PropagationLink &$to, /** * Delete every propagation link on the list - * @param PHP_ParserGenerator_PropagationLink|0 + * @param PropagationLink|0 */ public static function Plink_delete($plp) { diff --git a/ParserGenerator/Rule.php b/src/SmartyGenerator/ParserGenerator/Rule.php similarity index 89% rename from ParserGenerator/Rule.php rename to src/SmartyGenerator/ParserGenerator/Rule.php index 33637c1..826811a 100644 --- a/ParserGenerator/Rule.php +++ b/src/SmartyGenerator/ParserGenerator/Rule.php @@ -1,6 +1,8 @@ * @copyright 2006 Gregory Beaver * @license http://www.opensource.org/licenses/bsd-license.php New BSD License @@ -48,18 +50,18 @@ /** * Each production rule in the grammar is stored in this class * - * @package PHP_ParserGenerator + * @package \Smarty\ParserGenerator * @author Gregory Beaver * @copyright 2006 Gregory Beaver * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @version 0.1.5 * @since Class available since Release 0.1.0 */ -class PHP_ParserGenerator_Rule +class Rule { /** * Left-hand side of the rule - * @var array an array of {@link PHP_ParserGenerator_Symbol} objects + * @var array an array of {@link Symbol} objects */ public $lhs; /** @@ -79,7 +81,7 @@ class PHP_ParserGenerator_Rule public $nrhs; /** * The right-hand side symbols - * @var array an array of {@link PHP_ParserGenerator_Symbol} objects + * @var array an array of {@link Symbol} objects */ public $rhs; /** @@ -112,7 +114,7 @@ class PHP_ParserGenerator_Rule public $code; /** * Precedence symbol for this rule - * @var PHP_ParserGenerator_Symbol + * @var Symbol */ public $precsym; /** @@ -130,12 +132,12 @@ class PHP_ParserGenerator_Rule public $canReduce; /** * Next rule with the same left-hand side - * @var PHP_ParserGenerator_Rule|0 + * @var Rule|0 */ public $nextlhs; /** * Next rule in the global list - * @var PHP_ParserGenerator_Rule|0 + * @var Rule|0 */ public $next; } diff --git a/ParserGenerator/State.php b/src/SmartyGenerator/ParserGenerator/State.php similarity index 80% rename from ParserGenerator/State.php rename to src/SmartyGenerator/ParserGenerator/State.php index d7320dc..74832ee 100644 --- a/ParserGenerator/State.php +++ b/src/SmartyGenerator/ParserGenerator/State.php @@ -1,6 +1,8 @@ * @copyright 2006 Gregory Beaver * @license http://www.opensource.org/licenses/bsd-license.php New BSD License @@ -46,45 +48,29 @@ * @since File available since Release 0.1.0 */ -/** - * The structure used to represent a state in the associative array - * for a PHP_ParserGenerator_Config. - * @package PHP_ParserGenerator - * @author Gregory Beaver - * @copyright 2006 Gregory Beaver - * @license http://www.opensource.org/licenses/bsd-license.php New BSD License - * @version 0.1.5 - * @since Class available since Release 0.1.0 - */ -class PHP_ParserGenerator_StateNode -{ - public $key; - public $data; - public $from = 0; - public $next = 0; -} + /** * Each state of the generated parser's finite state machine * is encoded as an instance of this class * - * @package PHP_ParserGenerator + * @package \Smarty\ParserGenerator * @author Gregory Beaver * @copyright 2006 Gregory Beaver * @license http://www.php.net/license/3_01.txt PHP License 3.01 * @version 0.1.5 * @since Class available since Release 0.1.0 */ -class PHP_ParserGenerator_State +class State { /** * The basis configurations for this state - * @var PHP_ParserGenerator_Config + * @var Config */ public $bp; /** * All configurations in this state - * @var PHP_ParserGenerator_Config + * @var Config */ public $cfp; /** @@ -95,7 +81,7 @@ class PHP_ParserGenerator_State public $statenum; /** * Linked list of actions for this state. - * @var PHP_ParserGenerator_Action + * @var Action */ public $ap; /** @@ -129,13 +115,13 @@ class PHP_ParserGenerator_State */ public $iDflt; /** - * Associative array of PHP_ParserGenerator_State objects + * Associative array of State objects * * @var array */ public static $x3a = array(); /** - * Array of PHP_ParserGenerator_State objects + * Array of State objects * * @var array */ @@ -160,8 +146,8 @@ public static function stateResortCompare($a, $b) /** * Compare two states based on their configurations * - * @param PHP_ParserGenerator_Config|0 $a - * @param PHP_ParserGenerator_Config|0 $b + * @param Config|0 $a + * @param Config|0 $b * @return int */ public static function statecmp($a, $b) @@ -188,7 +174,7 @@ public static function statecmp($a, $b) * Hash a state based on its configuration * @return int */ - private static function statehash(PHP_ParserGenerator_Config $a) + private static function statehash(Config $a) { $h = 0; while ($a) { @@ -202,10 +188,10 @@ private static function statehash(PHP_ParserGenerator_Config $a) /** * Return a pointer to data assigned to the given key. Return NULL * if no such key. - * @param PHP_ParserGenerator_Config - * @return null|PHP_ParserGenerator_State + * @param Config + * @return null|State */ - public static function State_find(PHP_ParserGenerator_Config $key) + public static function State_find(Config $key) { if (!count(self::$x3a)) { return 0; @@ -229,12 +215,12 @@ public static function State_find(PHP_ParserGenerator_Config $key) * Insert a new record into the array. Return TRUE if successful. * Prior data with the same key is NOT overwritten * - * @param PHP_ParserGenerator_State $state - * @param PHP_ParserGenerator_Config $key + * @param State $state + * @param Config $key * @return unknown */ - public static function State_insert(PHP_ParserGenerator_State $state, - PHP_ParserGenerator_Config $key) + public static function State_insert(State $state, + Config $key) { $h = self::statehash($key); if (isset(self::$x3a[$h])) { @@ -252,7 +238,7 @@ public static function State_insert(PHP_ParserGenerator_State $state, $np = $np->next; } /* Insert the new data */ - $np = new PHP_ParserGenerator_StateNode; + $np = new StateNode; $np->key = $key; $np->data = $state; self::$states[] = $np; diff --git a/src/SmartyGenerator/ParserGenerator/StateNode.php b/src/SmartyGenerator/ParserGenerator/StateNode.php new file mode 100644 index 0000000..ce5899a --- /dev/null +++ b/src/SmartyGenerator/ParserGenerator/StateNode.php @@ -0,0 +1,20 @@ + + * @copyright 2006 Gregory Beaver + * @license http://www.opensource.org/licenses/bsd-license.php New BSD License + * @version 0.1.5 + * @since Class available since Release 0.1.0 + */ +class StateNode +{ + public $key; + public $data; + public $from = 0; + public $next = 0; +} \ No newline at end of file diff --git a/ParserGenerator/Symbol.php b/src/SmartyGenerator/ParserGenerator/Symbol.php similarity index 88% rename from ParserGenerator/Symbol.php rename to src/SmartyGenerator/ParserGenerator/Symbol.php index f600413..4ae6538 100644 --- a/ParserGenerator/Symbol.php +++ b/src/SmartyGenerator/ParserGenerator/Symbol.php @@ -1,6 +1,8 @@ * @copyright 2006 Gregory Beaver * @license http://www.opensource.org/licenses/bsd-license.php New BSD License @@ -48,14 +50,14 @@ /** * Symbols (terminals and nonterminals) of the grammar are stored in this class * - * @package PHP_ParserGenerator + * @package \Smarty\ParserGenerator * @author Gregory Beaver * @copyright 2006 Gregory Beaver * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @version 0.1.5 * @since Class available since Release 0.1.0 */ -class PHP_ParserGenerator_Symbol +class Symbol { /** * Symbols that start with a capital letter like FOO. @@ -101,20 +103,20 @@ class PHP_ParserGenerator_Symbol /** * Symbol type * - * One of PHP_ParserGenerator_Symbol::TERMINAL, - * PHP_ParserGenerator_Symbol::NONTERMINAL or - * PHP_ParserGenerator_Symbol::MULTITERMINAL + * One of Symbol::TERMINAL, + * Symbol::NONTERMINAL or + * Symbol::MULTITERMINAL * @var int */ public $type; /** * Linked list of rules that use this symbol, if it is a non-terminal. - * @var PHP_ParserGenerator_Rule + * @var Rule */ public $rule; /** * Fallback token in case this token doesn't parse - * @var PHP_ParserGenerator_Symbol + * @var Symbol */ public $fallback; /** @@ -127,9 +129,9 @@ class PHP_ParserGenerator_Symbol /** * Associativity if precedence is defined. * - * One of PHP_ParserGenerator_Symbol::LEFT, - * PHP_ParserGenerator_Symbol::RIGHT, PHP_ParserGenerator_Symbol::NONE - * or PHP_ParserGenerator_Symbol::UNK + * One of Symbol::LEFT, + * Symbol::RIGHT, Symbol::NONE + * or Symbol::UNK * @var unknown_type */ public $assoc; @@ -188,14 +190,14 @@ class PHP_ParserGenerator_Symbol public $nsubsym; /** * Array of terminal symbols in the MULTITERMINAL - * @var array an array of {@link PHP_ParserGenerator_Symbol} objects + * @var array an array of {@link Symbol} objects */ public $subsym = array(); /**#@-*/ /** * Singleton storage of symbols * - * @var array an array of PHP_ParserGenerator_Symbol objects + * @var array an array of Symbol objects */ private static $symbol_table = array(); /** @@ -203,14 +205,14 @@ class PHP_ParserGenerator_Symbol * Create a new symbol if this is the first time "x" has been seen. * (this is a singleton) * @param string - * @return PHP_ParserGenerator_Symbol + * @return Symbol */ public static function Symbol_new($x) { if (isset(self::$symbol_table[$x])) { return self::$symbol_table[$x]; } - $sp = new PHP_ParserGenerator_Symbol; + $sp = new Symbol; $sp->name = $x; $sp->type = preg_match('/[A-Z]/', $x[0]) ? self::TERMINAL : self::NONTERMINAL; $sp->rule = 0; @@ -259,8 +261,8 @@ public static function Symbol_find($x) * We find experimentally that leaving the symbols in their original * order (the order they appeared in the grammar file) gives the * smallest parser tables in SQLite. - * @param PHP_ParserGenerator_Symbol - * @param PHP_ParserGenerator_Symbol + * @param Symbol + * @param Symbol */ public static function sortSymbols($a, $b) { @@ -273,7 +275,7 @@ public static function sortSymbols($a, $b) /** * Return true if two symbols are the same. */ - public static function same_symbol(PHP_ParserGenerator_Symbol $a, PHP_ParserGenerator_Symbol $b) + public static function same_symbol(Symbol $a, Symbol $b) { if ($a === $b) return 1; if ($a->type != self::MULTITERMINAL) return 0;