Skip to content

Commit

Permalink
optimize lexer code for speed smarty-php/smarty#311
Browse files Browse the repository at this point in the history
  • Loading branch information
uwetews committed Nov 7, 2016
1 parent cd37883 commit 54c249c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions LexerGenerator/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,12 @@ public function doFirstMatch($rules, $statename, $ruleindex)
if (preg_match($this->yy_global_pattern' . $ruleindex . ',' . $this->input . ', $yymatches, null, ' .
$this->counter .
')) {
$yymatches = array_filter($yymatches);
if (empty($yymatches)) {
if (!isset($yymatches[ 0 ][1])) {
$yymatches = preg_grep("/(.|\s)+/", $yymatches);
} else {
$yymatches = array_filter($yymatches);
}
if (empty($yymatches)) {
throw new Exception(\'Error: lexing failed because a rule matched\' .
\' an empty string. Input "\' . substr(' . $this->input . ',
' . $this->counter . ', 5) . \'... state ' . $statename . '\');
Expand Down

0 comments on commit 54c249c

Please sign in to comment.