smarty_internal_templatelexer.php 36 KB

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