PageRenderTime 52ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/tools/smarty/sysplugins/smarty_internal_configfilelexer.php

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