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

/core/model/smarty/sysplugins/smarty_internal_configfileparser.php

http://github.com/modxcms/revolution
PHP | 1046 lines | 836 code | 67 blank | 143 comment | 118 complexity | fa7ad4eb968f5384f319879426f64e22 MD5 | raw file
Possible License(s): GPL-2.0, Apache-2.0, BSD-3-Clause, LGPL-2.1
  1. <?php
  2. class TPC_yyStackEntry
  3. {
  4. public $stateno; /* The state-number */
  5. public $major; /* The major token value. This is the code
  6. ** number for the token at this stack level */
  7. public $minor; /* The user-supplied minor token value. This
  8. ** is the value of the token */
  9. }
  10. // line 12 "../smarty/lexer/smarty_internal_configfileparser.y"
  11. /**
  12. * Smarty Internal Plugin Configfileparse
  13. *
  14. * This is the config file parser.
  15. * It is generated from the smarty_internal_configfileparser.y file
  16. *
  17. * @package Smarty
  18. * @subpackage Compiler
  19. * @author Uwe Tews
  20. */
  21. class Smarty_Internal_Configfileparser
  22. {
  23. // line 25 "../smarty/lexer/smarty_internal_configfileparser.y"
  24. const TPC_OPENB = 1;
  25. const TPC_SECTION = 2;
  26. const TPC_CLOSEB = 3;
  27. const TPC_DOT = 4;
  28. const TPC_ID = 5;
  29. const TPC_EQUAL = 6;
  30. const TPC_FLOAT = 7;
  31. const TPC_INT = 8;
  32. const TPC_BOOL = 9;
  33. const TPC_SINGLE_QUOTED_STRING = 10;
  34. const TPC_DOUBLE_QUOTED_STRING = 11;
  35. const TPC_TRIPPLE_QUOTES = 12;
  36. const TPC_TRIPPLE_TEXT = 13;
  37. const TPC_TRIPPLE_QUOTES_END = 14;
  38. const TPC_NAKED_STRING = 15;
  39. const TPC_OTHER = 16;
  40. const TPC_NEWLINE = 17;
  41. const TPC_COMMENTSTART = 18;
  42. const YY_NO_ACTION = 60;
  43. const YY_ACCEPT_ACTION = 59;
  44. const YY_ERROR_ACTION = 58;
  45. const YY_SZ_ACTTAB = 38;
  46. const YY_SHIFT_USE_DFLT = -8;
  47. const YY_SHIFT_MAX = 19;
  48. const YY_REDUCE_USE_DFLT = -17;
  49. const YY_REDUCE_MAX = 10;
  50. const YYNOCODE = 29;
  51. const YYSTACKDEPTH = 100;
  52. const YYNSTATE = 36;
  53. const YYNRULE = 22;
  54. const YYERRORSYMBOL = 19;
  55. const YYERRSYMDT = 'yy0';
  56. const YYFALLBACK = 0;
  57. public static $yy_action = array(
  58. 32, 31, 30, 29, 35, 13, 19, 3, 24, 26,
  59. 59, 9, 14, 1, 16, 25, 11, 28, 25, 11,
  60. 17, 27, 34, 20, 18, 15, 23, 5, 6, 22,
  61. 10, 8, 4, 12, 2, 33, 7, 21,
  62. );
  63. public static $yy_lookahead = array(
  64. 7, 8, 9, 10, 11, 12, 5, 23, 15, 16,
  65. 20, 21, 2, 23, 4, 17, 18, 14, 17, 18,
  66. 13, 14, 25, 26, 15, 2, 17, 3, 3, 17,
  67. 25, 25, 6, 1, 23, 27, 22, 24,
  68. );
  69. public static $yy_shift_ofst = array(
  70. -8, 1, 1, 1, -7, -2, -2, 32, -8, -8,
  71. -8, 9, 10, 7, 25, 24, 23, 3, 12, 26,
  72. );
  73. public static $yy_reduce_ofst = array(
  74. -10, -3, -3, -3, 8, 6, 5, 13, 11, 14,
  75. -16,
  76. );
  77. public static $yyExpectedTokens = array(
  78. array(),
  79. array(5, 17, 18,),
  80. array(5, 17, 18,),
  81. array(5, 17, 18,),
  82. array(7, 8, 9, 10, 11, 12, 15, 16,),
  83. array(17, 18,),
  84. array(17, 18,),
  85. array(1,),
  86. array(),
  87. array(),
  88. array(),
  89. array(15, 17,),
  90. array(2, 4,),
  91. array(13, 14,),
  92. array(3,),
  93. array(3,),
  94. array(2,),
  95. array(14,),
  96. array(17,),
  97. array(6,),
  98. array(),
  99. array(),
  100. array(),
  101. array(),
  102. array(),
  103. array(),
  104. array(),
  105. array(),
  106. array(),
  107. array(),
  108. array(),
  109. array(),
  110. array(),
  111. array(),
  112. array(),
  113. array(),
  114. );
  115. public static $yy_default = array(
  116. 44, 37, 41, 40, 58, 58, 58, 36, 44, 39,
  117. 44, 58, 58, 58, 58, 58, 58, 58, 58, 58,
  118. 43, 38, 57, 56, 53, 55, 54, 52, 51, 49,
  119. 48, 47, 46, 45, 42, 50,
  120. );
  121. public static $yyFallback = array();
  122. public static $yyRuleName = array(
  123. 'start ::= global_vars sections',
  124. 'global_vars ::= var_list',
  125. 'sections ::= sections section',
  126. 'sections ::=',
  127. 'section ::= OPENB SECTION CLOSEB newline var_list',
  128. 'section ::= OPENB DOT SECTION CLOSEB newline var_list',
  129. 'var_list ::= var_list newline',
  130. 'var_list ::= var_list var',
  131. 'var_list ::=',
  132. 'var ::= ID EQUAL value',
  133. 'value ::= FLOAT',
  134. 'value ::= INT',
  135. 'value ::= BOOL',
  136. 'value ::= SINGLE_QUOTED_STRING',
  137. 'value ::= DOUBLE_QUOTED_STRING',
  138. 'value ::= TRIPPLE_QUOTES TRIPPLE_TEXT TRIPPLE_QUOTES_END',
  139. 'value ::= TRIPPLE_QUOTES TRIPPLE_QUOTES_END',
  140. 'value ::= NAKED_STRING',
  141. 'value ::= OTHER',
  142. 'newline ::= NEWLINE',
  143. 'newline ::= COMMENTSTART NEWLINE',
  144. 'newline ::= COMMENTSTART NAKED_STRING NEWLINE',
  145. );
  146. public static $yyRuleInfo = array(
  147. array(0 => 20, 1 => 2),
  148. array(0 => 21, 1 => 1),
  149. array(0 => 22, 1 => 2),
  150. array(0 => 22, 1 => 0),
  151. array(0 => 24, 1 => 5),
  152. array(0 => 24, 1 => 6),
  153. array(0 => 23, 1 => 2),
  154. array(0 => 23, 1 => 2),
  155. array(0 => 23, 1 => 0),
  156. array(0 => 26, 1 => 3),
  157. array(0 => 27, 1 => 1),
  158. array(0 => 27, 1 => 1),
  159. array(0 => 27, 1 => 1),
  160. array(0 => 27, 1 => 1),
  161. array(0 => 27, 1 => 1),
  162. array(0 => 27, 1 => 3),
  163. array(0 => 27, 1 => 2),
  164. array(0 => 27, 1 => 1),
  165. array(0 => 27, 1 => 1),
  166. array(0 => 25, 1 => 1),
  167. array(0 => 25, 1 => 2),
  168. array(0 => 25, 1 => 3),
  169. );
  170. public static $yyReduceMap = array(
  171. 0 => 0,
  172. 2 => 0,
  173. 3 => 0,
  174. 19 => 0,
  175. 20 => 0,
  176. 21 => 0,
  177. 1 => 1,
  178. 4 => 4,
  179. 5 => 5,
  180. 6 => 6,
  181. 7 => 7,
  182. 8 => 8,
  183. 9 => 9,
  184. 10 => 10,
  185. 11 => 11,
  186. 12 => 12,
  187. 13 => 13,
  188. 14 => 14,
  189. 15 => 15,
  190. 16 => 16,
  191. 17 => 17,
  192. 18 => 17,
  193. );
  194. /**
  195. * helper map
  196. *
  197. * @var array
  198. */
  199. private static $escapes_single = array(
  200. '\\' => '\\',
  201. '\'' => '\''
  202. );
  203. /**
  204. * result status
  205. *
  206. * @var bool
  207. */
  208. public $successful = true;
  209. /**
  210. * return value
  211. *
  212. * @var mixed
  213. */
  214. public $retvalue = 0;
  215. /**
  216. * @var
  217. */
  218. public $yymajor;
  219. /**
  220. * compiler object
  221. *
  222. * @var Smarty_Internal_Config_File_Compiler
  223. */
  224. public $compiler = null;
  225. /**
  226. * smarty object
  227. *
  228. * @var Smarty
  229. */
  230. public $smarty = null;
  231. public $yyTraceFILE;
  232. public $yyTracePrompt;
  233. public $yyidx;
  234. public $yyerrcnt;
  235. public $yystack = array();
  236. public $yyTokenName = array(
  237. '$', 'OPENB', 'SECTION', 'CLOSEB',
  238. 'DOT', 'ID', 'EQUAL', 'FLOAT',
  239. 'INT', 'BOOL', 'SINGLE_QUOTED_STRING', 'DOUBLE_QUOTED_STRING',
  240. 'TRIPPLE_QUOTES', 'TRIPPLE_TEXT', 'TRIPPLE_QUOTES_END', 'NAKED_STRING',
  241. 'OTHER', 'NEWLINE', 'COMMENTSTART', 'error',
  242. 'start', 'global_vars', 'sections', 'var_list',
  243. 'section', 'newline', 'var', 'value',
  244. );
  245. /**
  246. * lexer object
  247. *
  248. * @var Smarty_Internal_Configfilelexer
  249. */
  250. private $lex;
  251. /**
  252. * internal error flag
  253. *
  254. * @var bool
  255. */
  256. private $internalError = false;
  257. /**
  258. * copy of config_overwrite property
  259. *
  260. * @var bool
  261. */
  262. private $configOverwrite = false;
  263. /**
  264. * copy of config_read_hidden property
  265. *
  266. * @var bool
  267. */
  268. private $configReadHidden = false;
  269. private $_retvalue;
  270. /**
  271. * constructor
  272. *
  273. * @param Smarty_Internal_Configfilelexer $lex
  274. * @param Smarty_Internal_Config_File_Compiler $compiler
  275. */
  276. public function __construct(Smarty_Internal_Configfilelexer $lex, Smarty_Internal_Config_File_Compiler $compiler)
  277. {
  278. $this->lex = $lex;
  279. $this->smarty = $compiler->smarty;
  280. $this->compiler = $compiler;
  281. $this->configOverwrite = $this->smarty->config_overwrite;
  282. $this->configReadHidden = $this->smarty->config_read_hidden;
  283. }
  284. public static function yy_destructor($yymajor, $yypminor)
  285. {
  286. switch ($yymajor) {
  287. default:
  288. break; /* If no destructor action specified: do nothing */
  289. }
  290. }
  291. /**
  292. * parse single quoted string
  293. * remove outer quotes
  294. * unescape inner quotes
  295. *
  296. * @param string $qstr
  297. *
  298. * @return string
  299. */
  300. private static function parse_single_quoted_string($qstr)
  301. {
  302. $escaped_string = substr($qstr, 1, strlen($qstr) - 2); //remove outer quotes
  303. $ss = preg_split('/(\\\\.)/', $escaped_string, -1, PREG_SPLIT_DELIM_CAPTURE);
  304. $str = '';
  305. foreach ($ss as $s) {
  306. if (strlen($s) === 2 && $s[ 0 ] === '\\') {
  307. if (isset(self::$escapes_single[ $s[ 1 ] ])) {
  308. $s = self::$escapes_single[ $s[ 1 ] ];
  309. }
  310. }
  311. $str .= $s;
  312. }
  313. return $str;
  314. } /* Index of top element in stack */
  315. /**
  316. * parse double quoted string
  317. *
  318. * @param string $qstr
  319. *
  320. * @return string
  321. */
  322. private static function parse_double_quoted_string($qstr)
  323. {
  324. $inner_str = substr($qstr, 1, strlen($qstr) - 2);
  325. return stripcslashes($inner_str);
  326. } /* Shifts left before out of the error */
  327. /**
  328. * parse triple quoted string
  329. *
  330. * @param string $qstr
  331. *
  332. * @return string
  333. */
  334. private static function parse_tripple_double_quoted_string($qstr)
  335. {
  336. return stripcslashes($qstr);
  337. } /* The parser's stack */
  338. public function Trace($TraceFILE, $zTracePrompt)
  339. {
  340. if (!$TraceFILE) {
  341. $zTracePrompt = 0;
  342. } elseif (!$zTracePrompt) {
  343. $TraceFILE = 0;
  344. }
  345. $this->yyTraceFILE = $TraceFILE;
  346. $this->yyTracePrompt = $zTracePrompt;
  347. }
  348. public function PrintTrace()
  349. {
  350. $this->yyTraceFILE = fopen('php://output', 'w');
  351. $this->yyTracePrompt = '<br>';
  352. }
  353. public function tokenName($tokenType)
  354. {
  355. if ($tokenType === 0) {
  356. return 'End of Input';
  357. }
  358. if ($tokenType > 0 && $tokenType < count($this->yyTokenName)) {
  359. return $this->yyTokenName[ $tokenType ];
  360. } else {
  361. return 'Unknown';
  362. }
  363. }
  364. public function yy_pop_parser_stack()
  365. {
  366. if (empty($this->yystack)) {
  367. return;
  368. }
  369. $yytos = array_pop($this->yystack);
  370. if ($this->yyTraceFILE && $this->yyidx >= 0) {
  371. fwrite(
  372. $this->yyTraceFILE,
  373. $this->yyTracePrompt . 'Popping ' . $this->yyTokenName[ $yytos->major ] .
  374. "\n"
  375. );
  376. }
  377. $yymajor = $yytos->major;
  378. self::yy_destructor($yymajor, $yytos->minor);
  379. $this->yyidx--;
  380. return $yymajor;
  381. }
  382. public function __destruct()
  383. {
  384. while ($this->yystack !== array()) {
  385. $this->yy_pop_parser_stack();
  386. }
  387. if (is_resource($this->yyTraceFILE)) {
  388. fclose($this->yyTraceFILE);
  389. }
  390. }
  391. public function yy_get_expected_tokens($token)
  392. {
  393. static $res3 = array();
  394. static $res4 = array();
  395. $state = $this->yystack[ $this->yyidx ]->stateno;
  396. $expected = self::$yyExpectedTokens[ $state ];
  397. if (isset($res3[ $state ][ $token ])) {
  398. if ($res3[ $state ][ $token ]) {
  399. return $expected;
  400. }
  401. } else {
  402. if ($res3[ $state ][ $token ] = in_array($token, self::$yyExpectedTokens[ $state ], true)) {
  403. return $expected;
  404. }
  405. }
  406. $stack = $this->yystack;
  407. $yyidx = $this->yyidx;
  408. do {
  409. $yyact = $this->yy_find_shift_action($token);
  410. if ($yyact >= self::YYNSTATE && $yyact < self::YYNSTATE + self::YYNRULE) {
  411. // reduce action
  412. $done = 0;
  413. do {
  414. if ($done++ === 100) {
  415. $this->yyidx = $yyidx;
  416. $this->yystack = $stack;
  417. // too much recursion prevents proper detection
  418. // so give up
  419. return array_unique($expected);
  420. }
  421. $yyruleno = $yyact - self::YYNSTATE;
  422. $this->yyidx -= self::$yyRuleInfo[ $yyruleno ][ 1 ];
  423. $nextstate = $this->yy_find_reduce_action(
  424. $this->yystack[ $this->yyidx ]->stateno,
  425. self::$yyRuleInfo[ $yyruleno ][ 0 ]
  426. );
  427. if (isset(self::$yyExpectedTokens[ $nextstate ])) {
  428. $expected = array_merge($expected, self::$yyExpectedTokens[ $nextstate ]);
  429. if (isset($res4[ $nextstate ][ $token ])) {
  430. if ($res4[ $nextstate ][ $token ]) {
  431. $this->yyidx = $yyidx;
  432. $this->yystack = $stack;
  433. return array_unique($expected);
  434. }
  435. } else {
  436. if ($res4[ $nextstate ][ $token ] =
  437. in_array($token, self::$yyExpectedTokens[ $nextstate ], true)) {
  438. $this->yyidx = $yyidx;
  439. $this->yystack = $stack;
  440. return array_unique($expected);
  441. }
  442. }
  443. }
  444. if ($nextstate < self::YYNSTATE) {
  445. // we need to shift a non-terminal
  446. $this->yyidx++;
  447. $x = new TPC_yyStackEntry;
  448. $x->stateno = $nextstate;
  449. $x->major = self::$yyRuleInfo[ $yyruleno ][ 0 ];
  450. $this->yystack[ $this->yyidx ] = $x;
  451. continue 2;
  452. } elseif ($nextstate === self::YYNSTATE + self::YYNRULE + 1) {
  453. $this->yyidx = $yyidx;
  454. $this->yystack = $stack;
  455. // the last token was just ignored, we can't accept
  456. // by ignoring input, this is in essence ignoring a
  457. // syntax error!
  458. return array_unique($expected);
  459. } elseif ($nextstate === self::YY_NO_ACTION) {
  460. $this->yyidx = $yyidx;
  461. $this->yystack = $stack;
  462. // input accepted, but not shifted (I guess)
  463. return $expected;
  464. } else {
  465. $yyact = $nextstate;
  466. }
  467. } while (true);
  468. }
  469. break;
  470. } while (true);
  471. $this->yyidx = $yyidx;
  472. $this->yystack = $stack;
  473. return array_unique($expected);
  474. }
  475. public function yy_is_expected_token($token)
  476. {
  477. static $res = array();
  478. static $res2 = array();
  479. if ($token === 0) {
  480. return true; // 0 is not part of this
  481. }
  482. $state = $this->yystack[ $this->yyidx ]->stateno;
  483. if (isset($res[ $state ][ $token ])) {
  484. if ($res[ $state ][ $token ]) {
  485. return true;
  486. }
  487. } else {
  488. if ($res[ $state ][ $token ] = in_array($token, self::$yyExpectedTokens[ $state ], true)) {
  489. return true;
  490. }
  491. }
  492. $stack = $this->yystack;
  493. $yyidx = $this->yyidx;
  494. do {
  495. $yyact = $this->yy_find_shift_action($token);
  496. if ($yyact >= self::YYNSTATE && $yyact < self::YYNSTATE + self::YYNRULE) {
  497. // reduce action
  498. $done = 0;
  499. do {
  500. if ($done++ === 100) {
  501. $this->yyidx = $yyidx;
  502. $this->yystack = $stack;
  503. // too much recursion prevents proper detection
  504. // so give up
  505. return true;
  506. }
  507. $yyruleno = $yyact - self::YYNSTATE;
  508. $this->yyidx -= self::$yyRuleInfo[ $yyruleno ][ 1 ];
  509. $nextstate = $this->yy_find_reduce_action(
  510. $this->yystack[ $this->yyidx ]->stateno,
  511. self::$yyRuleInfo[ $yyruleno ][ 0 ]
  512. );
  513. if (isset($res2[ $nextstate ][ $token ])) {
  514. if ($res2[ $nextstate ][ $token ]) {
  515. $this->yyidx = $yyidx;
  516. $this->yystack = $stack;
  517. return true;
  518. }
  519. } else {
  520. if ($res2[ $nextstate ][ $token ] =
  521. (isset(self::$yyExpectedTokens[ $nextstate ]) &&
  522. in_array($token, self::$yyExpectedTokens[ $nextstate ], true))) {
  523. $this->yyidx = $yyidx;
  524. $this->yystack = $stack;
  525. return true;
  526. }
  527. }
  528. if ($nextstate < self::YYNSTATE) {
  529. // we need to shift a non-terminal
  530. $this->yyidx++;
  531. $x = new TPC_yyStackEntry;
  532. $x->stateno = $nextstate;
  533. $x->major = self::$yyRuleInfo[ $yyruleno ][ 0 ];
  534. $this->yystack[ $this->yyidx ] = $x;
  535. continue 2;
  536. } elseif ($nextstate === self::YYNSTATE + self::YYNRULE + 1) {
  537. $this->yyidx = $yyidx;
  538. $this->yystack = $stack;
  539. if (!$token) {
  540. // end of input: this is valid
  541. return true;
  542. }
  543. // the last token was just ignored, we can't accept
  544. // by ignoring input, this is in essence ignoring a
  545. // syntax error!
  546. return false;
  547. } elseif ($nextstate === self::YY_NO_ACTION) {
  548. $this->yyidx = $yyidx;
  549. $this->yystack = $stack;
  550. // input accepted, but not shifted (I guess)
  551. return true;
  552. } else {
  553. $yyact = $nextstate;
  554. }
  555. } while (true);
  556. }
  557. break;
  558. } while (true);
  559. $this->yyidx = $yyidx;
  560. $this->yystack = $stack;
  561. return true;
  562. }
  563. public function yy_find_shift_action($iLookAhead)
  564. {
  565. $stateno = $this->yystack[ $this->yyidx ]->stateno;
  566. /* if ($this->yyidx < 0) return self::YY_NO_ACTION; */
  567. if (!isset(self::$yy_shift_ofst[ $stateno ])) {
  568. // no shift actions
  569. return self::$yy_default[ $stateno ];
  570. }
  571. $i = self::$yy_shift_ofst[ $stateno ];
  572. if ($i === self::YY_SHIFT_USE_DFLT) {
  573. return self::$yy_default[ $stateno ];
  574. }
  575. if ($iLookAhead === self::YYNOCODE) {
  576. return self::YY_NO_ACTION;
  577. }
  578. $i += $iLookAhead;
  579. if ($i < 0 || $i >= self::YY_SZ_ACTTAB ||
  580. self::$yy_lookahead[ $i ] != $iLookAhead) {
  581. if (count(self::$yyFallback) && $iLookAhead < count(self::$yyFallback)
  582. && ($iFallback = self::$yyFallback[ $iLookAhead ]) != 0) {
  583. if ($this->yyTraceFILE) {
  584. fwrite($this->yyTraceFILE, $this->yyTracePrompt . 'FALLBACK ' .
  585. $this->yyTokenName[ $iLookAhead ] . ' => ' .
  586. $this->yyTokenName[ $iFallback ] . "\n");
  587. }
  588. return $this->yy_find_shift_action($iFallback);
  589. }
  590. return self::$yy_default[ $stateno ];
  591. } else {
  592. return self::$yy_action[ $i ];
  593. }
  594. }
  595. public function yy_find_reduce_action($stateno, $iLookAhead)
  596. {
  597. /* $stateno = $this->yystack[$this->yyidx]->stateno; */
  598. if (!isset(self::$yy_reduce_ofst[ $stateno ])) {
  599. return self::$yy_default[ $stateno ];
  600. }
  601. $i = self::$yy_reduce_ofst[ $stateno ];
  602. if ($i === self::YY_REDUCE_USE_DFLT) {
  603. return self::$yy_default[ $stateno ];
  604. }
  605. if ($iLookAhead === self::YYNOCODE) {
  606. return self::YY_NO_ACTION;
  607. }
  608. $i += $iLookAhead;
  609. if ($i < 0 || $i >= self::YY_SZ_ACTTAB ||
  610. self::$yy_lookahead[ $i ] != $iLookAhead) {
  611. return self::$yy_default[ $stateno ];
  612. } else {
  613. return self::$yy_action[ $i ];
  614. }
  615. }
  616. public function yy_shift($yyNewState, $yyMajor, $yypMinor)
  617. {
  618. $this->yyidx++;
  619. if ($this->yyidx >= self::YYSTACKDEPTH) {
  620. $this->yyidx--;
  621. if ($this->yyTraceFILE) {
  622. fprintf($this->yyTraceFILE, "%sStack Overflow!\n", $this->yyTracePrompt);
  623. }
  624. while ($this->yyidx >= 0) {
  625. $this->yy_pop_parser_stack();
  626. }
  627. // line 239 "../smarty/lexer/smarty_internal_configfileparser.y"
  628. $this->internalError = true;
  629. $this->compiler->trigger_config_file_error('Stack overflow in configfile parser');
  630. return;
  631. }
  632. $yytos = new TPC_yyStackEntry;
  633. $yytos->stateno = $yyNewState;
  634. $yytos->major = $yyMajor;
  635. $yytos->minor = $yypMinor;
  636. $this->yystack[] = $yytos;
  637. if ($this->yyTraceFILE && $this->yyidx > 0) {
  638. fprintf(
  639. $this->yyTraceFILE,
  640. "%sShift %d\n",
  641. $this->yyTracePrompt,
  642. $yyNewState
  643. );
  644. fprintf($this->yyTraceFILE, "%sStack:", $this->yyTracePrompt);
  645. for ($i = 1; $i <= $this->yyidx; $i++) {
  646. fprintf(
  647. $this->yyTraceFILE,
  648. " %s",
  649. $this->yyTokenName[ $this->yystack[ $i ]->major ]
  650. );
  651. }
  652. fwrite($this->yyTraceFILE, "\n");
  653. }
  654. }
  655. public function yy_r0()
  656. {
  657. $this->_retvalue = null;
  658. }
  659. public function yy_r1()
  660. {
  661. $this->add_global_vars($this->yystack[ $this->yyidx + 0 ]->minor);
  662. $this->_retvalue = null;
  663. }
  664. public function yy_r4()
  665. {
  666. $this->add_section_vars($this->yystack[ $this->yyidx + -3 ]->minor, $this->yystack[ $this->yyidx + 0 ]->minor);
  667. $this->_retvalue = null;
  668. }
  669. // line 245 "../smarty/lexer/smarty_internal_configfileparser.y"
  670. public function yy_r5()
  671. {
  672. if ($this->configReadHidden) {
  673. $this->add_section_vars(
  674. $this->yystack[ $this->yyidx + -3 ]->minor,
  675. $this->yystack[ $this->yyidx + 0 ]->minor
  676. );
  677. }
  678. $this->_retvalue = null;
  679. }
  680. // line 250 "../smarty/lexer/smarty_internal_configfileparser.y"
  681. public function yy_r6()
  682. {
  683. $this->_retvalue = $this->yystack[ $this->yyidx + -1 ]->minor;
  684. }
  685. // line 264 "../smarty/lexer/smarty_internal_configfileparser.y"
  686. public function yy_r7()
  687. {
  688. $this->_retvalue =
  689. array_merge($this->yystack[ $this->yyidx + -1 ]->minor, array($this->yystack[ $this->yyidx + 0 ]->minor));
  690. }
  691. // line 269 "../smarty/lexer/smarty_internal_configfileparser.y"
  692. public function yy_r8()
  693. {
  694. $this->_retvalue = array();
  695. }
  696. // line 277 "../smarty/lexer/smarty_internal_configfileparser.y"
  697. public function yy_r9()
  698. {
  699. $this->_retvalue =
  700. array(
  701. 'key' => $this->yystack[ $this->yyidx + -2 ]->minor,
  702. 'value' => $this->yystack[ $this->yyidx + 0 ]->minor
  703. );
  704. }
  705. // line 281 "../smarty/lexer/smarty_internal_configfileparser.y"
  706. public function yy_r10()
  707. {
  708. $this->_retvalue = (float)$this->yystack[ $this->yyidx + 0 ]->minor;
  709. }
  710. // line 285 "../smarty/lexer/smarty_internal_configfileparser.y"
  711. public function yy_r11()
  712. {
  713. $this->_retvalue = (int)$this->yystack[ $this->yyidx + 0 ]->minor;
  714. }
  715. // line 291 "../smarty/lexer/smarty_internal_configfileparser.y"
  716. public function yy_r12()
  717. {
  718. $this->_retvalue = $this->parse_bool($this->yystack[ $this->yyidx + 0 ]->minor);
  719. }
  720. // line 296 "../smarty/lexer/smarty_internal_configfileparser.y"
  721. public function yy_r13()
  722. {
  723. $this->_retvalue = self::parse_single_quoted_string($this->yystack[ $this->yyidx + 0 ]->minor);
  724. }
  725. // line 300 "../smarty/lexer/smarty_internal_configfileparser.y"
  726. public function yy_r14()
  727. {
  728. $this->_retvalue = self::parse_double_quoted_string($this->yystack[ $this->yyidx + 0 ]->minor);
  729. }
  730. // line 304 "../smarty/lexer/smarty_internal_configfileparser.y"
  731. public function yy_r15()
  732. {
  733. $this->_retvalue = self::parse_tripple_double_quoted_string($this->yystack[ $this->yyidx + -1 ]->minor);
  734. }
  735. // line 308 "../smarty/lexer/smarty_internal_configfileparser.y"
  736. public function yy_r16()
  737. {
  738. $this->_retvalue = '';
  739. }
  740. // line 312 "../smarty/lexer/smarty_internal_configfileparser.y"
  741. public function yy_r17()
  742. {
  743. $this->_retvalue = $this->yystack[ $this->yyidx + 0 ]->minor;
  744. }
  745. // line 316 "../smarty/lexer/smarty_internal_configfileparser.y"
  746. public function yy_reduce($yyruleno)
  747. {
  748. if ($this->yyTraceFILE && $yyruleno >= 0
  749. && $yyruleno < count(self::$yyRuleName)) {
  750. fprintf(
  751. $this->yyTraceFILE,
  752. "%sReduce (%d) [%s].\n",
  753. $this->yyTracePrompt,
  754. $yyruleno,
  755. self::$yyRuleName[ $yyruleno ]
  756. );
  757. }
  758. $this->_retvalue = $yy_lefthand_side = null;
  759. if (isset(self::$yyReduceMap[ $yyruleno ])) {
  760. // call the action
  761. $this->_retvalue = null;
  762. $this->{'yy_r' . self::$yyReduceMap[ $yyruleno ]}();
  763. $yy_lefthand_side = $this->_retvalue;
  764. }
  765. $yygoto = self::$yyRuleInfo[ $yyruleno ][ 0 ];
  766. $yysize = self::$yyRuleInfo[ $yyruleno ][ 1 ];
  767. $this->yyidx -= $yysize;
  768. for ($i = $yysize; $i; $i--) {
  769. // pop all of the right-hand side parameters
  770. array_pop($this->yystack);
  771. }
  772. $yyact = $this->yy_find_reduce_action($this->yystack[ $this->yyidx ]->stateno, $yygoto);
  773. if ($yyact < self::YYNSTATE) {
  774. if (!$this->yyTraceFILE && $yysize) {
  775. $this->yyidx++;
  776. $x = new TPC_yyStackEntry;
  777. $x->stateno = $yyact;
  778. $x->major = $yygoto;
  779. $x->minor = $yy_lefthand_side;
  780. $this->yystack[ $this->yyidx ] = $x;
  781. } else {
  782. $this->yy_shift($yyact, $yygoto, $yy_lefthand_side);
  783. }
  784. } elseif ($yyact === self::YYNSTATE + self::YYNRULE + 1) {
  785. $this->yy_accept();
  786. }
  787. }
  788. // line 320 "../smarty/lexer/smarty_internal_configfileparser.y"
  789. public function yy_parse_failed()
  790. {
  791. if ($this->yyTraceFILE) {
  792. fprintf($this->yyTraceFILE, "%sFail!\n", $this->yyTracePrompt);
  793. }
  794. while ($this->yyidx >= 0) {
  795. $this->yy_pop_parser_stack();
  796. }
  797. }
  798. // line 324 "../smarty/lexer/smarty_internal_configfileparser.y"
  799. public function yy_syntax_error($yymajor, $TOKEN)
  800. {
  801. // line 232 "../smarty/lexer/smarty_internal_configfileparser.y"
  802. $this->internalError = true;
  803. $this->yymajor = $yymajor;
  804. $this->compiler->trigger_config_file_error();
  805. }
  806. public function yy_accept()
  807. {
  808. if ($this->yyTraceFILE) {
  809. fprintf($this->yyTraceFILE, "%sAccept!\n", $this->yyTracePrompt);
  810. }
  811. while ($this->yyidx >= 0) {
  812. $this->yy_pop_parser_stack();
  813. }
  814. // line 225 "../smarty/lexer/smarty_internal_configfileparser.y"
  815. $this->successful = !$this->internalError;
  816. $this->internalError = false;
  817. $this->retvalue = $this->_retvalue;
  818. }
  819. public function doParse($yymajor, $yytokenvalue)
  820. {
  821. $yyerrorhit = 0; /* True if yymajor has invoked an error */
  822. if ($this->yyidx === null || $this->yyidx < 0) {
  823. $this->yyidx = 0;
  824. $this->yyerrcnt = -1;
  825. $x = new TPC_yyStackEntry;
  826. $x->stateno = 0;
  827. $x->major = 0;
  828. $this->yystack = array();
  829. $this->yystack[] = $x;
  830. }
  831. $yyendofinput = ($yymajor == 0);
  832. if ($this->yyTraceFILE) {
  833. fprintf(
  834. $this->yyTraceFILE,
  835. "%sInput %s\n",
  836. $this->yyTracePrompt,
  837. $this->yyTokenName[ $yymajor ]
  838. );
  839. }
  840. do {
  841. $yyact = $this->yy_find_shift_action($yymajor);
  842. if ($yymajor < self::YYERRORSYMBOL &&
  843. !$this->yy_is_expected_token($yymajor)) {
  844. // force a syntax error
  845. $yyact = self::YY_ERROR_ACTION;
  846. }
  847. if ($yyact < self::YYNSTATE) {
  848. $this->yy_shift($yyact, $yymajor, $yytokenvalue);
  849. $this->yyerrcnt--;
  850. if ($yyendofinput && $this->yyidx >= 0) {
  851. $yymajor = 0;
  852. } else {
  853. $yymajor = self::YYNOCODE;
  854. }
  855. } elseif ($yyact < self::YYNSTATE + self::YYNRULE) {
  856. $this->yy_reduce($yyact - self::YYNSTATE);
  857. } elseif ($yyact === self::YY_ERROR_ACTION) {
  858. if ($this->yyTraceFILE) {
  859. fprintf(
  860. $this->yyTraceFILE,
  861. "%sSyntax Error!\n",
  862. $this->yyTracePrompt
  863. );
  864. }
  865. if (self::YYERRORSYMBOL) {
  866. if ($this->yyerrcnt < 0) {
  867. $this->yy_syntax_error($yymajor, $yytokenvalue);
  868. }
  869. $yymx = $this->yystack[ $this->yyidx ]->major;
  870. if ($yymx === self::YYERRORSYMBOL || $yyerrorhit) {
  871. if ($this->yyTraceFILE) {
  872. fprintf(
  873. $this->yyTraceFILE,
  874. "%sDiscard input token %s\n",
  875. $this->yyTracePrompt,
  876. $this->yyTokenName[ $yymajor ]
  877. );
  878. }
  879. $this->yy_destructor($yymajor, $yytokenvalue);
  880. $yymajor = self::YYNOCODE;
  881. } else {
  882. while ($this->yyidx >= 0 &&
  883. $yymx !== self::YYERRORSYMBOL &&
  884. ($yyact = $this->yy_find_shift_action(self::YYERRORSYMBOL)) >= self::YYNSTATE
  885. ) {
  886. $this->yy_pop_parser_stack();
  887. }
  888. if ($this->yyidx < 0 || $yymajor == 0) {
  889. $this->yy_destructor($yymajor, $yytokenvalue);
  890. $this->yy_parse_failed();
  891. $yymajor = self::YYNOCODE;
  892. } elseif ($yymx !== self::YYERRORSYMBOL) {
  893. $u2 = 0;
  894. $this->yy_shift($yyact, self::YYERRORSYMBOL, $u2);
  895. }
  896. }
  897. $this->yyerrcnt = 3;
  898. $yyerrorhit = 1;
  899. } else {
  900. if ($this->yyerrcnt <= 0) {
  901. $this->yy_syntax_error($yymajor, $yytokenvalue);
  902. }
  903. $this->yyerrcnt = 3;
  904. $this->yy_destructor($yymajor, $yytokenvalue);
  905. if ($yyendofinput) {
  906. $this->yy_parse_failed();
  907. }
  908. $yymajor = self::YYNOCODE;
  909. }
  910. } else {
  911. $this->yy_accept();
  912. $yymajor = self::YYNOCODE;
  913. }
  914. } while ($yymajor !== self::YYNOCODE && $this->yyidx >= 0);
  915. }
  916. /**
  917. * parse optional boolean keywords
  918. *
  919. * @param string $str
  920. *
  921. * @return bool
  922. */
  923. private function parse_bool($str)
  924. {
  925. $str = strtolower($str);
  926. if (in_array($str, array('on', 'yes', 'true'))) {
  927. $res = true;
  928. } else {
  929. $res = false;
  930. }
  931. return $res;
  932. }
  933. /**
  934. * set a config variable in target array
  935. *
  936. * @param array $var
  937. * @param array $target_array
  938. */
  939. private function set_var(array $var, array &$target_array)
  940. {
  941. $key = $var[ 'key' ];
  942. $value = $var[ 'value' ];
  943. if ($this->configOverwrite || !isset($target_array[ 'vars' ][ $key ])) {
  944. $target_array[ 'vars' ][ $key ] = $value;
  945. } else {
  946. settype($target_array[ 'vars' ][ $key ], 'array');
  947. $target_array[ 'vars' ][ $key ][] = $value;
  948. }
  949. }
  950. /**
  951. * add config variable to global vars
  952. *
  953. * @param array $vars
  954. */
  955. private function add_global_vars(array $vars)
  956. {
  957. if (!isset($this->compiler->config_data[ 'vars' ])) {
  958. $this->compiler->config_data[ 'vars' ] = array();
  959. }
  960. foreach ($vars as $var) {
  961. $this->set_var($var, $this->compiler->config_data);
  962. }
  963. }
  964. /**
  965. * add config variable to section
  966. *
  967. * @param string $section_name
  968. * @param array $vars
  969. */
  970. private function add_section_vars($section_name, array $vars)
  971. {
  972. if (!isset($this->compiler->config_data[ 'sections' ][ $section_name ][ 'vars' ])) {
  973. $this->compiler->config_data[ 'sections' ][ $section_name ][ 'vars' ] = array();
  974. }
  975. foreach ($vars as $var) {
  976. $this->set_var($var, $this->compiler->config_data[ 'sections' ][ $section_name ]);
  977. }
  978. }
  979. }