smarty_internal_templatelexer.php 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Templatelexer
  4. *
  5. * This is the lexer to break the template source into tokens
  6. * @package Smarty
  7. * @subpackage Compiler
  8. * @author Uwe Tews
  9. */
  10. /**
  11. * Smarty Internal Plugin Templatelexer
  12. */
  13. class Smarty_Internal_Templatelexer
  14. {
  15. public $data;
  16. public $counter;
  17. public $token;
  18. public $value;
  19. public $node;
  20. public $line;
  21. public $taglineno;
  22. public $state = 1;
  23. public $strip = false;
  24. private $heredoc_id_stack = Array();
  25. public $smarty_token_names = array ( // Text for parser error messages
  26. 'IDENTITY' => '===',
  27. 'NONEIDENTITY' => '!==',
  28. 'EQUALS' => '==',
  29. 'NOTEQUALS' => '!=',
  30. 'GREATEREQUAL' => '(>=,ge)',
  31. 'LESSEQUAL' => '(<=,le)',
  32. 'GREATERTHAN' => '(>,gt)',
  33. 'LESSTHAN' => '(<,lt)',
  34. 'MOD' => '(%,mod)',
  35. 'NOT' => '(!,not)',
  36. 'LAND' => '(&&,and)',
  37. 'LOR' => '(||,or)',
  38. 'LXOR' => 'xor',
  39. 'OPENP' => '(',
  40. 'CLOSEP' => ')',
  41. 'OPENB' => '[',
  42. 'CLOSEB' => ']',
  43. 'PTR' => '->',
  44. 'APTR' => '=>',
  45. 'EQUAL' => '=',
  46. 'NUMBER' => 'number',
  47. 'UNIMATH' => '+" , "-',
  48. 'MATH' => '*" , "/" , "%',
  49. 'INCDEC' => '++" , "--',
  50. 'SPACE' => ' ',
  51. 'DOLLAR' => '$',
  52. 'SEMICOLON' => ';',
  53. 'COLON' => ':',
  54. 'DOUBLECOLON' => '::',
  55. 'AT' => '@',
  56. 'HATCH' => '#',
  57. 'QUOTE' => '"',
  58. 'BACKTICK' => '`',
  59. 'VERT' => '|',
  60. 'DOT' => '.',
  61. 'COMMA' => '","',
  62. 'ANDSYM' => '"&"',
  63. 'QMARK' => '"?"',
  64. 'ID' => 'identifier',
  65. 'OTHER' => 'text',
  66. 'LINEBREAK' => 'newline',
  67. 'FAKEPHPSTARTTAG' => 'Fake PHP start tag',
  68. 'PHPSTARTTAG' => 'PHP start tag',
  69. 'PHPENDTAG' => 'PHP end tag',
  70. 'LITERALSTART' => 'Literal start',
  71. 'LITERALEND' => 'Literal end',
  72. 'LDELSLASH' => 'closing tag',
  73. 'COMMENT' => 'comment',
  74. 'LITERALEND' => 'literal close',
  75. 'AS' => 'as',
  76. 'TO' => 'to',
  77. );
  78. function __construct($data,$compiler)
  79. {
  80. // set instance object
  81. self::instance($this);
  82. // $this->data = preg_replace("/(\r\n|\r|\n)/", "\n", $data);
  83. $this->data = $data;
  84. $this->counter = 0;
  85. $this->line = 1;
  86. $this->smarty = $compiler->smarty;
  87. $this->compiler = $compiler;
  88. $this->ldel = preg_quote($this->smarty->left_delimiter,'/');
  89. $this->ldel_length = strlen($this->smarty->left_delimiter);
  90. $this->rdel = preg_quote($this->smarty->right_delimiter,'/');
  91. $this->smarty_token_names['LDEL'] = $this->smarty->left_delimiter;
  92. $this->smarty_token_names['RDEL'] = $this->smarty->right_delimiter;
  93. }
  94. public static function &instance($new_instance = null)
  95. {
  96. static $instance = null;
  97. if (isset($new_instance) && is_object($new_instance))
  98. $instance = $new_instance;
  99. return $instance;
  100. }
  101. private $_yy_state = 1;
  102. private $_yy_stack = array();
  103. function yylex()
  104. {
  105. return $this->{'yylex' . $this->_yy_state}();
  106. }
  107. function yypushstate($state)
  108. {
  109. array_push($this->_yy_stack, $this->_yy_state);
  110. $this->_yy_state = $state;
  111. }
  112. function yypopstate()
  113. {
  114. $this->_yy_state = array_pop($this->_yy_stack);
  115. }
  116. function yybegin($state)
  117. {
  118. $this->_yy_state = $state;
  119. }
  120. function yylex1()
  121. {
  122. $tokenMap = array (
  123. 1 => 0,
  124. 2 => 1,
  125. 4 => 0,
  126. 5 => 0,
  127. 6 => 0,
  128. 7 => 0,
  129. 8 => 0,
  130. 9 => 0,
  131. 10 => 0,
  132. 11 => 0,
  133. 12 => 0,
  134. 13 => 1,
  135. 15 => 0,
  136. 16 => 0,
  137. 17 => 0,
  138. 18 => 0,
  139. 19 => 0,
  140. 20 => 2,
  141. 23 => 0,
  142. );
  143. if ($this->counter >= strlen($this->data)) {
  144. return false; // end of input
  145. }
  146. $yy_global_pattern = "/^(\\{\\})|^(".$this->ldel."\\*([\S\s]*?)\\*".$this->rdel."\r?\n?)|^(<\\?(?:php\\w+|=|[a-zA-Z]+)?)|^(\\?>)|^(<%)|^(%>)|^([\t ]*[\r\n]+[\t ]*)|^(".$this->ldel."strip".$this->rdel.")|^(".$this->ldel."\/strip".$this->rdel.")|^(".$this->ldel."literal".$this->rdel.")|^(".$this->ldel."\\s{1,}\/)|^(".$this->ldel."\\s*(if|elseif|else if|while)(?![^\s]))|^(".$this->ldel."\\s*for(?![^\s]))|^(".$this->ldel."\\s*foreach(?![^\s]))|^(".$this->ldel."\\s{1,})|^(".$this->ldel."\/)|^(".$this->ldel.")|^(([\S\s]*?)(?=([\t ]*[\r\n]+[\t ]*|".$this->ldel."|<\\?|\\?>|<%|%>)))|^([\S\s]+)/";
  147. do {
  148. if (preg_match($yy_global_pattern, substr($this->data, $this->counter), $yymatches)) {
  149. $yysubmatches = $yymatches;
  150. $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns
  151. if (!count($yymatches)) {
  152. throw new Exception('Error: lexing failed because a rule matched' .
  153. 'an empty string. Input "' . substr($this->data,
  154. $this->counter, 5) . '... state TEXT');
  155. }
  156. next($yymatches); // skip global match
  157. $this->token = key($yymatches); // token number
  158. if ($tokenMap[$this->token]) {
  159. // extract sub-patterns for passing to lex function
  160. $yysubmatches = array_slice($yysubmatches, $this->token + 1,
  161. $tokenMap[$this->token]);
  162. } else {
  163. $yysubmatches = array();
  164. }
  165. $this->value = current($yymatches); // token value
  166. $r = $this->{'yy_r1_' . $this->token}($yysubmatches);
  167. if ($r === null) {
  168. $this->counter += strlen($this->value);
  169. $this->line += substr_count($this->value, "\n");
  170. // accept this token
  171. return true;
  172. } elseif ($r === true) {
  173. // we have changed state
  174. // process this token in the new state
  175. return $this->yylex();
  176. } elseif ($r === false) {
  177. $this->counter += strlen($this->value);
  178. $this->line += substr_count($this->value, "\n");
  179. if ($this->counter >= strlen($this->data)) {
  180. return false; // end of input
  181. }
  182. // skip this token
  183. continue;
  184. } } else {
  185. throw new Exception('Unexpected input at line' . $this->line .
  186. ': ' . $this->data[$this->counter]);
  187. }
  188. break;
  189. } while (true);
  190. } // end function
  191. const TEXT = 1;
  192. function yy_r1_1($yy_subpatterns)
  193. {
  194. $this->token = Smarty_Internal_Templateparser::TP_OTHER;
  195. }
  196. function yy_r1_2($yy_subpatterns)
  197. {
  198. $this->token = Smarty_Internal_Templateparser::TP_COMMENT;
  199. }
  200. function yy_r1_4($yy_subpatterns)
  201. {
  202. if (in_array($this->value, Array('<?', '<?=', '<?php'))) {
  203. $this->token = Smarty_Internal_Templateparser::TP_PHPSTARTTAG;
  204. } elseif ($this->value == '<?xml') {
  205. $this->token = Smarty_Internal_Templateparser::TP_XMLTAG;
  206. } else {
  207. $this->token = Smarty_Internal_Templateparser::TP_FAKEPHPSTARTTAG;
  208. $this->value = substr($this->value, 0, 2);
  209. }
  210. }
  211. function yy_r1_5($yy_subpatterns)
  212. {
  213. $this->token = Smarty_Internal_Templateparser::TP_PHPENDTAG;
  214. }
  215. function yy_r1_6($yy_subpatterns)
  216. {
  217. $this->token = Smarty_Internal_Templateparser::TP_ASPSTARTTAG;
  218. }
  219. function yy_r1_7($yy_subpatterns)
  220. {
  221. $this->token = Smarty_Internal_Templateparser::TP_ASPENDTAG;
  222. }
  223. function yy_r1_8($yy_subpatterns)
  224. {
  225. if ($this->strip) {
  226. return false;
  227. } else {
  228. $this->token = Smarty_Internal_Templateparser::TP_LINEBREAK;
  229. }
  230. }
  231. function yy_r1_9($yy_subpatterns)
  232. {
  233. $this->strip = true;
  234. return false;
  235. }
  236. function yy_r1_10($yy_subpatterns)
  237. {
  238. $this->strip = false;
  239. return false;
  240. }
  241. function yy_r1_11($yy_subpatterns)
  242. {
  243. $this->token = Smarty_Internal_Templateparser::TP_LITERALSTART;
  244. $this->yypushstate(self::LITERAL);
  245. }
  246. function yy_r1_12($yy_subpatterns)
  247. {
  248. if ($this->smarty->auto_literal) {
  249. $this->token = Smarty_Internal_Templateparser::TP_OTHER;
  250. } else {
  251. $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH;
  252. $this->yypushstate(self::SMARTY);
  253. $this->taglineno = $this->line;
  254. }
  255. }
  256. function yy_r1_13($yy_subpatterns)
  257. {
  258. if ($this->smarty->auto_literal && trim(substr($this->value,$this->ldel_length,1)) == '') {
  259. $this->token = Smarty_Internal_Templateparser::TP_OTHER;
  260. } else {
  261. $this->token = Smarty_Internal_Templateparser::TP_LDELIF;
  262. $this->yypushstate(self::SMARTY);
  263. $this->taglineno = $this->line;
  264. }
  265. }
  266. function yy_r1_15($yy_subpatterns)
  267. {
  268. if ($this->smarty->auto_literal && trim(substr($this->value,$this->ldel_length,1)) == '') {
  269. $this->token = Smarty_Internal_Templateparser::TP_OTHER;
  270. } else {
  271. $this->token = Smarty_Internal_Templateparser::TP_LDELFOR;
  272. $this->yypushstate(self::SMARTY);
  273. $this->taglineno = $this->line;
  274. }
  275. }
  276. function yy_r1_16($yy_subpatterns)
  277. {
  278. if ($this->smarty->auto_literal && trim(substr($this->value,$this->ldel_length,1)) == '') {
  279. $this->token = Smarty_Internal_Templateparser::TP_OTHER;
  280. } else {
  281. $this->token = Smarty_Internal_Templateparser::TP_LDELFOREACH;
  282. $this->yypushstate(self::SMARTY);
  283. $this->taglineno = $this->line;
  284. }
  285. }
  286. function yy_r1_17($yy_subpatterns)
  287. {
  288. if ($this->smarty->auto_literal) {
  289. $this->token = Smarty_Internal_Templateparser::TP_OTHER;
  290. } else {
  291. $this->token = Smarty_Internal_Templateparser::TP_LDEL;
  292. $this->yypushstate(self::SMARTY);
  293. $this->taglineno = $this->line;
  294. }
  295. }
  296. function yy_r1_18($yy_subpatterns)
  297. {
  298. $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH;
  299. $this->yypushstate(self::SMARTY);
  300. $this->taglineno = $this->line;
  301. }
  302. function yy_r1_19($yy_subpatterns)
  303. {
  304. $this->token = Smarty_Internal_Templateparser::TP_LDEL;
  305. $this->yypushstate(self::SMARTY);
  306. $this->taglineno = $this->line;
  307. }
  308. function yy_r1_20($yy_subpatterns)
  309. {
  310. $this->token = Smarty_Internal_Templateparser::TP_OTHER;
  311. }
  312. function yy_r1_23($yy_subpatterns)
  313. {
  314. $this->token = Smarty_Internal_Templateparser::TP_OTHER;
  315. }
  316. function yylex2()
  317. {
  318. $tokenMap = array (
  319. 1 => 0,
  320. 2 => 0,
  321. 3 => 1,
  322. 5 => 0,
  323. 6 => 0,
  324. 7 => 0,
  325. 8 => 0,
  326. 9 => 0,
  327. 10 => 0,
  328. 11 => 0,
  329. 12 => 0,
  330. 13 => 1,
  331. 15 => 1,
  332. 17 => 1,
  333. 19 => 0,
  334. 20 => 0,
  335. 21 => 0,
  336. 22 => 1,
  337. 24 => 1,
  338. 26 => 1,
  339. 28 => 1,
  340. 30 => 1,
  341. 32 => 1,
  342. 34 => 1,
  343. 36 => 1,
  344. 38 => 1,
  345. 40 => 1,
  346. 42 => 1,
  347. 44 => 0,
  348. 45 => 0,
  349. 46 => 0,
  350. 47 => 0,
  351. 48 => 0,
  352. 49 => 0,
  353. 50 => 0,
  354. 51 => 0,
  355. 52 => 0,
  356. 53 => 0,
  357. 54 => 3,
  358. 58 => 0,
  359. 59 => 0,
  360. 60 => 0,
  361. 61 => 0,
  362. 62 => 0,
  363. 63 => 0,
  364. 64 => 0,
  365. 65 => 1,
  366. 67 => 1,
  367. 69 => 1,
  368. 71 => 0,
  369. 72 => 0,
  370. 73 => 0,
  371. 74 => 0,
  372. 75 => 0,
  373. 76 => 0,
  374. 77 => 0,
  375. 78 => 0,
  376. 79 => 0,
  377. 80 => 0,
  378. 81 => 0,
  379. 82 => 0,
  380. 83 => 0,
  381. 84 => 0,
  382. 85 => 0,
  383. 86 => 0,
  384. 87 => 0,
  385. 88 => 0,
  386. );
  387. if ($this->counter >= strlen($this->data)) {
  388. return false; // end of input
  389. }
  390. $yy_global_pattern = "/^('[^'\\\\]*(?:\\\\.[^'\\\\]*)*')|^(".$this->ldel."\\s{1,}\/)|^(".$this->ldel."\\s*(if|elseif|else if|while)(?![^\s]))|^(".$this->ldel."\\s*for(?![^\s]))|^(".$this->ldel."\\s*foreach(?![^\s]))|^(".$this->ldel."\\s{1,})|^(\\s{1,}".$this->rdel.")|^(".$this->ldel."\/)|^(".$this->ldel.")|^(".$this->rdel.")|^(\\s+is\\s+in\\s+)|^(\\s+(AS|as)\\s+)|^(\\s+(to)\\s+)|^(\\s+(step)\\s+)|^(\\s+instanceof\\s+)|^(\\s*===\\s*)|^(\\s*!==\\s*)|^(\\s*==\\s*|\\s+(EQ|eq)\\s+)|^(\\s*!=\\s*|\\s*<>\\s*|\\s+(NE|NEQ|ne|neq)\\s+)|^(\\s*>=\\s*|\\s+(GE|GTE|ge|gte)\\s+)|^(\\s*<=\\s*|\\s+(LE|LTE|le|lte)\\s+)|^(\\s*>\\s*|\\s+(GT|gt)\\s+)|^(\\s*<\\s*|\\s+(LT|lt)\\s+)|^(\\s+(MOD|mod)\\s+)|^(!\\s*|(NOT|not)\\s+)|^(\\s*&&\\s*|\\s*(AND|and)\\s+)|^(\\s*\\|\\|\\s*|\\s*(OR|or)\\s+)|^(\\s*(XOR|xor)\\s+)|^(\\s+is\\s+odd\\s+by\\s+)|^(\\s+is\\s+not\\s+odd\\s+by\\s+)|^(\\s+is\\s+odd)|^(\\s+is\\s+not\\s+odd)|^(\\s+is\\s+even\\s+by\\s+)|^(\\s+is\\s+not\\s+even\\s+by\\s+)|^(\\s+is\\s+even)|^(\\s+is\\s+not\\s+even)|^(\\s+is\\s+div\\s+by\\s+)|^(\\s+is\\s+not\\s+div\\s+by\\s+)|^(\\((int(eger)?|bool(ean)?|float|double|real|string|binary|array|object)\\)\\s*)|^(\\(\\s*)|^(\\s*\\))|^(\\[\\s*)|^(\\s*\\])|^(\\s*->\\s*)|^(\\s*=>\\s*)|^(\\s*=\\s*)|^((\\+\\+|--)\\s*)|^(\\s*(\\+|-)\\s*)|^(\\s*(\\*|\/|%)\\s*)|^(\\$)|^(\\s*;)|^(::)|^(\\s*:\\s*)|^(@)|^(#)|^(\")|^(`)|^(\\|)|^(\\.)|^(\\s*,\\s*)|^(\\s*&\\s*)|^(\\s*\\?\\s*)|^(0[xX][0-9a-fA-F]+)|^([0-9]*[a-zA-Z_]\\w*)|^(\\d+)|^(\\s+)|^(.)/";
  391. do {
  392. if (preg_match($yy_global_pattern, substr($this->data, $this->counter), $yymatches)) {
  393. $yysubmatches = $yymatches;
  394. $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns
  395. if (!count($yymatches)) {
  396. throw new Exception('Error: lexing failed because a rule matched' .
  397. 'an empty string. Input "' . substr($this->data,
  398. $this->counter, 5) . '... state SMARTY');
  399. }
  400. next($yymatches); // skip global match
  401. $this->token = key($yymatches); // token number
  402. if ($tokenMap[$this->token]) {
  403. // extract sub-patterns for passing to lex function
  404. $yysubmatches = array_slice($yysubmatches, $this->token + 1,
  405. $tokenMap[$this->token]);
  406. } else {
  407. $yysubmatches = array();
  408. }
  409. $this->value = current($yymatches); // token value
  410. $r = $this->{'yy_r2_' . $this->token}($yysubmatches);
  411. if ($r === null) {
  412. $this->counter += strlen($this->value);
  413. $this->line += substr_count($this->value, "\n");
  414. // accept this token
  415. return true;
  416. } elseif ($r === true) {
  417. // we have changed state
  418. // process this token in the new state
  419. return $this->yylex();
  420. } elseif ($r === false) {
  421. $this->counter += strlen($this->value);
  422. $this->line += substr_count($this->value, "\n");
  423. if ($this->counter >= strlen($this->data)) {
  424. return false; // end of input
  425. }
  426. // skip this token
  427. continue;
  428. } } else {
  429. throw new Exception('Unexpected input at line' . $this->line .
  430. ': ' . $this->data[$this->counter]);
  431. }
  432. break;
  433. } while (true);
  434. } // end function
  435. const SMARTY = 2;
  436. function yy_r2_1($yy_subpatterns)
  437. {
  438. $this->token = Smarty_Internal_Templateparser::TP_SINGLEQUOTESTRING;
  439. }
  440. function yy_r2_2($yy_subpatterns)
  441. {
  442. if ($this->smarty->auto_literal) {
  443. $this->token = Smarty_Internal_Templateparser::TP_OTHER;
  444. } else {
  445. $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH;
  446. $this->yypushstate(self::SMARTY);
  447. $this->taglineno = $this->line;
  448. }
  449. }
  450. function yy_r2_3($yy_subpatterns)
  451. {
  452. if ($this->smarty->auto_literal && trim(substr($this->value,$this->ldel_length,1)) == '') {
  453. $this->token = Smarty_Internal_Templateparser::TP_OTHER;
  454. } else {
  455. $this->token = Smarty_Internal_Templateparser::TP_LDELIF;
  456. $this->yypushstate(self::SMARTY);
  457. $this->taglineno = $this->line;
  458. }
  459. }
  460. function yy_r2_5($yy_subpatterns)
  461. {
  462. if ($this->smarty->auto_literal && trim(substr($this->value,$this->ldel_length,1)) == '') {
  463. $this->token = Smarty_Internal_Templateparser::TP_OTHER;
  464. } else {
  465. $this->token = Smarty_Internal_Templateparser::TP_LDELFOR;
  466. $this->yypushstate(self::SMARTY);
  467. $this->taglineno = $this->line;
  468. }
  469. }
  470. function yy_r2_6($yy_subpatterns)
  471. {
  472. if ($this->smarty->auto_literal && trim(substr($this->value,$this->ldel_length,1)) == '') {
  473. $this->token = Smarty_Internal_Templateparser::TP_OTHER;
  474. } else {
  475. $this->token = Smarty_Internal_Templateparser::TP_LDELFOREACH;
  476. $this->yypushstate(self::SMARTY);
  477. $this->taglineno = $this->line;
  478. }
  479. }
  480. function yy_r2_7($yy_subpatterns)
  481. {
  482. if ($this->smarty->auto_literal) {
  483. $this->token = Smarty_Internal_Templateparser::TP_OTHER;
  484. } else {
  485. $this->token = Smarty_Internal_Templateparser::TP_LDEL;
  486. $this->yypushstate(self::SMARTY);
  487. $this->taglineno = $this->line;
  488. }
  489. }
  490. function yy_r2_8($yy_subpatterns)
  491. {
  492. if ($this->smarty->auto_literal) {
  493. $this->token = Smarty_Internal_Templateparser::TP_OTHER;
  494. } else {
  495. $this->token = Smarty_Internal_Templateparser::TP_RDEL;
  496. $this->yypopstate();
  497. }
  498. }
  499. function yy_r2_9($yy_subpatterns)
  500. {
  501. $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH;
  502. $this->yypushstate(self::SMARTY);
  503. $this->taglineno = $this->line;
  504. }
  505. function yy_r2_10($yy_subpatterns)
  506. {
  507. $this->token = Smarty_Internal_Templateparser::TP_LDEL;
  508. $this->yypushstate(self::SMARTY);
  509. $this->taglineno = $this->line;
  510. }
  511. function yy_r2_11($yy_subpatterns)
  512. {
  513. $this->token = Smarty_Internal_Templateparser::TP_RDEL;
  514. $this->yypopstate();
  515. }
  516. function yy_r2_12($yy_subpatterns)
  517. {
  518. $this->token = Smarty_Internal_Templateparser::TP_ISIN;
  519. }
  520. function yy_r2_13($yy_subpatterns)
  521. {
  522. $this->token = Smarty_Internal_Templateparser::TP_AS;
  523. }
  524. function yy_r2_15($yy_subpatterns)
  525. {
  526. $this->token = Smarty_Internal_Templateparser::TP_TO;
  527. }
  528. function yy_r2_17($yy_subpatterns)
  529. {
  530. $this->token = Smarty_Internal_Templateparser::TP_STEP;
  531. }
  532. function yy_r2_19($yy_subpatterns)
  533. {
  534. $this->token = Smarty_Internal_Templateparser::TP_INSTANCEOF;
  535. }
  536. function yy_r2_20($yy_subpatterns)
  537. {
  538. $this->token = Smarty_Internal_Templateparser::TP_IDENTITY;
  539. }
  540. function yy_r2_21($yy_subpatterns)
  541. {
  542. $this->token = Smarty_Internal_Templateparser::TP_NONEIDENTITY;
  543. }
  544. function yy_r2_22($yy_subpatterns)
  545. {
  546. $this->token = Smarty_Internal_Templateparser::TP_EQUALS;
  547. }
  548. function yy_r2_24($yy_subpatterns)
  549. {
  550. $this->token = Smarty_Internal_Templateparser::TP_NOTEQUALS;
  551. }
  552. function yy_r2_26($yy_subpatterns)
  553. {
  554. $this->token = Smarty_Internal_Templateparser::TP_GREATEREQUAL;
  555. }
  556. function yy_r2_28($yy_subpatterns)
  557. {
  558. $this->token = Smarty_Internal_Templateparser::TP_LESSEQUAL;
  559. }
  560. function yy_r2_30($yy_subpatterns)
  561. {
  562. $this->token = Smarty_Internal_Templateparser::TP_GREATERTHAN;
  563. }
  564. function yy_r2_32($yy_subpatterns)
  565. {
  566. $this->token = Smarty_Internal_Templateparser::TP_LESSTHAN;
  567. }
  568. function yy_r2_34($yy_subpatterns)
  569. {
  570. $this->token = Smarty_Internal_Templateparser::TP_MOD;
  571. }
  572. function yy_r2_36($yy_subpatterns)
  573. {
  574. $this->token = Smarty_Internal_Templateparser::TP_NOT;
  575. }
  576. function yy_r2_38($yy_subpatterns)
  577. {
  578. $this->token = Smarty_Internal_Templateparser::TP_LAND;
  579. }
  580. function yy_r2_40($yy_subpatterns)
  581. {
  582. $this->token = Smarty_Internal_Templateparser::TP_LOR;
  583. }
  584. function yy_r2_42($yy_subpatterns)
  585. {
  586. $this->token = Smarty_Internal_Templateparser::TP_LXOR;
  587. }
  588. function yy_r2_44($yy_subpatterns)
  589. {
  590. $this->token = Smarty_Internal_Templateparser::TP_ISODDBY;
  591. }
  592. function yy_r2_45($yy_subpatterns)
  593. {
  594. $this->token = Smarty_Internal_Templateparser::TP_ISNOTODDBY;
  595. }
  596. function yy_r2_46($yy_subpatterns)
  597. {
  598. $this->token = Smarty_Internal_Templateparser::TP_ISODD;
  599. }
  600. function yy_r2_47($yy_subpatterns)
  601. {
  602. $this->token = Smarty_Internal_Templateparser::TP_ISNOTODD;
  603. }
  604. function yy_r2_48($yy_subpatterns)
  605. {
  606. $this->token = Smarty_Internal_Templateparser::TP_ISEVENBY;
  607. }
  608. function yy_r2_49($yy_subpatterns)
  609. {
  610. $this->token = Smarty_Internal_Templateparser::TP_ISNOTEVENBY;
  611. }
  612. function yy_r2_50($yy_subpatterns)
  613. {
  614. $this->token = Smarty_Internal_Templateparser::TP_ISEVEN;
  615. }
  616. function yy_r2_51($yy_subpatterns)
  617. {
  618. $this->token = Smarty_Internal_Templateparser::TP_ISNOTEVEN;
  619. }
  620. function yy_r2_52($yy_subpatterns)
  621. {
  622. $this->token = Smarty_Internal_Templateparser::TP_ISDIVBY;
  623. }
  624. function yy_r2_53($yy_subpatterns)
  625. {
  626. $this->token = Smarty_Internal_Templateparser::TP_ISNOTDIVBY;
  627. }
  628. function yy_r2_54($yy_subpatterns)
  629. {
  630. $this->token = Smarty_Internal_Templateparser::TP_TYPECAST;
  631. }
  632. function yy_r2_58($yy_subpatterns)
  633. {
  634. $this->token = Smarty_Internal_Templateparser::TP_OPENP;
  635. }
  636. function yy_r2_59($yy_subpatterns)
  637. {
  638. $this->token = Smarty_Internal_Templateparser::TP_CLOSEP;
  639. }
  640. function yy_r2_60($yy_subpatterns)
  641. {
  642. $this->token = Smarty_Internal_Templateparser::TP_OPENB;
  643. }
  644. function yy_r2_61($yy_subpatterns)
  645. {
  646. $this->token = Smarty_Internal_Templateparser::TP_CLOSEB;
  647. }
  648. function yy_r2_62($yy_subpatterns)
  649. {
  650. $this->token = Smarty_Internal_Templateparser::TP_PTR;
  651. }
  652. function yy_r2_63($yy_subpatterns)
  653. {
  654. $this->token = Smarty_Internal_Templateparser::TP_APTR;
  655. }
  656. function yy_r2_64($yy_subpatterns)
  657. {
  658. $this->token = Smarty_Internal_Templateparser::TP_EQUAL;
  659. }
  660. function yy_r2_65($yy_subpatterns)
  661. {
  662. $this->token = Smarty_Internal_Templateparser::TP_INCDEC;
  663. }
  664. function yy_r2_67($yy_subpatterns)
  665. {
  666. $this->token = Smarty_Internal_Templateparser::TP_UNIMATH;
  667. }
  668. function yy_r2_69($yy_subpatterns)
  669. {
  670. $this->token = Smarty_Internal_Templateparser::TP_MATH;
  671. }
  672. function yy_r2_71($yy_subpatterns)
  673. {
  674. $this->token = Smarty_Internal_Templateparser::TP_DOLLAR;
  675. }
  676. function yy_r2_72($yy_subpatterns)
  677. {
  678. $this->token = Smarty_Internal_Templateparser::TP_SEMICOLON;
  679. }
  680. function yy_r2_73($yy_subpatterns)
  681. {
  682. $this->token = Smarty_Internal_Templateparser::TP_DOUBLECOLON;
  683. }
  684. function yy_r2_74($yy_subpatterns)
  685. {
  686. $this->token = Smarty_Internal_Templateparser::TP_COLON;
  687. }
  688. function yy_r2_75($yy_subpatterns)
  689. {
  690. $this->token = Smarty_Internal_Templateparser::TP_AT;
  691. }
  692. function yy_r2_76($yy_subpatterns)
  693. {
  694. $this->token = Smarty_Internal_Templateparser::TP_HATCH;
  695. }
  696. function yy_r2_77($yy_subpatterns)
  697. {
  698. $this->token = Smarty_Internal_Templateparser::TP_QUOTE;
  699. $this->yypushstate(self::DOUBLEQUOTEDSTRING);
  700. }
  701. function yy_r2_78($yy_subpatterns)
  702. {
  703. $this->token = Smarty_Internal_Templateparser::TP_BACKTICK;
  704. $this->yypopstate();
  705. }
  706. function yy_r2_79($yy_subpatterns)
  707. {
  708. $this->token = Smarty_Internal_Templateparser::TP_VERT;
  709. }
  710. function yy_r2_80($yy_subpatterns)
  711. {
  712. $this->token = Smarty_Internal_Templateparser::TP_DOT;
  713. }
  714. function yy_r2_81($yy_subpatterns)
  715. {
  716. $this->token = Smarty_Internal_Templateparser::TP_COMMA;
  717. }
  718. function yy_r2_82($yy_subpatterns)
  719. {
  720. $this->token = Smarty_Internal_Templateparser::TP_ANDSYM;
  721. }
  722. function yy_r2_83($yy_subpatterns)
  723. {
  724. $this->token = Smarty_Internal_Templateparser::TP_QMARK;
  725. }
  726. function yy_r2_84($yy_subpatterns)
  727. {
  728. $this->token = Smarty_Internal_Templateparser::TP_HEX;
  729. }
  730. function yy_r2_85($yy_subpatterns)
  731. {
  732. $this->token = Smarty_Internal_Templateparser::TP_ID;
  733. }
  734. function yy_r2_86($yy_subpatterns)
  735. {
  736. $this->token = Smarty_Internal_Templateparser::TP_INTEGER;
  737. }
  738. function yy_r2_87($yy_subpatterns)
  739. {
  740. $this->token = Smarty_Internal_Templateparser::TP_SPACE;
  741. }
  742. function yy_r2_88($yy_subpatterns)
  743. {
  744. $this->token = Smarty_Internal_Templateparser::TP_OTHER;
  745. }
  746. function yylex3()
  747. {
  748. $tokenMap = array (
  749. 1 => 0,
  750. 2 => 0,
  751. 3 => 0,
  752. 4 => 0,
  753. 5 => 0,
  754. 6 => 0,
  755. 7 => 0,
  756. 8 => 2,
  757. 11 => 0,
  758. );
  759. if ($this->counter >= strlen($this->data)) {
  760. return false; // end of input
  761. }
  762. $yy_global_pattern = "/^(".$this->ldel."literal".$this->rdel.")|^(".$this->ldel."\/literal".$this->rdel.")|^([\t ]*[\r\n]+[\t ]*)|^(<\\?(?:php\\w+|=|[a-zA-Z]+)?)|^(\\?>)|^(<%)|^(%>)|^(([\S\s]*?)(?=([\t ]*[\r\n]+[\t ]*|".$this->ldel."\/?literal".$this->rdel."|<\\?|<%)))|^([\S\s]+)/";
  763. do {
  764. if (preg_match($yy_global_pattern, substr($this->data, $this->counter), $yymatches)) {
  765. $yysubmatches = $yymatches;
  766. $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns
  767. if (!count($yymatches)) {
  768. throw new Exception('Error: lexing failed because a rule matched' .
  769. 'an empty string. Input "' . substr($this->data,
  770. $this->counter, 5) . '... state LITERAL');
  771. }
  772. next($yymatches); // skip global match
  773. $this->token = key($yymatches); // token number
  774. if ($tokenMap[$this->token]) {
  775. // extract sub-patterns for passing to lex function
  776. $yysubmatches = array_slice($yysubmatches, $this->token + 1,
  777. $tokenMap[$this->token]);
  778. } else {
  779. $yysubmatches = array();
  780. }
  781. $this->value = current($yymatches); // token value
  782. $r = $this->{'yy_r3_' . $this->token}($yysubmatches);
  783. if ($r === null) {
  784. $this->counter += strlen($this->value);
  785. $this->line += substr_count($this->value, "\n");
  786. // accept this token
  787. return true;
  788. } elseif ($r === true) {
  789. // we have changed state
  790. // process this token in the new state
  791. return $this->yylex();
  792. } elseif ($r === false) {
  793. $this->counter += strlen($this->value);
  794. $this->line += substr_count($this->value, "\n");
  795. if ($this->counter >= strlen($this->data)) {
  796. return false; // end of input
  797. }
  798. // skip this token
  799. continue;
  800. } } else {
  801. throw new Exception('Unexpected input at line' . $this->line .
  802. ': ' . $this->data[$this->counter]);
  803. }
  804. break;
  805. } while (true);
  806. } // end function
  807. const LITERAL = 3;
  808. function yy_r3_1($yy_subpatterns)
  809. {
  810. $this->token = Smarty_Internal_Templateparser::TP_LITERALSTART;
  811. $this->yypushstate(self::LITERAL);
  812. }
  813. function yy_r3_2($yy_subpatterns)
  814. {
  815. $this->token = Smarty_Internal_Templateparser::TP_LITERALEND;
  816. $this->yypopstate();
  817. }
  818. function yy_r3_3($yy_subpatterns)
  819. {
  820. $this->token = Smarty_Internal_Templateparser::TP_LITERAL;
  821. }
  822. function yy_r3_4($yy_subpatterns)
  823. {
  824. if (in_array($this->value, Array('<?', '<?=', '<?php'))) {
  825. $this->token = Smarty_Internal_Templateparser::TP_PHPSTARTTAG;
  826. } else {
  827. $this->token = Smarty_Internal_Templateparser::TP_FAKEPHPSTARTTAG;
  828. $this->value = substr($this->value, 0, 2);
  829. }
  830. }
  831. function yy_r3_5($yy_subpatterns)
  832. {
  833. $this->token = Smarty_Internal_Templateparser::TP_LITERAL;
  834. }
  835. function yy_r3_6($yy_subpatterns)
  836. {
  837. $this->token = Smarty_Internal_Templateparser::TP_ASPSTARTTAG;
  838. }
  839. function yy_r3_7($yy_subpatterns)
  840. {
  841. $this->token = Smarty_Internal_Templateparser::TP_ASPENDTAG;
  842. }
  843. function yy_r3_8($yy_subpatterns)
  844. {
  845. $this->token = Smarty_Internal_Templateparser::TP_LITERAL;
  846. }
  847. function yy_r3_11($yy_subpatterns)
  848. {
  849. $this->compiler->trigger_template_error ("missing or misspelled literal closing tag");
  850. }
  851. function yylex4()
  852. {
  853. $tokenMap = array (
  854. 1 => 0,
  855. 2 => 1,
  856. 4 => 0,
  857. 5 => 0,
  858. 6 => 0,
  859. 7 => 0,
  860. 8 => 0,
  861. 9 => 0,
  862. 10 => 0,
  863. 11 => 0,
  864. 12 => 0,
  865. 13 => 3,
  866. 17 => 0,
  867. );
  868. if ($this->counter >= strlen($this->data)) {
  869. return false; // end of input
  870. }
  871. $yy_global_pattern = "/^(".$this->ldel."\\s{1,}\/)|^(".$this->ldel."\\s*(if|elseif|else if|while)(?![^\s]))|^(".$this->ldel."\\s*for(?![^\s]))|^(".$this->ldel."\\s*foreach(?![^\s]))|^(".$this->ldel."\\s{1,})|^(".$this->ldel."\/)|^(".$this->ldel.")|^(\")|^(`\\$)|^(\\$[0-9]*[a-zA-Z_]\\w*)|^(\\$)|^(([^\"\\\\]*?)((?:\\\\.[^\"\\\\]*?)*?)(?=(".$this->ldel."|\\$|`\\$|\")))|^([\S\s]+)/";
  872. do {
  873. if (preg_match($yy_global_pattern, substr($this->data, $this->counter), $yymatches)) {
  874. $yysubmatches = $yymatches;
  875. $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns
  876. if (!count($yymatches)) {
  877. throw new Exception('Error: lexing failed because a rule matched' .
  878. 'an empty string. Input "' . substr($this->data,
  879. $this->counter, 5) . '... state DOUBLEQUOTEDSTRING');
  880. }
  881. next($yymatches); // skip global match
  882. $this->token = key($yymatches); // token number
  883. if ($tokenMap[$this->token]) {
  884. // extract sub-patterns for passing to lex function
  885. $yysubmatches = array_slice($yysubmatches, $this->token + 1,
  886. $tokenMap[$this->token]);
  887. } else {
  888. $yysubmatches = array();
  889. }
  890. $this->value = current($yymatches); // token value
  891. $r = $this->{'yy_r4_' . $this->token}($yysubmatches);
  892. if ($r === null) {
  893. $this->counter += strlen($this->value);
  894. $this->line += substr_count($this->value, "\n");
  895. // accept this token
  896. return true;
  897. } elseif ($r === true) {
  898. // we have changed state
  899. // process this token in the new state
  900. return $this->yylex();
  901. } elseif ($r === false) {
  902. $this->counter += strlen($this->value);
  903. $this->line += substr_count($this->value, "\n");
  904. if ($this->counter >= strlen($this->data)) {
  905. return false; // end of input
  906. }
  907. // skip this token
  908. continue;
  909. } } else {
  910. throw new Exception('Unexpected input at line' . $this->line .
  911. ': ' . $this->data[$this->counter]);
  912. }
  913. break;
  914. } while (true);
  915. } // end function
  916. const DOUBLEQUOTEDSTRING = 4;
  917. function yy_r4_1($yy_subpatterns)
  918. {
  919. if ($this->smarty->auto_literal) {
  920. $this->token = Smarty_Internal_Templateparser::TP_OTHER;
  921. } else {
  922. $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH;
  923. $this->yypushstate(self::SMARTY);
  924. $this->taglineno = $this->line;
  925. }
  926. }
  927. function yy_r4_2($yy_subpatterns)
  928. {
  929. if ($this->smarty->auto_literal && trim(substr($this->value,$this->ldel_length,1)) == '') {
  930. $this->token = Smarty_Internal_Templateparser::TP_OTHER;
  931. } else {
  932. $this->token = Smarty_Internal_Templateparser::TP_LDELIF;
  933. $this->yypushstate(self::SMARTY);
  934. $this->taglineno = $this->line;
  935. }
  936. }
  937. function yy_r4_4($yy_subpatterns)
  938. {
  939. if ($this->smarty->auto_literal && trim(substr($this->value,$this->ldel_length,1)) == '') {
  940. $this->token = Smarty_Internal_Templateparser::TP_OTHER;
  941. } else {
  942. $this->token = Smarty_Internal_Templateparser::TP_LDELFOR;
  943. $this->yypushstate(self::SMARTY);
  944. $this->taglineno = $this->line;
  945. }
  946. }
  947. function yy_r4_5($yy_subpatterns)
  948. {
  949. if ($this->smarty->auto_literal && trim(substr($this->value,$this->ldel_length,1)) == '') {
  950. $this->token = Smarty_Internal_Templateparser::TP_OTHER;
  951. } else {
  952. $this->token = Smarty_Internal_Templateparser::TP_LDELFOREACH;
  953. $this->yypushstate(self::SMARTY);
  954. $this->taglineno = $this->line;
  955. }
  956. }
  957. function yy_r4_6($yy_subpatterns)
  958. {
  959. if ($this->smarty->auto_literal) {
  960. $this->token = Smarty_Internal_Templateparser::TP_OTHER;
  961. } else {
  962. $this->token = Smarty_Internal_Templateparser::TP_LDEL;
  963. $this->yypushstate(self::SMARTY);
  964. $this->taglineno = $this->line;
  965. }
  966. }
  967. function yy_r4_7($yy_subpatterns)
  968. {
  969. $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH;
  970. $this->yypushstate(self::SMARTY);
  971. $this->taglineno = $this->line;
  972. }
  973. function yy_r4_8($yy_subpatterns)
  974. {
  975. $this->token = Smarty_Internal_Templateparser::TP_LDEL;
  976. $this->yypushstate(self::SMARTY);
  977. $this->taglineno = $this->line;
  978. }
  979. function yy_r4_9($yy_subpatterns)
  980. {
  981. $this->token = Smarty_Internal_Templateparser::TP_QUOTE;
  982. $this->yypopstate();
  983. }
  984. function yy_r4_10($yy_subpatterns)
  985. {
  986. $this->token = Smarty_Internal_Templateparser::TP_BACKTICK;
  987. $this->value = substr($this->value,0,-1);
  988. $this->yypushstate(self::SMARTY);
  989. $this->taglineno = $this->line;
  990. }
  991. function yy_r4_11($yy_subpatterns)
  992. {
  993. $this->token = Smarty_Internal_Templateparser::TP_DOLLARID;
  994. }
  995. function yy_r4_12($yy_subpatterns)
  996. {
  997. $this->token = Smarty_Internal_Templateparser::TP_OTHER;
  998. }
  999. function yy_r4_13($yy_subpatterns)
  1000. {
  1001. $this->token = Smarty_Internal_Templateparser::TP_OTHER;
  1002. }
  1003. function yy_r4_17($yy_subpatterns)
  1004. {
  1005. $this->token = Smarty_Internal_Templateparser::TP_OTHER;
  1006. }
  1007. }
  1008. ?>