diff options
Diffstat (limited to 'src/Lexer')
| -rw-r--r-- | src/Lexer/ConfigfileLexer.php | 707 | ||||
| -rw-r--r-- | src/Lexer/ConfigfileLexer.plex | 321 | ||||
| -rw-r--r-- | src/Lexer/TemplateLexer.php | 1083 | ||||
| -rw-r--r-- | src/Lexer/TemplateLexer.plex | 677 |
4 files changed, 2788 insertions, 0 deletions
diff --git a/src/Lexer/ConfigfileLexer.php b/src/Lexer/ConfigfileLexer.php new file mode 100644 index 00000000..d592c823 --- /dev/null +++ b/src/Lexer/ConfigfileLexer.php @@ -0,0 +1,707 @@ +<?php + +namespace Smarty\Lexer; + +/** +* Smarty Internal Plugin ConfigfileLexer +* +* This is the lexer to break the config file source into tokens +* @package Smarty +* @subpackage Config +* @author Uwe Tews +*/ +/** +* ConfigfileLexer +* +* This is the config file lexer. +* It is generated from the ConfigfileLexer.plex file +* +* @package Smarty +* @subpackage Compiler +* @author Uwe Tews +*/ +class ConfigfileLexer +{ + /** + * Source + * + * @var string + */ + public $data; + /** + * Source length + * + * @var int + */ + public $dataLength = null; + /** + * byte counter + * + * @var int + */ + public $counter; + /** + * token number + * + * @var int + */ + public $token; + /** + * token value + * + * @var string + */ + public $value; + /** + * current line + * + * @var int + */ + public $line; + /** + * state number + * + * @var int + */ + public $state = 1; + /** + * Smarty object + * + * @var Smarty + */ + public $smarty = null; + /** + * compiler object + * + * @var \Smarty\Compiler\Configfile + */ + private $compiler = null; + /** + * copy of config_booleanize + * + * @var bool + */ + private $configBooleanize = false; + /** + * trace file + * + * @var resource + */ + public $yyTraceFILE; + /** + * trace prompt + * + * @var string + */ + public $yyTracePrompt; + /** + * state names + * + * @var array + */ + public $state_name = array(1 => 'START', 2 => 'VALUE', 3 => 'NAKED_STRING_VALUE', 4 => 'COMMENT', 5 => 'SECTION', 6 => 'TRIPPLE'); + + /** + * storage for assembled token patterns + * + * @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; + + /** + * token names + * + * @var array + */ + public $smarty_token_names = array( // Text for parser error messages + ); + + /** + * constructor + * + * @param string $data template source + * @param \Smarty\Compiler\Configfile $compiler + */ + public function __construct($data, \Smarty\Compiler\Configfile $compiler) + { + $this->data = $data . "\n"; //now all lines are \n-terminated + $this->dataLength = strlen($data); + $this->counter = 0; + if (preg_match('/^\xEF\xBB\xBF/', $this->data, $match)) { + $this->counter += strlen($match[0]); + } + $this->line = 1; + $this->compiler = $compiler; + $this->smarty = $compiler->smarty; + $this->configBooleanize = $this->smarty->config_booleanize; + } + + public function replace ($input) { + return $input; + } + + public function PrintTrace() + { + $this->yyTraceFILE = fopen('php://output', 'w'); + $this->yyTracePrompt = '<br>'; + } + + + + private $_yy_state = 1; + private $_yy_stack = array(); + + public function yylex() + { + return $this->{'yylex' . $this->_yy_state}(); + } + + public function yypushstate($state) + { + if ($this->yyTraceFILE) { + fprintf($this->yyTraceFILE, "%sState push %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state); + } + array_push($this->_yy_stack, $this->_yy_state); + $this->_yy_state = $state; + if ($this->yyTraceFILE) { + fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state); + } + } + + public function yypopstate() + { + if ($this->yyTraceFILE) { + fprintf($this->yyTraceFILE, "%sState pop %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state); + } + $this->_yy_state = array_pop($this->_yy_stack); + if ($this->yyTraceFILE) { + fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state); + } + + } + + public function yybegin($state) + { + $this->_yy_state = $state; + if ($this->yyTraceFILE) { + fprintf($this->yyTraceFILE, "%sState set %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state); + } + } + + + + + public function yylex1() + { + if (!isset($this->yy_global_pattern1)) { + $this->yy_global_pattern1 = $this->replace("/\G(#|;)|\G(\\[)|\G(\\])|\G(=)|\G([ \t\r]+)|\G(\n)|\G([0-9]*[a-zA-Z_]\\w*)|\G([\S\s])/isS"); + } + if (!isset($this->dataLength)) { + $this->dataLength = strlen($this->data); + } + if ($this->counter >= $this->dataLength) { + return false; // end of input + } + + do { + if (preg_match($this->yy_global_pattern1,$this->data, $yymatches, 0, $this->counter)) { + 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->data, + $this->counter, 5) . '... state START'); + } + next($yymatches); // skip global match + $this->token = key($yymatches); // token number + $this->value = current($yymatches); // token value + $r = $this->{'yy_r1_' . $this->token}(); + if ($r === null) { + $this->counter += strlen($this->value); + $this->line += substr_count($this->value, "\n"); + // accept this token + return true; + } elseif ($r === true) { + // we have changed state + // process this token in the new state + return $this->yylex(); + } elseif ($r === false) { + $this->counter += strlen($this->value); + $this->line += substr_count($this->value, "\n"); + if ($this->counter >= $this->dataLength) { + return false; // end of input + } + // skip this token + continue; + } } else { + throw new Exception('Unexpected input at line' . $this->line . + ': ' . $this->data[$this->counter]); + } + break; + } while (true); + + } // end function + + + const START = 1; + public function yy_r1_1() + { + + $this->token = \Smarty\Parser\ConfigfileParser::TPC_COMMENTSTART; + $this->yypushstate(self::COMMENT); + } + public function yy_r1_2() + { + + $this->token = \Smarty\Parser\ConfigfileParser::TPC_OPENB; + $this->yypushstate(self::SECTION); + } + public function yy_r1_3() + { + + $this->token = \Smarty\Parser\ConfigfileParser::TPC_CLOSEB; + } + public function yy_r1_4() + { + + $this->token = \Smarty\Parser\ConfigfileParser::TPC_EQUAL; + $this->yypushstate(self::VALUE); + } + public function yy_r1_5() + { + + return false; + } + public function yy_r1_6() + { + + $this->token = \Smarty\Parser\ConfigfileParser::TPC_NEWLINE; + } + public function yy_r1_7() + { + + $this->token = \Smarty\Parser\ConfigfileParser::TPC_ID; + } + public function yy_r1_8() + { + + $this->token = \Smarty\Parser\ConfigfileParser::TPC_OTHER; + } + + + + public function yylex2() + { + if (!isset($this->yy_global_pattern2)) { + $this->yy_global_pattern2 = $this->replace("/\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 (!isset($this->dataLength)) { + $this->dataLength = strlen($this->data); + } + if ($this->counter >= $this->dataLength) { + return false; // end of input + } + + do { + if (preg_match($this->yy_global_pattern2,$this->data, $yymatches, 0, $this->counter)) { + 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->data, + $this->counter, 5) . '... state VALUE'); + } + next($yymatches); // skip global match + $this->token = key($yymatches); // token number + $this->value = current($yymatches); // token value + $r = $this->{'yy_r2_' . $this->token}(); + if ($r === null) { + $this->counter += strlen($this->value); + $this->line += substr_count($this->value, "\n"); + // accept this token + return true; + } elseif ($r === true) { + // we have changed state + // process this token in the new state + return $this->yylex(); + } elseif ($r === false) { + $this->counter += strlen($this->value); + $this->line += substr_count($this->value, "\n"); + if ($this->counter >= $this->dataLength) { + return false; // end of input + } + // skip this token + continue; + } } else { + throw new Exception('Unexpected input at line' . $this->line . + ': ' . $this->data[$this->counter]); + } + break; + } while (true); + + } // end function + + + const VALUE = 2; + public function yy_r2_1() + { + + return false; + } + public function yy_r2_2() + { + + $this->token = \Smarty\Parser\ConfigfileParser::TPC_FLOAT; + $this->yypopstate(); + } + public function yy_r2_3() + { + + $this->token = \Smarty\Parser\ConfigfileParser::TPC_INT; + $this->yypopstate(); + } + public function yy_r2_4() + { + + $this->token = \Smarty\Parser\ConfigfileParser::TPC_TRIPPLE_QUOTES; + $this->yypushstate(self::TRIPPLE); + } + public function yy_r2_5() + { + + $this->token = \Smarty\Parser\ConfigfileParser::TPC_SINGLE_QUOTED_STRING; + $this->yypopstate(); + } + public function yy_r2_6() + { + + $this->token = \Smarty\Parser\ConfigfileParser::TPC_DOUBLE_QUOTED_STRING; + $this->yypopstate(); + } + public function yy_r2_7() + { + + 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 + } else { + $this->token = \Smarty\Parser\ConfigfileParser::TPC_BOOL; + $this->yypopstate(); + } + } + public function yy_r2_8() + { + + $this->token = \Smarty\Parser\ConfigfileParser::TPC_NAKED_STRING; + $this->yypopstate(); + } + public function yy_r2_9() + { + + $this->token = \Smarty\Parser\ConfigfileParser::TPC_NAKED_STRING; + $this->value = ''; + $this->yypopstate(); + } + + + + public function yylex3() + { + if (!isset($this->yy_global_pattern3)) { + $this->yy_global_pattern3 = $this->replace("/\G([^\n]+?(?=[ \t\r]*\n))/isS"); + } + if (!isset($this->dataLength)) { + $this->dataLength = strlen($this->data); + } + if ($this->counter >= $this->dataLength) { + return false; // end of input + } + + do { + if (preg_match($this->yy_global_pattern3,$this->data, $yymatches, 0, $this->counter)) { + 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->data, + $this->counter, 5) . '... state NAKED_STRING_VALUE'); + } + next($yymatches); // skip global match + $this->token = key($yymatches); // token number + $this->value = current($yymatches); // token value + $r = $this->{'yy_r3_' . $this->token}(); + if ($r === null) { + $this->counter += strlen($this->value); + $this->line += substr_count($this->value, "\n"); + // accept this token + return true; + } elseif ($r === true) { + // we have changed state + // process this token in the new state + return $this->yylex(); + } elseif ($r === false) { + $this->counter += strlen($this->value); + $this->line += substr_count($this->value, "\n"); + if ($this->counter >= $this->dataLength) { + return false; // end of input + } + // skip this token + continue; + } } else { + throw new Exception('Unexpected input at line' . $this->line . + ': ' . $this->data[$this->counter]); + } + break; + } while (true); + + } // end function + + + const NAKED_STRING_VALUE = 3; + public function yy_r3_1() + { + + $this->token = \Smarty\Parser\ConfigfileParser::TPC_NAKED_STRING; + $this->yypopstate(); + } + + + + public function yylex4() + { + if (!isset($this->yy_global_pattern4)) { + $this->yy_global_pattern4 = $this->replace("/\G([ \t\r]+)|\G([^\n]+?(?=[ \t\r]*\n))|\G(\n)/isS"); + } + if (!isset($this->dataLength)) { + $this->dataLength = strlen($this->data); + } + if ($this->counter >= $this->dataLength) { + return false; // end of input + } + + do { + if (preg_match($this->yy_global_pattern4,$this->data, $yymatches, 0, $this->counter)) { + 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->data, + $this->counter, 5) . '... state COMMENT'); + } + next($yymatches); // skip global match + $this->token = key($yymatches); // token number + $this->value = current($yymatches); // token value + $r = $this->{'yy_r4_' . $this->token}(); + if ($r === null) { + $this->counter += strlen($this->value); + $this->line += substr_count($this->value, "\n"); + // accept this token + return true; + } elseif ($r === true) { + // we have changed state + // process this token in the new state + return $this->yylex(); + } elseif ($r === false) { + $this->counter += strlen($this->value); + $this->line += substr_count($this->value, "\n"); + if ($this->counter >= $this->dataLength) { + return false; // end of input + } + // skip this token + continue; + } } else { + throw new Exception('Unexpected input at line' . $this->line . + ': ' . $this->data[$this->counter]); + } + break; + } while (true); + + } // end function + + + const COMMENT = 4; + public function yy_r4_1() + { + + return false; + } + public function yy_r4_2() + { + + $this->token = \Smarty\Parser\ConfigfileParser::TPC_NAKED_STRING; + } + public function yy_r4_3() + { + + $this->token = \Smarty\Parser\ConfigfileParser::TPC_NEWLINE; + $this->yypopstate(); + } + + + + public function yylex5() + { + if (!isset($this->yy_global_pattern5)) { + $this->yy_global_pattern5 = $this->replace("/\G(\\.)|\G(.*?(?=[\.=[\]\r\n]))/isS"); + } + if (!isset($this->dataLength)) { + $this->dataLength = strlen($this->data); + } + if ($this->counter >= $this->dataLength) { + return false; // end of input + } + + do { + if (preg_match($this->yy_global_pattern5,$this->data, $yymatches, 0, $this->counter)) { + 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->data, + $this->counter, 5) . '... state SECTION'); + } + next($yymatches); // skip global match + $this->token = key($yymatches); // token number + $this->value = current($yymatches); // token value + $r = $this->{'yy_r5_' . $this->token}(); + if ($r === null) { + $this->counter += strlen($this->value); + $this->line += substr_count($this->value, "\n"); + // accept this token + return true; + } elseif ($r === true) { + // we have changed state + // process this token in the new state + return $this->yylex(); + } elseif ($r === false) { + $this->counter += strlen($this->value); + $this->line += substr_count($this->value, "\n"); + if ($this->counter >= $this->dataLength) { + return false; // end of input + } + // skip this token + continue; + } } else { + throw new Exception('Unexpected input at line' . $this->line . + ': ' . $this->data[$this->counter]); + } + break; + } while (true); + + } // end function + + + const SECTION = 5; + public function yy_r5_1() + { + + $this->token = \Smarty\Parser\ConfigfileParser::TPC_DOT; + } + public function yy_r5_2() + { + + $this->token = \Smarty\Parser\ConfigfileParser::TPC_SECTION; + $this->yypopstate(); + } + + + public function yylex6() + { + if (!isset($this->yy_global_pattern6)) { + $this->yy_global_pattern6 = $this->replace("/\G(\"\"\"(?=[ \t\r]*[\n#;]))|\G([\S\s])/isS"); + } + if (!isset($this->dataLength)) { + $this->dataLength = strlen($this->data); + } + if ($this->counter >= $this->dataLength) { + return false; // end of input + } + + do { + if (preg_match($this->yy_global_pattern6,$this->data, $yymatches, 0, $this->counter)) { + 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->data, + $this->counter, 5) . '... state TRIPPLE'); + } + next($yymatches); // skip global match + $this->token = key($yymatches); // token number + $this->value = current($yymatches); // token value + $r = $this->{'yy_r6_' . $this->token}(); + if ($r === null) { + $this->counter += strlen($this->value); + $this->line += substr_count($this->value, "\n"); + // accept this token + return true; + } elseif ($r === true) { + // we have changed state + // process this token in the new state + return $this->yylex(); + } elseif ($r === false) { + $this->counter += strlen($this->value); + $this->line += substr_count($this->value, "\n"); + if ($this->counter >= $this->dataLength) { + return false; // end of input + } + // skip this token + continue; + } } else { + throw new Exception('Unexpected input at line' . $this->line . + ': ' . $this->data[$this->counter]); + } + break; + } while (true); + + } // end function + + + const TRIPPLE = 6; + public function yy_r6_1() + { + + $this->token = \Smarty\Parser\ConfigfileParser::TPC_TRIPPLE_QUOTES_END; + $this->yypopstate(); + $this->yypushstate(self::START); + } + public function yy_r6_2() + { + + $to = strlen($this->data); + preg_match("/\"\"\"[ \t\r]*[\n#;]/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter); + if (isset($match[0][1])) { + $to = $match[0][1]; + } else { + $this->compiler->trigger_config_file_error ('missing or misspelled literal closing tag'); + } + $this->value = substr($this->data,$this->counter,$to-$this->counter); + $this->token = \Smarty\Parser\ConfigfileParser::TPC_TRIPPLE_TEXT; + } + + +} diff --git a/src/Lexer/ConfigfileLexer.plex b/src/Lexer/ConfigfileLexer.plex new file mode 100644 index 00000000..a895050c --- /dev/null +++ b/src/Lexer/ConfigfileLexer.plex @@ -0,0 +1,321 @@ +<?php + +namespace Smarty\Lexer; + +/** +* Smarty Internal Plugin ConfigfileLexer +* +* This is the lexer to break the config file source into tokens +* @package Smarty +* @subpackage Config +* @author Uwe Tews +*/ +/** +* ConfigfileLexer +* +* This is the config file lexer. +* It is generated from the ConfigfileLexer.plex file +* +* @package Smarty +* @subpackage Compiler +* @author Uwe Tews +*/ +class ConfigfileLexer +{ + /** + * Source + * + * @var string + */ + public $data; + /** + * Source length + * + * @var int + */ + public $dataLength = null; + /** + * byte counter + * + * @var int + */ + public $counter; + /** + * token number + * + * @var int + */ + public $token; + /** + * token value + * + * @var string + */ + public $value; + /** + * current line + * + * @var int + */ + public $line; + /** + * state number + * + * @var int + */ + public $state = 1; + /** + * Smarty object + * + * @var Smarty + */ + public $smarty = null; + /** + * compiler object + * + * @var \Smarty\Compiler\Configfile + */ + private $compiler = null; + /** + * copy of config_booleanize + * + * @var bool + */ + private $configBooleanize = false; + /** + * trace file + * + * @var resource + */ + public $yyTraceFILE; + /** + * trace prompt + * + * @var string + */ + public $yyTracePrompt; + /** + * state names + * + * @var array + */ + public $state_name = array(1 => 'START', 2 => 'VALUE', 3 => 'NAKED_STRING_VALUE', 4 => 'COMMENT', 5 => 'SECTION', 6 => 'TRIPPLE'); + + /** + * storage for assembled token patterns + * + * @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; + + /** + * token names + * + * @var array + */ + public $smarty_token_names = array( // Text for parser error messages + ); + + /** + * constructor + * + * @param string $data template source + * @param \Smarty\Compiler\Configfile $compiler + */ + public function __construct($data, \Smarty\Compiler\Configfile $compiler) + { + $this->data = $data . "\n"; //now all lines are \n-terminated + $this->dataLength = strlen($data); + $this->counter = 0; + if (preg_match('/^\xEF\xBB\xBF/', $this->data, $match)) { + $this->counter += strlen($match[0]); + } + $this->line = 1; + $this->compiler = $compiler; + $this->smarty = $compiler->smarty; + $this->configBooleanize = $this->smarty->config_booleanize; + } + + public function replace ($input) { + return $input; + } + + public function PrintTrace() + { + $this->yyTraceFILE = fopen('php://output', 'w'); + $this->yyTracePrompt = '<br>'; + } + + +/*!lex2php +%input $this->data +%counter $this->counter +%token $this->token +%value $this->value +%line $this->line +commentstart = /#|;/ +openB = /\[/ +closeB = /\]/ +section = /.*?(?=[\.=\[\]\r\n])/ +equal = /=/ +whitespace = /[ \t\r]+/ +dot = /\./ +id = /[0-9]*[a-zA-Z_]\w*/ +newline = /\n/ +single_quoted_string = /'[^'\\]*(?:\\.[^'\\]*)*'(?=[ \t\r]*[\n#;])/ +double_quoted_string = /"[^"\\]*(?:\\.[^"\\]*)*"(?=[ \t\r]*[\n#;])/ +tripple_quotes = /"""/ +tripple_quotes_end = /"""(?=[ \t\r]*[\n#;])/ +text = /[\S\s]/ +float = /\d+\.\d+(?=[ \t\r]*[\n#;])/ +int = /\d+(?=[ \t\r]*[\n#;])/ +maybe_bool = /[a-zA-Z]+(?=[ \t\r]*[\n#;])/ +naked_string = /[^\n]+?(?=[ \t\r]*\n)/ +*/ + +/*!lex2php +%statename START + +commentstart { + $this->token = \Smarty\Parser\ConfigfileParser::TPC_COMMENTSTART; + $this->yypushstate(self::COMMENT); +} +openB { + $this->token = \Smarty\Parser\ConfigfileParser::TPC_OPENB; + $this->yypushstate(self::SECTION); +} +closeB { + $this->token = \Smarty\Parser\ConfigfileParser::TPC_CLOSEB; +} +equal { + $this->token = \Smarty\Parser\ConfigfileParser::TPC_EQUAL; + $this->yypushstate(self::VALUE); +} +whitespace { + return false; +} +newline { + $this->token = \Smarty\Parser\ConfigfileParser::TPC_NEWLINE; +} +id { + $this->token = \Smarty\Parser\ConfigfileParser::TPC_ID; +} +text { + $this->token = \Smarty\Parser\ConfigfileParser::TPC_OTHER; +} + +*/ + +/*!lex2php +%statename VALUE + +whitespace { + return false; +} +float { + $this->token = \Smarty\Parser\ConfigfileParser::TPC_FLOAT; + $this->yypopstate(); +} +int { + $this->token = \Smarty\Parser\ConfigfileParser::TPC_INT; + $this->yypopstate(); +} +tripple_quotes { + $this->token = \Smarty\Parser\ConfigfileParser::TPC_TRIPPLE_QUOTES; + $this->yypushstate(self::TRIPPLE); +} +single_quoted_string { + $this->token = \Smarty\Parser\ConfigfileParser::TPC_SINGLE_QUOTED_STRING; + $this->yypopstate(); +} +double_quoted_string { + $this->token = \Smarty\Parser\ConfigfileParser::TPC_DOUBLE_QUOTED_STRING; + $this->yypopstate(); +} +maybe_bool { + 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 + } else { + $this->token = \Smarty\Parser\ConfigfileParser::TPC_BOOL; + $this->yypopstate(); + } +} +naked_string { + $this->token = \Smarty\Parser\ConfigfileParser::TPC_NAKED_STRING; + $this->yypopstate(); +} +newline { + $this->token = \Smarty\Parser\ConfigfileParser::TPC_NAKED_STRING; + $this->value = ''; + $this->yypopstate(); +} + +*/ + +/*!lex2php +%statename NAKED_STRING_VALUE + +naked_string { + $this->token = \Smarty\Parser\ConfigfileParser::TPC_NAKED_STRING; + $this->yypopstate(); +} + +*/ + +/*!lex2php +%statename COMMENT + +whitespace { + return false; +} +naked_string { + $this->token = \Smarty\Parser\ConfigfileParser::TPC_NAKED_STRING; +} +newline { + $this->token = \Smarty\Parser\ConfigfileParser::TPC_NEWLINE; + $this->yypopstate(); +} + +*/ + +/*!lex2php +%statename SECTION + +dot { + $this->token = \Smarty\Parser\ConfigfileParser::TPC_DOT; +} +section { + $this->token = \Smarty\Parser\ConfigfileParser::TPC_SECTION; + $this->yypopstate(); +} + +*/ +/*!lex2php +%statename TRIPPLE + +tripple_quotes_end { + $this->token = \Smarty\Parser\ConfigfileParser::TPC_TRIPPLE_QUOTES_END; + $this->yypopstate(); + $this->yypushstate(self::START); +} +text { + $to = strlen($this->data); + preg_match("/\"\"\"[ \t\r]*[\n#;]/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter); + if (isset($match[0][1])) { + $to = $match[0][1]; + } else { + $this->compiler->trigger_config_file_error ('missing or misspelled literal closing tag'); + } + $this->value = substr($this->data,$this->counter,$to-$this->counter); + $this->token = \Smarty\Parser\ConfigfileParser::TPC_TRIPPLE_TEXT; +} +*/ + +} diff --git a/src/Lexer/TemplateLexer.php b/src/Lexer/TemplateLexer.php new file mode 100644 index 00000000..5c7253ba --- /dev/null +++ b/src/Lexer/TemplateLexer.php @@ -0,0 +1,1083 @@ +<?php + +namespace Smarty\Lexer; + +/* + * This file is part of Smarty. + * + * (c) 2015 Uwe Tews + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * TemplateLexer + * This is the template file lexer. + * It is generated from the TemplateLexer.plex file + * + * + * @author Uwe Tews <uwe.tews@googlemail.com> + */ +class TemplateLexer +{ + /** + * Source + * + * @var string + */ + public $data; + + /** + * Source length + * + * @var int + */ + public $dataLength = null; + + /** + * byte counter + * + * @var int + */ + public $counter; + + /** + * token number + * + * @var int + */ + public $token; + + /** + * token value + * + * @var string + */ + public $value; + + /** + * current line + * + * @var int + */ + public $line; + + /** + * tag start line + * + * @var + */ + public $taglineno; + + /** + * state number + * + * @var int + */ + public $state = 1; + + /** + * Smarty object + * + * @var Smarty + */ + public $smarty = null; + + /** + * compiler object + * + * @var \Smarty\Compiler\Template + */ + public $compiler = null; + + /** + * trace file + * + * @var resource + */ + public $yyTraceFILE; + + /** + * trace prompt + * + * @var string + */ + public $yyTracePrompt; + + /** + * XML flag true while processing xml + * + * @var bool + */ + public $is_xml = false; + + /** + * state names + * + * @var array + */ + public $state_name = array(1 => 'TEXT', 2 => 'TAG', 3 => 'TAGBODY', 4 => 'LITERAL', 5 => 'DOUBLEQUOTEDSTRING',); + + /** + * token names + * + * @var array + */ + public $smarty_token_names = array( // Text for parser error messages + 'NOT' => '(!,not)', + 'OPENP' => '(', + 'CLOSEP' => ')', + 'OPENB' => '[', + 'CLOSEB' => ']', + 'PTR' => '->', + 'APTR' => '=>', + 'EQUAL' => '=', + 'NUMBER' => 'number', + 'UNIMATH' => '+" , "-', + 'MATH' => '*" , "/" , "%', + 'INCDEC' => '++" , "--', + 'SPACE' => ' ', + 'DOLLAR' => '$', + 'SEMICOLON' => ';', + 'COLON' => ':', + 'DOUBLECOLON' => '::', + 'AT' => '@', + 'HATCH' => '#', + 'QUOTE' => '"', + 'BACKTICK' => '`', + 'VERT' => '"|" modifier', + 'DOT' => '.', + 'COMMA' => '","', + 'QMARK' => '"?"', + 'ID' => 'id, name', + 'TEXT' => 'text', + 'LDELSLASH' => '{/..} closing tag', + 'LDEL' => '{...} Smarty tag', + 'COMMENT' => 'comment', + 'AS' => 'as', + 'TO' => 'to', + 'LOGOP' => '"<", "==" ... logical operator', + 'TLOGOP' => '"lt", "eq" ... logical operator; "is div by" ... if condition', + 'SCOND' => '"is even" ... if condition', + ); + + /** + * literal tag nesting level + * + * @var int + */ + private $literal_cnt = 0; + + /** + * preg token pattern for state TEXT + * + * @var string + */ + private $yy_global_pattern1 = null; + + /** + * preg token pattern for state TAG + * + * @var string + */ + private $yy_global_pattern2 = null; + + /** + * preg token pattern for state TAGBODY + * + * @var string + */ + private $yy_global_pattern3 = null; + + /** + * preg token pattern for state LITERAL + * + * @var string + */ + private $yy_global_pattern4 = null; + + /** + * preg token pattern for state DOUBLEQUOTEDSTRING + * + * @var null + */ + private $yy_global_pattern5 = null; + + /** + * preg token pattern for text + * + * @var null + */ + private $yy_global_text = null; + + /** + * preg token pattern for literal + * + * @var null + */ + private $yy_global_literal = null; + + /** + * constructor + * + * @param string $source template source + * @param \Smarty\Compiler\Template $compiler + */ + public function __construct($source, \Smarty\Compiler\Template $compiler) + { + $this->data = $source; + $this->dataLength = strlen($this->data); + $this->counter = 0; + if (preg_match('/^\xEF\xBB\xBF/i', $this->data, $match)) { + $this->counter += strlen($match[0]); + } + $this->line = 1; + $this->smarty = $compiler->getTemplate()->getSmarty(); + $this->compiler = $compiler; + $this->compiler->initDelimiterPreg(); + $this->smarty_token_names['LDEL'] = $this->smarty->getLeftDelimiter(); + $this->smarty_token_names['RDEL'] = $this->smarty->getRightDelimiter(); + } + + /** + * open lexer/parser trace file + * + */ + public function PrintTrace() + { + $this->yyTraceFILE = fopen('php://output', 'w'); + $this->yyTracePrompt = '<br>'; + } + + /** + * replace placeholders with runtime preg code + * + * @param string $preg + * + * @return string + */ + public function replace($preg) + { + return $this->compiler->replaceDelimiter($preg); + } + + /** + * check if current value is an autoliteral left delimiter + * + * @return bool + */ + public function isAutoLiteral() + { + return $this->smarty->getAutoLiteral() && isset($this->value[ $this->compiler->getLdelLength() ]) ? + strpos(" \n\t\r", $this->value[ $this->compiler->getLdelLength() ]) !== false : false; + } + + + private $_yy_state = 1; + private $_yy_stack = array(); + + public function yylex() + { + return $this->{'yylex' . $this->_yy_state}(); + } + + public function yypushstate($state) + { + if ($this->yyTraceFILE) { + fprintf($this->yyTraceFILE, "%sState push %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state); + } + array_push($this->_yy_stack, $this->_yy_state); + $this->_yy_state = $state; + if ($this->yyTraceFILE) { + fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state); + } + } + + public function yypopstate() + { + if ($this->yyTraceFILE) { + fprintf($this->yyTraceFILE, "%sState pop %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state); + } + $this->_yy_state = array_pop($this->_yy_stack); + if ($this->yyTraceFILE) { + fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state); + } + + } + + public function yybegin($state) + { + $this->_yy_state = $state; + if ($this->yyTraceFILE) { + fprintf($this->yyTraceFILE, "%sState set %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state); + } + } + + + + public function yylex1() + { + if (!isset($this->yy_global_pattern1)) { + $this->yy_global_pattern1 = $this->replace("/\G([{][}])|\G((SMARTYldel)SMARTYal[*])|\G((SMARTYldel)SMARTYautoliteral\\s+SMARTYliteral)|\G((SMARTYldel)SMARTYalliteral\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/]literal\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal)|\G([\S\s])/isS"); + } + if (!isset($this->dataLength)) { + $this->dataLength = strlen($this->data); + } + if ($this->counter >= $this->dataLength) { + return false; // end of input + } + + do { + if (preg_match($this->yy_global_pattern1,$this->data, $yymatches, 0, $this->counter)) { + 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->data, + $this->counter, 5) . '... state TEXT'); + } + next($yymatches); // skip global match + $this->token = key($yymatches); // token number + $this->value = current($yymatches); // token value + $r = $this->{'yy_r1_' . $this->token}(); + if ($r === null) { + $this->counter += strlen($this->value); + $this->line += substr_count($this->value, "\n"); + // accept this token + return true; + } elseif ($r === true) { + // we have changed state + // process this token in the new state + return $this->yylex(); + } elseif ($r === false) { + $this->counter += strlen($this->value); + $this->line += substr_count($this->value, "\n"); + if ($this->counter >= $this->dataLength) { + return false; // end of input + } + // skip this token + continue; + } } else { + throw new Exception('Unexpected input at line' . $this->line . + ': ' . $this->data[$this->counter]); + } + break; + } while (true); + + } // end function + + + const TEXT = 1; + public function yy_r1_1() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_TEXT; + } + public function yy_r1_2() + { + + $to = $this->dataLength; + preg_match("/[*]{$this->compiler->getRdelPreg()}[\n]?/",$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->getRightDelimiter()}'"); + } + $this->value = substr($this->data,$this->counter,$to-$this->counter); + return false; + } + public function yy_r1_4() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_TEXT; + } + public function yy_r1_6() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_LITERALSTART; + $this->yypushstate(self::LITERAL); + } + public function yy_r1_8() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_LITERALEND; + $this->yypushstate(self::LITERAL); + } + public function yy_r1_10() + { + + $this->yypushstate(self::TAG); + return true; + } + public function yy_r1_12() + { + + if (!isset($this->yy_global_text)) { + $this->yy_global_text = $this->replace('/(SMARTYldel)SMARTYal/isS'); + } + $to = $this->dataLength; + preg_match($this->yy_global_text, $this->data,$match,PREG_OFFSET_CAPTURE,$this->counter); + if (isset($match[0][1])) { + $to = $match[0][1]; + } + $this->value = substr($this->data,$this->counter,$to-$this->counter); + $this->token = \Smarty\Parser\TemplateParser::TP_TEXT; + } + + + public function yylex2() + { + if (!isset($this->yy_global_pattern2)) { + $this->yy_global_pattern2 = $this->replace("/\G((SMARTYldel)SMARTYal(if|elseif|else if|while)\\s+)|\G((SMARTYldel)SMARTYalfor\\s+)|\G((SMARTYldel)SMARTYalforeach(?![^\s]))|\G((SMARTYldel)SMARTYalsetfilter\\s+)|\G((SMARTYldel)SMARTYal[0-9]*[a-zA-Z_]\\w*(\\s+nocache)?\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[$]smarty\\.block\\.(child|parent)\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/][0-9]*[a-zA-Z_]\\w*\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[$][0-9]*[a-zA-Z_]\\w*(\\s+nocache)?\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/])|\G((SMARTYldel)SMARTYal)/isS"); + } + if (!isset($this->dataLength)) { + $this->dataLength = strlen($this->data); + } + if ($this->counter >= $this->dataLength) { + return false; // end of input + } + + do { + if (preg_match($this->yy_global_pattern2,$this->data, $yymatches, 0, $this->counter)) { + 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->data, + $this->counter, 5) . '... state TAG'); + } + next($yymatches); // skip global match + $this->token = key($yymatches); // token number + $this->value = current($yymatches); // token value + $r = $this->{'yy_r2_' . $this->token}(); + if ($r === null) { + $this->counter += strlen($this->value); + $this->line += substr_count($this->value, "\n"); + // accept this token + return true; + } elseif ($r === true) { + // we have changed state + // process this token in the new state + return $this->yylex(); + } elseif ($r === false) { + $this->counter += strlen($this->value); + $this->line += substr_count($this->value, "\n"); + if ($this->counter >= $this->dataLength) { + return false; // end of input + } + // skip this token + continue; + } } else { + throw new Exception('Unexpected input at line' . $this->line . + ': ' . $this->data[$this->counter]); + } + break; + } while (true); + + } // end function + + + const TAG = 2; + public function yy_r2_1() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_LDELIF; + $this->yybegin(self::TAGBODY); + $this->taglineno = $this->line; + } + public function yy_r2_4() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_LDELFOR; + $this->yybegin(self::TAGBODY); + $this->taglineno = $this->line; + } + public function yy_r2_6() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_LDELFOREACH; + $this->yybegin(self::TAGBODY); + $this->taglineno = $this->line; + } + public function yy_r2_8() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_LDELSETFILTER; + $this->yybegin(self::TAGBODY); + $this->taglineno = $this->line; + } + public function yy_r2_10() + { + + $this->yypopstate(); + $this->token = \Smarty\Parser\TemplateParser::TP_SIMPLETAG; + $this->taglineno = $this->line; + } + public function yy_r2_13() + { + + $this->yypopstate(); + $this->token = \Smarty\Parser\TemplateParser::TP_SMARTYBLOCKCHILDPARENT; + $this->taglineno = $this->line; + } + public function yy_r2_16() + { + + $this->yypopstate(); + $this->token = \Smarty\Parser\TemplateParser::TP_CLOSETAG; + $this->taglineno = $this->line; + } + public function yy_r2_18() + { + + if ($this->_yy_stack[count($this->_yy_stack)-1] === self::TEXT) { + $this->yypopstate(); + $this->token = \Smarty\Parser\TemplateParser::TP_SIMPELOUTPUT; + $this->taglineno = $this->line; + } else { + $this->value = $this->smarty->getLeftDelimiter(); + $this->token = \Smarty\Parser\TemplateParser::TP_LDEL; + $this->yybegin(self::TAGBODY); + $this->taglineno = $this->line; + } + } + public function yy_r2_21() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_LDELSLASH; + $this->yybegin(self::TAGBODY); + $this->taglineno = $this->line; + } + public function yy_r2_23() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_LDEL; + $this->yybegin(self::TAGBODY); + $this->taglineno = $this->line; + } + + + public function yylex3() + { + if (!isset($this->yy_global_pattern3)) { + $this->yy_global_pattern3 = $this->replace("/\G(\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal)|\G([\"])|\G('[^'\\\\]*(?:\\\\.[^'\\\\]*)*')|\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(array\\s*[(]\\s*)|\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 (!isset($this->dataLength)) { + $this->dataLength = strlen($this->data); + } + if ($this->counter >= $this->dataLength) { + return false; // end of input + } + + do { + if (preg_match($this->yy_global_pattern3,$this->data, $yymatches, 0, $this->counter)) { + 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->data, + $this->counter, 5) . '... state TAGBODY'); + } + next($yymatches); // skip global match + $this->token = key($yymatches); // token number + $this->value = current($yymatches); // token value + $r = $this->{'yy_r3_' . $this->token}(); + if ($r === null) { + $this->counter += strlen($this->value); + $this->line += substr_count($this->value, "\n"); + // accept this token + return true; + } elseif ($r === true) { + // we have changed state + // process this token in the new state + return $this->yylex(); + } elseif ($r === false) { + $this->counter += strlen($this->value); + $this->line += substr_count($this->value, "\n"); + if ($this->counter >= $this->dataLength) { + return false; // end of input + } + // skip this token + continue; + } } else { + throw new Exception('Unexpected input at line' . $this->line . + ': ' . $this->data[$this->counter]); + } + break; + } while (true); + + } // end function + + + const TAGBODY = 3; + public function yy_r3_1() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_RDEL; + $this->yypopstate(); + } + public function yy_r3_2() + { + + $this->yypushstate(self::TAG); + return true; + } + public function yy_r3_4() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_QUOTE; + $this->yypushstate(self::DOUBLEQUOTEDSTRING); + $this->compiler->enterDoubleQuote(); + } + public function yy_r3_5() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_SINGLEQUOTESTRING; + } + public function yy_r3_6() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_DOLLARID; + } + public function yy_r3_7() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_DOLLAR; + } + public function yy_r3_8() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_ISIN; + } + public function yy_r3_9() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_AS; + } + public function yy_r3_10() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_TO; + } + public function yy_r3_11() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_STEP; + } + public function yy_r3_12() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_INSTANCEOF; + } + public function yy_r3_13() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_LOGOP; + } + public function yy_r3_15() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_SLOGOP; + } + public function yy_r3_17() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_TLOGOP; + } + public function yy_r3_20() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_SINGLECOND; + } + public function yy_r3_23() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_NOT; + } + public function yy_r3_24() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_TYPECAST; + } + public function yy_r3_28() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_OPENP; + } + public function yy_r3_29() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_CLOSEP; + } + public function yy_r3_30() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_OPENB; + } + public function yy_r3_31() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_CLOSEB; + } + public function yy_r3_32() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_PTR; + } + public function yy_r3_33() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_APTR; + } + public function yy_r3_34() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_EQUAL; + } + public function yy_r3_35() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_INCDEC; + } + public function yy_r3_37() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_UNIMATH; + } + public function yy_r3_39() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_MATH; + } + public function yy_r3_41() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_AT; + } + public function yy_r3_42() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_ARRAYOPEN; + } + public function yy_r3_43() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_HATCH; + } + public function yy_r3_44() + { + + // resolve conflicts with shorttag and right_delimiter starting with '=' + if (substr($this->data, $this->counter + strlen($this->value) - 1, $this->compiler->getRdelLength()) === $this->smarty->getRightDelimiter()) { + preg_match('/\s+/',$this->value,$match); + $this->value = $match[0]; + $this->token = \Smarty\Parser\TemplateParser::TP_SPACE; + } else { + $this->token = \Smarty\Parser\TemplateParser::TP_ATTR; + } + } + public function yy_r3_45() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_NAMESPACE; + } + public function yy_r3_48() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_ID; + } + public function yy_r3_49() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_INTEGER; + } + public function yy_r3_50() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_BACKTICK; + $this->yypopstate(); + } + public function yy_r3_51() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_VERT; + } + public function yy_r3_52() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_DOT; + } + public function yy_r3_53() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_COMMA; + } + public function yy_r3_54() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_SEMICOLON; + } + public function yy_r3_55() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_DOUBLECOLON; + } + public function yy_r3_56() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_COLON; + } + public function yy_r3_57() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_QMARK; + } + public function yy_r3_58() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_HEX; + } + public function yy_r3_59() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_SPACE; + } + public function yy_r3_60() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_TEXT; + } + + + + public function yylex4() + { + if (!isset($this->yy_global_pattern4)) { + $this->yy_global_pattern4 = $this->replace("/\G((SMARTYldel)SMARTYalliteral\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/]literal\\s*SMARTYrdel)|\G([\S\s])/isS"); + } + if (!isset($this->dataLength)) { + $this->dataLength = strlen($this->data); + } + if ($this->counter >= $this->dataLength) { + return false; // end of input + } + + do { + if (preg_match($this->yy_global_pattern4,$this->data, $yymatches, 0, $this->counter)) { + 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->data, + $this->counter, 5) . '... state LITERAL'); + } + next($yymatches); // skip global match + $this->token = key($yymatches); // token number + $this->value = current($yymatches); // token value + $r = $this->{'yy_r4_' . $this->token}(); + if ($r === null) { + $this->counter += strlen($this->value); + $this->line += substr_count($this->value, "\n"); + // accept this token + return true; + } elseif ($r === true) { + // we have changed state + // process this token in the new state + return $this->yylex(); + } elseif ($r === false) { + $this->counter += strlen($this->value); + $this->line += substr_count($this->value, "\n"); + if ($this->counter >= $this->dataLength) { + return false; // end of input + } + // skip this token + continue; + } } else { + throw new Exception('Unexpected input at line' . $this->line . + ': ' . $this->data[$this->counter]); + } + break; + } while (true); + + } // end function + + + const LITERAL = 4; + public function yy_r4_1() + { + + $this->literal_cnt++; + $this->token = \Smarty\Parser\TemplateParser::TP_LITERAL; + } + public function yy_r4_3() + { + + if ($this->literal_cnt) { + $this->literal_cnt--; + $this->token = \Smarty\Parser\TemplateParser::TP_LITERAL; + } else { + $this->token = \Smarty\Parser\TemplateParser::TP_LITERALEND; + $this->yypopstate(); + } + } + public function yy_r4_5() + { + + if (!isset($this->yy_global_literal)) { + $this->yy_global_literal = $this->replace('/(SMARTYldel)SMARTYal[\/]?literalSMARTYrdel/isS'); + } + $to = $this->dataLength; + preg_match($this->yy_global_literal, $this->data,$match,PREG_OFFSET_CAPTURE,$this->counter); + if (isset($match[0][1])) { + $to = $match[0][1]; + } else { + $this->compiler->trigger_template_error ("missing or misspelled literal closing tag"); + } + $this->value = substr($this->data,$this->counter,$to-$this->counter); + $this->token = \Smarty\Parser\TemplateParser::TP_LITERAL; + } + + + public function yylex5() + { + if (!isset($this->yy_global_pattern5)) { + $this->yy_global_pattern5 = $this->replace("/\G((SMARTYldel)SMARTYautoliteral\\s+SMARTYliteral)|\G((SMARTYldel)SMARTYalliteral\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/]literal\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/])|\G((SMARTYldel)SMARTYal[0-9]*[a-zA-Z_]\\w*)|\G((SMARTYldel)SMARTYal)|\G([\"])|\G([`][$])|\G([$][0-9]*[a-zA-Z_]\\w*)|\G([$])|\G(([^\"\\\\]*?)((?:\\\\.[^\"\\\\]*?)*?)(?=((SMARTYldel)SMARTYal|\\$|`\\$|\"SMARTYliteral)))|\G([\S\s])/isS"); + } + if (!isset($this->dataLength)) { + $this->dataLength = strlen($this->data); + } + if ($this->counter >= $this->dataLength) { + return false; // end of input + } + + do { + if (preg_match($this->yy_global_pattern5,$this->data, $yymatches, 0, $this->counter)) { + 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->data, + $this->counter, 5) . '... state DOUBLEQUOTEDSTRING'); + } + next($yymatches); // skip global match + $this->token = key($yymatches); // token number + $this->value = current($yymatches); // token value + $r = $this->{'yy_r5_' . $this->token}(); + if ($r === null) { + $this->counter += strlen($this->value); + $this->line += substr_count($this->value, "\n"); + // accept this token + return true; + } elseif ($r === true) { + // we have changed state + // process this token in the new state + return $this->yylex(); + } elseif ($r === false) { + $this->counter += strlen($this->value); + $this->line += substr_count($this->value, "\n"); + if ($this->counter >= $this->dataLength) { + return false; // end of input + } + // skip this token + continue; + } } else { + throw new Exception('Unexpected input at line' . $this->line . + ': ' . $this->data[$this->counter]); + } + break; + } while (true); + + } // end function + + + const DOUBLEQUOTEDSTRING = 5; + public function yy_r5_1() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_TEXT; + } + public function yy_r5_3() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_TEXT; + } + public function yy_r5_5() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_TEXT; + } + public function yy_r5_7() + { + + $this->yypushstate(self::TAG); + return true; + } + public function yy_r5_9() + { + + $this->yypushstate(self::TAG); + return true; + } + public function yy_r5_11() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_LDEL; + $this->taglineno = $this->line; + $this->yypushstate(self::TAGBODY); + } + public function yy_r5_13() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_QUOTE; + $this->yypopstate(); + } + public function yy_r5_14() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_BACKTICK; + $this->value = substr($this->value,0,-1); + $this->yypushstate(self::TAGBODY); + $this->taglineno = $this->line; + } + public function yy_r5_15() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_DOLLARID; + } + public function yy_r5_16() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_TEXT; + } + public function yy_r5_17() + { + + $this->token = \Smarty\Parser\TemplateParser::TP_TEXT; + } + public function yy_r5_22() + { + + $to = $this->dataLength; + $this->value = substr($this->data,$this->counter,$to-$this->counter); + $this->token = \Smarty\Parser\TemplateParser::TP_TEXT; + } + + } + +
\ No newline at end of file diff --git a/src/Lexer/TemplateLexer.plex b/src/Lexer/TemplateLexer.plex new file mode 100644 index 00000000..d29b6559 --- /dev/null +++ b/src/Lexer/TemplateLexer.plex @@ -0,0 +1,677 @@ +<?php + +namespace Smarty\Lexer; + +/* + * This file is part of Smarty. + * + * (c) 2015 Uwe Tews + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * TemplateLexer + * This is the template file lexer. + * It is generated from the TemplateLexer.plex file + * + * + * @author Uwe Tews <uwe.tews@googlemail.com> + */ +class TemplateLexer +{ + /** + * Source + * + * @var string + */ + public $data; + + /** + * Source length + * + * @var int + */ + public $dataLength = null; + + /** + * byte counter + * + * @var int + */ + public $counter; + + /** + * token number + * + * @var int + */ + public $token; + + /** + * token value + * + * @var string + */ + public $value; + + /** + * current line + * + * @var int + */ + public $line; + + /** + * tag start line + * + * @var + */ + public $taglineno; + + /** + * state number + * + * @var int + */ + public $state = 1; + + /** + * Smarty object + * + * @var Smarty + */ + public $smarty = null; + + /** + * compiler object + * + * @var \Smarty\Compiler\Template + */ + public $compiler = null; + + /** + * trace file + * + * @var resource + */ + public $yyTraceFILE; + + /** + * trace prompt + * + * @var string + */ + public $yyTracePrompt; + + /** + * XML flag true while processing xml + * + * @var bool + */ + public $is_xml = false; + + /** + * state names + * + * @var array + */ + public $state_name = array(1 => 'TEXT', 2 => 'TAG', 3 => 'TAGBODY', 4 => 'LITERAL', 5 => 'DOUBLEQUOTEDSTRING',); + + /** + * token names + * + * @var array + */ + public $smarty_token_names = array( // Text for parser error messages + 'NOT' => '(!,not)', + 'OPENP' => '(', + 'CLOSEP' => ')', + 'OPENB' => '[', + 'CLOSEB' => ']', + 'PTR' => '->', + 'APTR' => '=>', + 'EQUAL' => '=', + 'NUMBER' => 'number', + 'UNIMATH' => '+" , "-', + 'MATH' => '*" , "/" , "%', + 'INCDEC' => '++" , "--', + 'SPACE' => ' ', + 'DOLLAR' => '$', + 'SEMICOLON' => ';', + 'COLON' => ':', + 'DOUBLECOLON' => '::', + 'AT' => '@', + 'HATCH' => '#', + 'QUOTE' => '"', + 'BACKTICK' => '`', + 'VERT' => '"|" modifier', + 'DOT' => '.', + 'COMMA' => '","', + 'QMARK' => '"?"', + 'ID' => 'id, name', + 'TEXT' => 'text', + 'LDELSLASH' => '{/..} closing tag', + 'LDEL' => '{...} Smarty tag', + 'COMMENT' => 'comment', + 'AS' => 'as', + 'TO' => 'to', + 'LOGOP' => '"<", "==" ... logical operator', + 'TLOGOP' => '"lt", "eq" ... logical operator; "is div by" ... if condition', + 'SCOND' => '"is even" ... if condition', + ); + + /** + * literal tag nesting level + * + * @var int + */ + private $literal_cnt = 0; + + /** + * preg token pattern for state TEXT + * + * @var string + */ + private $yy_global_pattern1 = null; + + /** + * preg token pattern for state TAG + * + * @var string + */ + private $yy_global_pattern2 = null; + + /** + * preg token pattern for state TAGBODY + * + * @var string + */ + private $yy_global_pattern3 = null; + + /** + * preg token pattern for state LITERAL + * + * @var string + */ + private $yy_global_pattern4 = null; + + /** + * preg token pattern for state DOUBLEQUOTEDSTRING + * + * @var null + */ + private $yy_global_pattern5 = null; + + /** + * preg token pattern for text + * + * @var null + */ + private $yy_global_text = null; + + /** + * preg token pattern for literal + * + * @var null + */ + private $yy_global_literal = null; + + /** + * constructor + * + * @param string $source template source + * @param \Smarty\Compiler\Template $compiler + */ + public function __construct($source, \Smarty\Compiler\Template $compiler) + { + $this->data = $source; + $this->dataLength = strlen($this->data); + $this->counter = 0; + if (preg_match('/^\xEF\xBB\xBF/i', $this->data, $match)) { + $this->counter += strlen($match[0]); + } + $this->line = 1; + $this->smarty = $compiler->getTemplate()->getSmarty(); + $this->compiler = $compiler; + $this->compiler->initDelimiterPreg(); + $this->smarty_token_names['LDEL'] = $this->smarty->getLeftDelimiter(); + $this->smarty_token_names['RDEL'] = $this->smarty->getRightDelimiter(); + } + + /** + * open lexer/parser trace file + * + */ + public function PrintTrace() + { + $this->yyTraceFILE = fopen('php://output', 'w'); + $this->yyTracePrompt = '<br>'; + } + + /** + * replace placeholders with runtime preg code + * + * @param string $preg + * + * @return string + */ + public function replace($preg) + { + return $this->compiler->replaceDelimiter($preg); + } + + /** + * check if current value is an autoliteral left delimiter + * + * @return bool + */ + public function isAutoLiteral() + { + return $this->smarty->getAutoLiteral() && isset($this->value[ $this->compiler->getLdelLength() ]) ? + strpos(" \n\t\r", $this->value[ $this->compiler->getLdelLength() ]) !== false : false; + } + + /*!lex2php + %input $this->data + %counter $this->counter + %token $this->token + %value $this->value + %line $this->line + userliteral = ~(SMARTYldel)SMARTYautoliteral\s+SMARTYliteral~ + char = ~[\S\s]~ + textdoublequoted = ~([^"\\]*?)((?:\\.[^"\\]*?)*?)(?=((SMARTYldel)SMARTYal|\$|`\$|"SMARTYliteral))~ + namespace = ~([0-9]*[a-zA-Z_]\w*)?(\\[0-9]*[a-zA-Z_]\w*)+~ + emptyjava = ~[{][}]~ + slash = ~[/]~ + ldel = ~(SMARTYldel)SMARTYal~ + rdel = ~\s*SMARTYrdel~ + nocacherdel = ~(\s+nocache)?\s*SMARTYrdel~ + smartyblockchildparent = ~[\$]smarty\.block\.(child|parent)~ + integer = ~\d+~ + hex = ~0[xX][0-9a-fA-F]+~ + math = ~\s*([*]{1,2}|[%/^&]|[<>]{2})\s*~ + comment = ~(SMARTYldel)SMARTYal[*]~ + 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*~ + slop = ~\s+(eq|ne|neq|gt|ge|gte|lt|le|lte|mod|and|or|xor)\s+~ + tlop = ~\s+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+~ + if = ~(if|elseif|else if|while)\s+~ + for = ~for\s+~ + array = ~array~ + 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 = ~["]~ + */ + /*!lex2php + %statename TEXT + emptyjava { + $this->token = \Smarty\Parser\TemplateParser::TP_TEXT; + } + comment { + $to = $this->dataLength; + preg_match("/[*]{$this->compiler->getRdelPreg()}[\n]?/",$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->getRightDelimiter()}'"); + } + $this->value = substr($this->data,$this->counter,$to-$this->counter); + return false; + } + userliteral { + $this->token = \Smarty\Parser\TemplateParser::TP_TEXT; + } + ldel literal rdel { + $this->token = \Smarty\Parser\TemplateParser::TP_LITERALSTART; + $this->yypushstate(self::LITERAL); + } + ldel slash literal rdel { + $this->token = \Smarty\Parser\TemplateParser::TP_LITERALEND; + $this->yypushstate(self::LITERAL); + } + ldel { + $this->yypushstate(self::TAG); + return true; + } + char { + if (!isset($this->yy_global_text)) { + $this->yy_global_text = $this->replace('/(SMARTYldel)SMARTYal/isS'); + } + $to = $this->dataLength; + preg_match($this->yy_global_text, $this->data,$match,PREG_OFFSET_CAPTURE,$this->counter); + if (isset($match[0][1])) { + $to = $match[0][1]; + } + $this->value = substr($this->data,$this->counter,$to-$this->counter); + $this->token = \Smarty\Parser\TemplateParser::TP_TEXT; + } + */ + /*!lex2php + %statename TAG + ldel if { + $this->token = \Smarty\Parser\TemplateParser::TP_LDELIF; + $this->yybegin(self::TAGBODY); + $this->taglineno = $this->line; + } + ldel for { + $this->token = \Smarty\Parser\TemplateParser::TP_LDELFOR; + $this->yybegin(self::TAGBODY); + $this->taglineno = $this->line; + } + ldel foreach { + $this->token = \Smarty\Parser\TemplateParser::TP_LDELFOREACH; + $this->yybegin(self::TAGBODY); + $this->taglineno = $this->line; + } + ldel setfilter { + $this->token = \Smarty\Parser\TemplateParser::TP_LDELSETFILTER; + $this->yybegin(self::TAGBODY); + $this->taglineno = $this->line; + } + ldel id nocacherdel { + $this->yypopstate(); + $this->token = \Smarty\Parser\TemplateParser::TP_SIMPLETAG; + $this->taglineno = $this->line; + } + ldel smartyblockchildparent rdel { + $this->yypopstate(); + $this->token = \Smarty\Parser\TemplateParser::TP_SMARTYBLOCKCHILDPARENT; + $this->taglineno = $this->line; + } + ldel slash id rdel { + $this->yypopstate(); + $this->token = \Smarty\Parser\TemplateParser::TP_CLOSETAG; + $this->taglineno = $this->line; + } + ldel dollar id nocacherdel { + if ($this->_yy_stack[count($this->_yy_stack)-1] === self::TEXT) { + $this->yypopstate(); + $this->token = \Smarty\Parser\TemplateParser::TP_SIMPELOUTPUT; + $this->taglineno = $this->line; + } else { + $this->value = $this->smarty->getLeftDelimiter(); + $this->token = \Smarty\Parser\TemplateParser::TP_LDEL; + $this->yybegin(self::TAGBODY); + $this->taglineno = $this->line; + } + } + ldel slash { + $this->token = \Smarty\Parser\TemplateParser::TP_LDELSLASH; + $this->yybegin(self::TAGBODY); + $this->taglineno = $this->line; + } + ldel { + $this->token = \Smarty\Parser\TemplateParser::TP_LDEL; + $this->yybegin(self::TAGBODY); + $this->taglineno = $this->line; + } + */ + /*!lex2php + %statename TAGBODY + rdel { + $this->token = \Smarty\Parser\TemplateParser::TP_RDEL; + $this->yypopstate(); + } + ldel { + $this->yypushstate(self::TAG); + return true; + } + double_quote { + $this->token = \Smarty\Parser\TemplateParser::TP_QUOTE; + $this->yypushstate(self::DOUBLEQUOTEDSTRING); + $this->compiler->enterDoubleQuote(); + } + singlequotestring { + $this->token = \Smarty\Parser\TemplateParser::TP_SINGLEQUOTESTRING; + } + dollar id { + $this->token = \Smarty\Parser\TemplateParser::TP_DOLLARID; + } + dollar { + $this->token = \Smarty\Parser\TemplateParser::TP_DOLLAR; + } + isin { + $this->token = \Smarty\Parser\TemplateParser::TP_ISIN; + } + as { + $this->token = \Smarty\Parser\TemplateParser::TP_AS; + } + to { + $this->token = \Smarty\Parser\TemplateParser::TP_TO; + } + step { + $this->token = \Smarty\Parser\TemplateParser::TP_STEP; + } + instanceof { + $this->token = \Smarty\Parser\TemplateParser::TP_INSTANCEOF; + } + lop { + $this->token = \Smarty\Parser\TemplateParser::TP_LOGOP; + } + slop { + $this->token = \Smarty\Parser\TemplateParser::TP_SLOGOP; + } + tlop { + $this->token = \Smarty\Parser\TemplateParser::TP_TLOGOP; + } + scond { + $this->token = \Smarty\Parser\TemplateParser::TP_SINGLECOND; + } + not{ + $this->token = \Smarty\Parser\TemplateParser::TP_NOT; + } + typecast { + $this->token = \Smarty\Parser\TemplateParser::TP_TYPECAST; + } + openP { + $this->token = \Smarty\Parser\TemplateParser::TP_OPENP; + } + closeP { + $this->token = \Smarty\Parser\TemplateParser::TP_CLOSEP; + } + openB { + $this->token = \Smarty\Parser\TemplateParser::TP_OPENB; + } + closeB { + $this->token = \Smarty\Parser\TemplateParser::TP_CLOSEB; + } + ptr { + $this->token = \Smarty\Parser\TemplateParser::TP_PTR; + } + aptr { + $this->token = \Smarty\Parser\TemplateParser::TP_APTR; + } + equal { + $this->token = \Smarty\Parser\TemplateParser::TP_EQUAL; + } + incdec { + $this->token = \Smarty\Parser\TemplateParser::TP_INCDEC; + } + unimath { + $this->token = \Smarty\Parser\TemplateParser::TP_UNIMATH; + } + math { + $this->token = \Smarty\Parser\TemplateParser::TP_MATH; + } + at { + $this->token = \Smarty\Parser\TemplateParser::TP_AT; + } + array openP { + $this->token = \Smarty\Parser\TemplateParser::TP_ARRAYOPEN; + } + hatch { + $this->token = \Smarty\Parser\TemplateParser::TP_HATCH; + } + attr { + // resolve conflicts with shorttag and right_delimiter starting with '=' + if (substr($this->data, $this->counter + strlen($this->value) - 1, $this->compiler->getRdelLength()) === $this->smarty->getRightDelimiter()) { + preg_match('/\s+/',$this->value,$match); + $this->value = $match[0]; + $this->token = \Smarty\Parser\TemplateParser::TP_SPACE; + } else { + $this->token = \Smarty\Parser\TemplateParser::TP_ATTR; + } + } + namespace { + $this->token = \Smarty\Parser\TemplateParser::TP_NAMESPACE; + } + id { + $this->token = \Smarty\Parser\TemplateParser::TP_ID; + } + integer { + $this->token = \Smarty\Parser\TemplateParser::TP_INTEGER; + } + backtick { + $this->token = \Smarty\Parser\TemplateParser::TP_BACKTICK; + $this->yypopstate(); + } + vert { + $this->token = \Smarty\Parser\TemplateParser::TP_VERT; + } + dot { + $this->token = \Smarty\Parser\TemplateParser::TP_DOT; + } + comma { + $this->token = \Smarty\Parser\TemplateParser::TP_COMMA; + } + semicolon { + $this->token = \Smarty\Parser\TemplateParser::TP_SEMICOLON; + } + doublecolon { + $this->token = \Smarty\Parser\TemplateParser::TP_DOUBLECOLON; + } + colon { + $this->token = \Smarty\Parser\TemplateParser::TP_COLON; + } + qmark { + $this->token = \Smarty\Parser\TemplateParser::TP_QMARK; + } + hex { + $this->token = \Smarty\Parser\TemplateParser::TP_HEX; + } + space { + $this->token = \Smarty\Parser\TemplateParser::TP_SPACE; + } + char { + $this->token = \Smarty\Parser\TemplateParser::TP_TEXT; + } + */ + + /*!lex2php + %statename LITERAL + ldel literal rdel { + $this->literal_cnt++; + $this->token = \Smarty\Parser\TemplateParser::TP_LITERAL; + } + ldel slash literal rdel { + if ($this->literal_cnt) { + $this->literal_cnt--; + $this->token = \Smarty\Parser\TemplateParser::TP_LITERAL; + } else { + $this->token = \Smarty\Parser\TemplateParser::TP_LITERALEND; + $this->yypopstate(); + } + } + char { + if (!isset($this->yy_global_literal)) { + $this->yy_global_literal = $this->replace('/(SMARTYldel)SMARTYal[\/]?literalSMARTYrdel/isS'); + } + $to = $this->dataLength; + preg_match($this->yy_global_literal, $this->data,$match,PREG_OFFSET_CAPTURE,$this->counter); + if (isset($match[0][1])) { + $to = $match[0][1]; + } else { + $this->compiler->trigger_template_error ("missing or misspelled literal closing tag"); + } + $this->value = substr($this->data,$this->counter,$to-$this->counter); + $this->token = \Smarty\Parser\TemplateParser::TP_LITERAL; + } + */ + /*!lex2php + %statename DOUBLEQUOTEDSTRING + userliteral { + $this->token = \Smarty\Parser\TemplateParser::TP_TEXT; + } + ldel literal rdel { + $this->token = \Smarty\Parser\TemplateParser::TP_TEXT; + } + ldel slash literal rdel { + $this->token = \Smarty\Parser\TemplateParser::TP_TEXT; + } + ldel slash { + $this->yypushstate(self::TAG); + return true; + } + ldel id { + $this->yypushstate(self::TAG); + return true; + } + ldel { + $this->token = \Smarty\Parser\TemplateParser::TP_LDEL; + $this->taglineno = $this->line; + $this->yypushstate(self::TAGBODY); + } + double_quote { + $this->token = \Smarty\Parser\TemplateParser::TP_QUOTE; + $this->yypopstate(); + } + backtick dollar { + $this->token = \Smarty\Parser\TemplateParser::TP_BACKTICK; + $this->value = substr($this->value,0,-1); + $this->yypushstate(self::TAGBODY); + $this->taglineno = $this->line; + } + dollar id { + $this->token = \Smarty\Parser\TemplateParser::TP_DOLLARID; + } + dollar { + $this->token = \Smarty\Parser\TemplateParser::TP_TEXT; + } + textdoublequoted { + $this->token = \Smarty\Parser\TemplateParser::TP_TEXT; + } + char { + $to = $this->dataLength; + $this->value = substr($this->data,$this->counter,$to-$this->counter); + $this->token = \Smarty\Parser\TemplateParser::TP_TEXT; + } + */ + } + +
\ No newline at end of file |
