From c4746e9080802a5fe794f7047c36ee79900431eb Mon Sep 17 00:00:00 2001 From: uwetews Date: Mon, 7 Nov 2016 03:08:11 +0100 Subject: [PATCH] - optimization of lexer speed https://github.com/smarty-php/smarty/issues/311 --- change_log.txt | 3 + lexer/smarty_internal_configfilelexer.plex | 20 ++-- lexer/smarty_internal_configfileparser.y | 16 --- lexer/smarty_internal_templatelexer.plex | 14 ++- libs/Smarty.class.php | 2 +- .../smarty_internal_config_file_compiler.php | 20 ++-- .../smarty_internal_configfilelexer.php | 105 ++++++++++-------- .../smarty_internal_configfileparser.php | 54 ++++----- .../smarty_internal_templatelexer.php | 84 ++++++++------ 9 files changed, 159 insertions(+), 159 deletions(-) diff --git a/change_log.txt b/change_log.txt index 438028265..751b0e6fe 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,7 @@ ===== 3.1.31-dev ===== (xx.xx.xx) + 07.11.2016 + - optimization of lexer speed https://github.com/smarty-php/smarty/issues/311 + 27.10.2016 - bugfix template function definitions array has not been cached between Smarty::fetch() and Smarty::display() calls https://github.com/smarty-php/smarty/issues/301 diff --git a/lexer/smarty_internal_configfilelexer.plex b/lexer/smarty_internal_configfilelexer.plex index 9a45a5f00..2c2e561a4 100644 --- a/lexer/smarty_internal_configfilelexer.plex +++ b/lexer/smarty_internal_configfilelexer.plex @@ -25,7 +25,13 @@ class Smarty_Internal_Configfilelexer * @var string */ public $data; - /** + /** + * Source length + * + * @var int + */ + public $dataLenght = null; + /** * byte counter * * @var int @@ -120,9 +126,8 @@ class Smarty_Internal_Configfilelexer */ function __construct($data, Smarty_Internal_Config_File_Compiler $compiler) { - // set instance object - self::instance($this); $this->data = $data . "\n"; //now all lines are \n-terminated + $this->dataLenght = strlen($data); $this->counter = 0; if (preg_match('/^\xEF\xBB\xBF/', $this->data, $match)) { $this->counter += strlen($match[0]); @@ -133,15 +138,6 @@ class Smarty_Internal_Configfilelexer $this->configBooleanize = $this->smarty->config_booleanize; } - public static function &instance($new_instance = null) - { - static $instance = null; - if (isset($new_instance) && is_object($new_instance)) { - $instance = $new_instance; - } - return $instance; - } - public function PrintTrace() { $this->yyTraceFILE = fopen('php://output', 'w'); diff --git a/lexer/smarty_internal_configfileparser.y b/lexer/smarty_internal_configfileparser.y index ac961772d..9d7f03f1f 100644 --- a/lexer/smarty_internal_configfileparser.y +++ b/lexer/smarty_internal_configfileparser.y @@ -91,8 +91,6 @@ class Smarty_Internal_Configfileparser */ function __construct(Smarty_Internal_Configfilelexer $lex, Smarty_Internal_Config_File_Compiler $compiler) { - // set instance object - self::instance($this); $this->lex = $lex; $this->smarty = $compiler->smarty; $this->compiler = $compiler; @@ -100,20 +98,6 @@ class Smarty_Internal_Configfileparser $this->configReadHidden = $this->smarty->config_read_hidden; } - /** - * @param null $new_instance - * - * @return null - */ - public static function &instance($new_instance = null) - { - static $instance = null; - if (isset($new_instance) && is_object($new_instance)) { - $instance = $new_instance; - } - return $instance; - } - /** * parse optional boolean keywords * diff --git a/lexer/smarty_internal_templatelexer.plex b/lexer/smarty_internal_templatelexer.plex index a455baf8e..bf0d97c79 100644 --- a/lexer/smarty_internal_templatelexer.plex +++ b/lexer/smarty_internal_templatelexer.plex @@ -25,6 +25,13 @@ class Smarty_Internal_Templatelexer */ public $data; + /** + * Source length + * + * @var int + */ + public $dataLenght = null; + /** * byte counter * @@ -225,6 +232,7 @@ class Smarty_Internal_Templatelexer function __construct($data, Smarty_Internal_TemplateCompilerBase $compiler) { $this->data = $data; + $this->dataLenght = strlen($data); $this->counter = 0; if (preg_match('/^\xEF\xBB\xBF/i', $this->data, $match)) { $this->counter += strlen($match[0]); @@ -366,7 +374,7 @@ class Smarty_Internal_Templatelexer $this->compiler->getTagCompiler('private_php')->parsePhp($this); } text { - $to = strlen($this->data); + $to = $this->dataLenght; preg_match("/($this->ldel)|(<[?]((php\s+|=)|\s+))|(<[%])|(<[?]xml\s+)|()|([?][>])|([%][>])/i",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter); if (isset($match[0][1])) { $to = $match[0][1]; @@ -606,7 +614,7 @@ class Smarty_Internal_Templatelexer } } text { - $to = strlen($this->data); + $to = $this->dataLenght; preg_match("/{$this->ldel}[\/]?literal{$this->rdel}/i",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter); if (isset($match[0][1])) { $to = $match[0][1]; @@ -670,7 +678,7 @@ class Smarty_Internal_Templatelexer $this->token = Smarty_Internal_Templateparser::TP_TEXT; } text { - $to = strlen($this->data); + $to = $this->dataLenght; $this->value = substr($this->data,$this->counter,$to-$this->counter); $this->token = Smarty_Internal_Templateparser::TP_TEXT; } diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index df0875e97..86c497e3b 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -114,7 +114,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.31-dev/40'; + const SMARTY_VERSION = '3.1.31-dev/41'; /** * define variable scopes diff --git a/libs/sysplugins/smarty_internal_config_file_compiler.php b/libs/sysplugins/smarty_internal_config_file_compiler.php index 1afb92c3b..b1ef958cd 100644 --- a/libs/sysplugins/smarty_internal_config_file_compiler.php +++ b/libs/sysplugins/smarty_internal_config_file_compiler.php @@ -111,11 +111,11 @@ public function compileTemplate(Smarty_Internal_Template $template) $this->smarty->_debug->start_compile($this->template); } // init the lexer/parser to compile the config file - /* @var Smarty_Internal_ConfigFileLexer $lex */ - $lex = new $this->lexer_class(str_replace(array("\r\n", "\r"), "\n", $template->source->getContent()) . "\n", + /* @var Smarty_Internal_ConfigFileLexer $this->lex */ + $this->lex = new $this->lexer_class(str_replace(array("\r\n", "\r"), "\n", $template->source->getContent()) . "\n", $this); - /* @var Smarty_Internal_ConfigFileParser $parser */ - $parser = new $this->parser_class($lex, $this); + /* @var Smarty_Internal_ConfigFileParser $this->parser */ + $this->parser = new $this->parser_class($this->lex, $this); if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) { $mbEncoding = mb_internal_encoding(); @@ -125,17 +125,17 @@ public function compileTemplate(Smarty_Internal_Template $template) } if ($this->smarty->_parserdebug) { - $parser->PrintTrace(); + $this->parser->PrintTrace(); } // get tokens from lexer and parse them - while ($lex->yylex()) { + while ($this->lex->yylex()) { if ($this->smarty->_parserdebug) { - echo "
Parsing {$parser->yyTokenName[$lex->token]} Token {$lex->value} Line {$lex->line} \n"; + echo "
Parsing {$this->parser->yyTokenName[$this->lex->token]} Token {$this->lex->value} Line {$this->lex->line} \n"; } - $parser->doParse($lex->token, $lex->value); + $this->parser->doParse($this->lex->token, $this->lex->value); } // finish parsing process - $parser->doParse(0, 0); + $this->parser->doParse(0, 0); if ($mbEncoding) { mb_internal_encoding($mbEncoding); @@ -166,8 +166,6 @@ public function compileTemplate(Smarty_Internal_Template $template) */ public function trigger_config_file_error($args = null) { - $this->lex = Smarty_Internal_Configfilelexer::instance(); - $this->parser = Smarty_Internal_Configfileparser::instance(); // get config source line which has error $line = $this->lex->line; if (isset($args)) { diff --git a/libs/sysplugins/smarty_internal_configfilelexer.php b/libs/sysplugins/smarty_internal_configfilelexer.php index eb42f0d9e..783d95fa6 100644 --- a/libs/sysplugins/smarty_internal_configfilelexer.php +++ b/libs/sysplugins/smarty_internal_configfilelexer.php @@ -28,6 +28,13 @@ class Smarty_Internal_Configfilelexer */ public $data; + /** + * Source length + * + * @var int + */ + public $dataLenght = null; + /** * byte counter * @@ -109,7 +116,7 @@ class Smarty_Internal_Configfilelexer /** * storage for assembled token patterns * - * @var sring + * @var string */ private $yy_global_pattern1 = null; @@ -139,9 +146,8 @@ class Smarty_Internal_Configfilelexer */ function __construct($data, Smarty_Internal_Config_File_Compiler $compiler) { - // set instance object - self::instance($this); $this->data = $data . "\n"; //now all lines are \n-terminated + $this->dataLenght = strlen($data); $this->counter = 0; if (preg_match('/^\xEF\xBB\xBF/', $this->data, $match)) { $this->counter += strlen($match[ 0 ]); @@ -152,15 +158,6 @@ function __construct($data, Smarty_Internal_Config_File_Compiler $compiler) $this->configBooleanize = $this->smarty->config_booleanize; } - public static function &instance($new_instance = null) - { - static $instance = null; - if (isset($new_instance) && is_object($new_instance)) { - $instance = $new_instance; - } - return $instance; - } - public function PrintTrace() { $this->yyTraceFILE = fopen('php://output', 'w'); @@ -223,17 +220,19 @@ public function yylex1() $this->yy_global_pattern1 = "/\G(#|;)|\G(\\[)|\G(\\])|\G(=)|\G([ \t\r]+)|\G(\n)|\G([0-9]*[a-zA-Z_]\\w*)|\G([\S\s])/isS"; } - if ($this->counter >= strlen($this->data)) { + if (!isset($this->dataLenght)) { + $this->dataLenght = strlen($this->data); + } + if ($this->counter >= $this->dataLenght) { return false; // end of input } do { if (preg_match($this->yy_global_pattern1, $this->data, $yymatches, null, $this->counter)) { - $yysubmatches = $yymatches; - if (strlen($yysubmatches[ 0 ]) < 200) { - $yymatches = preg_grep("/(.|\s)+/", $yysubmatches); + if (!isset($yymatches[ 0 ][ 1 ])) { + $yymatches = preg_grep("/(.|\s)+/", $yymatches); } else { - $yymatches = array_filter($yymatches, 'strlen'); + $yymatches = array_filter($yymatches); } if (empty($yymatches)) { throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . @@ -255,7 +254,7 @@ public function yylex1() } elseif ($r === false) { $this->counter += strlen($this->value); $this->line += substr_count($this->value, "\n"); - if ($this->counter >= strlen($this->data)) { + if ($this->counter >= $this->dataLenght) { return false; // end of input } // skip this token @@ -328,17 +327,19 @@ public function yylex2() $this->yy_global_pattern2 = "/\G([ \t\r]+)|\G(\\d+\\.\\d+(?=[ \t\r]*[\n#;]))|\G(\\d+(?=[ \t\r]*[\n#;]))|\G(\"\"\")|\G('[^'\\\\]*(?:\\\\.[^'\\\\]*)*'(?=[ \t\r]*[\n#;]))|\G(\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\"(?=[ \t\r]*[\n#;]))|\G([a-zA-Z]+(?=[ \t\r]*[\n#;]))|\G([^\n]+?(?=[ \t\r]*\n))|\G(\n)/isS"; } - if ($this->counter >= strlen($this->data)) { + if (!isset($this->dataLenght)) { + $this->dataLenght = strlen($this->data); + } + if ($this->counter >= $this->dataLenght) { return false; // end of input } do { if (preg_match($this->yy_global_pattern2, $this->data, $yymatches, null, $this->counter)) { - $yysubmatches = $yymatches; - if (strlen($yysubmatches[ 0 ]) < 200) { - $yymatches = preg_grep("/(.|\s)+/", $yysubmatches); + if (!isset($yymatches[ 0 ][ 1 ])) { + $yymatches = preg_grep("/(.|\s)+/", $yymatches); } else { - $yymatches = array_filter($yymatches, 'strlen'); + $yymatches = array_filter($yymatches); } if (empty($yymatches)) { throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . @@ -360,7 +361,7 @@ public function yylex2() } elseif ($r === false) { $this->counter += strlen($this->value); $this->line += substr_count($this->value, "\n"); - if ($this->counter >= strlen($this->data)) { + if ($this->counter >= $this->dataLenght) { return false; // end of input } // skip this token @@ -452,17 +453,19 @@ public function yylex3() if (!isset($this->yy_global_pattern3)) { $this->yy_global_pattern3 = "/\G([^\n]+?(?=[ \t\r]*\n))/isS"; } - if ($this->counter >= strlen($this->data)) { + if (!isset($this->dataLenght)) { + $this->dataLenght = strlen($this->data); + } + if ($this->counter >= $this->dataLenght) { return false; // end of input } do { if (preg_match($this->yy_global_pattern3, $this->data, $yymatches, null, $this->counter)) { - $yysubmatches = $yymatches; - if (strlen($yysubmatches[ 0 ]) < 200) { - $yymatches = preg_grep("/(.|\s)+/", $yysubmatches); + if (!isset($yymatches[ 0 ][ 1 ])) { + $yymatches = preg_grep("/(.|\s)+/", $yymatches); } else { - $yymatches = array_filter($yymatches, 'strlen'); + $yymatches = array_filter($yymatches); } if (empty($yymatches)) { throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . @@ -484,7 +487,7 @@ public function yylex3() } elseif ($r === false) { $this->counter += strlen($this->value); $this->line += substr_count($this->value, "\n"); - if ($this->counter >= strlen($this->data)) { + if ($this->counter >= $this->dataLenght) { return false; // end of input } // skip this token @@ -512,17 +515,19 @@ public function yylex4() if (!isset($this->yy_global_pattern4)) { $this->yy_global_pattern4 = "/\G([ \t\r]+)|\G([^\n]+?(?=[ \t\r]*\n))|\G(\n)/isS"; } - if ($this->counter >= strlen($this->data)) { + if (!isset($this->dataLenght)) { + $this->dataLenght = strlen($this->data); + } + if ($this->counter >= $this->dataLenght) { return false; // end of input } do { if (preg_match($this->yy_global_pattern4, $this->data, $yymatches, null, $this->counter)) { - $yysubmatches = $yymatches; - if (strlen($yysubmatches[ 0 ]) < 200) { - $yymatches = preg_grep("/(.|\s)+/", $yysubmatches); + if (!isset($yymatches[ 0 ][ 1 ])) { + $yymatches = preg_grep("/(.|\s)+/", $yymatches); } else { - $yymatches = array_filter($yymatches, 'strlen'); + $yymatches = array_filter($yymatches); } if (empty($yymatches)) { throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . @@ -544,7 +549,7 @@ public function yylex4() } elseif ($r === false) { $this->counter += strlen($this->value); $this->line += substr_count($this->value, "\n"); - if ($this->counter >= strlen($this->data)) { + if ($this->counter >= $this->dataLenght) { return false; // end of input } // skip this token @@ -584,17 +589,19 @@ public function yylex5() if (!isset($this->yy_global_pattern5)) { $this->yy_global_pattern5 = "/\G(\\.)|\G(.*?(?=[\.=[\]\r\n]))/isS"; } - if ($this->counter >= strlen($this->data)) { + if (!isset($this->dataLenght)) { + $this->dataLenght = strlen($this->data); + } + if ($this->counter >= $this->dataLenght) { return false; // end of input } do { if (preg_match($this->yy_global_pattern5, $this->data, $yymatches, null, $this->counter)) { - $yysubmatches = $yymatches; - if (strlen($yysubmatches[ 0 ]) < 200) { - $yymatches = preg_grep("/(.|\s)+/", $yysubmatches); + if (!isset($yymatches[ 0 ][ 1 ])) { + $yymatches = preg_grep("/(.|\s)+/", $yymatches); } else { - $yymatches = array_filter($yymatches, 'strlen'); + $yymatches = array_filter($yymatches); } if (empty($yymatches)) { throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . @@ -616,7 +623,7 @@ public function yylex5() } elseif ($r === false) { $this->counter += strlen($this->value); $this->line += substr_count($this->value, "\n"); - if ($this->counter >= strlen($this->data)) { + if ($this->counter >= $this->dataLenght) { return false; // end of input } // skip this token @@ -650,17 +657,19 @@ public function yylex6() if (!isset($this->yy_global_pattern6)) { $this->yy_global_pattern6 = "/\G(\"\"\"(?=[ \t\r]*[\n#;]))|\G([\S\s])/isS"; } - if ($this->counter >= strlen($this->data)) { + if (!isset($this->dataLenght)) { + $this->dataLenght = strlen($this->data); + } + if ($this->counter >= $this->dataLenght) { return false; // end of input } do { if (preg_match($this->yy_global_pattern6, $this->data, $yymatches, null, $this->counter)) { - $yysubmatches = $yymatches; - if (strlen($yysubmatches[ 0 ]) < 200) { - $yymatches = preg_grep("/(.|\s)+/", $yysubmatches); + if (!isset($yymatches[ 0 ][ 1 ])) { + $yymatches = preg_grep("/(.|\s)+/", $yymatches); } else { - $yymatches = array_filter($yymatches, 'strlen'); + $yymatches = array_filter($yymatches); } if (empty($yymatches)) { throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . @@ -682,7 +691,7 @@ public function yylex6() } elseif ($r === false) { $this->counter += strlen($this->value); $this->line += substr_count($this->value, "\n"); - if ($this->counter >= strlen($this->data)) { + if ($this->counter >= $this->dataLenght) { return false; // end of input } // skip this token diff --git a/libs/sysplugins/smarty_internal_configfileparser.php b/libs/sysplugins/smarty_internal_configfileparser.php index 9e2ac133f..b7551a2b5 100644 --- a/libs/sysplugins/smarty_internal_configfileparser.php +++ b/libs/sysplugins/smarty_internal_configfileparser.php @@ -168,8 +168,6 @@ class Smarty_Internal_Configfileparser */ function __construct(Smarty_Internal_Configfilelexer $lex, Smarty_Internal_Config_File_Compiler $compiler) { - // set instance object - self::instance($this); $this->lex = $lex; $this->smarty = $compiler->smarty; $this->compiler = $compiler; @@ -177,20 +175,6 @@ function __construct(Smarty_Internal_Configfilelexer $lex, Smarty_Internal_Confi $this->configReadHidden = $this->smarty->config_read_hidden; } - /** - * @param null $new_instance - * - * @return null - */ - public static function &instance($new_instance = null) - { - static $instance = null; - if (isset($new_instance) && is_object($new_instance)) { - $instance = $new_instance; - } - return $instance; - } - /** * parse optional boolean keywords * @@ -736,7 +720,7 @@ public function yy_shift($yyNewState, $yyMajor, $yypMinor) while ($this->yyidx >= 0) { $this->yy_pop_parser_stack(); } - #line 255 "../smarty/lexer/smarty_internal_configfileparser.y" + #line 239 "../smarty/lexer/smarty_internal_configfileparser.y" $this->internalError = true; $this->compiler->trigger_config_file_error("Stack overflow in configfile parser"); @@ -771,27 +755,27 @@ public function yy_shift($yyNewState, $yyMajor, $yypMinor) 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 11 => 11, 12 => 12, 13 => 13, 14 => 14, 15 => 15, 16 => 16, 17 => 17, 18 => 17,); - #line 261 "../smarty/lexer/smarty_internal_configfileparser.y" + #line 245 "../smarty/lexer/smarty_internal_configfileparser.y" function yy_r0() { $this->_retvalue = null; } - #line 266 "../smarty/lexer/smarty_internal_configfileparser.y" + #line 250 "../smarty/lexer/smarty_internal_configfileparser.y" function yy_r1() { $this->add_global_vars($this->yystack[ $this->yyidx + 0 ]->minor); $this->_retvalue = null; } - #line 280 "../smarty/lexer/smarty_internal_configfileparser.y" + #line 264 "../smarty/lexer/smarty_internal_configfileparser.y" function yy_r4() { $this->add_section_vars($this->yystack[ $this->yyidx + - 3 ]->minor, $this->yystack[ $this->yyidx + 0 ]->minor); $this->_retvalue = null; } - #line 285 "../smarty/lexer/smarty_internal_configfileparser.y" + #line 269 "../smarty/lexer/smarty_internal_configfileparser.y" function yy_r5() { if ($this->configReadHidden) { @@ -801,75 +785,75 @@ function yy_r5() $this->_retvalue = null; } - #line 293 "../smarty/lexer/smarty_internal_configfileparser.y" + #line 277 "../smarty/lexer/smarty_internal_configfileparser.y" function yy_r6() { $this->_retvalue = $this->yystack[ $this->yyidx + - 1 ]->minor; } - #line 297 "../smarty/lexer/smarty_internal_configfileparser.y" + #line 281 "../smarty/lexer/smarty_internal_configfileparser.y" function yy_r7() { $this->_retvalue = array_merge($this->yystack[ $this->yyidx + - 1 ]->minor, Array($this->yystack[ $this->yyidx + 0 ]->minor)); } - #line 301 "../smarty/lexer/smarty_internal_configfileparser.y" + #line 285 "../smarty/lexer/smarty_internal_configfileparser.y" function yy_r8() { $this->_retvalue = Array(); } - #line 307 "../smarty/lexer/smarty_internal_configfileparser.y" + #line 291 "../smarty/lexer/smarty_internal_configfileparser.y" function yy_r9() { $this->_retvalue = Array("key" => $this->yystack[ $this->yyidx + - 2 ]->minor, "value" => $this->yystack[ $this->yyidx + 0 ]->minor); } - #line 312 "../smarty/lexer/smarty_internal_configfileparser.y" + #line 296 "../smarty/lexer/smarty_internal_configfileparser.y" function yy_r10() { $this->_retvalue = (float) $this->yystack[ $this->yyidx + 0 ]->minor; } - #line 316 "../smarty/lexer/smarty_internal_configfileparser.y" + #line 300 "../smarty/lexer/smarty_internal_configfileparser.y" function yy_r11() { $this->_retvalue = (int) $this->yystack[ $this->yyidx + 0 ]->minor; } - #line 320 "../smarty/lexer/smarty_internal_configfileparser.y" + #line 304 "../smarty/lexer/smarty_internal_configfileparser.y" function yy_r12() { $this->_retvalue = $this->parse_bool($this->yystack[ $this->yyidx + 0 ]->minor); } - #line 324 "../smarty/lexer/smarty_internal_configfileparser.y" + #line 308 "../smarty/lexer/smarty_internal_configfileparser.y" function yy_r13() { $this->_retvalue = self::parse_single_quoted_string($this->yystack[ $this->yyidx + 0 ]->minor); } - #line 328 "../smarty/lexer/smarty_internal_configfileparser.y" + #line 312 "../smarty/lexer/smarty_internal_configfileparser.y" function yy_r14() { $this->_retvalue = self::parse_double_quoted_string($this->yystack[ $this->yyidx + 0 ]->minor); } - #line 332 "../smarty/lexer/smarty_internal_configfileparser.y" + #line 316 "../smarty/lexer/smarty_internal_configfileparser.y" function yy_r15() { $this->_retvalue = self::parse_tripple_double_quoted_string($this->yystack[ $this->yyidx + - 1 ]->minor); } - #line 336 "../smarty/lexer/smarty_internal_configfileparser.y" + #line 320 "../smarty/lexer/smarty_internal_configfileparser.y" function yy_r16() { $this->_retvalue = ''; } - #line 340 "../smarty/lexer/smarty_internal_configfileparser.y" + #line 324 "../smarty/lexer/smarty_internal_configfileparser.y" function yy_r17() { $this->_retvalue = $this->yystack[ $this->yyidx + 0 ]->minor; @@ -927,7 +911,7 @@ public function yy_parse_failed() public function yy_syntax_error($yymajor, $TOKEN) { - #line 248 "../smarty/lexer/smarty_internal_configfileparser.y" + #line 232 "../smarty/lexer/smarty_internal_configfileparser.y" $this->internalError = true; $this->yymajor = $yymajor; @@ -942,7 +926,7 @@ public function yy_accept() while ($this->yyidx >= 0) { $this->yy_pop_parser_stack(); } - #line 241 "../smarty/lexer/smarty_internal_configfileparser.y" + #line 225 "../smarty/lexer/smarty_internal_configfileparser.y" $this->successful = !$this->internalError; $this->internalError = false; diff --git a/libs/sysplugins/smarty_internal_templatelexer.php b/libs/sysplugins/smarty_internal_templatelexer.php index 05d958100..d35204462 100644 --- a/libs/sysplugins/smarty_internal_templatelexer.php +++ b/libs/sysplugins/smarty_internal_templatelexer.php @@ -25,6 +25,13 @@ class Smarty_Internal_Templatelexer */ public $data; + /** + * Source length + * + * @var int + */ + public $dataLenght = null; + /** * byte counter * @@ -202,6 +209,7 @@ class Smarty_Internal_Templatelexer function __construct($data, Smarty_Internal_TemplateCompilerBase $compiler) { $this->data = $data; + $this->dataLenght = strlen($data); $this->counter = 0; if (preg_match('/^\xEF\xBB\xBF/i', $this->data, $match)) { $this->counter += strlen($match[ 0 ]); @@ -291,17 +299,19 @@ public function yylex1() ")|\G(" . $this->ldel . "\\s*)|\G(\\s*" . $this->rdel . ")|\G((<[?]((php\\s+|=)|\\s+))|(<[%])|(<[?]xml\\s+)|()|([?][>])|([%][>]))|\G([\S\s])/isS"; } - if ($this->counter >= strlen($this->data)) { + if (!isset($this->dataLenght)) { + $this->dataLenght = strlen($this->data); + } + if ($this->counter >= $this->dataLenght) { return false; // end of input } do { if (preg_match($this->yy_global_pattern1, $this->data, $yymatches, null, $this->counter)) { - $yysubmatches = $yymatches; - if (strlen($yysubmatches[ 0 ]) < 200) { - $yymatches = preg_grep("/(.|\s)+/", $yysubmatches); + if (!isset($yymatches[ 0 ][ 1 ])) { + $yymatches = preg_grep("/(.|\s)+/", $yymatches); } else { - $yymatches = array_filter($yymatches, 'strlen'); + $yymatches = array_filter($yymatches); } if (empty($yymatches)) { throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . @@ -323,7 +333,7 @@ public function yylex1() } elseif ($r === false) { $this->counter += strlen($this->value); $this->line += substr_count($this->value, "\n"); - if ($this->counter >= strlen($this->data)) { + if ($this->counter >= $this->dataLenght) { return false; // end of input } // skip this token @@ -405,7 +415,7 @@ function yy_r1_10() function yy_r1_19() { - $to = strlen($this->data); + $to = $this->dataLenght; preg_match("/($this->ldel)|(<[?]((php\s+|=)|\s+))|(<[%])|(<[?]xml\s+)|()|([?][>])|([%][>])/i", $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter); if (isset($match[ 0 ][ 1 ])) { @@ -426,17 +436,19 @@ public function yylex2() $this->ldel . "\\s*[$][0-9]*[a-zA-Z_]\\w*(\\s+nocache)?\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*[\/])|\G(" . $this->ldel . "\\s*)/isS"; } - if ($this->counter >= strlen($this->data)) { + if (!isset($this->dataLenght)) { + $this->dataLenght = strlen($this->data); + } + if ($this->counter >= $this->dataLenght) { return false; // end of input } do { if (preg_match($this->yy_global_pattern2, $this->data, $yymatches, null, $this->counter)) { - $yysubmatches = $yymatches; - if (strlen($yysubmatches[ 0 ]) < 200) { - $yymatches = preg_grep("/(.|\s)+/", $yysubmatches); + if (!isset($yymatches[ 0 ][ 1 ])) { + $yymatches = preg_grep("/(.|\s)+/", $yymatches); } else { - $yymatches = array_filter($yymatches, 'strlen'); + $yymatches = array_filter($yymatches); } if (empty($yymatches)) { throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . @@ -458,7 +470,7 @@ public function yylex2() } elseif ($r === false) { $this->counter += strlen($this->value); $this->line += substr_count($this->value, "\n"); - if ($this->counter >= strlen($this->data)) { + if ($this->counter >= $this->dataLenght) { return false; // end of input } // skip this token @@ -567,17 +579,19 @@ public function yylex3() $this->yy_global_pattern3 = "/\G(\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*)|\G([\"])|\G('[^'\\\\]*(?:\\\\.[^'\\\\]*)*')|\G([$]smarty\\.block\\.(child|parent))|\G([$][0-9]*[a-zA-Z_]\\w*)|\G([$])|\G(\\s+is\\s+in\\s+)|\G(\\s+as\\s+)|\G(\\s+to\\s+)|\G(\\s+step\\s+)|\G(\\s+instanceof\\s+)|\G(\\s*(([!=][=]{1,2})|([<][=>]?)|([>][=]?)|[&|]{2})\\s*)|\G(\\s+(eq|ne|neq|gt|ge|gte|lt|le|lte|mod|and|or|xor)\\s+)|\G(\\s+(is\\s+(not\\s+)?(odd|even|div)\\s+by)\\s+)|\G(\\s+is\\s+(not\\s+)?(odd|even))|\G(([!]\\s*)|(not\\s+))|\G([(](int(eger)?|bool(ean)?|float|double|real|string|binary|array|object)[)]\\s*)|\G(\\s*[(]\\s*)|\G(\\s*[)])|\G(\\[\\s*)|\G(\\s*\\])|\G(\\s*[-][>]\\s*)|\G(\\s*[=][>]\\s*)|\G(\\s*[=]\\s*)|\G(([+]|[-]){2})|\G(\\s*([+]|[-])\\s*)|\G(\\s*([*]{1,2}|[%\/^&]|[<>]{2})\\s*)|\G([@])|\G([#])|\G(\\s+[0-9]*[a-zA-Z_][a-zA-Z0-9_\-:]*\\s*[=]\\s*)|\G(([0-9]*[a-zA-Z_]\\w*)?(\\\\[0-9]*[a-zA-Z_]\\w*)+)|\G([0-9]*[a-zA-Z_]\\w*)|\G(\\d+)|\G([`])|\G([|])|\G([.])|\G(\\s*[,]\\s*)|\G(\\s*[;]\\s*)|\G([:]{2})|\G(\\s*[:]\\s*)|\G(\\s*[?]\\s*)|\G(0[xX][0-9a-fA-F]+)|\G(\\s+)|\G([\S\s])/isS"; } - if ($this->counter >= strlen($this->data)) { + if (!isset($this->dataLenght)) { + $this->dataLenght = strlen($this->data); + } + if ($this->counter >= $this->dataLenght) { return false; // end of input } do { if (preg_match($this->yy_global_pattern3, $this->data, $yymatches, null, $this->counter)) { - $yysubmatches = $yymatches; - if (strlen($yysubmatches[ 0 ]) < 200) { - $yymatches = preg_grep("/(.|\s)+/", $yysubmatches); + if (!isset($yymatches[ 0 ][ 1 ])) { + $yymatches = preg_grep("/(.|\s)+/", $yymatches); } else { - $yymatches = array_filter($yymatches, 'strlen'); + $yymatches = array_filter($yymatches); } if (empty($yymatches)) { throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . @@ -599,7 +613,7 @@ public function yylex3() } elseif ($r === false) { $this->counter += strlen($this->value); $this->line += substr_count($this->value, "\n"); - if ($this->counter >= strlen($this->data)) { + if ($this->counter >= $this->dataLenght) { return false; // end of input } // skip this token @@ -912,17 +926,19 @@ public function yylex4() "/\G(" . $this->ldel . "\\s*literal\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*[\/]literal\\s*" . $this->rdel . ")|\G([\S\s])/isS"; } - if ($this->counter >= strlen($this->data)) { + if (!isset($this->dataLenght)) { + $this->dataLenght = strlen($this->data); + } + if ($this->counter >= $this->dataLenght) { return false; // end of input } do { if (preg_match($this->yy_global_pattern4, $this->data, $yymatches, null, $this->counter)) { - $yysubmatches = $yymatches; - if (strlen($yysubmatches[ 0 ]) < 200) { - $yymatches = preg_grep("/(.|\s)+/", $yysubmatches); + if (!isset($yymatches[ 0 ][ 1 ])) { + $yymatches = preg_grep("/(.|\s)+/", $yymatches); } else { - $yymatches = array_filter($yymatches, 'strlen'); + $yymatches = array_filter($yymatches); } if (empty($yymatches)) { throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . @@ -944,7 +960,7 @@ public function yylex4() } elseif ($r === false) { $this->counter += strlen($this->value); $this->line += substr_count($this->value, "\n"); - if ($this->counter >= strlen($this->data)) { + if ($this->counter >= $this->dataLenght) { return false; // end of input } // skip this token @@ -982,7 +998,7 @@ function yy_r4_2() function yy_r4_3() { - $to = strlen($this->data); + $to = $this->dataLenght; preg_match("/{$this->ldel}[\/]?literal{$this->rdel}/i", $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter); if (isset($match[ 0 ][ 1 ])) { @@ -1004,17 +1020,19 @@ public function yylex5() "\\s*)|\G([\"])|\G([`][$])|\G([$][0-9]*[a-zA-Z_]\\w*)|\G([$])|\G(([^\"\\\\]*?)((?:\\\\.[^\"\\\\]*?)*?)(?=(" . $this->ldel . "|\\$|`\\$|\")))|\G([\S\s])/isS"; } - if ($this->counter >= strlen($this->data)) { + if (!isset($this->dataLenght)) { + $this->dataLenght = strlen($this->data); + } + if ($this->counter >= $this->dataLenght) { return false; // end of input } do { if (preg_match($this->yy_global_pattern5, $this->data, $yymatches, null, $this->counter)) { - $yysubmatches = $yymatches; - if (strlen($yysubmatches[ 0 ]) < 200) { - $yymatches = preg_grep("/(.|\s)+/", $yysubmatches); + if (!isset($yymatches[ 0 ][ 1 ])) { + $yymatches = preg_grep("/(.|\s)+/", $yymatches); } else { - $yymatches = array_filter($yymatches, 'strlen'); + $yymatches = array_filter($yymatches); } if (empty($yymatches)) { throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . @@ -1036,7 +1054,7 @@ public function yylex5() } elseif ($r === false) { $this->counter += strlen($this->value); $this->line += substr_count($this->value, "\n"); - if ($this->counter >= strlen($this->data)) { + if ($this->counter >= $this->dataLenght) { return false; // end of input } // skip this token @@ -1141,7 +1159,7 @@ function yy_r5_10() function yy_r5_14() { - $to = strlen($this->data); + $to = $this->dataLenght; $this->value = substr($this->data, $this->counter, $to - $this->counter); $this->token = Smarty_Internal_Templateparser::TP_TEXT; }