summaryrefslogtreecommitdiff
path: root/lexer/smarty_internal_templatelexer.plex
diff options
context:
space:
mode:
authorUwe Tews <uwe.tews@googlemail.com>2015-05-23 18:56:00 +0200
committerUwe Tews <uwe.tews@googlemail.com>2015-05-23 18:56:00 +0200
commitec449734c327b9c6d940f366da143c6f172a0b27 (patch)
tree1615381d9cde59ce4333674509392b11f9405761 /lexer/smarty_internal_templatelexer.plex
parentc8ecad0b062b45a44f4aeef743b3afbd0e3a24d7 (diff)
downloadsmarty-ec449734c327b9c6d940f366da143c6f172a0b27.tar.gz
smarty-ec449734c327b9c6d940f366da143c6f172a0b27.tar.bz2
smarty-ec449734c327b9c6d940f366da143c6f172a0b27.zip
- improvement on php_handling to allow very large PHP sections, better error handling
- improvement allow extreme large comment sections (forum 25538)
Diffstat (limited to 'lexer/smarty_internal_templatelexer.plex')
-rw-r--r--lexer/smarty_internal_templatelexer.plex230
1 files changed, 113 insertions, 117 deletions
diff --git a/lexer/smarty_internal_templatelexer.plex b/lexer/smarty_internal_templatelexer.plex
index c6e3d0a9..bd9b7a94 100644
--- a/lexer/smarty_internal_templatelexer.plex
+++ b/lexer/smarty_internal_templatelexer.plex
@@ -56,12 +56,6 @@ class Smarty_Internal_Templatelexer
*/
public $taglineno;
/**
- * flag if parsing php script
- *
- * @var bool
- */
- public $is_phpScript = false;
- /**
* php code type
*
* @var string
@@ -108,25 +102,35 @@ class Smarty_Internal_Templatelexer
*
* @var Smarty_Internal_TemplateCompilerBase
*/
- private $compiler = null;
+ public $compiler = null;
/**
* literal tag nesting level
*
* @var int
*/
private $literal_cnt = 0;
+
+ /**
+ * PHP start tag string
+ *
+ * @var string
+ */
+
/**
* trace file
*
* @var resource
*/
public $yyTraceFILE;
+
/**
* trace prompt
*
* @var string
*/
+
public $yyTracePrompt;
+
/**
* state names
*
@@ -138,15 +142,22 @@ class Smarty_Internal_Templatelexer
/**
* storage for assembled token patterns
*
- * @var sring
+ * @var string
*/
private $yy_global_pattern1 = null;
+
private $yy_global_pattern2 = null;
+
private $yy_global_pattern3 = null;
+
private $yy_global_pattern4 = null;
+
private $yy_global_pattern5 = null;
+
private $yy_global_pattern6 = null;
+
private $yy_global_pattern7 = null;
+
private $yy_global_pattern8 = null;
/**
@@ -203,25 +214,33 @@ class Smarty_Internal_Templatelexer
{
$this->data = $data;
$this->counter = 0;
- if (preg_match('/^\xEF\xBB\xBF/', $this->data, $match)) {
+ if (preg_match('~^\xEF\xBB\xBF~i', $this->data, $match)) {
$this->counter += strlen($match[0]);
}
$this->line = 1;
$this->smarty = $compiler->smarty;
$this->compiler = $compiler;
- $this->ldel = preg_quote($this->smarty->left_delimiter, '/');
+ $this->ldel = preg_quote($this->smarty->left_delimiter, '~');
$this->ldel_length = strlen($this->smarty->left_delimiter);
- $this->rdel = preg_quote($this->smarty->right_delimiter, '/');
+ $this->rdel = preg_quote($this->smarty->right_delimiter, '~');
$this->rdel_length = strlen($this->smarty->right_delimiter);
$this->smarty_token_names['LDEL'] = $this->smarty->left_delimiter;
$this->smarty_token_names['RDEL'] = $this->smarty->right_delimiter;
}
- public function PrintTrace()
- {
+ public function PrintTrace()
+ {
$this->yyTraceFILE = fopen('php://output', 'w');
$this->yyTracePrompt = '<br>';
- }
+ }
+
+ /*
+ * Check if this tag is autoliteral
+ */
+ public function isAutoLiteral ()
+ {
+ return $this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false;
+ }
/*!lex2php
%input $this->data
@@ -229,72 +248,67 @@ class Smarty_Internal_Templatelexer
%token $this->token
%value $this->value
%line $this->line
- linebreak = /[\t ]*[\r\n]+[\t ]*/
- text = /[\S\s]/
- textdoublequoted = /([^"\\]*?)((?:\\.[^"\\]*?)*?)(?=(SMARTYldel|\$|`\$|"))/
- namespace = /([0-9]*[a-zA-Z_]\w*)?(\\[0-9]*[a-zA-Z_]\w*)+/
- all = /[\S\s]+/
- emptyjava = /\{\}/
- xmltag = /<[?]xml\s+([\S\s]*?)[?]>/
- php = #<[?](?:php(?=[\s=]))?((?:(?![?]>)[^/][^?'"/]*)(([/][*](?:(?![*][/])[\S\s][^*]*)*[*][/])|([/][/][^\n]*)|('[^'\\]*(?:\\.[^'\\]*)*')|("[^"\\]*(?:\\.[^"\\]*)*"))*)*[?]>#
- asp = #<[%]((?:(?![%]>)[^/][^%'"/]*)(([/][*](?:(?![*][/])[\S\s][^*]*)*[*][/])|([/][/][^\n]*)|('[^'\\]*(?:\\.[^'\\]*)*')|("[^"\\]*(?:\\.[^"\\]*)*"))*)*[%]>#
- phpscript = #<script\s+language\s*=\s*["']?\s*php\s*["']?\s*>((?:(?!</script>)[^/][^<'"/]*)(([/][*](?:(?![*][/])[\S\s][^*]*)*[*][/])|([/][/][^\n]*)|('[^'\\]*(?:\\.[^'\\]*)*')|("[^"\\]*(?:\\.[^"\\]*)*"))*)*</script>#
- phptag = #((SMARTYldel\s*php\s*(.)*?SMARTYrdel)((?:(?!(SMARTYldel\s*[/]php\s*SMARTYrdel))[^/\{][^SMARTYldelFIRST'"/]*)(([/][*](?:(?![*][/])[\S\s][^*]*)*[*][/])|([/][/][^\n]*)|('[^'\\]*(?:\\.[^'\\]*)*')|("[^"\\]*(?:\\.[^"\\]*)*"))*)*(SMARTYldel\s*[/]php\s*SMARTYrdel)?)|(SMARTYldel\s*[/]?php\s*SMARTYrdel)#
- unmatched = /((<[?](?:php\s+|=)?)|(<script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*[>])|<[%]|[?][>]|[%][>])/
- slash = /\//
- ldel = /SMARTYldel\s*/
- rdel = /\s*SMARTYrdel/
- nocacherdel = /(\s+nocache)?\s*SMARTYrdel/
- notblockid = /(?:(?!block)[0-9]*[a-zA-Z_]\w*)/
- smartyblockchildparent = /[\$]smarty\.block\.(child|parent)/
- integer = /\d+/
- hex = /0[xX][0-9a-fA-F]+/
- math = /\s*([*]{1,2}|[%\/^&]|[<>]{2})\s*/
- comment = /SMARTYldel[*]((?:(?![*]SMARTYrdel)[\S\s][^*]*))*[*]SMARTYrdel/
- incdec = /\+\+|\-\-/
- unimath = /\s*(\+|\-)\s*/
- openP = /\s*\(\s*/
- closeP = /\s*\)/
- openB = /\[\s*/
- closeB = /\s*\]/
- dollar = /\$/
- dot = /\./
- comma = /\s*\,\s*/
- doublecolon = /\:\:/
- colon = /\s*\:\s*/
- at = /@/
- hatch = /#/
- semicolon = /\s*\;\s*/
- equal = /\s*=\s*/
- space = /\s+/
- ptr = /\s*\->\s*/
- aptr = /\s*=>\s*/
- singlequotestring = /'[^'\\]*(?:\\.[^'\\]*)*'/
- backtick = /`/
- 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*/
- id = /[0-9]*[a-zA-Z_]\w*/
- literal = /literal/
- strip = /strip/
- lop = /\s*(([!=][=]{1,2})|([<][=>]?)|([>][=]?)|[&|]{2})\s*/
- tlop = /\s+(eq|ne|neg|gt|ge|gte|lt|le|lte|mod|and|or|xor|(is\s+(not\s+)?(odd|even|div)\s+by))\s+/
- scond = /\s+is\s+(not\s+)?(odd|even)/
- isin = /\s+is\s+in\s+/
- as = /\s+as\s+/
- to = /\s+to\s+/
- step = /\s+step\s+/
- block = /block/
- if = /(if|elseif|else if|while)\s+/
- for = /for\s+/
- foreach = /foreach(?![^\s])/
- setfilter = /setfilter\s+/
- instanceof = /\s+instanceof\s+/
- not = /!\s*|not\s+/
- typecast = /\((int(eger)?|bool(ean)?|float|double|real|string|binary|array|object)\)\s*/
- double_quote = /"/
- single_quote = /'/
+ linebreak = ~[\t ]*[\r\n]+[\t ]*~
+ text = ~[\S\s]~
+ textdoublequoted = ~([^"\\]*?)((?:\\.[^"\\]*?)*?)(?=(SMARTYldel|\$|`\$|"))~
+ namespace = ~([0-9]*[a-zA-Z_]\w*)?(\\[0-9]*[a-zA-Z_]\w*)+~
+ all = ~[\S\s]+~
+ emptyjava = ~[{][}]~
+ phpstart = ~(<[?]((php\s+|=)|\s+))|(<[%])|(<[?]xml\s+)|(<script\s+language\s*=\s*["']?\s*php\s*["']?\s*>)|([?][>])|([%][>])|(SMARTYldel\s*php(.*?)SMARTYrdel)|(SMARTYldel\s*[/]phpSMARTYrdel)~
+ slash = ~[/]~
+ ldel = ~SMARTYldel\s*~
+ rdel = ~\s*SMARTYrdel~
+ nocacherdel = ~(\s+nocache)?\s*SMARTYrdel~
+ notblockid = ~(?:(?!block)[0-9]*[a-zA-Z_]\w*)~
+ smartyblockchildparent = ~[\$]smarty\.block\.(child|parent)~
+ integer = ~\d+~
+ hex = ~0[xX][0-9a-fA-F]+~
+ math = ~\s*([*]{1,2}|[%/^&]|[<>]{2})\s*~
+ comment = ~SMARTYldel[*]~
+ incdec = ~([+]|[-]){2}~
+ unimath = ~\s*([+]|[-])\s*~
+ openP = ~\s*[(]\s*~
+ closeP = ~\s*[)]~
+ openB = ~\[\s*~
+ closeB = ~\s*\]~
+ dollar = ~[$]~
+ dot = ~[.]~
+ comma = ~\s*[,]\s*~
+ doublecolon = ~[:]{2}~
+ colon = ~\s*[:]\s*~
+ at = ~[@]~
+ hatch = ~[#]~
+ semicolon = ~\s*[;]\s*~
+ equal = ~\s*[=]\s*~
+ space = ~\s+~
+ ptr = ~\s*[-][>]\s*~
+ aptr = ~\s*[=][>]\s*~
+ singlequotestring = ~'[^'\\]*(?:\\.[^'\\]*)*'~
+ backtick = ~[`]~
+ 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*~
+ id = ~[0-9]*[a-zA-Z_]\w*~
+ literal = ~literal~
+ strip = ~strip~
+ lop = ~\s*(([!=][=]{1,2})|([<][=>]?)|([>][=]?)|[&|]{2})\s*~
+ tlop = ~\s+(eq|ne|neg|gt|ge|gte|lt|le|lte|mod|and|or|xor|(is\s+(not\s+)?(odd|even|div)\s+by))\s+~
+ scond = ~\s+is\s+(not\s+)?(odd|even)~
+ isin = ~\s+is\s+in\s+~
+ as = ~\s+as\s+~
+ to = ~\s+to\s+~
+ step = ~\s+step\s+~
+ block = ~block~
+ if = ~(if|elseif|else if|while)\s+~
+ for = ~for\s+~
+ foreach = ~foreach(?![^\s])~
+ setfilter = ~setfilter\s+~
+ instanceof = ~\s+instanceof\s+~
+ not = ~([!]\s*)|(not\s+)~
+ typecast = ~[(](int(eger)?|bool(ean)?|float|double|real|string|binary|array|object)[)]\s*~
+ double_quote = ~["]~
+ single_quote = ~[']~
*/
/*!lex2php
%statename TEXT
@@ -302,7 +316,19 @@ class Smarty_Internal_Templatelexer
$this->token = Smarty_Internal_Templateparser::TP_TEXT;
}
comment {
- $this->token = Smarty_Internal_Templateparser::TP_COMMENT;
+ preg_match("~[*]{$this->rdel}~",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
+ 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->right_delimiter}'");
+ }
+ $this->value = substr($this->data,$this->counter,$to-$this->counter);
+ return false;
+ }
+ phpstart {
+ $obj = new Smarty_Internal_Compile_Private_Php();
+ $obj->parsePhp($this);
+ $this->token = Smarty_Internal_Templateparser::TP_PHP;
}
ldel literal rdel {
if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) {
@@ -323,33 +349,9 @@ class Smarty_Internal_Templatelexer
rdel {
$this->token = Smarty_Internal_Templateparser::TP_TEXT;
}
- xmltag {
- $this->token = Smarty_Internal_Templateparser::TP_XMLTAG;
- $this->taglineno = $this->line;
- }
- asp {
- $this->phpType = 'asp';
- $this->taglineno = $this->line;
- $this->token = Smarty_Internal_Templateparser::TP_PHP;
- }
- php {
- $this->phpType = 'php';
- $this->taglineno = $this->line;
- $this->token = Smarty_Internal_Templateparser::TP_PHP;
- }
- phpscript {
- $this->phpType = 'script';
- $this->taglineno = $this->line;
- $this->token = Smarty_Internal_Templateparser::TP_PHP;
- }
- unmatched {
- $this->phpType = 'unmatched';
- $this->taglineno = $this->line;
- $this->token = Smarty_Internal_Templateparser::TP_PHP;
- }
text {
$to = strlen($this->data);
- preg_match("/{$this->ldel}|<[?]|<%|[?]>|%>|<script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*>/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
+ preg_match("~($this->ldel)|([<]script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*[>])|([<][?])|([<][%])|([?][>])|([%][>])~i",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
if (isset($match[0][1])) {
$to = $match[0][1];
}
@@ -379,12 +381,6 @@ class Smarty_Internal_Templatelexer
$this->yybegin(self::TAGBODY);
$this->taglineno = $this->line;
}
- phptag {
- $this->yypopstate();
- $this->token = Smarty_Internal_Templateparser::TP_PHP;
- $this->phpType = 'tag';
- $this->taglineno = $this->line;
- }
ldel id nocacherdel {
$this->yypopstate();
$this->token = Smarty_Internal_Templateparser::TP_SIMPLETAG;
@@ -503,7 +499,7 @@ class Smarty_Internal_Templatelexer
attr {
// resolve conflicts with shorttag and right_delimiter starting with '='
if (substr($this->data, $this->counter + strlen($this->value) - 1, $this->rdel_length) == $this->smarty->right_delimiter) {
- preg_match("/\s+/",$this->value,$match);
+ preg_match("~\s+~",$this->value,$match);
$this->value = $match[0];
$this->token = Smarty_Internal_Templateparser::TP_SPACE;
} else {
@@ -580,7 +576,7 @@ class Smarty_Internal_Templatelexer
}
text {
$to = strlen($this->data);
- preg_match("/{$this->ldel}\/?literal{$this->rdel}/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
+ 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];
} else {
@@ -674,7 +670,7 @@ class Smarty_Internal_Templatelexer
}
text {
$to = strlen($this->data);
- preg_match("/SMARTYldel\s*((\/)?strip\s*SMARTYrdel|block\s+)/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
+ preg_match("~SMARTYldel\s*(([/])?strip\s*SMARTYrdel|block\s+)~i",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
if (isset($match[0][1])) {
$to = $match[0][1];
}
@@ -719,7 +715,7 @@ class Smarty_Internal_Templatelexer
}
text {
$to = strlen($this->data);
- preg_match("/SMARTYldel\s*(literal\s*SMARTYrdel|(\/)?block(\s|SMARTYrdel)|[\$]smarty\.block\.(child|parent))/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
+ preg_match("~SMARTYldel\s*(literal\s*SMARTYrdel|([/])?block(\s|SMARTYrdel)|[\$]smarty\.block\.(child|parent))~i",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
if (isset($match[0][1])) {
$to = $match[0][1];
}
@@ -747,7 +743,7 @@ class Smarty_Internal_Templatelexer
}
text {
$to = strlen($this->data);
- preg_match("/{$this->ldel}\/?literal\s*{$this->rdel}/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
+ preg_match("~{$this->ldel}[/]?literal\s*{$this->rdel}~i",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
if (isset($match[0][1])) {
$to = $match[0][1];
} else {