Skip to content

Commit

Permalink
lexer/parser optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
uwetews committed Nov 5, 2017
1 parent dd9c076 commit 3799714
Show file tree
Hide file tree
Showing 10 changed files with 2,009 additions and 2,476 deletions.
5 changes: 4 additions & 1 deletion change_log.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
===== 3.1.32 - dev ===
05.11.2017 3.1.32-dev-32
- lexer/parser optimization

26.10.2017 3.1.32-dev-28
- bugfix Smarty version was not filled in header comment of compiled and cached files
- optimization replace internal Smarty::$ds property by DIRECTORY_SEPARATOR
Expand All @@ -7,7 +10,7 @@
for backward compatibility code is moved from Smarty class to an external class and still can be
called.
- correction of PHPDoc blocks
- minor code cleanup
- minor code cleanup

21.10.2017
- bugfix custom delimiters could fail since modification of version 3.1.32-dev-23
Expand Down
6 changes: 3 additions & 3 deletions lexer/smarty_internal_configfilelexer.plex
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ double_quoted_string {
$this->yypopstate();
}
maybe_bool {
if (!$this->configBooleanize || !in_array(strtolower($this->value), Array("true", "false", "on", "off", "yes", "no")) ) {
if (!$this->configBooleanize || !in_array(strtolower($this->value), array('true', 'false', 'on', 'off', 'yes', 'no')) ) {
$this->yypopstate();
$this->yypushstate(self::NAKED_STRING_VALUE);
return true; //reprocess in new state
Expand All @@ -250,7 +250,7 @@ naked_string {
}
newline {
$this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
$this->value = "";
$this->value = '';
$this->yypopstate();
}

Expand Down Expand Up @@ -308,7 +308,7 @@ text {
if (isset($match[0][1])) {
$to = $match[0][1];
} else {
$this->compiler->trigger_template_error ("missing or misspelled literal closing tag");
$this->compiler->trigger_template_error ('missing or misspelled literal closing tag');
}
$this->value = substr($this->data,$this->counter,$to-$this->counter);
$this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_TEXT;
Expand Down
26 changes: 13 additions & 13 deletions lexer/smarty_internal_configfileparser.y
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Smarty_Internal_Configfileparser
*
* @var array
*/
private static $escapes_single = Array('\\' => '\\',
private static $escapes_single = array('\\' => '\\',
'\'' => '\'');

/**
Expand Down Expand Up @@ -131,7 +131,7 @@ class Smarty_Internal_Configfileparser

$ss = preg_split('/(\\\\.)/', $escaped_string, - 1, PREG_SPLIT_DELIM_CAPTURE);

$str = "";
$str = '';
foreach ($ss as $s) {
if (strlen($s) === 2 && $s[0] === '\\') {
if (isset(self::$escapes_single[$s[1]])) {
Expand Down Expand Up @@ -174,10 +174,10 @@ class Smarty_Internal_Configfileparser
* @param array $var
* @param array $target_array
*/
private function set_var(Array $var, Array &$target_array)
private function set_var(array $var, array &$target_array)
{
$key = $var["key"];
$value = $var["value"];
$key = $var['key'];
$value = $var['value'];

if ($this->configOverwrite || !isset($target_array['vars'][$key])) {
$target_array['vars'][$key] = $value;
Expand All @@ -192,10 +192,10 @@ class Smarty_Internal_Configfileparser
*
* @param array $vars
*/
private function add_global_vars(Array $vars)
private function add_global_vars(array $vars)
{
if (!isset($this->compiler->config_data['vars'])) {
$this->compiler->config_data['vars'] = Array();
$this->compiler->config_data['vars'] = array();
}
foreach ($vars as $var) {
$this->set_var($var, $this->compiler->config_data);
Expand All @@ -208,10 +208,10 @@ class Smarty_Internal_Configfileparser
* @param string $section_name
* @param array $vars
*/
private function add_section_vars($section_name, Array $vars)
private function add_section_vars($section_name, array $vars)
{
if (!isset($this->compiler->config_data['sections'][$section_name]['vars'])) {
$this->compiler->config_data['sections'][$section_name]['vars'] = Array();
$this->compiler->config_data['sections'][$section_name]['vars'] = array();
}
foreach ($vars as $var) {
$this->set_var($var, $this->compiler->config_data['sections'][$section_name]);
Expand All @@ -238,7 +238,7 @@ class Smarty_Internal_Configfileparser
%stack_overflow
{
$this->internalError = true;
$this->compiler->trigger_config_file_error("Stack overflow in configfile parser");
$this->compiler->trigger_config_file_error('Stack overflow in configfile parser');
}

// Complete config file
Expand Down Expand Up @@ -279,17 +279,17 @@ var_list(res) ::= var_list(vl) newline. {
}

var_list(res) ::= var_list(vl) var(v). {
res = array_merge(vl, Array(v));
res = array_merge(vl, array(v));
}

var_list(res) ::= . {
res = Array();
res = array();
}


// Var
var(res) ::= ID(id) EQUAL value(v). {
res = Array("key" => id, "value" => v);
res = array('key' => id, 'value' => v);
}


Expand Down
4 changes: 2 additions & 2 deletions lexer/smarty_internal_templatelexer.plex
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ class Smarty_Internal_Templatelexer
aptr = ~\s*[=][>]\s*~
singlequotestring = ~'[^'\\]*(?:\\.[^'\\]*)*'~
backtick = ~[`]~
vert = ~[|]~
vert = ~[|][@]?~
qmark = ~\s*[?]\s*~
constant = ~[_]+[A-Z0-9][0-9A-Z_]*|[A-Z][0-9A-Z_]*(?![0-9A-Z_]*[a-z])~
attr = ~\s+[0-9]*[a-zA-Z_][a-zA-Z0-9_\-:]*\s*[=]\s*~
Expand Down Expand Up @@ -344,7 +344,7 @@ class Smarty_Internal_Templatelexer
if (isset($match[0][1])) {
$to = $match[0][1] + strlen($match[0][0]);
} else {
$this->compiler->trigger_template_error ("missing or misspelled comment closing tag '*{$this->smarty->getRightDelimiter()}'");
$this->compiler->trigger_template_error ("missing or misspelled comment closing tag '{$this->smarty->getRightDelimiter()}'");
}
$this->value = substr($this->data,$this->counter,$to-$this->counter);
return false;
Expand Down
Loading

0 comments on commit 3799714

Please sign in to comment.