PageRenderTime 53ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/resources/libs/smarty/sysplugins/smarty_internal_templatelexer.php

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