summaryrefslogtreecommitdiff
path: root/lexer/smarty_internal_templatelexer.plex
diff options
context:
space:
mode:
authorUwe Tews <uwe.tews@googlemail.com>2015-05-06 00:03:26 +0200
committerUwe Tews <uwe.tews@googlemail.com>2015-05-06 00:03:26 +0200
commitd92714cc7e1567c103d4329df5bbc22080bf59c8 (patch)
tree32d0582941a6700123f87282f2de7e2a13e80212 /lexer/smarty_internal_templatelexer.plex
parentd7ff1eec4748a9d25af68d055352d86e329c303d (diff)
downloadsmarty-d92714cc7e1567c103d4329df5bbc22080bf59c8.tar.gz
smarty-d92714cc7e1567c103d4329df5bbc22080bf59c8.tar.bz2
smarty-d92714cc7e1567c103d4329df5bbc22080bf59c8.zip
- optimization move <?php ?> handling from parser to new compiler module
Diffstat (limited to 'lexer/smarty_internal_templatelexer.plex')
-rw-r--r--lexer/smarty_internal_templatelexer.plex74
1 files changed, 44 insertions, 30 deletions
diff --git a/lexer/smarty_internal_templatelexer.plex b/lexer/smarty_internal_templatelexer.plex
index d988c12b..c41fe10b 100644
--- a/lexer/smarty_internal_templatelexer.plex
+++ b/lexer/smarty_internal_templatelexer.plex
@@ -61,6 +61,12 @@ class Smarty_Internal_Templatelexer
* @var bool
*/
public $is_phpScript = false;
+ /**
+ * php code type
+ *
+ * @var string
+ */
+ public $phpType = '';
/**
* escaped left delimiter
*
@@ -227,11 +233,12 @@ class Smarty_Internal_Templatelexer
namespace = /([0-9]*[a-zA-Z_]\w*)?(\\[0-9]*[a-zA-Z_]\w*)+/
all = /[\S\s]+/
emptyjava = /\{\}/
- phpstarttag = /(<script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*>)|(<\?(?:php\w+|=|[a-zA-Z]+)?)/
- phpendtag = /\?>/
- phpendscript = /<\/script>/
- aspstarttag = /<%/
- aspendtag = /%>/
+ xmltag = /<\?xml\s+([\S\s]*?)\?>/
+ php = /(<\?(?:php\s+|=)?)((('[^'\\]*(?:\\.[^'\\]*)*')|("[^"\\]*(?:\\.[^"\\]*)*")|(\/\*(.)*?\*\/)|.)*?)\?>/
+ phpscript = /<script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*>((('[^'\\]*(?:\\.[^'\\]*)*')|("[^"\\]*(?:\\.[^"\\]*)*")|(\/\*(.)*?\*\/)|.)*?)<\/script>/
+ phptag = /(SMARTYldel\s*php\s*(.)*?SMARTYrdel((.)*?)SMARTYldel\s*\/php\s*SMARTYrdel)|(SMARTYldel\s*[\/]?php\s*(.)*?SMARTYrdel)/
+ asp = /<%((('[^'\\]*(?:\\.[^'\\]*)*')|("[^"\\]*(?:\\.[^"\\]*)*")|(\/\*(.)*?\*\/)|.)*?)%>/
+ unmatched = /(<(\?(?:php\s+|=)?|(script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*>)|%))|\?>|%>/
slash = /\//
ldel = /SMARTYldel\s*/
rdel = /\s*SMARTYrdel/
@@ -372,6 +379,15 @@ class Smarty_Internal_Templatelexer
$this->taglineno = $this->line;
}
}
+ phptag {
+ if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) {
+ $this->token = Smarty_Internal_Templateparser::TP_TEXT;
+ } else {
+ $this->token = Smarty_Internal_Templateparser::TP_PHP;
+ $this->phpType = 'tag';
+ $this->taglineno = $this->line;
+ }
+ }
ldel slash {
if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) {
$this->token = Smarty_Internal_Templateparser::TP_TEXT;
@@ -390,38 +406,36 @@ class Smarty_Internal_Templatelexer
$this->taglineno = $this->line;
}
}
- phpstarttag {
- if (($script = strpos($this->value, '<s') === 0) || in_array($this->value, Array('<?', '<?=', '<?php'))) {
- if ($script) {
- $this->is_phpScript = true;
- }
- $this->token = Smarty_Internal_Templateparser::TP_PHPSTARTTAG;
- } elseif ($this->value == '<?xml') {
- $this->token = Smarty_Internal_Templateparser::TP_XMLTAG;
- } else {
- $this->token = Smarty_Internal_Templateparser::TP_TEXT;
- //$this->value = substr($this->value, 0, 2);
- }
- }
- phpendtag {
- $this->token = Smarty_Internal_Templateparser::TP_PHPENDTAG;
- }
- phpendscript {
- $this->token = Smarty_Internal_Templateparser::TP_PHPENDSCRIPT;
- }
rdel {
$this->token = Smarty_Internal_Templateparser::TP_TEXT;
}
- aspstarttag {
- $this->token = Smarty_Internal_Templateparser::TP_ASPSTARTTAG;
+ 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;
}
- aspendtag {
- $this->token = Smarty_Internal_Templateparser::TP_ASPENDTAG;
+ unmatched {
+ $this->phpType = 'unmatched';
+ $this->taglineno = $this->line;
+ $this->token = Smarty_Internal_Templateparser::TP_PHP;
}
text {
- $phpEndScript = $this->is_phpScript ? '|<\\/script>' : '';
$to = strlen($this->data);
- preg_match("/{$this->ldel}|<\?|<%|\?>|%>|<script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*>{$phpEndScript}/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
+ preg_match("/{$this->ldel}|<\?|<%|\?>|%>|<script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*>/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
if (isset($match[0][1])) {
$to = $match[0][1];
}