You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

smarty_internal_configfilelexer.php 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Configfilelexer
  4. *
  5. * This is the lexer to break the config file source into tokens
  6. *
  7. * @package Smarty
  8. * @subpackage Config
  9. * @author Uwe Tews
  10. */
  11. /**
  12. * Smarty_Internal_Configfilelexer
  13. *
  14. * This is the config file lexer.
  15. * It is generated from the smarty_internal_configfilelexer.plex file
  16. *
  17. * @package Smarty
  18. * @subpackage Compiler
  19. * @author Uwe Tews
  20. */
  21. class Smarty_Internal_Configfilelexer
  22. {
  23. /**
  24. * Source
  25. *
  26. * @var string
  27. */
  28. public $data;
  29. /**
  30. * byte counter
  31. *
  32. * @var int
  33. */
  34. public $counter;
  35. /**
  36. * token number
  37. *
  38. * @var int
  39. */
  40. public $token;
  41. /**
  42. * token value
  43. *
  44. * @var string
  45. */
  46. public $value;
  47. /**
  48. * current line
  49. *
  50. * @var int
  51. */
  52. public $line;
  53. /**
  54. * state number
  55. *
  56. * @var int
  57. */
  58. public $state = 1;
  59. /**
  60. * Smarty object
  61. *
  62. * @var Smarty
  63. */
  64. public $smarty = null;
  65. /**
  66. * compiler object
  67. *
  68. * @var Smarty_Internal_Config_File_Compiler
  69. */
  70. private $compiler = null;
  71. /**
  72. * copy of config_booleanize
  73. *
  74. * @var bool
  75. */
  76. private $configBooleanize = false;
  77. /**
  78. * trace file
  79. *
  80. * @var resource
  81. */
  82. public $yyTraceFILE;
  83. /**
  84. * trace prompt
  85. *
  86. * @var string
  87. */
  88. public $yyTracePrompt;
  89. /**
  90. * state names
  91. *
  92. * @var array
  93. */
  94. public $state_name = array(1 => 'START', 2 => 'VALUE', 3 => 'NAKED_STRING_VALUE', 4 => 'COMMENT', 5 => 'SECTION',
  95. 6 => 'TRIPPLE');
  96. /**
  97. * storage for assembled token patterns
  98. *
  99. * @var sring
  100. */
  101. private $yy_global_pattern1 = null;
  102. private $yy_global_pattern2 = null;
  103. private $yy_global_pattern3 = null;
  104. private $yy_global_pattern4 = null;
  105. private $yy_global_pattern5 = null;
  106. private $yy_global_pattern6 = null;
  107. /**
  108. * token names
  109. *
  110. * @var array
  111. */
  112. public $smarty_token_names = array( // Text for parser error messages
  113. );
  114. /**
  115. * constructor
  116. *
  117. * @param string $data template source
  118. * @param Smarty_Internal_Config_File_Compiler $compiler
  119. */
  120. function __construct($data, Smarty_Internal_Config_File_Compiler $compiler)
  121. {
  122. // set instance object
  123. self::instance($this);
  124. $this->data = $data . "\n"; //now all lines are \n-terminated
  125. $this->counter = 0;
  126. if (preg_match('/^\xEF\xBB\xBF/', $this->data, $match)) {
  127. $this->counter += strlen($match[0]);
  128. }
  129. $this->line = 1;
  130. $this->compiler = $compiler;
  131. $this->smarty = $compiler->smarty;
  132. $this->configBooleanize = $this->smarty->config_booleanize;
  133. }
  134. public static function &instance($new_instance = null)
  135. {
  136. static $instance = null;
  137. if (isset($new_instance) && is_object($new_instance)) {
  138. $instance = $new_instance;
  139. }
  140. return $instance;
  141. }
  142. public function PrintTrace()
  143. {
  144. $this->yyTraceFILE = fopen('php://output', 'w');
  145. $this->yyTracePrompt = '<br>';
  146. }
  147. private $_yy_state = 1;
  148. private $_yy_stack = array();
  149. public function yylex()
  150. {
  151. return $this->{'yylex' . $this->_yy_state}();
  152. }
  153. public function yypushstate($state)
  154. {
  155. if ($this->yyTraceFILE) {
  156. fprintf($this->yyTraceFILE, "%sState push %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state);
  157. }
  158. array_push($this->_yy_stack, $this->_yy_state);
  159. $this->_yy_state = $state;
  160. if ($this->yyTraceFILE) {
  161. fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state);
  162. }
  163. }
  164. public function yypopstate()
  165. {
  166. if ($this->yyTraceFILE) {
  167. fprintf($this->yyTraceFILE, "%sState pop %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state);
  168. }
  169. $this->_yy_state = array_pop($this->_yy_stack);
  170. if ($this->yyTraceFILE) {
  171. fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state);
  172. }
  173. }
  174. public function yybegin($state)
  175. {
  176. $this->_yy_state = $state;
  177. if ($this->yyTraceFILE) {
  178. fprintf($this->yyTraceFILE, "%sState set %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state);
  179. }
  180. }
  181. public function yylex1()
  182. {
  183. if (!isset($this->yy_global_pattern1)) {
  184. $this->yy_global_pattern1 = "/\G(#|;)|\G(\\[)|\G(\\])|\G(=)|\G([ \t\r]+)|\G(\n)|\G([0-9]*[a-zA-Z_]\\w*)|\G([\S\s])/isS";
  185. }
  186. if ($this->counter >= strlen($this->data)) {
  187. return false; // end of input
  188. }
  189. do {
  190. if (preg_match($this->yy_global_pattern1, $this->data, $yymatches, null, $this->counter)) {
  191. $yysubmatches = $yymatches;
  192. if (strlen($yysubmatches[0]) < 200) {
  193. $yymatches = preg_grep("/(.|\s)+/", $yysubmatches);
  194. } else {
  195. $yymatches = array_filter($yymatches, 'strlen');
  196. }
  197. if (empty($yymatches)) {
  198. throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . substr($this->data, $this->counter, 5) . '... state START');
  199. }
  200. next($yymatches); // skip global match
  201. $this->token = key($yymatches); // token number
  202. $this->value = current($yymatches); // token value
  203. $r = $this->{'yy_r1_' . $this->token}();
  204. if ($r === null) {
  205. $this->counter += strlen($this->value);
  206. $this->line += substr_count($this->value, "\n");
  207. // accept this token
  208. return true;
  209. } elseif ($r === true) {
  210. // we have changed state
  211. // process this token in the new state
  212. return $this->yylex();
  213. } elseif ($r === false) {
  214. $this->counter += strlen($this->value);
  215. $this->line += substr_count($this->value, "\n");
  216. if ($this->counter >= strlen($this->data)) {
  217. return false; // end of input
  218. }
  219. // skip this token
  220. continue;
  221. }
  222. } else {
  223. throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[$this->counter]);
  224. }
  225. break;
  226. } while (true);
  227. } // end function
  228. const START = 1;
  229. function yy_r1_1()
  230. {
  231. $this->token = Smarty_Internal_Configfileparser::TPC_COMMENTSTART;
  232. $this->yypushstate(self::COMMENT);
  233. }
  234. function yy_r1_2()
  235. {
  236. $this->token = Smarty_Internal_Configfileparser::TPC_OPENB;
  237. $this->yypushstate(self::SECTION);
  238. }
  239. function yy_r1_3()
  240. {
  241. $this->token = Smarty_Internal_Configfileparser::TPC_CLOSEB;
  242. }
  243. function yy_r1_4()
  244. {
  245. $this->token = Smarty_Internal_Configfileparser::TPC_EQUAL;
  246. $this->yypushstate(self::VALUE);
  247. }
  248. function yy_r1_5()
  249. {
  250. return false;
  251. }
  252. function yy_r1_6()
  253. {
  254. $this->token = Smarty_Internal_Configfileparser::TPC_NEWLINE;
  255. }
  256. function yy_r1_7()
  257. {
  258. $this->token = Smarty_Internal_Configfileparser::TPC_ID;
  259. }
  260. function yy_r1_8()
  261. {
  262. $this->token = Smarty_Internal_Configfileparser::TPC_OTHER;
  263. }
  264. public function yylex2()
  265. {
  266. if (!isset($this->yy_global_pattern2)) {
  267. $this->yy_global_pattern2 = "/\G([ \t\r]+)|\G(\\d+\\.\\d+(?=[ \t\r]*[\n#;]))|\G(\\d+(?=[ \t\r]*[\n#;]))|\G(\"\"\")|\G('[^'\\\\]*(?:\\\\.[^'\\\\]*)*'(?=[ \t\r]*[\n#;]))|\G(\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\"(?=[ \t\r]*[\n#;]))|\G([a-zA-Z]+(?=[ \t\r]*[\n#;]))|\G([^\n]+?(?=[ \t\r]*\n))|\G(\n)/isS";
  268. }
  269. if ($this->counter >= strlen($this->data)) {
  270. return false; // end of input
  271. }
  272. do {
  273. if (preg_match($this->yy_global_pattern2, $this->data, $yymatches, null, $this->counter)) {
  274. $yysubmatches = $yymatches;
  275. if (strlen($yysubmatches[0]) < 200) {
  276. $yymatches = preg_grep("/(.|\s)+/", $yysubmatches);
  277. } else {
  278. $yymatches = array_filter($yymatches, 'strlen');
  279. }
  280. if (empty($yymatches)) {
  281. throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . substr($this->data, $this->counter, 5) . '... state VALUE');
  282. }
  283. next($yymatches); // skip global match
  284. $this->token = key($yymatches); // token number
  285. $this->value = current($yymatches); // token value
  286. $r = $this->{'yy_r2_' . $this->token}();
  287. if ($r === null) {
  288. $this->counter += strlen($this->value);
  289. $this->line += substr_count($this->value, "\n");
  290. // accept this token
  291. return true;
  292. } elseif ($r === true) {
  293. // we have changed state
  294. // process this token in the new state
  295. return $this->yylex();
  296. } elseif ($r === false) {
  297. $this->counter += strlen($this->value);
  298. $this->line += substr_count($this->value, "\n");
  299. if ($this->counter >= strlen($this->data)) {
  300. return false; // end of input
  301. }
  302. // skip this token
  303. continue;
  304. }
  305. } else {
  306. throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[$this->counter]);
  307. }
  308. break;
  309. } while (true);
  310. } // end function
  311. const VALUE = 2;
  312. function yy_r2_1()
  313. {
  314. return false;
  315. }
  316. function yy_r2_2()
  317. {
  318. $this->token = Smarty_Internal_Configfileparser::TPC_FLOAT;
  319. $this->yypopstate();
  320. }
  321. function yy_r2_3()
  322. {
  323. $this->token = Smarty_Internal_Configfileparser::TPC_INT;
  324. $this->yypopstate();
  325. }
  326. function yy_r2_4()
  327. {
  328. $this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_QUOTES;
  329. $this->yypushstate(self::TRIPPLE);
  330. }
  331. function yy_r2_5()
  332. {
  333. $this->token = Smarty_Internal_Configfileparser::TPC_SINGLE_QUOTED_STRING;
  334. $this->yypopstate();
  335. }
  336. function yy_r2_6()
  337. {
  338. $this->token = Smarty_Internal_Configfileparser::TPC_DOUBLE_QUOTED_STRING;
  339. $this->yypopstate();
  340. }
  341. function yy_r2_7()
  342. {
  343. if (!$this->configBooleanize || !in_array(strtolower($this->value), Array("true", "false", "on", "off", "yes",
  344. "no"))
  345. ) {
  346. $this->yypopstate();
  347. $this->yypushstate(self::NAKED_STRING_VALUE);
  348. return true; //reprocess in new state
  349. } else {
  350. $this->token = Smarty_Internal_Configfileparser::TPC_BOOL;
  351. $this->yypopstate();
  352. }
  353. }
  354. function yy_r2_8()
  355. {
  356. $this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
  357. $this->yypopstate();
  358. }
  359. function yy_r2_9()
  360. {
  361. $this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
  362. $this->value = "";
  363. $this->yypopstate();
  364. }
  365. public function yylex3()
  366. {
  367. if (!isset($this->yy_global_pattern3)) {
  368. $this->yy_global_pattern3 = "/\G([^\n]+?(?=[ \t\r]*\n))/isS";
  369. }
  370. if ($this->counter >= strlen($this->data)) {
  371. return false; // end of input
  372. }
  373. do {
  374. if (preg_match($this->yy_global_pattern3, $this->data, $yymatches, null, $this->counter)) {
  375. $yysubmatches = $yymatches;
  376. if (strlen($yysubmatches[0]) < 200) {
  377. $yymatches = preg_grep("/(.|\s)+/", $yysubmatches);
  378. } else {
  379. $yymatches = array_filter($yymatches, 'strlen');
  380. }
  381. if (empty($yymatches)) {
  382. throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . substr($this->data, $this->counter, 5) . '... state NAKED_STRING_VALUE');
  383. }
  384. next($yymatches); // skip global match
  385. $this->token = key($yymatches); // token number
  386. $this->value = current($yymatches); // token value
  387. $r = $this->{'yy_r3_' . $this->token}();
  388. if ($r === null) {
  389. $this->counter += strlen($this->value);
  390. $this->line += substr_count($this->value, "\n");
  391. // accept this token
  392. return true;
  393. } elseif ($r === true) {
  394. // we have changed state
  395. // process this token in the new state
  396. return $this->yylex();
  397. } elseif ($r === false) {
  398. $this->counter += strlen($this->value);
  399. $this->line += substr_count($this->value, "\n");
  400. if ($this->counter >= strlen($this->data)) {
  401. return false; // end of input
  402. }
  403. // skip this token
  404. continue;
  405. }
  406. } else {
  407. throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[$this->counter]);
  408. }
  409. break;
  410. } while (true);
  411. } // end function
  412. const NAKED_STRING_VALUE = 3;
  413. function yy_r3_1()
  414. {
  415. $this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
  416. $this->yypopstate();
  417. }
  418. public function yylex4()
  419. {
  420. if (!isset($this->yy_global_pattern4)) {
  421. $this->yy_global_pattern4 = "/\G([ \t\r]+)|\G([^\n]+?(?=[ \t\r]*\n))|\G(\n)/isS";
  422. }
  423. if ($this->counter >= strlen($this->data)) {
  424. return false; // end of input
  425. }
  426. do {
  427. if (preg_match($this->yy_global_pattern4, $this->data, $yymatches, null, $this->counter)) {
  428. $yysubmatches = $yymatches;
  429. if (strlen($yysubmatches[0]) < 200) {
  430. $yymatches = preg_grep("/(.|\s)+/", $yysubmatches);
  431. } else {
  432. $yymatches = array_filter($yymatches, 'strlen');
  433. }
  434. if (empty($yymatches)) {
  435. throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . substr($this->data, $this->counter, 5) . '... state COMMENT');
  436. }
  437. next($yymatches); // skip global match
  438. $this->token = key($yymatches); // token number
  439. $this->value = current($yymatches); // token value
  440. $r = $this->{'yy_r4_' . $this->token}();
  441. if ($r === null) {
  442. $this->counter += strlen($this->value);
  443. $this->line += substr_count($this->value, "\n");
  444. // accept this token
  445. return true;
  446. } elseif ($r === true) {
  447. // we have changed state
  448. // process this token in the new state
  449. return $this->yylex();
  450. } elseif ($r === false) {
  451. $this->counter += strlen($this->value);
  452. $this->line += substr_count($this->value, "\n");
  453. if ($this->counter >= strlen($this->data)) {
  454. return false; // end of input
  455. }
  456. // skip this token
  457. continue;
  458. }
  459. } else {
  460. throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[$this->counter]);
  461. }
  462. break;
  463. } while (true);
  464. } // end function
  465. const COMMENT = 4;
  466. function yy_r4_1()
  467. {
  468. return false;
  469. }
  470. function yy_r4_2()
  471. {
  472. $this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
  473. }
  474. function yy_r4_3()
  475. {
  476. $this->token = Smarty_Internal_Configfileparser::TPC_NEWLINE;
  477. $this->yypopstate();
  478. }
  479. public function yylex5()
  480. {
  481. if (!isset($this->yy_global_pattern5)) {
  482. $this->yy_global_pattern5 = "/\G(\\.)|\G(.*?(?=[\.=[\]\r\n]))/isS";
  483. }
  484. if ($this->counter >= strlen($this->data)) {
  485. return false; // end of input
  486. }
  487. do {
  488. if (preg_match($this->yy_global_pattern5, $this->data, $yymatches, null, $this->counter)) {
  489. $yysubmatches = $yymatches;
  490. if (strlen($yysubmatches[0]) < 200) {
  491. $yymatches = preg_grep("/(.|\s)+/", $yysubmatches);
  492. } else {
  493. $yymatches = array_filter($yymatches, 'strlen');
  494. }
  495. if (empty($yymatches)) {
  496. throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . substr($this->data, $this->counter, 5) . '... state SECTION');
  497. }
  498. next($yymatches); // skip global match
  499. $this->token = key($yymatches); // token number
  500. $this->value = current($yymatches); // token value
  501. $r = $this->{'yy_r5_' . $this->token}();
  502. if ($r === null) {
  503. $this->counter += strlen($this->value);
  504. $this->line += substr_count($this->value, "\n");
  505. // accept this token
  506. return true;
  507. } elseif ($r === true) {
  508. // we have changed state
  509. // process this token in the new state
  510. return $this->yylex();
  511. } elseif ($r === false) {
  512. $this->counter += strlen($this->value);
  513. $this->line += substr_count($this->value, "\n");
  514. if ($this->counter >= strlen($this->data)) {
  515. return false; // end of input
  516. }
  517. // skip this token
  518. continue;
  519. }
  520. } else {
  521. throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[$this->counter]);
  522. }
  523. break;
  524. } while (true);
  525. } // end function
  526. const SECTION = 5;
  527. function yy_r5_1()
  528. {
  529. $this->token = Smarty_Internal_Configfileparser::TPC_DOT;
  530. }
  531. function yy_r5_2()
  532. {
  533. $this->token = Smarty_Internal_Configfileparser::TPC_SECTION;
  534. $this->yypopstate();
  535. }
  536. public function yylex6()
  537. {
  538. if (!isset($this->yy_global_pattern6)) {
  539. $this->yy_global_pattern6 = "/\G(\"\"\"(?=[ \t\r]*[\n#;]))|\G([\S\s])/isS";
  540. }
  541. if ($this->counter >= strlen($this->data)) {
  542. return false; // end of input
  543. }
  544. do {
  545. if (preg_match($this->yy_global_pattern6, $this->data, $yymatches, null, $this->counter)) {
  546. $yysubmatches = $yymatches;
  547. if (strlen($yysubmatches[0]) < 200) {
  548. $yymatches = preg_grep("/(.|\s)+/", $yysubmatches);
  549. } else {
  550. $yymatches = array_filter($yymatches, 'strlen');
  551. }
  552. if (empty($yymatches)) {
  553. throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . substr($this->data, $this->counter, 5) . '... state TRIPPLE');
  554. }
  555. next($yymatches); // skip global match
  556. $this->token = key($yymatches); // token number
  557. $this->value = current($yymatches); // token value
  558. $r = $this->{'yy_r6_' . $this->token}();
  559. if ($r === null) {
  560. $this->counter += strlen($this->value);
  561. $this->line += substr_count($this->value, "\n");
  562. // accept this token
  563. return true;
  564. } elseif ($r === true) {
  565. // we have changed state
  566. // process this token in the new state
  567. return $this->yylex();
  568. } elseif ($r === false) {
  569. $this->counter += strlen($this->value);
  570. $this->line += substr_count($this->value, "\n");
  571. if ($this->counter >= strlen($this->data)) {
  572. return false; // end of input
  573. }
  574. // skip this token
  575. continue;
  576. }
  577. } else {
  578. throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[$this->counter]);
  579. }
  580. break;
  581. } while (true);
  582. } // end function
  583. const TRIPPLE = 6;
  584. function yy_r6_1()
  585. {
  586. $this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_QUOTES_END;
  587. $this->yypopstate();
  588. $this->yypushstate(self::START);
  589. }
  590. function yy_r6_2()
  591. {
  592. $to = strlen($this->data);
  593. preg_match("/\"\"\"[ \t\r]*[\n#;]/", $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter);
  594. if (isset($match[0][1])) {
  595. $to = $match[0][1];
  596. } else {
  597. $this->compiler->trigger_template_error("missing or misspelled literal closing tag");
  598. }
  599. $this->value = substr($this->data, $this->counter, $to - $this->counter);
  600. $this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_TEXT;
  601. }
  602. }