PageRenderTime 51ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/src/classes/Parser/Constant.php

https://github.com/Nycto/phpVocab
PHP | 76 lines | 21 code | 14 blank | 41 comment | 0 complexity | 1257a7b4c0b36ea01c1f156d62c56486 MD5 | raw file
  1. <?php
  2. /**
  3. * @license Artistic License 2.0
  4. *
  5. * This file is part of phpVocab.
  6. *
  7. * phpVocab is free software: you can redistribute it and/or modify
  8. * it under the terms of the Artistic License as published by
  9. * the Open Source Initiative, either version 2.0 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * phpVocab is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * Artistic License for more details.
  16. *
  17. * You should have received a copy of the Artistic License
  18. * along with phpVocab. If not, see <http://www.phpVocab.com/license.php>
  19. * or <http://www.opensource.org/licenses/artistic-license-2.0.php>.
  20. *
  21. * @author James Frasca <James@RoundEights.com>
  22. * @copyright Copyright 2009, James Frasca, All Rights Reserved
  23. */
  24. namespace vc\Parser;
  25. use \vc\Tokens\Token as Token;
  26. /**
  27. * Parses an Alias declaration
  28. */
  29. class Constant
  30. {
  31. /**
  32. * The parser for constructing value objects
  33. *
  34. * @var \vc\Parser\Value
  35. */
  36. private $value;
  37. /**
  38. * Constructor...
  39. *
  40. * @param \vc\Parser\Value $value The parser for constructing value objects
  41. */
  42. public function __construct ( \vc\Parser\Value $value )
  43. {
  44. $this->value = $value;
  45. }
  46. /**
  47. * Parses the given token reader
  48. *
  49. * @param \vc\Tokens\Access $access The token access
  50. * @return \vc\Data\Constant Returns the created constant
  51. */
  52. public function parseConstant ( \vc\Tokens\Access $access )
  53. {
  54. $access->findRequired( array(Token::T_CONST) );
  55. $name = $access->findRequired( array(Token::T_STRING) );
  56. $const = new \vc\Data\Constant( $name->getContent() );
  57. $access->findRequired( array(Token::T_EQUALS) );
  58. $const->setValue( $this->value->parseValue($access) );
  59. $access->findRequired( array(Token::T_SEMICOLON) );
  60. return $const;
  61. }
  62. }