PageRenderTime 58ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/library/Smarty/sysplugins/smarty_internal_configfilelexer.php

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