PageRenderTime 58ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/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

Large files files are truncated, but you can click here to view the full file

  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. func

Large files files are truncated, but you can click here to view the full file