PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/vark_c/ast/nodes/Assert.php

https://bitbucket.org/bakboord/vark
PHP | 45 lines | 24 code | 4 blank | 17 comment | 0 complexity | 0b493db99ee1da21b514f0069012fef6 MD5 | raw file
  1. <?php
  2. /*
  3. Vark - compiles vark programs to PHP
  4. Copyright (C) 2013 Alex Deleyn <alex@bakboord.be>
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. namespace vark\c\ast;
  17. use vark\c\parse;
  18. class Assert extends parse\Node
  19. {
  20. public static function parse( $source )
  21. {
  22. $nodes = array();
  23. $nodes[] = $source->read( 'assert' );
  24. $nodes[] = util\parse_expression( $source );
  25. $nodes[] = $source->read( 'newline' );
  26. return new self( $nodes );
  27. }
  28. public function phpify( $out )
  29. {
  30. $out(
  31. $this[0]->whitespace,
  32. 'if(!(',
  33. $this[1],
  34. '))throw new \vark\r\AssertError();',
  35. $this[2]
  36. );
  37. }
  38. }