/lib/ezc/Template/src/parsers/ast/implementations/ast_tree_output.php

https://bitbucket.org/ericsagnes/ezpublish-multisite · PHP · 550 lines · 195 code · 47 blank · 308 comment · 0 complexity · bb3fda1131ce15ce2f3002d96fd56659 MD5 · raw file

  1. <?php
  2. /**
  3. * File containing the ezcTemplateAstNodeGenerator class
  4. *
  5. * @package Template
  6. * @version //autogen//
  7. * @copyright Copyright (C) 2005-2010 eZ Systems AS. All rights reserved.
  8. * @license http://ez.no/licenses/new_bsd New BSD License
  9. * @access private
  10. */
  11. /**
  12. * Iterates the AST tree and outputs the result as text.
  13. *
  14. * Implements the ezcTemplateTstNodeVisitor interface for visiting the nodes
  15. * and generating the appropriate ast nodes for them.
  16. *
  17. * @package Template
  18. * @version //autogen//
  19. * @access private
  20. */
  21. class ezcTemplateAstTreeOutput extends ezcTemplateTreeOutput implements ezcTemplateAstNodeVisitor
  22. {
  23. /**
  24. * Initialize with correct node class name and regex for extraction.
  25. * The extraction will remove the prefix <i>ezcTemplate</i> and the suffix
  26. * <i>AstNode</i>.
  27. */
  28. public function __construct()
  29. {
  30. parent::__construct( 'ezcTemplateAstNode', "#^ezcTemplate(.+)AstNode#" );
  31. }
  32. /**
  33. * Convenience function for outputting a node.
  34. * Instantiates the ezcTemplateAstTreeOutput class and calls accept() on
  35. * $node, the resulting text is returned.
  36. *
  37. * @param ezcTemplateAstNode $node
  38. * @return string
  39. */
  40. static public function output( ezcTemplateAstNode $node )
  41. {
  42. $treeOutput = new ezcTemplateAstTreeOutput();
  43. $node->accept( $treeOutput );
  44. return $treeOutput->text . "\n";
  45. }
  46. /**
  47. * visitLiteralAstNode
  48. *
  49. * @param ezcTemplateLiteralAstNode $node
  50. * @return void
  51. */
  52. public function visitLiteralAstNode( ezcTemplateLiteralAstNode $node )
  53. {
  54. $this->text .= $this->outputNode( $node );
  55. }
  56. /**
  57. * visitConstantAstNode
  58. *
  59. * @param ezcTemplateConstantAstNode $node
  60. * @return void
  61. */
  62. public function visitConstantAstNode( ezcTemplateConstantAstNode $node )
  63. {
  64. $this->text .= $this->outputNode( $node );
  65. }
  66. /**
  67. * visitEolCommentAstNode
  68. *
  69. * @param ezcTemplateEolCommentAstNode $node
  70. * @return void
  71. */
  72. public function visitEolCommentAstNode( ezcTemplateEolCommentAstNode $node )
  73. {
  74. $this->text .= $this->outputNode( $node );
  75. }
  76. /**
  77. * visitBlockCommentAstNode
  78. *
  79. * @param ezcTemplateBlockCommentAstNode $node
  80. * @return void
  81. */
  82. public function visitBlockCommentAstNode( ezcTemplateBlockCommentAstNode $node )
  83. {
  84. $this->text .= $this->outputNode( $node );
  85. }
  86. /**
  87. * visitVariableAstNode
  88. *
  89. * @param ezcTemplateVariableAstNode $node
  90. * @return void
  91. */
  92. public function visitVariableAstNode( ezcTemplateVariableAstNode $node )
  93. {
  94. $this->text .= $this->outputNode( $node );
  95. }
  96. /**
  97. * visitDynamicVariableAstNode
  98. *
  99. * @param ezcTemplateDynamicVariableAstNode $node
  100. * @return void
  101. */
  102. public function visitDynamicVariableAstNode( ezcTemplateDynamicVariableAstNode $node )
  103. {
  104. $this->text .= $this->outputNode( $node );
  105. }
  106. /**
  107. * visitDynamicStringAstNode
  108. *
  109. * @param ezcTemplateDynamicStringAstNode $node
  110. * @return void
  111. */
  112. public function visitDynamicStringAstNode( ezcTemplateDynamicStringAstNode $node )
  113. {
  114. $this->text .= $this->outputNode( $node );
  115. }
  116. /**
  117. * visitArrayFetchOperatorAstNode
  118. *
  119. * @param ezcTemplateArrayFetchOperatorAstNode $node
  120. * @return void
  121. */
  122. public function visitArrayFetchOperatorAstNode( ezcTemplateArrayFetchOperatorAstNode $node )
  123. {
  124. $this->text .= $this->outputNode( $node );
  125. }
  126. /**
  127. * visitUnaryOperatorAstNode
  128. *
  129. * @param ezcTemplateOperatorAstNode $node
  130. * @return void
  131. */
  132. public function visitUnaryOperatorAstNode( ezcTemplateOperatorAstNode $node )
  133. {
  134. $this->text .= $this->outputNode( $node );
  135. }
  136. /**
  137. * visitBinaryOperatorAstNode
  138. *
  139. * @param ezcTemplateOperatorAstNode $node
  140. * @return void
  141. */
  142. public function visitBinaryOperatorAstNode( ezcTemplateOperatorAstNode $node )
  143. {
  144. $this->text .= $this->outputNode( $node );
  145. }
  146. /**
  147. * visitFunctionCallAstNode
  148. *
  149. * @param ezcTemplateFunctionCallAstNode $node
  150. * @return void
  151. */
  152. public function visitFunctionCallAstNode( ezcTemplateFunctionCallAstNode $node )
  153. {
  154. $this->text .= $this->outputNode( $node );
  155. }
  156. /**
  157. * visitBodyAstNode
  158. *
  159. * @param ezcTemplateBodyAstNode $node
  160. * @return void
  161. */
  162. public function visitBodyAstNode( ezcTemplateBodyAstNode $node )
  163. {
  164. $this->text .= $this->outputNode( $node );
  165. }
  166. /**
  167. * visitRootAstNode
  168. *
  169. * @param ezcTemplateBodyAstNode $node
  170. * @return void
  171. */
  172. public function visitRootAstNode( ezcTemplateBodyAstNode $node )
  173. {
  174. $this->text .= $this->outputNode( $node );
  175. }
  176. /**
  177. * visitGenericStatementAstNode
  178. *
  179. * @param ezcTemplateGenericStatementAstNode $node
  180. * @return void
  181. */
  182. public function visitGenericStatementAstNode( ezcTemplateGenericStatementAstNode $node )
  183. {
  184. $this->text .= $this->outputNode( $node );
  185. }
  186. /**
  187. * visitIfAstNode
  188. *
  189. * @param ezcTemplateIfAstNode $node
  190. * @return void
  191. */
  192. public function visitIfAstNode( ezcTemplateIfAstNode $node )
  193. {
  194. $this->text .= $this->outputNode( $node );
  195. }
  196. /**
  197. * visitDynamicBlockAstNode
  198. *
  199. * @param ezcTemplateDynamicBlockAstNode $node
  200. * @return void
  201. */
  202. public function visitDynamicBlockAstNode( ezcTemplateDynamicBlockAstNode $node )
  203. {
  204. $this->text .= $this->outputNode( $node );
  205. }
  206. /**
  207. * visitWhileAstNode
  208. *
  209. * @param ezcTemplateWhileAstNode $node
  210. * @return void
  211. */
  212. public function visitWhileAstNode( ezcTemplateWhileAstNode $node )
  213. {
  214. $this->text .= $this->outputNode( $node );
  215. }
  216. /**
  217. * visitDoWhileAstNode
  218. *
  219. * @param ezcTemplateDoWhileAstNode $node
  220. * @return void
  221. */
  222. public function visitDoWhileAstNode( ezcTemplateDoWhileAstNode $node )
  223. {
  224. $this->text .= $this->outputNode( $node );
  225. }
  226. /**
  227. * visitForAstNode
  228. *
  229. * @param ezcTemplateForAstNode $node
  230. * @return void
  231. */
  232. public function visitForAstNode( ezcTemplateForAstNode $node )
  233. {
  234. $this->text .= $this->outputNode( $node );
  235. }
  236. /**
  237. * visitForeachAstNode
  238. *
  239. * @param ezcTemplateForeachAstNode $node
  240. * @return void
  241. */
  242. public function visitForeachAstNode( ezcTemplateForeachAstNode $node )
  243. {
  244. $this->text .= $this->outputNode( $node );
  245. }
  246. /**
  247. * visitBreakAstNode
  248. *
  249. * @param ezcTemplateBreakAstNode $node
  250. * @return void
  251. */
  252. public function visitBreakAstNode( ezcTemplateBreakAstNode $node )
  253. {
  254. $this->text .= $this->outputNode( $node );
  255. }
  256. /**
  257. * visitContinueAstNode
  258. *
  259. * @param ezcTemplateContinueAstNode $node
  260. * @return void
  261. */
  262. public function visitContinueAstNode( ezcTemplateContinueAstNode $node )
  263. {
  264. $this->text .= $this->outputNode( $node );
  265. }
  266. /**
  267. * visitReturnAstNode
  268. *
  269. * @param ezcTemplateReturnAstNode $node
  270. * @return void
  271. */
  272. public function visitReturnAstNode( ezcTemplateReturnAstNode $node )
  273. {
  274. $this->text .= $this->outputNode( $node );
  275. }
  276. /**
  277. * visitRequireAstNode
  278. *
  279. * @param ezcTemplateRequireAstNode $node
  280. * @return void
  281. */
  282. public function visitRequireAstNode( ezcTemplateRequireAstNode $node )
  283. {
  284. $this->text .= $this->outputNode( $node );
  285. }
  286. /**
  287. * visitRequireOnceAstNode
  288. *
  289. * @param ezcTemplateRequireOnceAstNode $node
  290. * @return void
  291. */
  292. public function visitRequireOnceAstNode( ezcTemplateRequireOnceAstNode $node )
  293. {
  294. $this->text .= $this->outputNode( $node );
  295. }
  296. /**
  297. * visitIncludeAstNode
  298. *
  299. * @param ezcTemplateIncludeAstNode $node
  300. * @return void
  301. */
  302. public function visitIncludeAstNode( ezcTemplateIncludeAstNode $node )
  303. {
  304. $this->text .= $this->outputNode( $node );
  305. }
  306. /**
  307. * visitIncludeOnceAstNode
  308. *
  309. * @param ezcTemplateIncludeOnceAstNode $node
  310. * @return void
  311. */
  312. public function visitIncludeOnceAstNode( ezcTemplateIncludeOnceAstNode $node )
  313. {
  314. $this->text .= $this->outputNode( $node );
  315. }
  316. /**
  317. * visitSwitchAstNode
  318. *
  319. * @param ezcTemplateSwitchAstNode $node
  320. * @return void
  321. */
  322. public function visitSwitchAstNode( ezcTemplateSwitchAstNode $node )
  323. {
  324. $this->text .= $this->outputNode( $node );
  325. }
  326. /**
  327. * visitCaseAstNode
  328. *
  329. * @param ezcTemplateCaseAstNode $node
  330. * @return void
  331. */
  332. public function visitCaseAstNode( ezcTemplateCaseAstNode $node )
  333. {
  334. $this->text .= $this->outputNode( $node );
  335. }
  336. /**
  337. * visitDefaultAstNode
  338. *
  339. * @param ezcTemplateDefaultAstNode $node
  340. * @return void
  341. */
  342. public function visitDefaultAstNode( ezcTemplateDefaultAstNode $node )
  343. {
  344. $this->text .= $this->outputNode( $node );
  345. }
  346. /**
  347. * visitConditionBodyAstNode
  348. *
  349. * @param ezcTemplateConditionBodyAstNode $node
  350. * @return void
  351. */
  352. public function visitConditionBodyAstNode( ezcTemplateConditionBodyAstNode $node )
  353. {
  354. $this->text .= $this->outputNode( $node );
  355. }
  356. /**
  357. * visitOutputAstNode
  358. *
  359. * @param ezcTemplateOutputAstNode $node
  360. * @return void
  361. */
  362. public function visitOutputAstNode( ezcTemplateOutputAstNode $node )
  363. {
  364. $this->text .= $this->outputNode( $node );
  365. }
  366. /**
  367. * visitTryAstNode
  368. *
  369. * @param ezcTemplateTryAstNode $node
  370. * @return void
  371. */
  372. public function visitTryAstNode( ezcTemplateTryAstNode $node )
  373. {
  374. $this->text .= $this->outputNode( $node );
  375. }
  376. /**
  377. * visitCatchAstNode
  378. *
  379. * @param ezcTemplateCatchAstNode $node
  380. * @return void
  381. */
  382. public function visitCatchAstNode( ezcTemplateCatchAstNode $node )
  383. {
  384. $this->text .= $this->outputNode( $node );
  385. }
  386. /**
  387. * visitEchoAstNode
  388. *
  389. * @param ezcTemplateEchoAstNode $node
  390. * @return void
  391. */
  392. public function visitEchoAstNode( ezcTemplateEchoAstNode $node )
  393. {
  394. $this->text .= $this->outputNode( $node );
  395. }
  396. /**
  397. * visitPrintAstNode
  398. *
  399. * @param ezcTemplatePrintAstNode $node
  400. * @return void
  401. */
  402. public function visitPrintAstNode( ezcTemplatePrintAstNode $node )
  403. {
  404. $this->text .= $this->outputNode( $node );
  405. }
  406. /**
  407. * visitIssetAstNode
  408. *
  409. * @param ezcTemplateIssetAstNode $node
  410. * @return void
  411. */
  412. public function visitIssetAstNode( ezcTemplateIssetAstNode $node )
  413. {
  414. $this->text .= $this->outputNode( $node );
  415. }
  416. /**
  417. * visitUnsetAstNode
  418. *
  419. * @param ezcTemplateUnsetAstNode $node
  420. * @return void
  421. */
  422. public function visitUnsetAstNode( ezcTemplateUnsetAstNode $node )
  423. {
  424. $this->text .= $this->outputNode( $node );
  425. }
  426. /**
  427. * visitEmptyAstNode
  428. *
  429. * @param ezcTemplateEmptyAstNode $node
  430. * @return void
  431. */
  432. public function visitEmptyAstNode( ezcTemplateEmptyAstNode $node )
  433. {
  434. $this->text .= $this->outputNode( $node );
  435. }
  436. /**
  437. * visitParenthesisAstNode
  438. *
  439. * @param ezcTemplateParenthesisAstNode $node
  440. * @return void
  441. */
  442. public function visitParenthesisAstNode( ezcTemplateParenthesisAstNode $node )
  443. {
  444. $this->text .= $this->outputNode( $node );
  445. }
  446. /**
  447. * visitCurlyBracesAstNode
  448. *
  449. * @param ezcTemplateCurlyBracesAstNode $node
  450. * @return void
  451. */
  452. public function visitCurlyBracesAstNode( ezcTemplateCurlyBracesAstNode $node )
  453. {
  454. $this->text .= $this->outputNode( $node );
  455. }
  456. /**
  457. * visitTypeCastAstNode
  458. *
  459. * @param ezcTemplateTypeCastAstNode $node
  460. * @return void
  461. */
  462. public function visitTypeCastAstNode( ezcTemplateTypeCastAstNode $node )
  463. {
  464. $this->text .= $this->outputNode( $node );
  465. }
  466. /**
  467. * visitNopAstNode
  468. *
  469. * @param ezcTemplateNopAstNode $node
  470. * @return void
  471. */
  472. public function visitNopAstNode( ezcTemplateNopAstNode $node )
  473. {
  474. $this->text .= $this->outputNode( $node );
  475. }
  476. /**
  477. * Extracts position data from the specified node and set in the out parameters.
  478. * Ast nodes has no position so it always returns false.
  479. *
  480. * @param Object $node The node to examine.
  481. * @param int $startLine The starting line for the node.
  482. * @param int $startColumn The starting column for the node.
  483. * @param int $endLine The starting line for the node.
  484. * @param int $endColumn The starting column for the node.
  485. * @return bool True if the extraction was succesful.
  486. */
  487. protected function extractNodePosition( $node, &$startLine, &$startColumn, &$endLine, &$endColumn )
  488. {
  489. return false;
  490. }
  491. /**
  492. * Extracts the properties from the specified node and returns it as an array.
  493. * The properties are taken using get_object_vars().
  494. *
  495. * @param Object $node The node to examine.
  496. * @return array(name=>value)
  497. */
  498. protected function extractNodeProperties( $node )
  499. {
  500. return get_object_vars( $node );
  501. }
  502. }
  503. ?>