PageRenderTime 395ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/view/SSTemplateParser.php

https://github.com/Novusvetus/sapphire
PHP | 3951 lines | 3582 code | 201 blank | 168 comment | 618 complexity | e85fd4c3b23fac26549bbffc974166fe MD5 | raw file
Possible License(s): MIT, BSD-3-Clause, CC-BY-3.0, GPL-2.0, LGPL-2.1
  1. <?php
  2. /*
  3. WARNING: This file has been machine generated. Do not edit it, or your changes will be overwritten next time it is compiled.
  4. */
  5. // We want this to work when run by hand too
  6. if (defined(THIRDPARTY_PATH)) {
  7. require THIRDPARTY_PATH . '/php-peg/Parser.php' ;
  8. }
  9. else {
  10. $base = dirname(__FILE__);
  11. require $base.'/../thirdparty/php-peg/Parser.php';
  12. }
  13. /**
  14. This is the exception raised when failing to parse a template. Note that we don't currently do any static analysis, so we can't know
  15. if the template will run, just if it's malformed. It also won't catch mistakes that still look valid.
  16. */
  17. class SSTemplateParseException extends Exception {
  18. function __construct($message, $parser) {
  19. $prior = substr($parser->string, 0, $parser->pos);
  20. preg_match_all('/\r\n|\r|\n/', $prior, $matches);
  21. $line = count($matches[0])+1;
  22. parent::__construct("Parse error in template on line $line. Error was: $message");
  23. }
  24. }
  25. /**
  26. This is the parser for the SilverStripe template language. It gets called on a string and uses a php-peg parser to match
  27. that string against the language structure, building up the PHP code to execute that structure as it parses
  28. The $result array that is built up as part of the parsing (see thirdparty/php-peg/README.md for more on how parsers
  29. build results) has one special member, 'php', which contains the php equivalent of that part of the template tree.
  30. Some match rules generate alternate php, or other variations, so check the per-match documentation too.
  31. Terms used:
  32. Marked: A string or lookup in the template that has been explictly marked as such - lookups by prepending with "$"
  33. (like $Foo.Bar), strings by wrapping with single or double quotes ('Foo' or "Foo")
  34. Bare: The opposite of marked. An argument that has to has it's type inferred by usage and 2.4 defaults.
  35. Example of using a bare argument for a loop block: <% loop Foo %>
  36. Block: One of two SS template structures. The special characters "<%" and "%>" are used to wrap the opening and
  37. (required or forbidden depending on which block exactly) closing block marks.
  38. Open Block: An SS template block that doesn't wrap any content or have a closing end tag (in fact, a closing end tag is
  39. forbidden)
  40. Closed Block: An SS template block that wraps content, and requires a counterpart <% end_blockname %> tag
  41. */
  42. class SSTemplateParser extends Parser {
  43. /**
  44. * @var bool - Set true by SSTemplateParser::compileString if the template should include comments intended
  45. * for debugging (template source, included files, etc)
  46. */
  47. protected $includeDebuggingComments = false;
  48. /**
  49. * Override the function that constructs the result arrays to also prepare a 'php' item in the array
  50. */
  51. function construct($matchrule, $name, $arguments = null) {
  52. $res = parent::construct($matchrule, $name, $arguments);
  53. if (!isset($res['php'])) $res['php'] = '';
  54. return $res;
  55. }
  56. /* Template: (Comment | If | Require | CacheBlock | UncachedBlock | OldI18NTag | ClosedBlock | OpenBlock | MalformedBlock | Injection | Text)+ */
  57. protected $match_Template_typestack = array('Template');
  58. function match_Template ($stack = array()) {
  59. $matchrule = "Template"; $result = $this->construct($matchrule, $matchrule, null);
  60. $count = 0;
  61. while (true) {
  62. $res_42 = $result;
  63. $pos_42 = $this->pos;
  64. $_41 = NULL;
  65. do {
  66. $_39 = NULL;
  67. do {
  68. $res_0 = $result;
  69. $pos_0 = $this->pos;
  70. $matcher = 'match_'.'Comment'; $key = $matcher; $pos = $this->pos;
  71. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  72. if ($subres !== FALSE) {
  73. $this->store( $result, $subres );
  74. $_39 = TRUE; break;
  75. }
  76. $result = $res_0;
  77. $this->pos = $pos_0;
  78. $_37 = NULL;
  79. do {
  80. $res_2 = $result;
  81. $pos_2 = $this->pos;
  82. $matcher = 'match_'.'If'; $key = $matcher; $pos = $this->pos;
  83. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  84. if ($subres !== FALSE) {
  85. $this->store( $result, $subres );
  86. $_37 = TRUE; break;
  87. }
  88. $result = $res_2;
  89. $this->pos = $pos_2;
  90. $_35 = NULL;
  91. do {
  92. $res_4 = $result;
  93. $pos_4 = $this->pos;
  94. $matcher = 'match_'.'Require'; $key = $matcher; $pos = $this->pos;
  95. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  96. if ($subres !== FALSE) {
  97. $this->store( $result, $subres );
  98. $_35 = TRUE; break;
  99. }
  100. $result = $res_4;
  101. $this->pos = $pos_4;
  102. $_33 = NULL;
  103. do {
  104. $res_6 = $result;
  105. $pos_6 = $this->pos;
  106. $matcher = 'match_'.'CacheBlock'; $key = $matcher; $pos = $this->pos;
  107. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  108. if ($subres !== FALSE) {
  109. $this->store( $result, $subres );
  110. $_33 = TRUE; break;
  111. }
  112. $result = $res_6;
  113. $this->pos = $pos_6;
  114. $_31 = NULL;
  115. do {
  116. $res_8 = $result;
  117. $pos_8 = $this->pos;
  118. $matcher = 'match_'.'UncachedBlock'; $key = $matcher; $pos = $this->pos;
  119. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  120. if ($subres !== FALSE) {
  121. $this->store( $result, $subres );
  122. $_31 = TRUE; break;
  123. }
  124. $result = $res_8;
  125. $this->pos = $pos_8;
  126. $_29 = NULL;
  127. do {
  128. $res_10 = $result;
  129. $pos_10 = $this->pos;
  130. $matcher = 'match_'.'OldI18NTag'; $key = $matcher; $pos = $this->pos;
  131. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  132. if ($subres !== FALSE) {
  133. $this->store( $result, $subres );
  134. $_29 = TRUE; break;
  135. }
  136. $result = $res_10;
  137. $this->pos = $pos_10;
  138. $_27 = NULL;
  139. do {
  140. $res_12 = $result;
  141. $pos_12 = $this->pos;
  142. $matcher = 'match_'.'ClosedBlock'; $key = $matcher; $pos = $this->pos;
  143. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  144. if ($subres !== FALSE) {
  145. $this->store( $result, $subres );
  146. $_27 = TRUE; break;
  147. }
  148. $result = $res_12;
  149. $this->pos = $pos_12;
  150. $_25 = NULL;
  151. do {
  152. $res_14 = $result;
  153. $pos_14 = $this->pos;
  154. $matcher = 'match_'.'OpenBlock'; $key = $matcher; $pos = $this->pos;
  155. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  156. if ($subres !== FALSE) {
  157. $this->store( $result, $subres );
  158. $_25 = TRUE; break;
  159. }
  160. $result = $res_14;
  161. $this->pos = $pos_14;
  162. $_23 = NULL;
  163. do {
  164. $res_16 = $result;
  165. $pos_16 = $this->pos;
  166. $matcher = 'match_'.'MalformedBlock'; $key = $matcher; $pos = $this->pos;
  167. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  168. if ($subres !== FALSE) {
  169. $this->store( $result, $subres );
  170. $_23 = TRUE; break;
  171. }
  172. $result = $res_16;
  173. $this->pos = $pos_16;
  174. $_21 = NULL;
  175. do {
  176. $res_18 = $result;
  177. $pos_18 = $this->pos;
  178. $matcher = 'match_'.'Injection'; $key = $matcher; $pos = $this->pos;
  179. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  180. if ($subres !== FALSE) {
  181. $this->store( $result, $subres );
  182. $_21 = TRUE; break;
  183. }
  184. $result = $res_18;
  185. $this->pos = $pos_18;
  186. $matcher = 'match_'.'Text'; $key = $matcher; $pos = $this->pos;
  187. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  188. if ($subres !== FALSE) {
  189. $this->store( $result, $subres );
  190. $_21 = TRUE; break;
  191. }
  192. $result = $res_18;
  193. $this->pos = $pos_18;
  194. $_21 = FALSE; break;
  195. }
  196. while(0);
  197. if( $_21 === TRUE ) { $_23 = TRUE; break; }
  198. $result = $res_16;
  199. $this->pos = $pos_16;
  200. $_23 = FALSE; break;
  201. }
  202. while(0);
  203. if( $_23 === TRUE ) { $_25 = TRUE; break; }
  204. $result = $res_14;
  205. $this->pos = $pos_14;
  206. $_25 = FALSE; break;
  207. }
  208. while(0);
  209. if( $_25 === TRUE ) { $_27 = TRUE; break; }
  210. $result = $res_12;
  211. $this->pos = $pos_12;
  212. $_27 = FALSE; break;
  213. }
  214. while(0);
  215. if( $_27 === TRUE ) { $_29 = TRUE; break; }
  216. $result = $res_10;
  217. $this->pos = $pos_10;
  218. $_29 = FALSE; break;
  219. }
  220. while(0);
  221. if( $_29 === TRUE ) { $_31 = TRUE; break; }
  222. $result = $res_8;
  223. $this->pos = $pos_8;
  224. $_31 = FALSE; break;
  225. }
  226. while(0);
  227. if( $_31 === TRUE ) { $_33 = TRUE; break; }
  228. $result = $res_6;
  229. $this->pos = $pos_6;
  230. $_33 = FALSE; break;
  231. }
  232. while(0);
  233. if( $_33 === TRUE ) { $_35 = TRUE; break; }
  234. $result = $res_4;
  235. $this->pos = $pos_4;
  236. $_35 = FALSE; break;
  237. }
  238. while(0);
  239. if( $_35 === TRUE ) { $_37 = TRUE; break; }
  240. $result = $res_2;
  241. $this->pos = $pos_2;
  242. $_37 = FALSE; break;
  243. }
  244. while(0);
  245. if( $_37 === TRUE ) { $_39 = TRUE; break; }
  246. $result = $res_0;
  247. $this->pos = $pos_0;
  248. $_39 = FALSE; break;
  249. }
  250. while(0);
  251. if( $_39 === FALSE) { $_41 = FALSE; break; }
  252. $_41 = TRUE; break;
  253. }
  254. while(0);
  255. if( $_41 === FALSE) {
  256. $result = $res_42;
  257. $this->pos = $pos_42;
  258. unset( $res_42 );
  259. unset( $pos_42 );
  260. break;
  261. }
  262. $count += 1;
  263. }
  264. if ($count > 0) { return $this->finalise($result); }
  265. else { return FALSE; }
  266. }
  267. function Template_STR(&$res, $sub) {
  268. $res['php'] .= $sub['php'] . PHP_EOL ;
  269. }
  270. /* Word: / [A-Za-z_] [A-Za-z0-9_]* / */
  271. protected $match_Word_typestack = array('Word');
  272. function match_Word ($stack = array()) {
  273. $matchrule = "Word"; $result = $this->construct($matchrule, $matchrule, null);
  274. if (( $subres = $this->rx( '/ [A-Za-z_] [A-Za-z0-9_]* /' ) ) !== FALSE) {
  275. $result["text"] .= $subres;
  276. return $this->finalise($result);
  277. }
  278. else { return FALSE; }
  279. }
  280. /* Number: / [0-9]+ / */
  281. protected $match_Number_typestack = array('Number');
  282. function match_Number ($stack = array()) {
  283. $matchrule = "Number"; $result = $this->construct($matchrule, $matchrule, null);
  284. if (( $subres = $this->rx( '/ [0-9]+ /' ) ) !== FALSE) {
  285. $result["text"] .= $subres;
  286. return $this->finalise($result);
  287. }
  288. else { return FALSE; }
  289. }
  290. /* Value: / [A-Za-z0-9_]+ / */
  291. protected $match_Value_typestack = array('Value');
  292. function match_Value ($stack = array()) {
  293. $matchrule = "Value"; $result = $this->construct($matchrule, $matchrule, null);
  294. if (( $subres = $this->rx( '/ [A-Za-z0-9_]+ /' ) ) !== FALSE) {
  295. $result["text"] .= $subres;
  296. return $this->finalise($result);
  297. }
  298. else { return FALSE; }
  299. }
  300. /* CallArguments: :Argument ( < "," < :Argument )* */
  301. protected $match_CallArguments_typestack = array('CallArguments');
  302. function match_CallArguments ($stack = array()) {
  303. $matchrule = "CallArguments"; $result = $this->construct($matchrule, $matchrule, null);
  304. $_53 = NULL;
  305. do {
  306. $matcher = 'match_'.'Argument'; $key = $matcher; $pos = $this->pos;
  307. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  308. if ($subres !== FALSE) {
  309. $this->store( $result, $subres, "Argument" );
  310. }
  311. else { $_53 = FALSE; break; }
  312. while (true) {
  313. $res_52 = $result;
  314. $pos_52 = $this->pos;
  315. $_51 = NULL;
  316. do {
  317. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  318. if (substr($this->string,$this->pos,1) == ',') {
  319. $this->pos += 1;
  320. $result["text"] .= ',';
  321. }
  322. else { $_51 = FALSE; break; }
  323. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  324. $matcher = 'match_'.'Argument'; $key = $matcher; $pos = $this->pos;
  325. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  326. if ($subres !== FALSE) {
  327. $this->store( $result, $subres, "Argument" );
  328. }
  329. else { $_51 = FALSE; break; }
  330. $_51 = TRUE; break;
  331. }
  332. while(0);
  333. if( $_51 === FALSE) {
  334. $result = $res_52;
  335. $this->pos = $pos_52;
  336. unset( $res_52 );
  337. unset( $pos_52 );
  338. break;
  339. }
  340. }
  341. $_53 = TRUE; break;
  342. }
  343. while(0);
  344. if( $_53 === TRUE ) { return $this->finalise($result); }
  345. if( $_53 === FALSE) { return FALSE; }
  346. }
  347. /**
  348. * Values are bare words in templates, but strings in PHP. We rely on PHP's type conversion to back-convert strings
  349. * to numbers when needed.
  350. */
  351. function CallArguments_Argument(&$res, $sub) {
  352. if (!empty($res['php'])) $res['php'] .= ', ';
  353. $res['php'] .= ($sub['ArgumentMode'] == 'default') ? $sub['string_php'] : str_replace('$$FINAL', 'XML_val', $sub['php']);
  354. }
  355. /* Call: Method:Word ( "(" < :CallArguments? > ")" )? */
  356. protected $match_Call_typestack = array('Call');
  357. function match_Call ($stack = array()) {
  358. $matchrule = "Call"; $result = $this->construct($matchrule, $matchrule, null);
  359. $_63 = NULL;
  360. do {
  361. $matcher = 'match_'.'Word'; $key = $matcher; $pos = $this->pos;
  362. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  363. if ($subres !== FALSE) {
  364. $this->store( $result, $subres, "Method" );
  365. }
  366. else { $_63 = FALSE; break; }
  367. $res_62 = $result;
  368. $pos_62 = $this->pos;
  369. $_61 = NULL;
  370. do {
  371. if (substr($this->string,$this->pos,1) == '(') {
  372. $this->pos += 1;
  373. $result["text"] .= '(';
  374. }
  375. else { $_61 = FALSE; break; }
  376. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  377. $res_58 = $result;
  378. $pos_58 = $this->pos;
  379. $matcher = 'match_'.'CallArguments'; $key = $matcher; $pos = $this->pos;
  380. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  381. if ($subres !== FALSE) {
  382. $this->store( $result, $subres, "CallArguments" );
  383. }
  384. else {
  385. $result = $res_58;
  386. $this->pos = $pos_58;
  387. unset( $res_58 );
  388. unset( $pos_58 );
  389. }
  390. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  391. if (substr($this->string,$this->pos,1) == ')') {
  392. $this->pos += 1;
  393. $result["text"] .= ')';
  394. }
  395. else { $_61 = FALSE; break; }
  396. $_61 = TRUE; break;
  397. }
  398. while(0);
  399. if( $_61 === FALSE) {
  400. $result = $res_62;
  401. $this->pos = $pos_62;
  402. unset( $res_62 );
  403. unset( $pos_62 );
  404. }
  405. $_63 = TRUE; break;
  406. }
  407. while(0);
  408. if( $_63 === TRUE ) { return $this->finalise($result); }
  409. if( $_63 === FALSE) { return FALSE; }
  410. }
  411. /* LookupStep: :Call &"." */
  412. protected $match_LookupStep_typestack = array('LookupStep');
  413. function match_LookupStep ($stack = array()) {
  414. $matchrule = "LookupStep"; $result = $this->construct($matchrule, $matchrule, null);
  415. $_67 = NULL;
  416. do {
  417. $matcher = 'match_'.'Call'; $key = $matcher; $pos = $this->pos;
  418. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  419. if ($subres !== FALSE) {
  420. $this->store( $result, $subres, "Call" );
  421. }
  422. else { $_67 = FALSE; break; }
  423. $res_66 = $result;
  424. $pos_66 = $this->pos;
  425. if (substr($this->string,$this->pos,1) == '.') {
  426. $this->pos += 1;
  427. $result["text"] .= '.';
  428. $result = $res_66;
  429. $this->pos = $pos_66;
  430. }
  431. else {
  432. $result = $res_66;
  433. $this->pos = $pos_66;
  434. $_67 = FALSE; break;
  435. }
  436. $_67 = TRUE; break;
  437. }
  438. while(0);
  439. if( $_67 === TRUE ) { return $this->finalise($result); }
  440. if( $_67 === FALSE) { return FALSE; }
  441. }
  442. /* LastLookupStep: :Call */
  443. protected $match_LastLookupStep_typestack = array('LastLookupStep');
  444. function match_LastLookupStep ($stack = array()) {
  445. $matchrule = "LastLookupStep"; $result = $this->construct($matchrule, $matchrule, null);
  446. $matcher = 'match_'.'Call'; $key = $matcher; $pos = $this->pos;
  447. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  448. if ($subres !== FALSE) {
  449. $this->store( $result, $subres, "Call" );
  450. return $this->finalise($result);
  451. }
  452. else { return FALSE; }
  453. }
  454. /* Lookup: LookupStep ("." LookupStep)* "." LastLookupStep | LastLookupStep */
  455. protected $match_Lookup_typestack = array('Lookup');
  456. function match_Lookup ($stack = array()) {
  457. $matchrule = "Lookup"; $result = $this->construct($matchrule, $matchrule, null);
  458. $_81 = NULL;
  459. do {
  460. $res_70 = $result;
  461. $pos_70 = $this->pos;
  462. $_78 = NULL;
  463. do {
  464. $matcher = 'match_'.'LookupStep'; $key = $matcher; $pos = $this->pos;
  465. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  466. if ($subres !== FALSE) { $this->store( $result, $subres ); }
  467. else { $_78 = FALSE; break; }
  468. while (true) {
  469. $res_75 = $result;
  470. $pos_75 = $this->pos;
  471. $_74 = NULL;
  472. do {
  473. if (substr($this->string,$this->pos,1) == '.') {
  474. $this->pos += 1;
  475. $result["text"] .= '.';
  476. }
  477. else { $_74 = FALSE; break; }
  478. $matcher = 'match_'.'LookupStep'; $key = $matcher; $pos = $this->pos;
  479. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  480. if ($subres !== FALSE) {
  481. $this->store( $result, $subres );
  482. }
  483. else { $_74 = FALSE; break; }
  484. $_74 = TRUE; break;
  485. }
  486. while(0);
  487. if( $_74 === FALSE) {
  488. $result = $res_75;
  489. $this->pos = $pos_75;
  490. unset( $res_75 );
  491. unset( $pos_75 );
  492. break;
  493. }
  494. }
  495. if (substr($this->string,$this->pos,1) == '.') {
  496. $this->pos += 1;
  497. $result["text"] .= '.';
  498. }
  499. else { $_78 = FALSE; break; }
  500. $matcher = 'match_'.'LastLookupStep'; $key = $matcher; $pos = $this->pos;
  501. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  502. if ($subres !== FALSE) { $this->store( $result, $subres ); }
  503. else { $_78 = FALSE; break; }
  504. $_78 = TRUE; break;
  505. }
  506. while(0);
  507. if( $_78 === TRUE ) { $_81 = TRUE; break; }
  508. $result = $res_70;
  509. $this->pos = $pos_70;
  510. $matcher = 'match_'.'LastLookupStep'; $key = $matcher; $pos = $this->pos;
  511. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  512. if ($subres !== FALSE) {
  513. $this->store( $result, $subres );
  514. $_81 = TRUE; break;
  515. }
  516. $result = $res_70;
  517. $this->pos = $pos_70;
  518. $_81 = FALSE; break;
  519. }
  520. while(0);
  521. if( $_81 === TRUE ) { return $this->finalise($result); }
  522. if( $_81 === FALSE) { return FALSE; }
  523. }
  524. function Lookup__construct(&$res) {
  525. $res['php'] = '$scope';
  526. $res['LookupSteps'] = array();
  527. }
  528. /**
  529. * The basic generated PHP of LookupStep and LastLookupStep is the same, except that LookupStep calls 'obj' to
  530. * get the next ViewableData in the sequence, and LastLookupStep calls different methods (XML_val, hasValue, obj)
  531. * depending on the context the lookup is used in.
  532. */
  533. function Lookup_AddLookupStep(&$res, $sub, $method) {
  534. $res['LookupSteps'][] = $sub;
  535. $property = $sub['Call']['Method']['text'];
  536. if (isset($sub['Call']['CallArguments']) && $arguments = $sub['Call']['CallArguments']['php']) {
  537. $res['php'] .= "->$method('$property', array($arguments), true)";
  538. }
  539. else {
  540. $res['php'] .= "->$method('$property', null, true)";
  541. }
  542. }
  543. function Lookup_LookupStep(&$res, $sub) {
  544. $this->Lookup_AddLookupStep($res, $sub, 'obj');
  545. }
  546. function Lookup_LastLookupStep(&$res, $sub) {
  547. $this->Lookup_AddLookupStep($res, $sub, '$$FINAL');
  548. }
  549. /* SimpleInjection: '$' :Lookup */
  550. protected $match_SimpleInjection_typestack = array('SimpleInjection');
  551. function match_SimpleInjection ($stack = array()) {
  552. $matchrule = "SimpleInjection"; $result = $this->construct($matchrule, $matchrule, null);
  553. $_85 = NULL;
  554. do {
  555. if (substr($this->string,$this->pos,1) == '$') {
  556. $this->pos += 1;
  557. $result["text"] .= '$';
  558. }
  559. else { $_85 = FALSE; break; }
  560. $matcher = 'match_'.'Lookup'; $key = $matcher; $pos = $this->pos;
  561. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  562. if ($subres !== FALSE) {
  563. $this->store( $result, $subres, "Lookup" );
  564. }
  565. else { $_85 = FALSE; break; }
  566. $_85 = TRUE; break;
  567. }
  568. while(0);
  569. if( $_85 === TRUE ) { return $this->finalise($result); }
  570. if( $_85 === FALSE) { return FALSE; }
  571. }
  572. /* BracketInjection: '{$' :Lookup "}" */
  573. protected $match_BracketInjection_typestack = array('BracketInjection');
  574. function match_BracketInjection ($stack = array()) {
  575. $matchrule = "BracketInjection"; $result = $this->construct($matchrule, $matchrule, null);
  576. $_90 = NULL;
  577. do {
  578. if (( $subres = $this->literal( '{$' ) ) !== FALSE) { $result["text"] .= $subres; }
  579. else { $_90 = FALSE; break; }
  580. $matcher = 'match_'.'Lookup'; $key = $matcher; $pos = $this->pos;
  581. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  582. if ($subres !== FALSE) {
  583. $this->store( $result, $subres, "Lookup" );
  584. }
  585. else { $_90 = FALSE; break; }
  586. if (substr($this->string,$this->pos,1) == '}') {
  587. $this->pos += 1;
  588. $result["text"] .= '}';
  589. }
  590. else { $_90 = FALSE; break; }
  591. $_90 = TRUE; break;
  592. }
  593. while(0);
  594. if( $_90 === TRUE ) { return $this->finalise($result); }
  595. if( $_90 === FALSE) { return FALSE; }
  596. }
  597. /* Injection: BracketInjection | SimpleInjection */
  598. protected $match_Injection_typestack = array('Injection');
  599. function match_Injection ($stack = array()) {
  600. $matchrule = "Injection"; $result = $this->construct($matchrule, $matchrule, null);
  601. $_95 = NULL;
  602. do {
  603. $res_92 = $result;
  604. $pos_92 = $this->pos;
  605. $matcher = 'match_'.'BracketInjection'; $key = $matcher; $pos = $this->pos;
  606. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  607. if ($subres !== FALSE) {
  608. $this->store( $result, $subres );
  609. $_95 = TRUE; break;
  610. }
  611. $result = $res_92;
  612. $this->pos = $pos_92;
  613. $matcher = 'match_'.'SimpleInjection'; $key = $matcher; $pos = $this->pos;
  614. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  615. if ($subres !== FALSE) {
  616. $this->store( $result, $subres );
  617. $_95 = TRUE; break;
  618. }
  619. $result = $res_92;
  620. $this->pos = $pos_92;
  621. $_95 = FALSE; break;
  622. }
  623. while(0);
  624. if( $_95 === TRUE ) { return $this->finalise($result); }
  625. if( $_95 === FALSE) { return FALSE; }
  626. }
  627. function Injection_STR(&$res, $sub) {
  628. $res['php'] = '$val .= '. str_replace('$$FINAL', 'XML_val', $sub['Lookup']['php']) . ';';
  629. }
  630. /* DollarMarkedLookup: SimpleInjection */
  631. protected $match_DollarMarkedLookup_typestack = array('DollarMarkedLookup');
  632. function match_DollarMarkedLookup ($stack = array()) {
  633. $matchrule = "DollarMarkedLookup"; $result = $this->construct($matchrule, $matchrule, null);
  634. $matcher = 'match_'.'SimpleInjection'; $key = $matcher; $pos = $this->pos;
  635. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  636. if ($subres !== FALSE) {
  637. $this->store( $result, $subres );
  638. return $this->finalise($result);
  639. }
  640. else { return FALSE; }
  641. }
  642. function DollarMarkedLookup_STR(&$res, $sub) {
  643. $res['Lookup'] = $sub['Lookup'];
  644. }
  645. /* QuotedString: q:/['"]/ String:/ (\\\\ | \\. | [^$q\\])* / '$q' */
  646. protected $match_QuotedString_typestack = array('QuotedString');
  647. function match_QuotedString ($stack = array()) {
  648. $matchrule = "QuotedString"; $result = $this->construct($matchrule, $matchrule, null);
  649. $_101 = NULL;
  650. do {
  651. $stack[] = $result; $result = $this->construct( $matchrule, "q" );
  652. if (( $subres = $this->rx( '/[\'"]/' ) ) !== FALSE) {
  653. $result["text"] .= $subres;
  654. $subres = $result; $result = array_pop($stack);
  655. $this->store( $result, $subres, 'q' );
  656. }
  657. else {
  658. $result = array_pop($stack);
  659. $_101 = FALSE; break;
  660. }
  661. $stack[] = $result; $result = $this->construct( $matchrule, "String" );
  662. if (( $subres = $this->rx( '/ (\\\\\\\\ | \\\\. | [^'.$this->expression($result, $stack, 'q').'\\\\])* /' ) ) !== FALSE) {
  663. $result["text"] .= $subres;
  664. $subres = $result; $result = array_pop($stack);
  665. $this->store( $result, $subres, 'String' );
  666. }
  667. else {
  668. $result = array_pop($stack);
  669. $_101 = FALSE; break;
  670. }
  671. if (( $subres = $this->literal( ''.$this->expression($result, $stack, 'q').'' ) ) !== FALSE) { $result["text"] .= $subres; }
  672. else { $_101 = FALSE; break; }
  673. $_101 = TRUE; break;
  674. }
  675. while(0);
  676. if( $_101 === TRUE ) { return $this->finalise($result); }
  677. if( $_101 === FALSE) { return FALSE; }
  678. }
  679. /* FreeString: /[^,)%!=|&]+/ */
  680. protected $match_FreeString_typestack = array('FreeString');
  681. function match_FreeString ($stack = array()) {
  682. $matchrule = "FreeString"; $result = $this->construct($matchrule, $matchrule, null);
  683. if (( $subres = $this->rx( '/[^,)%!=|&]+/' ) ) !== FALSE) {
  684. $result["text"] .= $subres;
  685. return $this->finalise($result);
  686. }
  687. else { return FALSE; }
  688. }
  689. /* Argument:
  690. :DollarMarkedLookup |
  691. :QuotedString |
  692. :Lookup !(< FreeString)|
  693. :FreeString */
  694. protected $match_Argument_typestack = array('Argument');
  695. function match_Argument ($stack = array()) {
  696. $matchrule = "Argument"; $result = $this->construct($matchrule, $matchrule, null);
  697. $_121 = NULL;
  698. do {
  699. $res_104 = $result;
  700. $pos_104 = $this->pos;
  701. $matcher = 'match_'.'DollarMarkedLookup'; $key = $matcher; $pos = $this->pos;
  702. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  703. if ($subres !== FALSE) {
  704. $this->store( $result, $subres, "DollarMarkedLookup" );
  705. $_121 = TRUE; break;
  706. }
  707. $result = $res_104;
  708. $this->pos = $pos_104;
  709. $_119 = NULL;
  710. do {
  711. $res_106 = $result;
  712. $pos_106 = $this->pos;
  713. $matcher = 'match_'.'QuotedString'; $key = $matcher; $pos = $this->pos;
  714. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  715. if ($subres !== FALSE) {
  716. $this->store( $result, $subres, "QuotedString" );
  717. $_119 = TRUE; break;
  718. }
  719. $result = $res_106;
  720. $this->pos = $pos_106;
  721. $_117 = NULL;
  722. do {
  723. $res_108 = $result;
  724. $pos_108 = $this->pos;
  725. $_114 = NULL;
  726. do {
  727. $matcher = 'match_'.'Lookup'; $key = $matcher; $pos = $this->pos;
  728. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  729. if ($subres !== FALSE) {
  730. $this->store( $result, $subres, "Lookup" );
  731. }
  732. else { $_114 = FALSE; break; }
  733. $res_113 = $result;
  734. $pos_113 = $this->pos;
  735. $_112 = NULL;
  736. do {
  737. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  738. $matcher = 'match_'.'FreeString'; $key = $matcher; $pos = $this->pos;
  739. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  740. if ($subres !== FALSE) {
  741. $this->store( $result, $subres );
  742. }
  743. else { $_112 = FALSE; break; }
  744. $_112 = TRUE; break;
  745. }
  746. while(0);
  747. if( $_112 === TRUE ) {
  748. $result = $res_113;
  749. $this->pos = $pos_113;
  750. $_114 = FALSE; break;
  751. }
  752. if( $_112 === FALSE) {
  753. $result = $res_113;
  754. $this->pos = $pos_113;
  755. }
  756. $_114 = TRUE; break;
  757. }
  758. while(0);
  759. if( $_114 === TRUE ) { $_117 = TRUE; break; }
  760. $result = $res_108;
  761. $this->pos = $pos_108;
  762. $matcher = 'match_'.'FreeString'; $key = $matcher; $pos = $this->pos;
  763. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  764. if ($subres !== FALSE) {
  765. $this->store( $result, $subres, "FreeString" );
  766. $_117 = TRUE; break;
  767. }
  768. $result = $res_108;
  769. $this->pos = $pos_108;
  770. $_117 = FALSE; break;
  771. }
  772. while(0);
  773. if( $_117 === TRUE ) { $_119 = TRUE; break; }
  774. $result = $res_106;
  775. $this->pos = $pos_106;
  776. $_119 = FALSE; break;
  777. }
  778. while(0);
  779. if( $_119 === TRUE ) { $_121 = TRUE; break; }
  780. $result = $res_104;
  781. $this->pos = $pos_104;
  782. $_121 = FALSE; break;
  783. }
  784. while(0);
  785. if( $_121 === TRUE ) { return $this->finalise($result); }
  786. if( $_121 === FALSE) { return FALSE; }
  787. }
  788. /**
  789. * If we get a bare value, we don't know enough to determine exactly what php would be the translation, because
  790. * we don't know if the position of use indicates a lookup or a string argument.
  791. *
  792. * Instead, we record 'ArgumentMode' as a member of this matches results node, which can be:
  793. * - lookup if this argument was unambiguously a lookup (marked as such)
  794. * - string is this argument was unambiguously a string (marked as such, or impossible to parse as lookup)
  795. * - default if this argument needs to be handled as per 2.4
  796. *
  797. * In the case of 'default', there is no php member of the results node, but instead 'lookup_php', which
  798. * should be used by the parent if the context indicates a lookup, and 'string_php' which should be used
  799. * if the context indicates a string
  800. */
  801. function Argument_DollarMarkedLookup(&$res, $sub) {
  802. $res['ArgumentMode'] = 'lookup';
  803. $res['php'] = $sub['Lookup']['php'];
  804. }
  805. function Argument_QuotedString(&$res, $sub) {
  806. $res['ArgumentMode'] = 'string';
  807. $res['php'] = "'" . str_replace("'", "\\'", $sub['String']['text']) . "'";
  808. }
  809. function Argument_Lookup(&$res, $sub) {
  810. if (count($sub['LookupSteps']) == 1 && !isset($sub['LookupSteps'][0]['Call']['Arguments'])) {
  811. $res['ArgumentMode'] = 'default';
  812. $res['lookup_php'] = $sub['php'];
  813. $res['string_php'] = "'".$sub['LookupSteps'][0]['Call']['Method']['text']."'";
  814. }
  815. else {
  816. $res['ArgumentMode'] = 'lookup';
  817. $res['php'] = $sub['php'];
  818. }
  819. }
  820. function Argument_FreeString(&$res, $sub) {
  821. $res['ArgumentMode'] = 'string';
  822. $res['php'] = "'" . str_replace("'", "\\'", $sub['text']) . "'";
  823. }
  824. /* ComparisonOperator: "==" | "!=" | "=" */
  825. protected $match_ComparisonOperator_typestack = array('ComparisonOperator');
  826. function match_ComparisonOperator ($stack = array()) {
  827. $matchrule = "ComparisonOperator"; $result = $this->construct($matchrule, $matchrule, null);
  828. $_130 = NULL;
  829. do {
  830. $res_123 = $result;
  831. $pos_123 = $this->pos;
  832. if (( $subres = $this->literal( '==' ) ) !== FALSE) {
  833. $result["text"] .= $subres;
  834. $_130 = TRUE; break;
  835. }
  836. $result = $res_123;
  837. $this->pos = $pos_123;
  838. $_128 = NULL;
  839. do {
  840. $res_125 = $result;
  841. $pos_125 = $this->pos;
  842. if (( $subres = $this->literal( '!=' ) ) !== FALSE) {
  843. $result["text"] .= $subres;
  844. $_128 = TRUE; break;
  845. }
  846. $result = $res_125;
  847. $this->pos = $pos_125;
  848. if (substr($this->string,$this->pos,1) == '=') {
  849. $this->pos += 1;
  850. $result["text"] .= '=';
  851. $_128 = TRUE; break;
  852. }
  853. $result = $res_125;
  854. $this->pos = $pos_125;
  855. $_128 = FALSE; break;
  856. }
  857. while(0);
  858. if( $_128 === TRUE ) { $_130 = TRUE; break; }
  859. $result = $res_123;
  860. $this->pos = $pos_123;
  861. $_130 = FALSE; break;
  862. }
  863. while(0);
  864. if( $_130 === TRUE ) { return $this->finalise($result); }
  865. if( $_130 === FALSE) { return FALSE; }
  866. }
  867. /* Comparison: Argument < ComparisonOperator > Argument */
  868. protected $match_Comparison_typestack = array('Comparison');
  869. function match_Comparison ($stack = array()) {
  870. $matchrule = "Comparison"; $result = $this->construct($matchrule, $matchrule, null);
  871. $_137 = NULL;
  872. do {
  873. $matcher = 'match_'.'Argument'; $key = $matcher; $pos = $this->pos;
  874. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  875. if ($subres !== FALSE) { $this->store( $result, $subres ); }
  876. else { $_137 = FALSE; break; }
  877. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  878. $matcher = 'match_'.'ComparisonOperator'; $key = $matcher; $pos = $this->pos;
  879. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  880. if ($subres !== FALSE) { $this->store( $result, $subres ); }
  881. else { $_137 = FALSE; break; }
  882. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  883. $matcher = 'match_'.'Argument'; $key = $matcher; $pos = $this->pos;
  884. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  885. if ($subres !== FALSE) { $this->store( $result, $subres ); }
  886. else { $_137 = FALSE; break; }
  887. $_137 = TRUE; break;
  888. }
  889. while(0);
  890. if( $_137 === TRUE ) { return $this->finalise($result); }
  891. if( $_137 === FALSE) { return FALSE; }
  892. }
  893. function Comparison_Argument(&$res, $sub) {
  894. if ($sub['ArgumentMode'] == 'default') {
  895. if (!empty($res['php'])) $res['php'] .= $sub['string_php'];
  896. else $res['php'] = str_replace('$$FINAL', 'XML_val', $sub['lookup_php']);
  897. }
  898. else {
  899. $res['php'] .= str_replace('$$FINAL', 'XML_val', $sub['php']);
  900. }
  901. }
  902. function Comparison_ComparisonOperator(&$res, $sub) {
  903. $res['php'] .= ($sub['text'] == '=' ? '==' : $sub['text']);
  904. }
  905. /* PresenceCheck: (Not:'not' <)? Argument */
  906. protected $match_PresenceCheck_typestack = array('PresenceCheck');
  907. function match_PresenceCheck ($stack = array()) {
  908. $matchrule = "PresenceCheck"; $result = $this->construct($matchrule, $matchrule, null);
  909. $_144 = NULL;
  910. do {
  911. $res_142 = $result;
  912. $pos_142 = $this->pos;
  913. $_141 = NULL;
  914. do {
  915. $stack[] = $result; $result = $this->construct( $matchrule, "Not" );
  916. if (( $subres = $this->literal( 'not' ) ) !== FALSE) {
  917. $result["text"] .= $subres;
  918. $subres = $result; $result = array_pop($stack);
  919. $this->store( $result, $subres, 'Not' );
  920. }
  921. else {
  922. $result = array_pop($stack);
  923. $_141 = FALSE; break;
  924. }
  925. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  926. $_141 = TRUE; break;
  927. }
  928. while(0);
  929. if( $_141 === FALSE) {
  930. $result = $res_142;
  931. $this->pos = $pos_142;
  932. unset( $res_142 );
  933. unset( $pos_142 );
  934. }
  935. $matcher = 'match_'.'Argument'; $key = $matcher; $pos = $this->pos;
  936. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  937. if ($subres !== FALSE) { $this->store( $result, $subres ); }
  938. else { $_144 = FALSE; break; }
  939. $_144 = TRUE; break;
  940. }
  941. while(0);
  942. if( $_144 === TRUE ) { return $this->finalise($result); }
  943. if( $_144 === FALSE) { return FALSE; }
  944. }
  945. function PresenceCheck_Not(&$res, $sub) {
  946. $res['php'] = '!';
  947. }
  948. function PresenceCheck_Argument(&$res, $sub) {
  949. if ($sub['ArgumentMode'] == 'string') {
  950. $res['php'] .= '((bool)'.$sub['php'].')';
  951. }
  952. else {
  953. $php = ($sub['ArgumentMode'] == 'default' ? $sub['lookup_php'] : $sub['php']);
  954. // TODO: kinda hacky - maybe we need a way to pass state down the parse chain so
  955. // Lookup_LastLookupStep and Argument_BareWord can produce hasValue instead of XML_val
  956. $res['php'] .= str_replace('$$FINAL', 'hasValue', $php);
  957. }
  958. }
  959. /* IfArgumentPortion: Comparison | PresenceCheck */
  960. protected $match_IfArgumentPortion_typestack = array('IfArgumentPortion');
  961. function match_IfArgumentPortion ($stack = array()) {
  962. $matchrule = "IfArgumentPortion"; $result = $this->construct($matchrule, $matchrule, null);
  963. $_149 = NULL;
  964. do {
  965. $res_146 = $result;
  966. $pos_146 = $this->pos;
  967. $matcher = 'match_'.'Comparison'; $key = $matcher; $pos = $this->pos;
  968. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  969. if ($subres !== FALSE) {
  970. $this->store( $result, $subres );
  971. $_149 = TRUE; break;
  972. }
  973. $result = $res_146;
  974. $this->pos = $pos_146;
  975. $matcher = 'match_'.'PresenceCheck'; $key = $matcher; $pos = $this->pos;
  976. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  977. if ($subres !== FALSE) {
  978. $this->store( $result, $subres );
  979. $_149 = TRUE; break;
  980. }
  981. $result = $res_146;
  982. $this->pos = $pos_146;
  983. $_149 = FALSE; break;
  984. }
  985. while(0);
  986. if( $_149 === TRUE ) { return $this->finalise($result); }
  987. if( $_149 === FALSE) { return FALSE; }
  988. }
  989. function IfArgumentPortion_STR(&$res, $sub) {
  990. $res['php'] = $sub['php'];
  991. }
  992. /* BooleanOperator: "||" | "&&" */
  993. protected $match_BooleanOperator_typestack = array('BooleanOperator');
  994. function match_BooleanOperator ($stack = array()) {
  995. $matchrule = "BooleanOperator"; $result = $this->construct($matchrule, $matchrule, null);
  996. $_154 = NULL;
  997. do {
  998. $res_151 = $result;
  999. $pos_151 = $this->pos;
  1000. if (( $subres = $this->literal( '||' ) ) !== FALSE) {
  1001. $result["text"] .= $subres;
  1002. $_154 = TRUE; break;
  1003. }
  1004. $result = $res_151;
  1005. $this->pos = $pos_151;
  1006. if (( $subres = $this->literal( '&&' ) ) !== FALSE) {
  1007. $result["text"] .= $subres;
  1008. $_154 = TRUE; break;
  1009. }
  1010. $result = $res_151;
  1011. $this->pos = $pos_151;
  1012. $_154 = FALSE; break;
  1013. }
  1014. while(0);
  1015. if( $_154 === TRUE ) { return $this->finalise($result); }
  1016. if( $_154 === FALSE) { return FALSE; }
  1017. }
  1018. /* IfArgument: :IfArgumentPortion ( < :BooleanOperator < :IfArgumentPortion )* */
  1019. protected $match_IfArgument_typestack = array('IfArgument');
  1020. function match_IfArgument ($stack = array()) {
  1021. $matchrule = "IfArgument"; $result = $this->construct($matchrule, $matchrule, null);
  1022. $_163 = NULL;
  1023. do {
  1024. $matcher = 'match_'.'IfArgumentPortion'; $key = $matcher; $pos = $this->pos;
  1025. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1026. if ($subres !== FALSE) {
  1027. $this->store( $result, $subres, "IfArgumentPortion" );
  1028. }
  1029. else { $_163 = FALSE; break; }
  1030. while (true) {
  1031. $res_162 = $result;
  1032. $pos_162 = $this->pos;
  1033. $_161 = NULL;
  1034. do {
  1035. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  1036. $matcher = 'match_'.'BooleanOperator'; $key = $matcher; $pos = $this->pos;
  1037. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1038. if ($subres !== FALSE) {
  1039. $this->store( $result, $subres, "BooleanOperator" );
  1040. }
  1041. else { $_161 = FALSE; break; }
  1042. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  1043. $matcher = 'match_'.'IfArgumentPortion'; $key = $matcher; $pos = $this->pos;
  1044. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1045. if ($subres !== FALSE) {
  1046. $this->store( $result, $subres, "IfArgumentPortion" );
  1047. }
  1048. else { $_161 = FALSE; break; }
  1049. $_161 = TRUE; break;
  1050. }
  1051. while(0);
  1052. if( $_161 === FALSE) {
  1053. $result = $res_162;
  1054. $this->pos = $pos_162;
  1055. unset( $res_162 );
  1056. unset( $pos_162 );
  1057. break;
  1058. }
  1059. }
  1060. $_163 = TRUE; break;
  1061. }
  1062. while(0);
  1063. if( $_163 === TRUE ) { return $this->finalise($result); }
  1064. if( $_163 === FALSE) { return FALSE; }
  1065. }
  1066. function IfArgument_IfArgumentPortion(&$res, $sub) {
  1067. $res['php'] .= $sub['php'];
  1068. }
  1069. function IfArgument_BooleanOperator(&$res, $sub) {
  1070. $res['php'] .= $sub['text'];
  1071. }
  1072. /* IfPart: '<%' < 'if' [ :IfArgument > '%>' Template:$TemplateMatcher? */
  1073. protected $match_IfPart_typestack = array('IfPart');
  1074. function match_IfPart ($stack = array()) {
  1075. $matchrule = "IfPart"; $result = $this->construct($matchrule, $matchrule, null);
  1076. $_173 = NULL;
  1077. do {
  1078. if (( $subres = $this->literal( '<%' ) ) !== FALSE) { $result["text"] .= $subres; }
  1079. else { $_173 = FALSE; break; }
  1080. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  1081. if (( $subres = $this->literal( 'if' ) ) !== FALSE) { $result["text"] .= $subres; }
  1082. else { $_173 = FALSE; break; }
  1083. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  1084. else { $_173 = FALSE; break; }
  1085. $matcher = 'match_'.'IfArgument'; $key = $matcher; $pos = $this->pos;
  1086. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1087. if ($subres !== FALSE) {
  1088. $this->store( $result, $subres, "IfArgument" );
  1089. }
  1090. else { $_173 = FALSE; break; }
  1091. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  1092. if (( $subres = $this->literal( '%>' ) ) !== FALSE) { $result["text"] .= $subres; }
  1093. else { $_173 = FALSE; break; }
  1094. $res_172 = $result;
  1095. $pos_172 = $this->pos;
  1096. $matcher = 'match_'.$this->expression($result, $stack, 'TemplateMatcher'); $key = $matcher; $pos = $this->pos;
  1097. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1098. if ($subres !== FALSE) {
  1099. $this->store( $result, $subres, "Template" );
  1100. }
  1101. else {
  1102. $result = $res_172;
  1103. $this->pos = $pos_172;
  1104. unset( $res_172 );
  1105. unset( $pos_172 );
  1106. }
  1107. $_173 = TRUE; break;
  1108. }
  1109. while(0);
  1110. if( $_173 === TRUE ) { return $this->finalise($result); }
  1111. if( $_173 === FALSE) { return FALSE; }
  1112. }
  1113. /* ElseIfPart: '<%' < 'else_if' [ :IfArgument > '%>' Template:$TemplateMatcher */
  1114. protected $match_ElseIfPart_typestack = array('ElseIfPart');
  1115. function match_ElseIfPart ($stack = array()) {
  1116. $matchrule = "ElseIfPart"; $result = $this->construct($matchrule, $matchrule, null);
  1117. $_183 = NULL;
  1118. do {
  1119. if (( $subres = $this->literal( '<%' ) ) !== FALSE) { $result["text"] .= $subres; }
  1120. else { $_183 = FALSE; break; }
  1121. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  1122. if (( $subres = $this->literal( 'else_if' ) ) !== FALSE) { $result["text"] .= $subres; }
  1123. else { $_183 = FALSE; break; }
  1124. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  1125. else { $_183 = FALSE; break; }
  1126. $matcher = 'match_'.'IfArgument'; $key = $matcher; $pos = $this->pos;
  1127. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1128. if ($subres !== FALSE) {
  1129. $this->store( $result, $subres, "IfArgument" );
  1130. }
  1131. else { $_183 = FALSE; break; }
  1132. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  1133. if (( $subres = $this->literal( '%>' ) ) !== FALSE) { $result["text"] .= $subres; }
  1134. else { $_183 = FALSE; break; }
  1135. $matcher = 'match_'.$this->expression($result, $stack, 'TemplateMatcher'); $key = $matcher; $pos = $this->pos;
  1136. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1137. if ($subres !== FALSE) {
  1138. $this->store( $result, $subres, "Template" );
  1139. }
  1140. else { $_183 = FALSE; break; }
  1141. $_183 = TRUE; break;
  1142. }
  1143. while(0);
  1144. if( $_183 === TRUE ) { return $this->finalise($result); }
  1145. if( $_183 === FALSE) { return FALSE; }
  1146. }
  1147. /* ElsePart: '<%' < 'else' > '%>' Template:$TemplateMatcher */
  1148. protected $match_ElsePart_typestack = array('ElsePart');
  1149. function match_ElsePart ($stack = array()) {
  1150. $matchrule = "ElsePart"; $result = $this->construct($matchrule, $matchrule, null);
  1151. $_191 = NULL;
  1152. do {
  1153. if (( $subres = $this->literal( '<%' ) ) !== FALSE) { $result["text"] .= $subres; }
  1154. else { $_191 = FALSE; break; }
  1155. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  1156. if (( $subres = $this->literal( 'else' ) ) !== FALSE) { $result["text"] .= $subres; }
  1157. else { $_191 = FALSE; break; }
  1158. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  1159. if (( $subres = $this->literal( '%>' ) ) !== FALSE) { $result["text"] .= $subres; }
  1160. else { $_191 = FALSE; break; }
  1161. $matcher = 'match_'.$this->expression($result, $stack, 'TemplateMatcher'); $key = $matcher; $pos = $this->pos;
  1162. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1163. if ($subres !== FALSE) {
  1164. $this->store( $result, $subres, "Template" );
  1165. }
  1166. else { $_191 = FALSE; break; }
  1167. $_191 = TRUE; break;
  1168. }
  1169. while(0);
  1170. if( $_191 === TRUE ) { return $this->finalise($result); }
  1171. if( $_191 === FALSE) { return FALSE; }
  1172. }
  1173. /* If: IfPart ElseIfPart* ElsePart? '<%' < 'end_if' > '%>' */
  1174. protected $match_If_typestack = array('If');
  1175. function match_If ($stack = array()) {
  1176. $matchrule = "If"; $result = $this->construct($matchrule, $matchrule, null);
  1177. $_201 = NULL;
  1178. do {
  1179. $matcher = 'match_'.'IfPart'; $key = $matcher; $pos = $this->pos;
  1180. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1181. if ($subres !== FALSE) { $this->store( $result, $subres ); }
  1182. else { $_201 = FALSE; break; }
  1183. while (true) {
  1184. $res_194 = $result;
  1185. $pos_194 = $this->pos;
  1186. $matcher = 'match_'.'ElseIfPart'; $key = $matcher; $pos = $this->pos;
  1187. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1188. if ($subres !== FALSE) { $this->store( $result, $subres ); }
  1189. else {
  1190. $result = $res_194;
  1191. $this->pos = $pos_194;
  1192. unset( $res_194 );
  1193. unset( $pos_194 );
  1194. break;
  1195. }
  1196. }
  1197. $res_195 = $result;
  1198. $pos_195 = $this->pos;
  1199. $matcher = 'match_'.'ElsePart'; $key = $matcher; $pos = $this->pos;
  1200. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1201. if ($subres !== FALSE) { $this->store( $result, $subres ); }
  1202. else {
  1203. $result = $res_195;
  1204. $this->pos = $pos_195;
  1205. unset( $res_195 );
  1206. unset( $pos_195 );
  1207. }
  1208. if (( $subres = $this->literal( '<%' ) ) !== FALSE) { $result["text"] .= $subres; }
  1209. else { $_201 = FALSE; break; }
  1210. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  1211. if (( $subres = $this->literal( 'end_if' ) ) !== FALSE) { $result["text"] .= $subres; }
  1212. else { $_201 = FALSE; break; }
  1213. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  1214. if (( $subres = $this->literal( '%>' ) ) !== FALSE) { $result["text"] .= $subres; }
  1215. else { $_201 = FALSE; break; }
  1216. $_201 = TRUE; break;
  1217. }
  1218. while(0);
  1219. if( $_201 === TRUE ) { return $this->finalise($result); }
  1220. if( $_201 === FALSE) { return FALSE; }
  1221. }
  1222. function If_IfPart(&$res, $sub) {
  1223. $res['php'] =
  1224. 'if (' . $sub['IfArgument']['php'] . ') { ' . PHP_EOL .
  1225. (isset($sub['Template']) ? $sub['Template']['php'] : '') . PHP_EOL .
  1226. '}';
  1227. }
  1228. function If_ElseIfPart(&$res, $sub) {
  1229. $res['php'] .=
  1230. 'else if (' . $sub['IfArgument']['php'] . ') { ' . PHP_EOL .
  1231. $sub['Template']['php'] . PHP_EOL .
  1232. '}';
  1233. }
  1234. function If_ElsePart(&$res, $sub) {
  1235. $res['php'] .=
  1236. 'else { ' . PHP_EOL .
  1237. $sub['Template']['php'] . PHP_EOL .
  1238. '}';
  1239. }
  1240. /* Require: '<%' < 'require' [ Call:(Method:Word "(" < :CallArguments > ")") > '%>' */
  1241. protected $match_Require_typestack = array('Require');
  1242. function match_Require ($stack = array()) {
  1243. $matchrule = "Require"; $result = $this->construct($matchrule, $matchrule, null);
  1244. $_217 = NULL;
  1245. do {
  1246. if (( $subres = $this->literal( '<%' ) ) !== FALSE) { $result["text"] .= $subres; }
  1247. else { $_217 = FALSE; break; }
  1248. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  1249. if (( $subres = $this->literal( 'require' ) ) !== FALSE) { $result["text"] .= $subres; }
  1250. else { $_217 = FALSE; break; }
  1251. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  1252. else { $_217 = FALSE; break; }
  1253. $stack[] = $result; $result = $this->construct( $matchrule, "Call" );
  1254. $_213 = NULL;
  1255. do {
  1256. $matcher = 'match_'.'Word'; $key = $matcher; $pos = $this->pos;
  1257. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1258. if ($subres !== FALSE) {
  1259. $this->store( $result, $subres, "Method" );
  1260. }
  1261. else { $_213 = FALSE; break; }
  1262. if (substr($this->string,$this->pos,1) == '(') {
  1263. $this->pos += 1;
  1264. $result["text"] .= '(';
  1265. }
  1266. else { $_213 = FALSE; break; }
  1267. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  1268. $matcher = 'match_'.'CallArguments'; $key = $matcher; $pos = $this->pos;
  1269. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1270. if ($subres !== FALSE) {
  1271. $this->store( $result, $subres, "CallArguments" );
  1272. }
  1273. else { $_213 = FALSE; break; }
  1274. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  1275. if (substr($this->string,$this->pos,1) == ')') {
  1276. $this->pos += 1;
  1277. $result["text"] .= ')';
  1278. }
  1279. else { $_213 = FALSE; break; }
  1280. $_213 = TRUE; break;
  1281. }
  1282. while(0);
  1283. if( $_213 === TRUE ) {
  1284. $subres = $result; $result = array_pop($stack);
  1285. $this->store( $result, $subres, 'Call' );
  1286. }
  1287. if( $_213 === FALSE) {
  1288. $result = array_pop($stack);
  1289. $_217 = FALSE; break;
  1290. }
  1291. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  1292. if (( $subres = $this->literal( '%>' ) ) !== FALSE) { $result["text"] .= $subres; }
  1293. else { $_217 = FALSE; break; }
  1294. $_217 = TRUE; break;
  1295. }
  1296. while(0);
  1297. if( $_217 === TRUE ) { return $this->finalise($result); }
  1298. if( $_217 === FALSE) { return FALSE; }
  1299. }
  1300. function Require_Call(&$res, $sub) {
  1301. $res['php'] = "Requirements::".$sub['Method']['text'].'('.$sub['CallArguments']['php'].');';
  1302. }
  1303. /* CacheBlockArgument:
  1304. !( "if " | "unless " )
  1305. (
  1306. :DollarMarkedLookup |
  1307. :QuotedString |
  1308. :Lookup
  1309. ) */
  1310. protected $match_CacheBlockArgument_typestack = array('CacheBlockArgument');
  1311. function match_CacheBlockArgument ($stack = array()) {
  1312. $matchrule = "CacheBlockArgument"; $result = $this->construct($matchrule, $matchrule, null);
  1313. $_237 = NULL;
  1314. do {
  1315. $res_225 = $result;
  1316. $pos_225 = $this->pos;
  1317. $_224 = NULL;
  1318. do {
  1319. $_222 = NULL;
  1320. do {
  1321. $res_219 = $result;
  1322. $pos_219 = $this->pos;
  1323. if (( $subres = $this->literal( 'if ' ) ) !== FALSE) {
  1324. $result["text"] .= $subres;
  1325. $_222 = TRUE; break;
  1326. }
  1327. $result = $res_219;
  1328. $this->pos = $pos_219;
  1329. if (( $subres = $this->literal( 'unless ' ) ) !== FALSE) {
  1330. $result["text"] .= $subres;
  1331. $_222 = TRUE; break;
  1332. }
  1333. $result = $res_219;
  1334. $this->pos = $pos_219;
  1335. $_222 = FALSE; break;
  1336. }
  1337. while(0);
  1338. if( $_222 === FALSE) { $_224 = FALSE; break; }
  1339. $_224 = TRUE; break;
  1340. }
  1341. while(0);
  1342. if( $_224 === TRUE ) {
  1343. $result = $res_225;
  1344. $this->pos = $pos_225;
  1345. $_237 = FALSE; break;
  1346. }
  1347. if( $_224 === FALSE) {
  1348. $result = $res_225;
  1349. $this->pos = $pos_225;
  1350. }
  1351. $_235 = NULL;
  1352. do {
  1353. $_233 = NULL;
  1354. do {
  1355. $res_226 = $result;
  1356. $pos_226 = $this->pos;
  1357. $matcher = 'match_'.'DollarMarkedLookup'; $key = $matcher; $pos = $this->pos;
  1358. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1359. if ($subres !== FALSE) {
  1360. $this->store( $result, $subres, "DollarMarkedLookup" );
  1361. $_233 = TRUE; break;
  1362. }
  1363. $result = $res_226;
  1364. $this->pos = $pos_226;
  1365. $_231 = NULL;
  1366. do {
  1367. $res_228 = $result;
  1368. $pos_228 = $this->pos;
  1369. $matcher = 'match_'.'QuotedString'; $key = $matcher; $pos = $this->pos;
  1370. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1371. if ($subres !== FALSE) {
  1372. $this->store( $result, $subres, "QuotedString" );
  1373. $_231 = TRUE; break;
  1374. }
  1375. $result = $res_228;
  1376. $this->pos = $pos_228;
  1377. $matcher = 'match_'.'Lookup'; $key = $matcher; $pos = $this->pos;
  1378. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1379. if ($subres !== FALSE) {
  1380. $this->store( $result, $subres, "Lookup" );
  1381. $_231 = TRUE; break;
  1382. }
  1383. $result = $res_228;
  1384. $this->pos = $pos_228;
  1385. $_231 = FALSE; break;
  1386. }
  1387. while(0);
  1388. if( $_231 === TRUE ) { $_233 = TRUE; break; }
  1389. $result = $res_226;
  1390. $this->pos = $pos_226;
  1391. $_233 = FALSE; break;
  1392. }
  1393. while(0);
  1394. if( $_233 === FALSE) { $_235 = FALSE; break; }
  1395. $_235 = TRUE; break;
  1396. }
  1397. while(0);
  1398. if( $_235 === FALSE) { $_237 = FALSE; break; }
  1399. $_237 = TRUE; break;
  1400. }
  1401. while(0);
  1402. if( $_237 === TRUE ) { return $this->finalise($result); }
  1403. if( $_237 === FALSE) { return FALSE; }
  1404. }
  1405. function CacheBlockArgument_DollarMarkedLookup(&$res, $sub) {
  1406. $res['php'] = $sub['Lookup']['php'];
  1407. }
  1408. function CacheBlockArgument_QuotedString(&$res, $sub) {
  1409. $res['php'] = "'" . str_replace("'", "\\'", $sub['String']['text']) . "'";
  1410. }
  1411. function CacheBlockArgument_Lookup(&$res, $sub) {
  1412. $res['php'] = $sub['php'];
  1413. }
  1414. /* CacheBlockArguments: CacheBlockArgument ( < "," < CacheBlockArgument )* */
  1415. protected $match_CacheBlockArguments_typestack = array('CacheBlockArguments');
  1416. function match_CacheBlockArguments ($stack = array()) {
  1417. $matchrule = "CacheBlockArguments"; $result = $this->construct($matchrule, $matchrule, null);
  1418. $_246 = NULL;
  1419. do {
  1420. $matcher = 'match_'.'CacheBlockArgument'; $key = $matcher; $pos = $this->pos;
  1421. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1422. if ($subres !== FALSE) { $this->store( $result, $subres ); }
  1423. else { $_246 = FALSE; break; }
  1424. while (true) {
  1425. $res_245 = $result;
  1426. $pos_245 = $this->pos;
  1427. $_244 = NULL;
  1428. do {
  1429. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  1430. if (substr($this->string,$this->pos,1) == ',') {
  1431. $this->pos += 1;
  1432. $result["text"] .= ',';
  1433. }
  1434. else { $_244 = FALSE; break; }
  1435. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  1436. $matcher = 'match_'.'CacheBlockArgument'; $key = $matcher; $pos = $this->pos;
  1437. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1438. if ($subres !== FALSE) { $this->store( $result, $subres ); }
  1439. else { $_244 = FALSE; break; }
  1440. $_244 = TRUE; break;
  1441. }
  1442. while(0);
  1443. if( $_244 === FALSE) {
  1444. $result = $res_245;
  1445. $this->pos = $pos_245;
  1446. unset( $res_245 );
  1447. unset( $pos_245 );
  1448. break;
  1449. }
  1450. }
  1451. $_246 = TRUE; break;
  1452. }
  1453. while(0);
  1454. if( $_246 === TRUE ) { return $this->finalise($result); }
  1455. if( $_246 === FALSE) { return FALSE; }
  1456. }
  1457. function CacheBlockArguments_CacheBlockArgument(&$res, $sub) {
  1458. if (!empty($res['php'])) $res['php'] .= ".'_'.";
  1459. else $res['php'] = '';
  1460. $res['php'] .= str_replace('$$FINAL', 'XML_val', $sub['php']);
  1461. }
  1462. /* CacheBlockTemplate: (Comment | If | Require | OldI18NTag | ClosedBlock | OpenBlock | MalformedBlock | Injection | Text)+ */
  1463. protected $match_CacheBlockTemplate_typestack = array('CacheBlockTemplate','Template');
  1464. function match_CacheBlockTemplate ($stack = array()) {
  1465. $matchrule = "CacheBlockTemplate"; $result = $this->construct($matchrule, $matchrule, array('TemplateMatcher' => 'CacheRestrictedTemplate'));
  1466. $count = 0;
  1467. while (true) {
  1468. $res_282 = $result;
  1469. $pos_282 = $this->pos;
  1470. $_281 = NULL;
  1471. do {
  1472. $_279 = NULL;
  1473. do {
  1474. $res_248 = $result;
  1475. $pos_248 = $this->pos;
  1476. $matcher = 'match_'.'Comment'; $key = $matcher; $pos = $this->pos;
  1477. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1478. if ($subres !== FALSE) {
  1479. $this->store( $result, $subres );
  1480. $_279 = TRUE; break;
  1481. }
  1482. $result = $res_248;
  1483. $this->pos = $pos_248;
  1484. $_277 = NULL;
  1485. do {
  1486. $res_250 = $result;
  1487. $pos_250 = $this->pos;
  1488. $matcher = 'match_'.'If'; $key = $matcher; $pos = $this->pos;
  1489. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1490. if ($subres !== FALSE) {
  1491. $this->store( $result, $subres );
  1492. $_277 = TRUE; break;
  1493. }
  1494. $result = $res_250;
  1495. $this->pos = $pos_250;
  1496. $_275 = NULL;
  1497. do {
  1498. $res_252 = $result;
  1499. $pos_252 = $this->pos;
  1500. $matcher = 'match_'.'Require'; $key = $matcher; $pos = $this->pos;
  1501. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1502. if ($subres !== FALSE) {
  1503. $this->store( $result, $subres );
  1504. $_275 = TRUE; break;
  1505. }
  1506. $result = $res_252;
  1507. $this->pos = $pos_252;
  1508. $_273 = NULL;
  1509. do {
  1510. $res_254 = $result;
  1511. $pos_254 = $this->pos;
  1512. $matcher = 'match_'.'OldI18NTag'; $key = $matcher; $pos = $this->pos;
  1513. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1514. if ($subres !== FALSE) {
  1515. $this->store( $result, $subres );
  1516. $_273 = TRUE; break;
  1517. }
  1518. $result = $res_254;
  1519. $this->pos = $pos_254;
  1520. $_271 = NULL;
  1521. do {
  1522. $res_256 = $result;
  1523. $pos_256 = $this->pos;
  1524. $matcher = 'match_'.'ClosedBlock'; $key = $matcher; $pos = $this->pos;
  1525. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1526. if ($subres !== FALSE) {
  1527. $this->store( $result, $subres );
  1528. $_271 = TRUE; break;
  1529. }
  1530. $result = $res_256;
  1531. $this->pos = $pos_256;
  1532. $_269 = NULL;
  1533. do {
  1534. $res_258 = $result;
  1535. $pos_258 = $this->pos;
  1536. $matcher = 'match_'.'OpenBlock'; $key = $matcher; $pos = $this->pos;
  1537. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1538. if ($subres !== FALSE) {
  1539. $this->store( $result, $subres );
  1540. $_269 = TRUE; break;
  1541. }
  1542. $result = $res_258;
  1543. $this->pos = $pos_258;
  1544. $_267 = NULL;
  1545. do {
  1546. $res_260 = $result;
  1547. $pos_260 = $this->pos;
  1548. $matcher = 'match_'.'MalformedBlock'; $key = $matcher; $pos = $this->pos;
  1549. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1550. if ($subres !== FALSE) {
  1551. $this->store( $result, $subres );
  1552. $_267 = TRUE; break;
  1553. }
  1554. $result = $res_260;
  1555. $this->pos = $pos_260;
  1556. $_265 = NULL;
  1557. do {
  1558. $res_262 = $result;
  1559. $pos_262 = $this->pos;
  1560. $matcher = 'match_'.'Injection'; $key = $matcher; $pos = $this->pos;
  1561. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1562. if ($subres !== FALSE) {
  1563. $this->store( $result, $subres );
  1564. $_265 = TRUE; break;
  1565. }
  1566. $result = $res_262;
  1567. $this->pos = $pos_262;
  1568. $matcher = 'match_'.'Text'; $key = $matcher; $pos = $this->pos;
  1569. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1570. if ($subres !== FALSE) {
  1571. $this->store( $result, $subres );
  1572. $_265 = TRUE; break;
  1573. }
  1574. $result = $res_262;
  1575. $this->pos = $pos_262;
  1576. $_265 = FALSE; break;
  1577. }
  1578. while(0);
  1579. if( $_265 === TRUE ) { $_267 = TRUE; break; }
  1580. $result = $res_260;
  1581. $this->pos = $pos_260;
  1582. $_267 = FALSE; break;
  1583. }
  1584. while(0);
  1585. if( $_267 === TRUE ) { $_269 = TRUE; break; }
  1586. $result = $res_258;
  1587. $this->pos = $pos_258;
  1588. $_269 = FALSE; break;
  1589. }
  1590. while(0);
  1591. if( $_269 === TRUE ) { $_271 = TRUE; break; }
  1592. $result = $res_256;
  1593. $this->pos = $pos_256;
  1594. $_271 = FALSE; break;
  1595. }
  1596. while(0);
  1597. if( $_271 === TRUE ) { $_273 = TRUE; break; }
  1598. $result = $res_254;
  1599. $this->pos = $pos_254;
  1600. $_273 = FALSE; break;
  1601. }
  1602. while(0);
  1603. if( $_273 === TRUE ) { $_275 = TRUE; break; }
  1604. $result = $res_252;
  1605. $this->pos = $pos_252;
  1606. $_275 = FALSE; break;
  1607. }
  1608. while(0);
  1609. if( $_275 === TRUE ) { $_277 = TRUE; break; }
  1610. $result = $res_250;
  1611. $this->pos = $pos_250;
  1612. $_277 = FALSE; break;
  1613. }
  1614. while(0);
  1615. if( $_277 === TRUE ) { $_279 = TRUE; break; }
  1616. $result = $res_248;
  1617. $this->pos = $pos_248;
  1618. $_279 = FALSE; break;
  1619. }
  1620. while(0);
  1621. if( $_279 === FALSE) { $_281 = FALSE; break; }
  1622. $_281 = TRUE; break;
  1623. }
  1624. while(0);
  1625. if( $_281 === FALSE) {
  1626. $result = $res_282;
  1627. $this->pos = $pos_282;
  1628. unset( $res_282 );
  1629. unset( $pos_282 );
  1630. break;
  1631. }
  1632. $count += 1;
  1633. }
  1634. if ($count > 0) { return $this->finalise($result); }
  1635. else { return FALSE; }
  1636. }
  1637. /* UncachedBlock:
  1638. '<%' < "uncached" < CacheBlockArguments? ( < Conditional:("if"|"unless") > Condition:IfArgument )? > '%>'
  1639. Template:$TemplateMatcher?
  1640. '<%' < 'end_' ("uncached"|"cached"|"cacheblock") > '%>' */
  1641. protected $match_UncachedBlock_typestack = array('UncachedBlock');
  1642. function match_UncachedBlock ($stack = array()) {
  1643. $matchrule = "UncachedBlock"; $result = $this->construct($matchrule, $matchrule, null);
  1644. $_319 = NULL;
  1645. do {
  1646. if (( $subres = $this->literal( '<%' ) ) !== FALSE) { $result["text"] .= $subres; }
  1647. else { $_319 = FALSE; break; }
  1648. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  1649. if (( $subres = $this->literal( 'uncached' ) ) !== FALSE) { $result["text"] .= $subres; }
  1650. else { $_319 = FALSE; break; }
  1651. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  1652. $res_287 = $result;
  1653. $pos_287 = $this->pos;
  1654. $matcher = 'match_'.'CacheBlockArguments'; $key = $matcher; $pos = $this->pos;
  1655. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1656. if ($subres !== FALSE) { $this->store( $result, $subres ); }
  1657. else {
  1658. $result = $res_287;
  1659. $this->pos = $pos_287;
  1660. unset( $res_287 );
  1661. unset( $pos_287 );
  1662. }
  1663. $res_299 = $result;
  1664. $pos_299 = $this->pos;
  1665. $_298 = NULL;
  1666. do {
  1667. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  1668. $stack[] = $result; $result = $this->construct( $matchrule, "Conditional" );
  1669. $_294 = NULL;
  1670. do {
  1671. $_292 = NULL;
  1672. do {
  1673. $res_289 = $result;
  1674. $pos_289 = $this->pos;
  1675. if (( $subres = $this->literal( 'if' ) ) !== FALSE) {
  1676. $result["text"] .= $subres;
  1677. $_292 = TRUE; break;
  1678. }
  1679. $result = $res_289;
  1680. $this->pos = $pos_289;
  1681. if (( $subres = $this->literal( 'unless' ) ) !== FALSE) {
  1682. $result["text"] .= $subres;
  1683. $_292 = TRUE; break;
  1684. }
  1685. $result = $res_289;
  1686. $this->pos = $pos_289;
  1687. $_292 = FALSE; break;
  1688. }
  1689. while(0);
  1690. if( $_292 === FALSE) { $_294 = FALSE; break; }
  1691. $_294 = TRUE; break;
  1692. }
  1693. while(0);
  1694. if( $_294 === TRUE ) {
  1695. $subres = $result; $result = array_pop($stack);
  1696. $this->store( $result, $subres, 'Conditional' );
  1697. }
  1698. if( $_294 === FALSE) {
  1699. $result = array_pop($stack);
  1700. $_298 = FALSE; break;
  1701. }
  1702. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  1703. $matcher = 'match_'.'IfArgument'; $key = $matcher; $pos = $this->pos;
  1704. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1705. if ($subres !== FALSE) {
  1706. $this->store( $result, $subres, "Condition" );
  1707. }
  1708. else { $_298 = FALSE; break; }
  1709. $_298 = TRUE; break;
  1710. }
  1711. while(0);
  1712. if( $_298 === FALSE) {
  1713. $result = $res_299;
  1714. $this->pos = $pos_299;
  1715. unset( $res_299 );
  1716. unset( $pos_299 );
  1717. }
  1718. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  1719. if (( $subres = $this->literal( '%>' ) ) !== FALSE) { $result["text"] .= $subres; }
  1720. else { $_319 = FALSE; break; }
  1721. $res_302 = $result;
  1722. $pos_302 = $this->pos;
  1723. $matcher = 'match_'.$this->expression($result, $stack, 'TemplateMatcher'); $key = $matcher; $pos = $this->pos;
  1724. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1725. if ($subres !== FALSE) {
  1726. $this->store( $result, $subres, "Template" );
  1727. }
  1728. else {
  1729. $result = $res_302;
  1730. $this->pos = $pos_302;
  1731. unset( $res_302 );
  1732. unset( $pos_302 );
  1733. }
  1734. if (( $subres = $this->literal( '<%' ) ) !== FALSE) { $result["text"] .= $subres; }
  1735. else { $_319 = FALSE; break; }
  1736. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  1737. if (( $subres = $this->literal( 'end_' ) ) !== FALSE) { $result["text"] .= $subres; }
  1738. else { $_319 = FALSE; break; }
  1739. $_315 = NULL;
  1740. do {
  1741. $_313 = NULL;
  1742. do {
  1743. $res_306 = $result;
  1744. $pos_306 = $this->pos;
  1745. if (( $subres = $this->literal( 'uncached' ) ) !== FALSE) {
  1746. $result["text"] .= $subres;
  1747. $_313 = TRUE; break;
  1748. }
  1749. $result = $res_306;
  1750. $this->pos = $pos_306;
  1751. $_311 = NULL;
  1752. do {
  1753. $res_308 = $result;
  1754. $pos_308 = $this->pos;
  1755. if (( $subres = $this->literal( 'cached' ) ) !== FALSE) {
  1756. $result["text"] .= $subres;
  1757. $_311 = TRUE; break;
  1758. }
  1759. $result = $res_308;
  1760. $this->pos = $pos_308;
  1761. if (( $subres = $this->literal( 'cacheblock' ) ) !== FALSE) {
  1762. $result["text"] .= $subres;
  1763. $_311 = TRUE; break;
  1764. }
  1765. $result = $res_308;
  1766. $this->pos = $pos_308;
  1767. $_311 = FALSE; break;
  1768. }
  1769. while(0);
  1770. if( $_311 === TRUE ) { $_313 = TRUE; break; }
  1771. $result = $res_306;
  1772. $this->pos = $pos_306;
  1773. $_313 = FALSE; break;
  1774. }
  1775. while(0);
  1776. if( $_313 === FALSE) { $_315 = FALSE; break; }
  1777. $_315 = TRUE; break;
  1778. }
  1779. while(0);
  1780. if( $_315 === FALSE) { $_319 = FALSE; break; }
  1781. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  1782. if (( $subres = $this->literal( '%>' ) ) !== FALSE) { $result["text"] .= $subres; }
  1783. else { $_319 = FALSE; break; }
  1784. $_319 = TRUE; break;
  1785. }
  1786. while(0);
  1787. if( $_319 === TRUE ) { return $this->finalise($result); }
  1788. if( $_319 === FALSE) { return FALSE; }
  1789. }
  1790. function UncachedBlock_Template(&$res, $sub){
  1791. $res['php'] = $sub['php'];
  1792. }
  1793. /* CacheRestrictedTemplate: (Comment | If | Require | CacheBlock | UncachedBlock | OldI18NTag | ClosedBlock | OpenBlock | MalformedBlock | Injection | Text)+ */
  1794. protected $match_CacheRestrictedTemplate_typestack = array('CacheRestrictedTemplate','Template');
  1795. function match_CacheRestrictedTemplate ($stack = array()) {
  1796. $matchrule = "CacheRestrictedTemplate"; $result = $this->construct($matchrule, $matchrule, null);
  1797. $count = 0;
  1798. while (true) {
  1799. $res_363 = $result;
  1800. $pos_363 = $this->pos;
  1801. $_362 = NULL;
  1802. do {
  1803. $_360 = NULL;
  1804. do {
  1805. $res_321 = $result;
  1806. $pos_321 = $this->pos;
  1807. $matcher = 'match_'.'Comment'; $key = $matcher; $pos = $this->pos;
  1808. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1809. if ($subres !== FALSE) {
  1810. $this->store( $result, $subres );
  1811. $_360 = TRUE; break;
  1812. }
  1813. $result = $res_321;
  1814. $this->pos = $pos_321;
  1815. $_358 = NULL;
  1816. do {
  1817. $res_323 = $result;
  1818. $pos_323 = $this->pos;
  1819. $matcher = 'match_'.'If'; $key = $matcher; $pos = $this->pos;
  1820. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1821. if ($subres !== FALSE) {
  1822. $this->store( $result, $subres );
  1823. $_358 = TRUE; break;
  1824. }
  1825. $result = $res_323;
  1826. $this->pos = $pos_323;
  1827. $_356 = NULL;
  1828. do {
  1829. $res_325 = $result;
  1830. $pos_325 = $this->pos;
  1831. $matcher = 'match_'.'Require'; $key = $matcher; $pos = $this->pos;
  1832. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1833. if ($subres !== FALSE) {
  1834. $this->store( $result, $subres );
  1835. $_356 = TRUE; break;
  1836. }
  1837. $result = $res_325;
  1838. $this->pos = $pos_325;
  1839. $_354 = NULL;
  1840. do {
  1841. $res_327 = $result;
  1842. $pos_327 = $this->pos;
  1843. $matcher = 'match_'.'CacheBlock'; $key = $matcher; $pos = $this->pos;
  1844. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1845. if ($subres !== FALSE) {
  1846. $this->store( $result, $subres );
  1847. $_354 = TRUE; break;
  1848. }
  1849. $result = $res_327;
  1850. $this->pos = $pos_327;
  1851. $_352 = NULL;
  1852. do {
  1853. $res_329 = $result;
  1854. $pos_329 = $this->pos;
  1855. $matcher = 'match_'.'UncachedBlock'; $key = $matcher; $pos = $this->pos;
  1856. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1857. if ($subres !== FALSE) {
  1858. $this->store( $result, $subres );
  1859. $_352 = TRUE; break;
  1860. }
  1861. $result = $res_329;
  1862. $this->pos = $pos_329;
  1863. $_350 = NULL;
  1864. do {
  1865. $res_331 = $result;
  1866. $pos_331 = $this->pos;
  1867. $matcher = 'match_'.'OldI18NTag'; $key = $matcher; $pos = $this->pos;
  1868. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1869. if ($subres !== FALSE) {
  1870. $this->store( $result, $subres );
  1871. $_350 = TRUE; break;
  1872. }
  1873. $result = $res_331;
  1874. $this->pos = $pos_331;
  1875. $_348 = NULL;
  1876. do {
  1877. $res_333 = $result;
  1878. $pos_333 = $this->pos;
  1879. $matcher = 'match_'.'ClosedBlock'; $key = $matcher; $pos = $this->pos;
  1880. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1881. if ($subres !== FALSE) {
  1882. $this->store( $result, $subres );
  1883. $_348 = TRUE; break;
  1884. }
  1885. $result = $res_333;
  1886. $this->pos = $pos_333;
  1887. $_346 = NULL;
  1888. do {
  1889. $res_335 = $result;
  1890. $pos_335 = $this->pos;
  1891. $matcher = 'match_'.'OpenBlock'; $key = $matcher; $pos = $this->pos;
  1892. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1893. if ($subres !== FALSE) {
  1894. $this->store( $result, $subres );
  1895. $_346 = TRUE; break;
  1896. }
  1897. $result = $res_335;
  1898. $this->pos = $pos_335;
  1899. $_344 = NULL;
  1900. do {
  1901. $res_337 = $result;
  1902. $pos_337 = $this->pos;
  1903. $matcher = 'match_'.'MalformedBlock'; $key = $matcher; $pos = $this->pos;
  1904. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1905. if ($subres !== FALSE) {
  1906. $this->store( $result, $subres );
  1907. $_344 = TRUE; break;
  1908. }
  1909. $result = $res_337;
  1910. $this->pos = $pos_337;
  1911. $_342 = NULL;
  1912. do {
  1913. $res_339 = $result;
  1914. $pos_339 = $this->pos;
  1915. $matcher = 'match_'.'Injection'; $key = $matcher; $pos = $this->pos;
  1916. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1917. if ($subres !== FALSE) {
  1918. $this->store( $result, $subres );
  1919. $_342 = TRUE; break;
  1920. }
  1921. $result = $res_339;
  1922. $this->pos = $pos_339;
  1923. $matcher = 'match_'.'Text'; $key = $matcher; $pos = $this->pos;
  1924. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  1925. if ($subres !== FALSE) {
  1926. $this->store( $result, $subres );
  1927. $_342 = TRUE; break;
  1928. }
  1929. $result = $res_339;
  1930. $this->pos = $pos_339;
  1931. $_342 = FALSE; break;
  1932. }
  1933. while(0);
  1934. if( $_342 === TRUE ) { $_344 = TRUE; break; }
  1935. $result = $res_337;
  1936. $this->pos = $pos_337;
  1937. $_344 = FALSE; break;
  1938. }
  1939. while(0);
  1940. if( $_344 === TRUE ) { $_346 = TRUE; break; }
  1941. $result = $res_335;
  1942. $this->pos = $pos_335;
  1943. $_346 = FALSE; break;
  1944. }
  1945. while(0);
  1946. if( $_346 === TRUE ) { $_348 = TRUE; break; }
  1947. $result = $res_333;
  1948. $this->pos = $pos_333;
  1949. $_348 = FALSE; break;
  1950. }
  1951. while(0);
  1952. if( $_348 === TRUE ) { $_350 = TRUE; break; }
  1953. $result = $res_331;
  1954. $this->pos = $pos_331;
  1955. $_350 = FALSE; break;
  1956. }
  1957. while(0);
  1958. if( $_350 === TRUE ) { $_352 = TRUE; break; }
  1959. $result = $res_329;
  1960. $this->pos = $pos_329;
  1961. $_352 = FALSE; break;
  1962. }
  1963. while(0);
  1964. if( $_352 === TRUE ) { $_354 = TRUE; break; }
  1965. $result = $res_327;
  1966. $this->pos = $pos_327;
  1967. $_354 = FALSE; break;
  1968. }
  1969. while(0);
  1970. if( $_354 === TRUE ) { $_356 = TRUE; break; }
  1971. $result = $res_325;
  1972. $this->pos = $pos_325;
  1973. $_356 = FALSE; break;
  1974. }
  1975. while(0);
  1976. if( $_356 === TRUE ) { $_358 = TRUE; break; }
  1977. $result = $res_323;
  1978. $this->pos = $pos_323;
  1979. $_358 = FALSE; break;
  1980. }
  1981. while(0);
  1982. if( $_358 === TRUE ) { $_360 = TRUE; break; }
  1983. $result = $res_321;
  1984. $this->pos = $pos_321;
  1985. $_360 = FALSE; break;
  1986. }
  1987. while(0);
  1988. if( $_360 === FALSE) { $_362 = FALSE; break; }
  1989. $_362 = TRUE; break;
  1990. }
  1991. while(0);
  1992. if( $_362 === FALSE) {
  1993. $result = $res_363;
  1994. $this->pos = $pos_363;
  1995. unset( $res_363 );
  1996. unset( $pos_363 );
  1997. break;
  1998. }
  1999. $count += 1;
  2000. }
  2001. if ($count > 0) { return $this->finalise($result); }
  2002. else { return FALSE; }
  2003. }
  2004. function CacheRestrictedTemplate_CacheBlock(&$res, $sub) {
  2005. throw new SSTemplateParseException('You cant have cache blocks nested within with, loop or control blocks that are within cache blocks', $this);
  2006. }
  2007. function CacheRestrictedTemplate_UncachedBlock(&$res, $sub) {
  2008. throw new SSTemplateParseException('You cant have uncache blocks nested within with, loop or control blocks that are within cache blocks', $this);
  2009. }
  2010. /* CacheBlock:
  2011. '<%' < CacheTag:("cached"|"cacheblock") < (CacheBlockArguments)? ( < Conditional:("if"|"unless") > Condition:IfArgument )? > '%>'
  2012. (CacheBlock | UncachedBlock | CacheBlockTemplate)*
  2013. '<%' < 'end_' ("cached"|"uncached"|"cacheblock") > '%>' */
  2014. protected $match_CacheBlock_typestack = array('CacheBlock');
  2015. function match_CacheBlock ($stack = array()) {
  2016. $matchrule = "CacheBlock"; $result = $this->construct($matchrule, $matchrule, null);
  2017. $_418 = NULL;
  2018. do {
  2019. if (( $subres = $this->literal( '<%' ) ) !== FALSE) { $result["text"] .= $subres; }
  2020. else { $_418 = FALSE; break; }
  2021. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2022. $stack[] = $result; $result = $this->construct( $matchrule, "CacheTag" );
  2023. $_371 = NULL;
  2024. do {
  2025. $_369 = NULL;
  2026. do {
  2027. $res_366 = $result;
  2028. $pos_366 = $this->pos;
  2029. if (( $subres = $this->literal( 'cached' ) ) !== FALSE) {
  2030. $result["text"] .= $subres;
  2031. $_369 = TRUE; break;
  2032. }
  2033. $result = $res_366;
  2034. $this->pos = $pos_366;
  2035. if (( $subres = $this->literal( 'cacheblock' ) ) !== FALSE) {
  2036. $result["text"] .= $subres;
  2037. $_369 = TRUE; break;
  2038. }
  2039. $result = $res_366;
  2040. $this->pos = $pos_366;
  2041. $_369 = FALSE; break;
  2042. }
  2043. while(0);
  2044. if( $_369 === FALSE) { $_371 = FALSE; break; }
  2045. $_371 = TRUE; break;
  2046. }
  2047. while(0);
  2048. if( $_371 === TRUE ) {
  2049. $subres = $result; $result = array_pop($stack);
  2050. $this->store( $result, $subres, 'CacheTag' );
  2051. }
  2052. if( $_371 === FALSE) {
  2053. $result = array_pop($stack);
  2054. $_418 = FALSE; break;
  2055. }
  2056. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2057. $res_376 = $result;
  2058. $pos_376 = $this->pos;
  2059. $_375 = NULL;
  2060. do {
  2061. $matcher = 'match_'.'CacheBlockArguments'; $key = $matcher; $pos = $this->pos;
  2062. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  2063. if ($subres !== FALSE) { $this->store( $result, $subres ); }
  2064. else { $_375 = FALSE; break; }
  2065. $_375 = TRUE; break;
  2066. }
  2067. while(0);
  2068. if( $_375 === FALSE) {
  2069. $result = $res_376;
  2070. $this->pos = $pos_376;
  2071. unset( $res_376 );
  2072. unset( $pos_376 );
  2073. }
  2074. $res_388 = $result;
  2075. $pos_388 = $this->pos;
  2076. $_387 = NULL;
  2077. do {
  2078. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2079. $stack[] = $result; $result = $this->construct( $matchrule, "Conditional" );
  2080. $_383 = NULL;
  2081. do {
  2082. $_381 = NULL;
  2083. do {
  2084. $res_378 = $result;
  2085. $pos_378 = $this->pos;
  2086. if (( $subres = $this->literal( 'if' ) ) !== FALSE) {
  2087. $result["text"] .= $subres;
  2088. $_381 = TRUE; break;
  2089. }
  2090. $result = $res_378;
  2091. $this->pos = $pos_378;
  2092. if (( $subres = $this->literal( 'unless' ) ) !== FALSE) {
  2093. $result["text"] .= $subres;
  2094. $_381 = TRUE; break;
  2095. }
  2096. $result = $res_378;
  2097. $this->pos = $pos_378;
  2098. $_381 = FALSE; break;
  2099. }
  2100. while(0);
  2101. if( $_381 === FALSE) { $_383 = FALSE; break; }
  2102. $_383 = TRUE; break;
  2103. }
  2104. while(0);
  2105. if( $_383 === TRUE ) {
  2106. $subres = $result; $result = array_pop($stack);
  2107. $this->store( $result, $subres, 'Conditional' );
  2108. }
  2109. if( $_383 === FALSE) {
  2110. $result = array_pop($stack);
  2111. $_387 = FALSE; break;
  2112. }
  2113. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2114. $matcher = 'match_'.'IfArgument'; $key = $matcher; $pos = $this->pos;
  2115. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  2116. if ($subres !== FALSE) {
  2117. $this->store( $result, $subres, "Condition" );
  2118. }
  2119. else { $_387 = FALSE; break; }
  2120. $_387 = TRUE; break;
  2121. }
  2122. while(0);
  2123. if( $_387 === FALSE) {
  2124. $result = $res_388;
  2125. $this->pos = $pos_388;
  2126. unset( $res_388 );
  2127. unset( $pos_388 );
  2128. }
  2129. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2130. if (( $subres = $this->literal( '%>' ) ) !== FALSE) { $result["text"] .= $subres; }
  2131. else { $_418 = FALSE; break; }
  2132. while (true) {
  2133. $res_401 = $result;
  2134. $pos_401 = $this->pos;
  2135. $_400 = NULL;
  2136. do {
  2137. $_398 = NULL;
  2138. do {
  2139. $res_391 = $result;
  2140. $pos_391 = $this->pos;
  2141. $matcher = 'match_'.'CacheBlock'; $key = $matcher; $pos = $this->pos;
  2142. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  2143. if ($subres !== FALSE) {
  2144. $this->store( $result, $subres );
  2145. $_398 = TRUE; break;
  2146. }
  2147. $result = $res_391;
  2148. $this->pos = $pos_391;
  2149. $_396 = NULL;
  2150. do {
  2151. $res_393 = $result;
  2152. $pos_393 = $this->pos;
  2153. $matcher = 'match_'.'UncachedBlock'; $key = $matcher; $pos = $this->pos;
  2154. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  2155. if ($subres !== FALSE) {
  2156. $this->store( $result, $subres );
  2157. $_396 = TRUE; break;
  2158. }
  2159. $result = $res_393;
  2160. $this->pos = $pos_393;
  2161. $matcher = 'match_'.'CacheBlockTemplate'; $key = $matcher; $pos = $this->pos;
  2162. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  2163. if ($subres !== FALSE) {
  2164. $this->store( $result, $subres );
  2165. $_396 = TRUE; break;
  2166. }
  2167. $result = $res_393;
  2168. $this->pos = $pos_393;
  2169. $_396 = FALSE; break;
  2170. }
  2171. while(0);
  2172. if( $_396 === TRUE ) { $_398 = TRUE; break; }
  2173. $result = $res_391;
  2174. $this->pos = $pos_391;
  2175. $_398 = FALSE; break;
  2176. }
  2177. while(0);
  2178. if( $_398 === FALSE) { $_400 = FALSE; break; }
  2179. $_400 = TRUE; break;
  2180. }
  2181. while(0);
  2182. if( $_400 === FALSE) {
  2183. $result = $res_401;
  2184. $this->pos = $pos_401;
  2185. unset( $res_401 );
  2186. unset( $pos_401 );
  2187. break;
  2188. }
  2189. }
  2190. if (( $subres = $this->literal( '<%' ) ) !== FALSE) { $result["text"] .= $subres; }
  2191. else { $_418 = FALSE; break; }
  2192. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2193. if (( $subres = $this->literal( 'end_' ) ) !== FALSE) { $result["text"] .= $subres; }
  2194. else { $_418 = FALSE; break; }
  2195. $_414 = NULL;
  2196. do {
  2197. $_412 = NULL;
  2198. do {
  2199. $res_405 = $result;
  2200. $pos_405 = $this->pos;
  2201. if (( $subres = $this->literal( 'cached' ) ) !== FALSE) {
  2202. $result["text"] .= $subres;
  2203. $_412 = TRUE; break;
  2204. }
  2205. $result = $res_405;
  2206. $this->pos = $pos_405;
  2207. $_410 = NULL;
  2208. do {
  2209. $res_407 = $result;
  2210. $pos_407 = $this->pos;
  2211. if (( $subres = $this->literal( 'uncached' ) ) !== FALSE) {
  2212. $result["text"] .= $subres;
  2213. $_410 = TRUE; break;
  2214. }
  2215. $result = $res_407;
  2216. $this->pos = $pos_407;
  2217. if (( $subres = $this->literal( 'cacheblock' ) ) !== FALSE) {
  2218. $result["text"] .= $subres;
  2219. $_410 = TRUE; break;
  2220. }
  2221. $result = $res_407;
  2222. $this->pos = $pos_407;
  2223. $_410 = FALSE; break;
  2224. }
  2225. while(0);
  2226. if( $_410 === TRUE ) { $_412 = TRUE; break; }
  2227. $result = $res_405;
  2228. $this->pos = $pos_405;
  2229. $_412 = FALSE; break;
  2230. }
  2231. while(0);
  2232. if( $_412 === FALSE) { $_414 = FALSE; break; }
  2233. $_414 = TRUE; break;
  2234. }
  2235. while(0);
  2236. if( $_414 === FALSE) { $_418 = FALSE; break; }
  2237. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2238. if (( $subres = $this->literal( '%>' ) ) !== FALSE) { $result["text"] .= $subres; }
  2239. else { $_418 = FALSE; break; }
  2240. $_418 = TRUE; break;
  2241. }
  2242. while(0);
  2243. if( $_418 === TRUE ) { return $this->finalise($result); }
  2244. if( $_418 === FALSE) { return FALSE; }
  2245. }
  2246. function CacheBlock__construct(&$res){
  2247. $res['subblocks'] = 0;
  2248. }
  2249. function CacheBlock_CacheBlockArguments(&$res, $sub){
  2250. $res['key'] = !empty($sub['php']) ? $sub['php'] : '';
  2251. }
  2252. function CacheBlock_Condition(&$res, $sub){
  2253. $res['condition'] = ($res['Conditional']['text'] == 'if' ? '(' : '!(') . $sub['php'] . ') && ';
  2254. }
  2255. function CacheBlock_CacheBlock(&$res, $sub){
  2256. $res['php'] .= $sub['php'];
  2257. }
  2258. function CacheBlock_UncachedBlock(&$res, $sub){
  2259. $res['php'] .= $sub['php'];
  2260. }
  2261. function CacheBlock_CacheBlockTemplate(&$res, $sub){
  2262. // Get the block counter
  2263. $block = ++$res['subblocks'];
  2264. // Build the key for this block from the passed cache key, the block index, and the sha hash of the template itself
  2265. $key = "'" . sha1($sub['php']) . (isset($res['key']) && $res['key'] ? "_'.sha1(".$res['key'].")" : "'") . ".'_$block'";
  2266. // Get any condition
  2267. $condition = isset($res['condition']) ? $res['condition'] : '';
  2268. $res['php'] .= 'if ('.$condition.'($partial = $cache->load('.$key.'))) $val .= $partial;' . PHP_EOL;
  2269. $res['php'] .= 'else { $oldval = $val; $val = "";' . PHP_EOL;
  2270. $res['php'] .= $sub['php'] . PHP_EOL;
  2271. $res['php'] .= $condition . ' $cache->save($val); $val = $oldval . $val;' . PHP_EOL;
  2272. $res['php'] .= '}';
  2273. }
  2274. /* OldTPart: "_t" < "(" < QuotedString (< "," < CallArguments)? > ")" */
  2275. protected $match_OldTPart_typestack = array('OldTPart');
  2276. function match_OldTPart ($stack = array()) {
  2277. $matchrule = "OldTPart"; $result = $this->construct($matchrule, $matchrule, null);
  2278. $_433 = NULL;
  2279. do {
  2280. if (( $subres = $this->literal( '_t' ) ) !== FALSE) { $result["text"] .= $subres; }
  2281. else { $_433 = FALSE; break; }
  2282. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2283. if (substr($this->string,$this->pos,1) == '(') {
  2284. $this->pos += 1;
  2285. $result["text"] .= '(';
  2286. }
  2287. else { $_433 = FALSE; break; }
  2288. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2289. $matcher = 'match_'.'QuotedString'; $key = $matcher; $pos = $this->pos;
  2290. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  2291. if ($subres !== FALSE) { $this->store( $result, $subres ); }
  2292. else { $_433 = FALSE; break; }
  2293. $res_430 = $result;
  2294. $pos_430 = $this->pos;
  2295. $_429 = NULL;
  2296. do {
  2297. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2298. if (substr($this->string,$this->pos,1) == ',') {
  2299. $this->pos += 1;
  2300. $result["text"] .= ',';
  2301. }
  2302. else { $_429 = FALSE; break; }
  2303. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2304. $matcher = 'match_'.'CallArguments'; $key = $matcher; $pos = $this->pos;
  2305. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  2306. if ($subres !== FALSE) { $this->store( $result, $subres ); }
  2307. else { $_429 = FALSE; break; }
  2308. $_429 = TRUE; break;
  2309. }
  2310. while(0);
  2311. if( $_429 === FALSE) {
  2312. $result = $res_430;
  2313. $this->pos = $pos_430;
  2314. unset( $res_430 );
  2315. unset( $pos_430 );
  2316. }
  2317. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2318. if (substr($this->string,$this->pos,1) == ')') {
  2319. $this->pos += 1;
  2320. $result["text"] .= ')';
  2321. }
  2322. else { $_433 = FALSE; break; }
  2323. $_433 = TRUE; break;
  2324. }
  2325. while(0);
  2326. if( $_433 === TRUE ) { return $this->finalise($result); }
  2327. if( $_433 === FALSE) { return FALSE; }
  2328. }
  2329. function OldTPart__construct(&$res) {
  2330. $res['php'] = "_t(";
  2331. }
  2332. function OldTPart_QuotedString(&$res, $sub) {
  2333. $entity = $sub['String']['text'];
  2334. if (strpos($entity, '.') === false) {
  2335. $res['php'] .= "\$scope->XML_val('I18NNamespace').'.$entity'";
  2336. }
  2337. else {
  2338. $res['php'] .= "'$entity'";
  2339. }
  2340. }
  2341. function OldTPart_CallArguments(&$res, $sub) {
  2342. $res['php'] .= ',' . $sub['php'];
  2343. }
  2344. function OldTPart__finalise(&$res) {
  2345. $res['php'] .= ')';
  2346. }
  2347. /* OldTTag: "<%" < OldTPart > "%>" */
  2348. protected $match_OldTTag_typestack = array('OldTTag');
  2349. function match_OldTTag ($stack = array()) {
  2350. $matchrule = "OldTTag"; $result = $this->construct($matchrule, $matchrule, null);
  2351. $_440 = NULL;
  2352. do {
  2353. if (( $subres = $this->literal( '<%' ) ) !== FALSE) { $result["text"] .= $subres; }
  2354. else { $_440 = FALSE; break; }
  2355. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2356. $matcher = 'match_'.'OldTPart'; $key = $matcher; $pos = $this->pos;
  2357. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  2358. if ($subres !== FALSE) { $this->store( $result, $subres ); }
  2359. else { $_440 = FALSE; break; }
  2360. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2361. if (( $subres = $this->literal( '%>' ) ) !== FALSE) { $result["text"] .= $subres; }
  2362. else { $_440 = FALSE; break; }
  2363. $_440 = TRUE; break;
  2364. }
  2365. while(0);
  2366. if( $_440 === TRUE ) { return $this->finalise($result); }
  2367. if( $_440 === FALSE) { return FALSE; }
  2368. }
  2369. function OldTTag_OldTPart(&$res, $sub) {
  2370. $res['php'] = $sub['php'];
  2371. }
  2372. /* OldSprintfTag: "<%" < "sprintf" < "(" < OldTPart < "," < CallArguments > ")" > "%>" */
  2373. protected $match_OldSprintfTag_typestack = array('OldSprintfTag');
  2374. function match_OldSprintfTag ($stack = array()) {
  2375. $matchrule = "OldSprintfTag"; $result = $this->construct($matchrule, $matchrule, null);
  2376. $_457 = NULL;
  2377. do {
  2378. if (( $subres = $this->literal( '<%' ) ) !== FALSE) { $result["text"] .= $subres; }
  2379. else { $_457 = FALSE; break; }
  2380. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2381. if (( $subres = $this->literal( 'sprintf' ) ) !== FALSE) { $result["text"] .= $subres; }
  2382. else { $_457 = FALSE; break; }
  2383. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2384. if (substr($this->string,$this->pos,1) == '(') {
  2385. $this->pos += 1;
  2386. $result["text"] .= '(';
  2387. }
  2388. else { $_457 = FALSE; break; }
  2389. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2390. $matcher = 'match_'.'OldTPart'; $key = $matcher; $pos = $this->pos;
  2391. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  2392. if ($subres !== FALSE) { $this->store( $result, $subres ); }
  2393. else { $_457 = FALSE; break; }
  2394. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2395. if (substr($this->string,$this->pos,1) == ',') {
  2396. $this->pos += 1;
  2397. $result["text"] .= ',';
  2398. }
  2399. else { $_457 = FALSE; break; }
  2400. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2401. $matcher = 'match_'.'CallArguments'; $key = $matcher; $pos = $this->pos;
  2402. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  2403. if ($subres !== FALSE) { $this->store( $result, $subres ); }
  2404. else { $_457 = FALSE; break; }
  2405. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2406. if (substr($this->string,$this->pos,1) == ')') {
  2407. $this->pos += 1;
  2408. $result["text"] .= ')';
  2409. }
  2410. else { $_457 = FALSE; break; }
  2411. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2412. if (( $subres = $this->literal( '%>' ) ) !== FALSE) { $result["text"] .= $subres; }
  2413. else { $_457 = FALSE; break; }
  2414. $_457 = TRUE; break;
  2415. }
  2416. while(0);
  2417. if( $_457 === TRUE ) { return $this->finalise($result); }
  2418. if( $_457 === FALSE) { return FALSE; }
  2419. }
  2420. function OldSprintfTag__construct(&$res) {
  2421. $res['php'] = "sprintf(";
  2422. }
  2423. function OldSprintfTag_OldTPart(&$res, $sub) {
  2424. $res['php'] .= $sub['php'];
  2425. }
  2426. function OldSprintfTag_CallArguments(&$res, $sub) {
  2427. $res['php'] .= ',' . $sub['php'] . ')';
  2428. }
  2429. /* OldI18NTag: OldSprintfTag | OldTTag */
  2430. protected $match_OldI18NTag_typestack = array('OldI18NTag');
  2431. function match_OldI18NTag ($stack = array()) {
  2432. $matchrule = "OldI18NTag"; $result = $this->construct($matchrule, $matchrule, null);
  2433. $_462 = NULL;
  2434. do {
  2435. $res_459 = $result;
  2436. $pos_459 = $this->pos;
  2437. $matcher = 'match_'.'OldSprintfTag'; $key = $matcher; $pos = $this->pos;
  2438. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  2439. if ($subres !== FALSE) {
  2440. $this->store( $result, $subres );
  2441. $_462 = TRUE; break;
  2442. }
  2443. $result = $res_459;
  2444. $this->pos = $pos_459;
  2445. $matcher = 'match_'.'OldTTag'; $key = $matcher; $pos = $this->pos;
  2446. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  2447. if ($subres !== FALSE) {
  2448. $this->store( $result, $subres );
  2449. $_462 = TRUE; break;
  2450. }
  2451. $result = $res_459;
  2452. $this->pos = $pos_459;
  2453. $_462 = FALSE; break;
  2454. }
  2455. while(0);
  2456. if( $_462 === TRUE ) { return $this->finalise($result); }
  2457. if( $_462 === FALSE) { return FALSE; }
  2458. }
  2459. function OldI18NTag_STR(&$res, $sub) {
  2460. $res['php'] = '$val .= ' . $sub['php'] . ';';
  2461. }
  2462. /* BlockArguments: :Argument ( < "," < :Argument)* */
  2463. protected $match_BlockArguments_typestack = array('BlockArguments');
  2464. function match_BlockArguments ($stack = array()) {
  2465. $matchrule = "BlockArguments"; $result = $this->construct($matchrule, $matchrule, null);
  2466. $_471 = NULL;
  2467. do {
  2468. $matcher = 'match_'.'Argument'; $key = $matcher; $pos = $this->pos;
  2469. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  2470. if ($subres !== FALSE) {
  2471. $this->store( $result, $subres, "Argument" );
  2472. }
  2473. else { $_471 = FALSE; break; }
  2474. while (true) {
  2475. $res_470 = $result;
  2476. $pos_470 = $this->pos;
  2477. $_469 = NULL;
  2478. do {
  2479. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2480. if (substr($this->string,$this->pos,1) == ',') {
  2481. $this->pos += 1;
  2482. $result["text"] .= ',';
  2483. }
  2484. else { $_469 = FALSE; break; }
  2485. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2486. $matcher = 'match_'.'Argument'; $key = $matcher; $pos = $this->pos;
  2487. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  2488. if ($subres !== FALSE) {
  2489. $this->store( $result, $subres, "Argument" );
  2490. }
  2491. else { $_469 = FALSE; break; }
  2492. $_469 = TRUE; break;
  2493. }
  2494. while(0);
  2495. if( $_469 === FALSE) {
  2496. $result = $res_470;
  2497. $this->pos = $pos_470;
  2498. unset( $res_470 );
  2499. unset( $pos_470 );
  2500. break;
  2501. }
  2502. }
  2503. $_471 = TRUE; break;
  2504. }
  2505. while(0);
  2506. if( $_471 === TRUE ) { return $this->finalise($result); }
  2507. if( $_471 === FALSE) { return FALSE; }
  2508. }
  2509. /* NotBlockTag: "end_" | (("if" | "else_if" | "else" | "require" | "cached" | "uncached" | "cacheblock") ] ) */
  2510. protected $match_NotBlockTag_typestack = array('NotBlockTag');
  2511. function match_NotBlockTag ($stack = array()) {
  2512. $matchrule = "NotBlockTag"; $result = $this->construct($matchrule, $matchrule, null);
  2513. $_505 = NULL;
  2514. do {
  2515. $res_473 = $result;
  2516. $pos_473 = $this->pos;
  2517. if (( $subres = $this->literal( 'end_' ) ) !== FALSE) {
  2518. $result["text"] .= $subres;
  2519. $_505 = TRUE; break;
  2520. }
  2521. $result = $res_473;
  2522. $this->pos = $pos_473;
  2523. $_503 = NULL;
  2524. do {
  2525. $_500 = NULL;
  2526. do {
  2527. $_498 = NULL;
  2528. do {
  2529. $res_475 = $result;
  2530. $pos_475 = $this->pos;
  2531. if (( $subres = $this->literal( 'if' ) ) !== FALSE) {
  2532. $result["text"] .= $subres;
  2533. $_498 = TRUE; break;
  2534. }
  2535. $result = $res_475;
  2536. $this->pos = $pos_475;
  2537. $_496 = NULL;
  2538. do {
  2539. $res_477 = $result;
  2540. $pos_477 = $this->pos;
  2541. if (( $subres = $this->literal( 'else_if' ) ) !== FALSE) {
  2542. $result["text"] .= $subres;
  2543. $_496 = TRUE; break;
  2544. }
  2545. $result = $res_477;
  2546. $this->pos = $pos_477;
  2547. $_494 = NULL;
  2548. do {
  2549. $res_479 = $result;
  2550. $pos_479 = $this->pos;
  2551. if (( $subres = $this->literal( 'else' ) ) !== FALSE) {
  2552. $result["text"] .= $subres;
  2553. $_494 = TRUE; break;
  2554. }
  2555. $result = $res_479;
  2556. $this->pos = $pos_479;
  2557. $_492 = NULL;
  2558. do {
  2559. $res_481 = $result;
  2560. $pos_481 = $this->pos;
  2561. if (( $subres = $this->literal( 'require' ) ) !== FALSE) {
  2562. $result["text"] .= $subres;
  2563. $_492 = TRUE; break;
  2564. }
  2565. $result = $res_481;
  2566. $this->pos = $pos_481;
  2567. $_490 = NULL;
  2568. do {
  2569. $res_483 = $result;
  2570. $pos_483 = $this->pos;
  2571. if (( $subres = $this->literal( 'cached' ) ) !== FALSE) {
  2572. $result["text"] .= $subres;
  2573. $_490 = TRUE; break;
  2574. }
  2575. $result = $res_483;
  2576. $this->pos = $pos_483;
  2577. $_488 = NULL;
  2578. do {
  2579. $res_485 = $result;
  2580. $pos_485 = $this->pos;
  2581. if (( $subres = $this->literal( 'uncached' ) ) !== FALSE) {
  2582. $result["text"] .= $subres;
  2583. $_488 = TRUE; break;
  2584. }
  2585. $result = $res_485;
  2586. $this->pos = $pos_485;
  2587. if (( $subres = $this->literal( 'cacheblock' ) ) !== FALSE) {
  2588. $result["text"] .= $subres;
  2589. $_488 = TRUE; break;
  2590. }
  2591. $result = $res_485;
  2592. $this->pos = $pos_485;
  2593. $_488 = FALSE; break;
  2594. }
  2595. while(0);
  2596. if( $_488 === TRUE ) { $_490 = TRUE; break; }
  2597. $result = $res_483;
  2598. $this->pos = $pos_483;
  2599. $_490 = FALSE; break;
  2600. }
  2601. while(0);
  2602. if( $_490 === TRUE ) { $_492 = TRUE; break; }
  2603. $result = $res_481;
  2604. $this->pos = $pos_481;
  2605. $_492 = FALSE; break;
  2606. }
  2607. while(0);
  2608. if( $_492 === TRUE ) { $_494 = TRUE; break; }
  2609. $result = $res_479;
  2610. $this->pos = $pos_479;
  2611. $_494 = FALSE; break;
  2612. }
  2613. while(0);
  2614. if( $_494 === TRUE ) { $_496 = TRUE; break; }
  2615. $result = $res_477;
  2616. $this->pos = $pos_477;
  2617. $_496 = FALSE; break;
  2618. }
  2619. while(0);
  2620. if( $_496 === TRUE ) { $_498 = TRUE; break; }
  2621. $result = $res_475;
  2622. $this->pos = $pos_475;
  2623. $_498 = FALSE; break;
  2624. }
  2625. while(0);
  2626. if( $_498 === FALSE) { $_500 = FALSE; break; }
  2627. $_500 = TRUE; break;
  2628. }
  2629. while(0);
  2630. if( $_500 === FALSE) { $_503 = FALSE; break; }
  2631. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2632. else { $_503 = FALSE; break; }
  2633. $_503 = TRUE; break;
  2634. }
  2635. while(0);
  2636. if( $_503 === TRUE ) { $_505 = TRUE; break; }
  2637. $result = $res_473;
  2638. $this->pos = $pos_473;
  2639. $_505 = FALSE; break;
  2640. }
  2641. while(0);
  2642. if( $_505 === TRUE ) { return $this->finalise($result); }
  2643. if( $_505 === FALSE) { return FALSE; }
  2644. }
  2645. /* ClosedBlock: '<%' < !NotBlockTag BlockName:Word ( [ :BlockArguments ] )? > Zap:'%>' Template:$TemplateMatcher? '<%' < 'end_' '$BlockName' > '%>' */
  2646. protected $match_ClosedBlock_typestack = array('ClosedBlock');
  2647. function match_ClosedBlock ($stack = array()) {
  2648. $matchrule = "ClosedBlock"; $result = $this->construct($matchrule, $matchrule, null);
  2649. $_525 = NULL;
  2650. do {
  2651. if (( $subres = $this->literal( '<%' ) ) !== FALSE) { $result["text"] .= $subres; }
  2652. else { $_525 = FALSE; break; }
  2653. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2654. $res_509 = $result;
  2655. $pos_509 = $this->pos;
  2656. $matcher = 'match_'.'NotBlockTag'; $key = $matcher; $pos = $this->pos;
  2657. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  2658. if ($subres !== FALSE) {
  2659. $this->store( $result, $subres );
  2660. $result = $res_509;
  2661. $this->pos = $pos_509;
  2662. $_525 = FALSE; break;
  2663. }
  2664. else {
  2665. $result = $res_509;
  2666. $this->pos = $pos_509;
  2667. }
  2668. $matcher = 'match_'.'Word'; $key = $matcher; $pos = $this->pos;
  2669. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  2670. if ($subres !== FALSE) {
  2671. $this->store( $result, $subres, "BlockName" );
  2672. }
  2673. else { $_525 = FALSE; break; }
  2674. $res_515 = $result;
  2675. $pos_515 = $this->pos;
  2676. $_514 = NULL;
  2677. do {
  2678. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2679. else { $_514 = FALSE; break; }
  2680. $matcher = 'match_'.'BlockArguments'; $key = $matcher; $pos = $this->pos;
  2681. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  2682. if ($subres !== FALSE) {
  2683. $this->store( $result, $subres, "BlockArguments" );
  2684. }
  2685. else { $_514 = FALSE; break; }
  2686. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2687. else { $_514 = FALSE; break; }
  2688. $_514 = TRUE; break;
  2689. }
  2690. while(0);
  2691. if( $_514 === FALSE) {
  2692. $result = $res_515;
  2693. $this->pos = $pos_515;
  2694. unset( $res_515 );
  2695. unset( $pos_515 );
  2696. }
  2697. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2698. $stack[] = $result; $result = $this->construct( $matchrule, "Zap" );
  2699. if (( $subres = $this->literal( '%>' ) ) !== FALSE) {
  2700. $result["text"] .= $subres;
  2701. $subres = $result; $result = array_pop($stack);
  2702. $this->store( $result, $subres, 'Zap' );
  2703. }
  2704. else {
  2705. $result = array_pop($stack);
  2706. $_525 = FALSE; break;
  2707. }
  2708. $res_518 = $result;
  2709. $pos_518 = $this->pos;
  2710. $matcher = 'match_'.$this->expression($result, $stack, 'TemplateMatcher'); $key = $matcher; $pos = $this->pos;
  2711. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  2712. if ($subres !== FALSE) {
  2713. $this->store( $result, $subres, "Template" );
  2714. }
  2715. else {
  2716. $result = $res_518;
  2717. $this->pos = $pos_518;
  2718. unset( $res_518 );
  2719. unset( $pos_518 );
  2720. }
  2721. if (( $subres = $this->literal( '<%' ) ) !== FALSE) { $result["text"] .= $subres; }
  2722. else { $_525 = FALSE; break; }
  2723. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2724. if (( $subres = $this->literal( 'end_' ) ) !== FALSE) { $result["text"] .= $subres; }
  2725. else { $_525 = FALSE; break; }
  2726. if (( $subres = $this->literal( ''.$this->expression($result, $stack, 'BlockName').'' ) ) !== FALSE) { $result["text"] .= $subres; }
  2727. else { $_525 = FALSE; break; }
  2728. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2729. if (( $subres = $this->literal( '%>' ) ) !== FALSE) { $result["text"] .= $subres; }
  2730. else { $_525 = FALSE; break; }
  2731. $_525 = TRUE; break;
  2732. }
  2733. while(0);
  2734. if( $_525 === TRUE ) { return $this->finalise($result); }
  2735. if( $_525 === FALSE) { return FALSE; }
  2736. }
  2737. /**
  2738. * As mentioned in the parser comment, block handling is kept fairly generic for extensibility. The match rule
  2739. * builds up two important elements in the match result array:
  2740. * 'ArgumentCount' - how many arguments were passed in the opening tag
  2741. * 'Arguments' an array of the Argument match rule result arrays
  2742. *
  2743. * Once a block has successfully been matched against, it will then look for the actual handler, which should
  2744. * be on this class (either defined or extended on) as ClosedBlock_Handler_Name(&$res), where Name is the
  2745. * tag name, first letter captialized (i.e Control, Loop, With, etc).
  2746. *
  2747. * This function will be called with the match rule result array as it's first argument. It should return
  2748. * the php result of this block as it's return value, or throw an error if incorrect arguments were passed.
  2749. */
  2750. function ClosedBlock__construct(&$res) {
  2751. $res['ArgumentCount'] = 0;
  2752. }
  2753. function ClosedBlock_BlockArguments(&$res, $sub) {
  2754. if (isset($sub['Argument']['ArgumentMode'])) {
  2755. $res['Arguments'] = array($sub['Argument']);
  2756. $res['ArgumentCount'] = 1;
  2757. }
  2758. else {
  2759. $res['Arguments'] = $sub['Argument'];
  2760. $res['ArgumentCount'] = count($res['Arguments']);
  2761. }
  2762. }
  2763. function ClosedBlock__finalise(&$res) {
  2764. $blockname = $res['BlockName']['text'];
  2765. $method = 'ClosedBlock_Handle_'.ucfirst(strtolower($blockname));
  2766. if (method_exists($this, $method)) $res['php'] = $this->$method($res);
  2767. else {
  2768. throw new SSTemplateParseException('Unknown closed block "'.$blockname.'" encountered. Perhaps you are not supposed to close this block, or have mis-spelled it?', $this);
  2769. }
  2770. }
  2771. /**
  2772. * This is an example of a block handler function. This one handles the loop tag.
  2773. */
  2774. function ClosedBlock_Handle_Loop(&$res) {
  2775. if ($res['ArgumentCount'] != 1) {
  2776. throw new SSTemplateParseException('Either no or too many arguments in control block. Must be one argument only.', $this);
  2777. }
  2778. $arg = $res['Arguments'][0];
  2779. if ($arg['ArgumentMode'] == 'string') {
  2780. throw new SSTemplateParseException('Control block cant take string as argument.', $this);
  2781. }
  2782. $on = str_replace('$$FINAL', 'obj', ($arg['ArgumentMode'] == 'default') ? $arg['lookup_php'] : $arg['php']);
  2783. return
  2784. $on . '; $scope->pushScope(); while (($key = $scope->next()) !== false) {' . PHP_EOL .
  2785. $res['Template']['php'] . PHP_EOL .
  2786. '}; $scope->popScope(); ';
  2787. }
  2788. /**
  2789. * The deprecated closed block handler for control blocks
  2790. * @deprecated
  2791. */
  2792. function ClosedBlock_Handle_Control(&$res) {
  2793. return $this->ClosedBlock_Handle_Loop($res);
  2794. }
  2795. /**
  2796. * The closed block handler for with blocks
  2797. */
  2798. function ClosedBlock_Handle_With(&$res) {
  2799. if ($res['ArgumentCount'] != 1) {
  2800. throw new SSTemplateParseException('Either no or too many arguments in with block. Must be one argument only.', $this);
  2801. }
  2802. $arg = $res['Arguments'][0];
  2803. if ($arg['ArgumentMode'] == 'string') {
  2804. throw new SSTemplateParseException('Control block cant take string as argument.', $this);
  2805. }
  2806. $on = str_replace('$$FINAL', 'obj', ($arg['ArgumentMode'] == 'default') ? $arg['lookup_php'] : $arg['php']);
  2807. return
  2808. $on . '; $scope->pushScope();' . PHP_EOL .
  2809. $res['Template']['php'] . PHP_EOL .
  2810. '; $scope->popScope(); ';
  2811. }
  2812. /* OpenBlock: '<%' < !NotBlockTag BlockName:Word ( [ :BlockArguments ] )? > '%>' */
  2813. protected $match_OpenBlock_typestack = array('OpenBlock');
  2814. function match_OpenBlock ($stack = array()) {
  2815. $matchrule = "OpenBlock"; $result = $this->construct($matchrule, $matchrule, null);
  2816. $_538 = NULL;
  2817. do {
  2818. if (( $subres = $this->literal( '<%' ) ) !== FALSE) { $result["text"] .= $subres; }
  2819. else { $_538 = FALSE; break; }
  2820. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2821. $res_529 = $result;
  2822. $pos_529 = $this->pos;
  2823. $matcher = 'match_'.'NotBlockTag'; $key = $matcher; $pos = $this->pos;
  2824. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  2825. if ($subres !== FALSE) {
  2826. $this->store( $result, $subres );
  2827. $result = $res_529;
  2828. $this->pos = $pos_529;
  2829. $_538 = FALSE; break;
  2830. }
  2831. else {
  2832. $result = $res_529;
  2833. $this->pos = $pos_529;
  2834. }
  2835. $matcher = 'match_'.'Word'; $key = $matcher; $pos = $this->pos;
  2836. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  2837. if ($subres !== FALSE) {
  2838. $this->store( $result, $subres, "BlockName" );
  2839. }
  2840. else { $_538 = FALSE; break; }
  2841. $res_535 = $result;
  2842. $pos_535 = $this->pos;
  2843. $_534 = NULL;
  2844. do {
  2845. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2846. else { $_534 = FALSE; break; }
  2847. $matcher = 'match_'.'BlockArguments'; $key = $matcher; $pos = $this->pos;
  2848. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  2849. if ($subres !== FALSE) {
  2850. $this->store( $result, $subres, "BlockArguments" );
  2851. }
  2852. else { $_534 = FALSE; break; }
  2853. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2854. else { $_534 = FALSE; break; }
  2855. $_534 = TRUE; break;
  2856. }
  2857. while(0);
  2858. if( $_534 === FALSE) {
  2859. $result = $res_535;
  2860. $this->pos = $pos_535;
  2861. unset( $res_535 );
  2862. unset( $pos_535 );
  2863. }
  2864. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2865. if (( $subres = $this->literal( '%>' ) ) !== FALSE) { $result["text"] .= $subres; }
  2866. else { $_538 = FALSE; break; }
  2867. $_538 = TRUE; break;
  2868. }
  2869. while(0);
  2870. if( $_538 === TRUE ) { return $this->finalise($result); }
  2871. if( $_538 === FALSE) { return FALSE; }
  2872. }
  2873. function OpenBlock__construct(&$res) {
  2874. $res['ArgumentCount'] = 0;
  2875. }
  2876. function OpenBlock_BlockArguments(&$res, $sub) {
  2877. if (isset($sub['Argument']['ArgumentMode'])) {
  2878. $res['Arguments'] = array($sub['Argument']);
  2879. $res['ArgumentCount'] = 1;
  2880. }
  2881. else {
  2882. $res['Arguments'] = $sub['Argument'];
  2883. $res['ArgumentCount'] = count($res['Arguments']);
  2884. }
  2885. }
  2886. function OpenBlock__finalise(&$res) {
  2887. $blockname = $res['BlockName']['text'];
  2888. $method = 'OpenBlock_Handle_'.ucfirst(strtolower($blockname));
  2889. if (method_exists($this, $method)) $res['php'] = $this->$method($res);
  2890. else {
  2891. throw new SSTemplateParseException('Unknown open block "'.$blockname.'" encountered. Perhaps you missed the closing tag or have mis-spelled it?', $this);
  2892. }
  2893. }
  2894. /**
  2895. * This is an open block handler, for the <% include %> tag
  2896. */
  2897. function OpenBlock_Handle_Include(&$res) {
  2898. if ($res['ArgumentCount'] != 1) throw new SSTemplateParseException('Include takes exactly one argument', $this);
  2899. $arg = $res['Arguments'][0];
  2900. $php = ($arg['ArgumentMode'] == 'default') ? $arg['string_php'] : $arg['php'];
  2901. if($this->includeDebuggingComments) { // Add include filename comments on dev sites
  2902. return
  2903. '$val .= \'<!-- include '.$php.' -->\';'. "\n".
  2904. '$val .= SSViewer::parse_template('.$php.', $scope->getItem());'. "\n".
  2905. '$val .= \'<!-- end include '.$php.' -->\';'. "\n";
  2906. }
  2907. else {
  2908. return
  2909. '$val .= SSViewer::execute_template('.$php.', $scope->getItem());'. "\n";
  2910. }
  2911. }
  2912. /**
  2913. * This is an open block handler, for the <% debug %> utility tag
  2914. */
  2915. function OpenBlock_Handle_Debug(&$res) {
  2916. if ($res['ArgumentCount'] == 0) return '$scope->debug();';
  2917. else if ($res['ArgumentCount'] == 1) {
  2918. $arg = $res['Arguments'][0];
  2919. if ($arg['ArgumentMode'] == 'string') return 'Debug::show('.$arg['php'].');';
  2920. $php = ($arg['ArgumentMode'] == 'default') ? $arg['lookup_php'] : $arg['php'];
  2921. return '$val .= Debug::show('.str_replace('FINALGET!', 'cachedCall', $php).');';
  2922. }
  2923. else {
  2924. throw new SSTemplateParseException('Debug takes 0 or 1 argument only.', $this);
  2925. }
  2926. }
  2927. /**
  2928. * This is an open block handler, for the <% base_tag %> tag
  2929. */
  2930. function OpenBlock_Handle_Base_tag(&$res) {
  2931. if ($res['ArgumentCount'] != 0) throw new SSTemplateParseException('Base_tag takes no arguments', $this);
  2932. return '$val .= SSViewer::get_base_tag($val);';
  2933. }
  2934. /**
  2935. * This is an open block handler, for the <% current_page %> tag
  2936. */
  2937. function OpenBlock_Handle_Current_page(&$res) {
  2938. if ($res['ArgumentCount'] != 0) throw new SSTemplateParseException('Current_page takes no arguments', $this);
  2939. return '$val .= $_SERVER[SCRIPT_URL];';
  2940. }
  2941. /* MismatchedEndBlock: '<%' < 'end_' :Word > '%>' */
  2942. protected $match_MismatchedEndBlock_typestack = array('MismatchedEndBlock');
  2943. function match_MismatchedEndBlock ($stack = array()) {
  2944. $matchrule = "MismatchedEndBlock"; $result = $this->construct($matchrule, $matchrule, null);
  2945. $_546 = NULL;
  2946. do {
  2947. if (( $subres = $this->literal( '<%' ) ) !== FALSE) { $result["text"] .= $subres; }
  2948. else { $_546 = FALSE; break; }
  2949. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2950. if (( $subres = $this->literal( 'end_' ) ) !== FALSE) { $result["text"] .= $subres; }
  2951. else { $_546 = FALSE; break; }
  2952. $matcher = 'match_'.'Word'; $key = $matcher; $pos = $this->pos;
  2953. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  2954. if ($subres !== FALSE) {
  2955. $this->store( $result, $subres, "Word" );
  2956. }
  2957. else { $_546 = FALSE; break; }
  2958. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2959. if (( $subres = $this->literal( '%>' ) ) !== FALSE) { $result["text"] .= $subres; }
  2960. else { $_546 = FALSE; break; }
  2961. $_546 = TRUE; break;
  2962. }
  2963. while(0);
  2964. if( $_546 === TRUE ) { return $this->finalise($result); }
  2965. if( $_546 === FALSE) { return FALSE; }
  2966. }
  2967. function MismatchedEndBlock__finalise(&$res) {
  2968. $blockname = $res['Word']['text'];
  2969. throw new SSTemplateParseException('Unexpected close tag end_'.$blockname.' encountered. Perhaps you have mis-nested blocks, or have mis-spelled a tag?', $this);
  2970. }
  2971. /* MalformedOpenTag: '<%' < !NotBlockTag Tag:Word !( ( [ :BlockArguments ] )? > '%>' ) */
  2972. protected $match_MalformedOpenTag_typestack = array('MalformedOpenTag');
  2973. function match_MalformedOpenTag ($stack = array()) {
  2974. $matchrule = "MalformedOpenTag"; $result = $this->construct($matchrule, $matchrule, null);
  2975. $_561 = NULL;
  2976. do {
  2977. if (( $subres = $this->literal( '<%' ) ) !== FALSE) { $result["text"] .= $subres; }
  2978. else { $_561 = FALSE; break; }
  2979. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  2980. $res_550 = $result;
  2981. $pos_550 = $this->pos;
  2982. $matcher = 'match_'.'NotBlockTag'; $key = $matcher; $pos = $this->pos;
  2983. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  2984. if ($subres !== FALSE) {
  2985. $this->store( $result, $subres );
  2986. $result = $res_550;
  2987. $this->pos = $pos_550;
  2988. $_561 = FALSE; break;
  2989. }
  2990. else {
  2991. $result = $res_550;
  2992. $this->pos = $pos_550;
  2993. }
  2994. $matcher = 'match_'.'Word'; $key = $matcher; $pos = $this->pos;
  2995. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  2996. if ($subres !== FALSE) {
  2997. $this->store( $result, $subres, "Tag" );
  2998. }
  2999. else { $_561 = FALSE; break; }
  3000. $res_560 = $result;
  3001. $pos_560 = $this->pos;
  3002. $_559 = NULL;
  3003. do {
  3004. $res_556 = $result;
  3005. $pos_556 = $this->pos;
  3006. $_555 = NULL;
  3007. do {
  3008. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  3009. else { $_555 = FALSE; break; }
  3010. $matcher = 'match_'.'BlockArguments'; $key = $matcher; $pos = $this->pos;
  3011. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  3012. if ($subres !== FALSE) {
  3013. $this->store( $result, $subres, "BlockArguments" );
  3014. }
  3015. else { $_555 = FALSE; break; }
  3016. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  3017. else { $_555 = FALSE; break; }
  3018. $_555 = TRUE; break;
  3019. }
  3020. while(0);
  3021. if( $_555 === FALSE) {
  3022. $result = $res_556;
  3023. $this->pos = $pos_556;
  3024. unset( $res_556 );
  3025. unset( $pos_556 );
  3026. }
  3027. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  3028. if (( $subres = $this->literal( '%>' ) ) !== FALSE) { $result["text"] .= $subres; }
  3029. else { $_559 = FALSE; break; }
  3030. $_559 = TRUE; break;
  3031. }
  3032. while(0);
  3033. if( $_559 === TRUE ) {
  3034. $result = $res_560;
  3035. $this->pos = $pos_560;
  3036. $_561 = FALSE; break;
  3037. }
  3038. if( $_559 === FALSE) {
  3039. $result = $res_560;
  3040. $this->pos = $pos_560;
  3041. }
  3042. $_561 = TRUE; break;
  3043. }
  3044. while(0);
  3045. if( $_561 === TRUE ) { return $this->finalise($result); }
  3046. if( $_561 === FALSE) { return FALSE; }
  3047. }
  3048. function MalformedOpenTag__finalise(&$res) {
  3049. $tag = $res['Tag']['text'];
  3050. throw new SSTemplateParseException("Malformed opening block tag $tag. Perhaps you have tried to use operators?", $this);
  3051. }
  3052. /* MalformedCloseTag: '<%' < Tag:('end_' :Word ) !( > '%>' ) */
  3053. protected $match_MalformedCloseTag_typestack = array('MalformedCloseTag');
  3054. function match_MalformedCloseTag ($stack = array()) {
  3055. $matchrule = "MalformedCloseTag"; $result = $this->construct($matchrule, $matchrule, null);
  3056. $_573 = NULL;
  3057. do {
  3058. if (( $subres = $this->literal( '<%' ) ) !== FALSE) { $result["text"] .= $subres; }
  3059. else { $_573 = FALSE; break; }
  3060. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  3061. $stack[] = $result; $result = $this->construct( $matchrule, "Tag" );
  3062. $_567 = NULL;
  3063. do {
  3064. if (( $subres = $this->literal( 'end_' ) ) !== FALSE) { $result["text"] .= $subres; }
  3065. else { $_567 = FALSE; break; }
  3066. $matcher = 'match_'.'Word'; $key = $matcher; $pos = $this->pos;
  3067. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  3068. if ($subres !== FALSE) {
  3069. $this->store( $result, $subres, "Word" );
  3070. }
  3071. else { $_567 = FALSE; break; }
  3072. $_567 = TRUE; break;
  3073. }
  3074. while(0);
  3075. if( $_567 === TRUE ) {
  3076. $subres = $result; $result = array_pop($stack);
  3077. $this->store( $result, $subres, 'Tag' );
  3078. }
  3079. if( $_567 === FALSE) {
  3080. $result = array_pop($stack);
  3081. $_573 = FALSE; break;
  3082. }
  3083. $res_572 = $result;
  3084. $pos_572 = $this->pos;
  3085. $_571 = NULL;
  3086. do {
  3087. if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
  3088. if (( $subres = $this->literal( '%>' ) ) !== FALSE) { $result["text"] .= $subres; }
  3089. else { $_571 = FALSE; break; }
  3090. $_571 = TRUE; break;
  3091. }
  3092. while(0);
  3093. if( $_571 === TRUE ) {
  3094. $result = $res_572;
  3095. $this->pos = $pos_572;
  3096. $_573 = FALSE; break;
  3097. }
  3098. if( $_571 === FALSE) {
  3099. $result = $res_572;
  3100. $this->pos = $pos_572;
  3101. }
  3102. $_573 = TRUE; break;
  3103. }
  3104. while(0);
  3105. if( $_573 === TRUE ) { return $this->finalise($result); }
  3106. if( $_573 === FALSE) { return FALSE; }
  3107. }
  3108. function MalformedCloseTag__finalise(&$res) {
  3109. $tag = $res['Tag']['text'];
  3110. throw new SSTemplateParseException("Malformed closing block tag $tag. Perhaps you have tried to pass an argument to one?", $this);
  3111. }
  3112. /* MalformedBlock: MalformedOpenTag | MalformedCloseTag */
  3113. protected $match_MalformedBlock_typestack = array('MalformedBlock');
  3114. function match_MalformedBlock ($stack = array()) {
  3115. $matchrule = "MalformedBlock"; $result = $this->construct($matchrule, $matchrule, null);
  3116. $_578 = NULL;
  3117. do {
  3118. $res_575 = $result;
  3119. $pos_575 = $this->pos;
  3120. $matcher = 'match_'.'MalformedOpenTag'; $key = $matcher; $pos = $this->pos;
  3121. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  3122. if ($subres !== FALSE) {
  3123. $this->store( $result, $subres );
  3124. $_578 = TRUE; break;
  3125. }
  3126. $result = $res_575;
  3127. $this->pos = $pos_575;
  3128. $matcher = 'match_'.'MalformedCloseTag'; $key = $matcher; $pos = $this->pos;
  3129. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  3130. if ($subres !== FALSE) {
  3131. $this->store( $result, $subres );
  3132. $_578 = TRUE; break;
  3133. }
  3134. $result = $res_575;
  3135. $this->pos = $pos_575;
  3136. $_578 = FALSE; break;
  3137. }
  3138. while(0);
  3139. if( $_578 === TRUE ) { return $this->finalise($result); }
  3140. if( $_578 === FALSE) { return FALSE; }
  3141. }
  3142. /* Comment: "<%--" (!"--%>" /./)+ "--%>" */
  3143. protected $match_Comment_typestack = array('Comment');
  3144. function match_Comment ($stack = array()) {
  3145. $matchrule = "Comment"; $result = $this->construct($matchrule, $matchrule, null);
  3146. $_586 = NULL;
  3147. do {
  3148. if (( $subres = $this->literal( '<%--' ) ) !== FALSE) { $result["text"] .= $subres; }
  3149. else { $_586 = FALSE; break; }
  3150. $count = 0;
  3151. while (true) {
  3152. $res_584 = $result;
  3153. $pos_584 = $this->pos;
  3154. $_583 = NULL;
  3155. do {
  3156. $res_581 = $result;
  3157. $pos_581 = $this->pos;
  3158. if (( $subres = $this->literal( '--%>' ) ) !== FALSE) {
  3159. $result["text"] .= $subres;
  3160. $result = $res_581;
  3161. $this->pos = $pos_581;
  3162. $_583 = FALSE; break;
  3163. }
  3164. else {
  3165. $result = $res_581;
  3166. $this->pos = $pos_581;
  3167. }
  3168. if (( $subres = $this->rx( '/./' ) ) !== FALSE) { $result["text"] .= $subres; }
  3169. else { $_583 = FALSE; break; }
  3170. $_583 = TRUE; break;
  3171. }
  3172. while(0);
  3173. if( $_583 === FALSE) {
  3174. $result = $res_584;
  3175. $this->pos = $pos_584;
  3176. unset( $res_584 );
  3177. unset( $pos_584 );
  3178. break;
  3179. }
  3180. $count += 1;
  3181. }
  3182. if ($count > 0) { }
  3183. else { $_586 = FALSE; break; }
  3184. if (( $subres = $this->literal( '--%>' ) ) !== FALSE) { $result["text"] .= $subres; }
  3185. else { $_586 = FALSE; break; }
  3186. $_586 = TRUE; break;
  3187. }
  3188. while(0);
  3189. if( $_586 === TRUE ) { return $this->finalise($result); }
  3190. if( $_586 === FALSE) { return FALSE; }
  3191. }
  3192. function Comment__construct(&$res) {
  3193. $res['php'] = '';
  3194. }
  3195. /* TopTemplate: (Comment | If | Require | CacheBlock | UncachedBlock | OldI18NTag | ClosedBlock | OpenBlock | MalformedBlock | MismatchedEndBlock | Injection | Text)+ */
  3196. protected $match_TopTemplate_typestack = array('TopTemplate','Template');
  3197. function match_TopTemplate ($stack = array()) {
  3198. $matchrule = "TopTemplate"; $result = $this->construct($matchrule, $matchrule, array('TemplateMatcher' => 'Template'));
  3199. $count = 0;
  3200. while (true) {
  3201. $res_634 = $result;
  3202. $pos_634 = $this->pos;
  3203. $_633 = NULL;
  3204. do {
  3205. $_631 = NULL;
  3206. do {
  3207. $res_588 = $result;
  3208. $pos_588 = $this->pos;
  3209. $matcher = 'match_'.'Comment'; $key = $matcher; $pos = $this->pos;
  3210. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  3211. if ($subres !== FALSE) {
  3212. $this->store( $result, $subres );
  3213. $_631 = TRUE; break;
  3214. }
  3215. $result = $res_588;
  3216. $this->pos = $pos_588;
  3217. $_629 = NULL;
  3218. do {
  3219. $res_590 = $result;
  3220. $pos_590 = $this->pos;
  3221. $matcher = 'match_'.'If'; $key = $matcher; $pos = $this->pos;
  3222. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  3223. if ($subres !== FALSE) {
  3224. $this->store( $result, $subres );
  3225. $_629 = TRUE; break;
  3226. }
  3227. $result = $res_590;
  3228. $this->pos = $pos_590;
  3229. $_627 = NULL;
  3230. do {
  3231. $res_592 = $result;
  3232. $pos_592 = $this->pos;
  3233. $matcher = 'match_'.'Require'; $key = $matcher; $pos = $this->pos;
  3234. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  3235. if ($subres !== FALSE) {
  3236. $this->store( $result, $subres );
  3237. $_627 = TRUE; break;
  3238. }
  3239. $result = $res_592;
  3240. $this->pos = $pos_592;
  3241. $_625 = NULL;
  3242. do {
  3243. $res_594 = $result;
  3244. $pos_594 = $this->pos;
  3245. $matcher = 'match_'.'CacheBlock'; $key = $matcher; $pos = $this->pos;
  3246. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  3247. if ($subres !== FALSE) {
  3248. $this->store( $result, $subres );
  3249. $_625 = TRUE; break;
  3250. }
  3251. $result = $res_594;
  3252. $this->pos = $pos_594;
  3253. $_623 = NULL;
  3254. do {
  3255. $res_596 = $result;
  3256. $pos_596 = $this->pos;
  3257. $matcher = 'match_'.'UncachedBlock'; $key = $matcher; $pos = $this->pos;
  3258. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  3259. if ($subres !== FALSE) {
  3260. $this->store( $result, $subres );
  3261. $_623 = TRUE; break;
  3262. }
  3263. $result = $res_596;
  3264. $this->pos = $pos_596;
  3265. $_621 = NULL;
  3266. do {
  3267. $res_598 = $result;
  3268. $pos_598 = $this->pos;
  3269. $matcher = 'match_'.'OldI18NTag'; $key = $matcher; $pos = $this->pos;
  3270. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  3271. if ($subres !== FALSE) {
  3272. $this->store( $result, $subres );
  3273. $_621 = TRUE; break;
  3274. }
  3275. $result = $res_598;
  3276. $this->pos = $pos_598;
  3277. $_619 = NULL;
  3278. do {
  3279. $res_600 = $result;
  3280. $pos_600 = $this->pos;
  3281. $matcher = 'match_'.'ClosedBlock'; $key = $matcher; $pos = $this->pos;
  3282. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  3283. if ($subres !== FALSE) {
  3284. $this->store( $result, $subres );
  3285. $_619 = TRUE; break;
  3286. }
  3287. $result = $res_600;
  3288. $this->pos = $pos_600;
  3289. $_617 = NULL;
  3290. do {
  3291. $res_602 = $result;
  3292. $pos_602 = $this->pos;
  3293. $matcher = 'match_'.'OpenBlock'; $key = $matcher; $pos = $this->pos;
  3294. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  3295. if ($subres !== FALSE) {
  3296. $this->store( $result, $subres );
  3297. $_617 = TRUE; break;
  3298. }
  3299. $result = $res_602;
  3300. $this->pos = $pos_602;
  3301. $_615 = NULL;
  3302. do {
  3303. $res_604 = $result;
  3304. $pos_604 = $this->pos;
  3305. $matcher = 'match_'.'MalformedBlock'; $key = $matcher; $pos = $this->pos;
  3306. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  3307. if ($subres !== FALSE) {
  3308. $this->store( $result, $subres );
  3309. $_615 = TRUE; break;
  3310. }
  3311. $result = $res_604;
  3312. $this->pos = $pos_604;
  3313. $_613 = NULL;
  3314. do {
  3315. $res_606 = $result;
  3316. $pos_606 = $this->pos;
  3317. $matcher = 'match_'.'MismatchedEndBlock'; $key = $matcher; $pos = $this->pos;
  3318. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  3319. if ($subres !== FALSE) {
  3320. $this->store( $result, $subres );
  3321. $_613 = TRUE; break;
  3322. }
  3323. $result = $res_606;
  3324. $this->pos = $pos_606;
  3325. $_611 = NULL;
  3326. do {
  3327. $res_608 = $result;
  3328. $pos_608 = $this->pos;
  3329. $matcher = 'match_'.'Injection'; $key = $matcher; $pos = $this->pos;
  3330. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  3331. if ($subres !== FALSE) {
  3332. $this->store( $result, $subres );
  3333. $_611 = TRUE; break;
  3334. }
  3335. $result = $res_608;
  3336. $this->pos = $pos_608;
  3337. $matcher = 'match_'.'Text'; $key = $matcher; $pos = $this->pos;
  3338. $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );
  3339. if ($subres !== FALSE) {
  3340. $this->store( $result, $subres );
  3341. $_611 = TRUE; break;
  3342. }
  3343. $result = $res_608;
  3344. $this->pos = $pos_608;
  3345. $_611 = FALSE; break;
  3346. }
  3347. while(0);
  3348. if( $_611 === TRUE ) { $_613 = TRUE; break; }
  3349. $result = $res_606;
  3350. $this->pos = $pos_606;
  3351. $_613 = FALSE; break;
  3352. }
  3353. while(0);
  3354. if( $_613 === TRUE ) { $_615 = TRUE; break; }
  3355. $result = $res_604;
  3356. $this->pos = $pos_604;
  3357. $_615 = FALSE; break;
  3358. }
  3359. while(0);
  3360. if( $_615 === TRUE ) { $_617 = TRUE; break; }
  3361. $result = $res_602;
  3362. $this->pos = $pos_602;
  3363. $_617 = FALSE; break;
  3364. }
  3365. while(0);
  3366. if( $_617 === TRUE ) { $_619 = TRUE; break; }
  3367. $result = $res_600;
  3368. $this->pos = $pos_600;
  3369. $_619 = FALSE; break;
  3370. }
  3371. while(0);
  3372. if( $_619 === TRUE ) { $_621 = TRUE; break; }
  3373. $result = $res_598;
  3374. $this->pos = $pos_598;
  3375. $_621 = FALSE; break;
  3376. }
  3377. while(0);
  3378. if( $_621 === TRUE ) { $_623 = TRUE; break; }
  3379. $result = $res_596;
  3380. $this->pos = $pos_596;
  3381. $_623 = FALSE; break;
  3382. }
  3383. while(0);
  3384. if( $_623 === TRUE ) { $_625 = TRUE; break; }
  3385. $result = $res_594;
  3386. $this->pos = $pos_594;
  3387. $_625 = FALSE; break;
  3388. }
  3389. while(0);
  3390. if( $_625 === TRUE ) { $_627 = TRUE; break; }
  3391. $result = $res_592;
  3392. $this->pos = $pos_592;
  3393. $_627 = FALSE; break;
  3394. }
  3395. while(0);
  3396. if( $_627 === TRUE ) { $_629 = TRUE; break; }
  3397. $result = $res_590;
  3398. $this->pos = $pos_590;
  3399. $_629 = FALSE; break;
  3400. }
  3401. while(0);
  3402. if( $_629 === TRUE ) { $_631 = TRUE; break; }
  3403. $result = $res_588;
  3404. $this->pos = $pos_588;
  3405. $_631 = FALSE; break;
  3406. }
  3407. while(0);
  3408. if( $_631 === FALSE) { $_633 = FALSE; break; }
  3409. $_633 = TRUE; break;
  3410. }
  3411. while(0);
  3412. if( $_633 === FALSE) {
  3413. $result = $res_634;
  3414. $this->pos = $pos_634;
  3415. unset( $res_634 );
  3416. unset( $pos_634 );
  3417. break;
  3418. }
  3419. $count += 1;
  3420. }
  3421. if ($count > 0) { return $this->finalise($result); }
  3422. else { return FALSE; }
  3423. }
  3424. /**
  3425. * The TopTemplate also includes the opening stanza to start off the template
  3426. */
  3427. function TopTemplate__construct(&$res) {
  3428. $res['php'] = "<?php" . PHP_EOL;
  3429. }
  3430. /* Text: (
  3431. / [^<${\\]+ / |
  3432. / (\\.) / |
  3433. '<' !'%' |
  3434. '$' !(/[A-Za-z_]/) |
  3435. '{' !'$' |
  3436. '{$' !(/[A-Za-z_]/)
  3437. )+ */
  3438. protected $match_Text_typestack = array('Text');
  3439. function match_Text ($stack = array()) {
  3440. $matchrule = "Text"; $result = $this->construct($matchrule, $matchrule, null);
  3441. $count = 0;
  3442. while (true) {
  3443. $res_673 = $result;
  3444. $pos_673 = $this->pos;
  3445. $_672 = NULL;
  3446. do {
  3447. $_670 = NULL;
  3448. do {
  3449. $res_635 = $result;
  3450. $pos_635 = $this->pos;
  3451. if (( $subres = $this->rx( '/ [^<${\\\\]+ /' ) ) !== FALSE) {
  3452. $result["text"] .= $subres;
  3453. $_670 = TRUE; break;
  3454. }
  3455. $result = $res_635;
  3456. $this->pos = $pos_635;
  3457. $_668 = NULL;
  3458. do {
  3459. $res_637 = $result;
  3460. $pos_637 = $this->pos;
  3461. if (( $subres = $this->rx( '/ (\\\\.) /' ) ) !== FALSE) {
  3462. $result["text"] .= $subres;
  3463. $_668 = TRUE; break;
  3464. }
  3465. $result = $res_637;
  3466. $this->pos = $pos_637;
  3467. $_666 = NULL;
  3468. do {
  3469. $res_639 = $result;
  3470. $pos_639 = $this->pos;
  3471. $_642 = NULL;
  3472. do {
  3473. if (substr($this->string,$this->pos,1) == '<') {
  3474. $this->pos += 1;
  3475. $result["text"] .= '<';
  3476. }
  3477. else { $_642 = FALSE; break; }
  3478. $res_641 = $result;
  3479. $pos_641 = $this->pos;
  3480. if (substr($this->string,$this->pos,1) == '%') {
  3481. $this->pos += 1;
  3482. $result["text"] .= '%';
  3483. $result = $res_641;
  3484. $this->pos = $pos_641;
  3485. $_642 = FALSE; break;
  3486. }
  3487. else {
  3488. $result = $res_641;
  3489. $this->pos = $pos_641;
  3490. }
  3491. $_642 = TRUE; break;
  3492. }
  3493. while(0);
  3494. if( $_642 === TRUE ) { $_666 = TRUE; break; }
  3495. $result = $res_639;
  3496. $this->pos = $pos_639;
  3497. $_664 = NULL;
  3498. do {
  3499. $res_644 = $result;
  3500. $pos_644 = $this->pos;
  3501. $_649 = NULL;
  3502. do {
  3503. if (substr($this->string,$this->pos,1) == '$') {
  3504. $this->pos += 1;
  3505. $result["text"] .= '$';
  3506. }
  3507. else { $_649 = FALSE; break; }
  3508. $res_648 = $result;
  3509. $pos_648 = $this->pos;
  3510. $_647 = NULL;
  3511. do {
  3512. if (( $subres = $this->rx( '/[A-Za-z_]/' ) ) !== FALSE) { $result["text"] .= $subres; }
  3513. else { $_647 = FALSE; break; }
  3514. $_647 = TRUE; break;
  3515. }
  3516. while(0);
  3517. if( $_647 === TRUE ) {
  3518. $result = $res_648;
  3519. $this->pos = $pos_648;
  3520. $_649 = FALSE; break;
  3521. }
  3522. if( $_647 === FALSE) {
  3523. $result = $res_648;
  3524. $this->pos = $pos_648;
  3525. }
  3526. $_649 = TRUE; break;
  3527. }
  3528. while(0);
  3529. if( $_649 === TRUE ) { $_664 = TRUE; break; }
  3530. $result = $res_644;
  3531. $this->pos = $pos_644;
  3532. $_662 = NULL;
  3533. do {
  3534. $res_651 = $result;
  3535. $pos_651 = $this->pos;
  3536. $_654 = NULL;
  3537. do {
  3538. if (substr($this->string,$this->pos,1) == '{') {
  3539. $this->pos += 1;
  3540. $result["text"] .= '{';
  3541. }
  3542. else { $_654 = FALSE; break; }
  3543. $res_653 = $result;
  3544. $pos_653 = $this->pos;
  3545. if (substr($this->string,$this->pos,1) == '$') {
  3546. $this->pos += 1;
  3547. $result["text"] .= '$';
  3548. $result = $res_653;
  3549. $this->pos = $pos_653;
  3550. $_654 = FALSE; break;
  3551. }
  3552. else {
  3553. $result = $res_653;
  3554. $this->pos = $pos_653;
  3555. }
  3556. $_654 = TRUE; break;
  3557. }
  3558. while(0);
  3559. if( $_654 === TRUE ) { $_662 = TRUE; break; }
  3560. $result = $res_651;
  3561. $this->pos = $pos_651;
  3562. $_660 = NULL;
  3563. do {
  3564. if (( $subres = $this->literal( '{$' ) ) !== FALSE) { $result["text"] .= $subres; }
  3565. else { $_660 = FALSE; break; }
  3566. $res_659 = $result;
  3567. $pos_659 = $this->pos;
  3568. $_658 = NULL;
  3569. do {
  3570. if (( $subres = $this->rx( '/[A-Za-z_]/' ) ) !== FALSE) { $result["text"] .= $subres; }
  3571. else { $_658 = FALSE; break; }
  3572. $_658 = TRUE; break;
  3573. }
  3574. while(0);
  3575. if( $_658 === TRUE ) {
  3576. $result = $res_659;
  3577. $this->pos = $pos_659;
  3578. $_660 = FALSE; break;
  3579. }
  3580. if( $_658 === FALSE) {
  3581. $result = $res_659;
  3582. $this->pos = $pos_659;
  3583. }
  3584. $_660 = TRUE; break;
  3585. }
  3586. while(0);
  3587. if( $_660 === TRUE ) { $_662 = TRUE; break; }
  3588. $result = $res_651;
  3589. $this->pos = $pos_651;
  3590. $_662 = FALSE; break;
  3591. }
  3592. while(0);
  3593. if( $_662 === TRUE ) { $_664 = TRUE; break; }
  3594. $result = $res_644;
  3595. $this->pos = $pos_644;
  3596. $_664 = FALSE; break;
  3597. }
  3598. while(0);
  3599. if( $_664 === TRUE ) { $_666 = TRUE; break; }
  3600. $result = $res_639;
  3601. $this->pos = $pos_639;
  3602. $_666 = FALSE; break;
  3603. }
  3604. while(0);
  3605. if( $_666 === TRUE ) { $_668 = TRUE; break; }
  3606. $result = $res_637;
  3607. $this->pos = $pos_637;
  3608. $_668 = FALSE; break;
  3609. }
  3610. while(0);
  3611. if( $_668 === TRUE ) { $_670 = TRUE; break; }
  3612. $result = $res_635;
  3613. $this->pos = $pos_635;
  3614. $_670 = FALSE; break;
  3615. }
  3616. while(0);
  3617. if( $_670 === FALSE) { $_672 = FALSE; break; }
  3618. $_672 = TRUE; break;
  3619. }
  3620. while(0);
  3621. if( $_672 === FALSE) {
  3622. $result = $res_673;
  3623. $this->pos = $pos_673;
  3624. unset( $res_673 );
  3625. unset( $pos_673 );
  3626. break;
  3627. }
  3628. $count += 1;
  3629. }
  3630. if ($count > 0) { return $this->finalise($result); }
  3631. else { return FALSE; }
  3632. }
  3633. /**
  3634. * We convert text
  3635. */
  3636. function Text__finalise(&$res) {
  3637. $text = $res['text'];
  3638. // Unescape any escaped characters in the text, then put back escapes for any single quotes and backslashes
  3639. $text = stripslashes($text);
  3640. $text = addcslashes($text, '\'\\');
  3641. // TODO: This is pretty ugly & gets applied on all files not just html. I wonder if we can make this non-dynamically calculated
  3642. $text = preg_replace(
  3643. '/href\s*\=\s*\"\#/',
  3644. 'href="\' . (SSViewer::$options[\'rewriteHashlinks\'] ? Convert::raw2att( $_SERVER[\'REQUEST_URI\'] ) : "") . \'#',
  3645. $text
  3646. );
  3647. $res['php'] .= '$val .= \'' . $text . '\';' . PHP_EOL;
  3648. }
  3649. /******************
  3650. * Here ends the parser itself. Below are utility methods to use the parser
  3651. */
  3652. /**
  3653. * Compiles some passed template source code into the php code that will execute as per the template source.
  3654. *
  3655. * @static
  3656. * @throws SSTemplateParseException
  3657. * @param $string - The source of the template
  3658. * @param string $templateName - The name of the template, normally the filename the template source was loaded from
  3659. * @param bool $includeDebuggingComments - True is debugging comments should be included in the output
  3660. * @return mixed|string - The php that, when executed (via include or exec) will behave as per the template source
  3661. */
  3662. static function compileString($string, $templateName = "", $includeDebuggingComments=false) {
  3663. if (!trim($string)) {
  3664. $code = '';
  3665. }
  3666. else {
  3667. // Construct a parser instance
  3668. $parser = new SSTemplateParser($string);
  3669. $parser->includeDebuggingComments = $includeDebuggingComments;
  3670. // Ignore UTF8 BOM at begining of string. TODO: Confirm this is needed, make sure SSViewer handles UTF (and other encodings) properly
  3671. if(substr($string, 0,3) == pack("CCC", 0xef, 0xbb, 0xbf)) $parser->pos = 3;
  3672. // Match the source against the parser
  3673. $result = $parser->match_TopTemplate();
  3674. if(!$result) throw new SSTemplateParseException('Unexpected problem parsing template', $parser);
  3675. // Get the result
  3676. $code = $result['php'];
  3677. }
  3678. // Include top level debugging comments if desired
  3679. if($includeDebuggingComments && $templateName && stripos($code, "<?xml") === false) {
  3680. // If this template is a full HTML page, then put the comments just inside the HTML tag to prevent any IE glitches
  3681. if(stripos($code, "<html") !== false) {
  3682. $code = preg_replace('/(<html[^>]*>)/i', "\\1<!-- template $templateName -->", $code);
  3683. $code = preg_replace('/(<\/html[^>]*>)/i', "<!-- end template $templateName -->\\1", $code);
  3684. } else {
  3685. $code = "<!-- template $templateName -->\n" . $code . "\n<!-- end template $templateName -->";
  3686. }
  3687. }
  3688. return $code;
  3689. }
  3690. /**
  3691. * Compiles some file that contains template source code, and returns the php code that will execute as per that
  3692. * source
  3693. *
  3694. * @static
  3695. * @param $template - A file path that contains template source code
  3696. * @return mixed|string - The php that, when executed (via include or exec) will behave as per the template source
  3697. */
  3698. static function compileFile($template) {
  3699. return self::compileString(file_get_contents($template), $template);
  3700. }
  3701. }