コード例 #1
0
ファイル: Visibility.php プロジェクト: Nycto/phpVocab
 /**
  * Builds a new instance of this enum using a token to determine the value
  *
  * @param \vc\Tokens\Token $token
  * @return \vc\Data\Visibility
  */
 public static function fromToken(\vc\Tokens\Token $token)
 {
     if ($token->is(Token::T_PUBLIC)) {
         return self::vPublic();
     } else {
         if ($token->is(Token::T_PROTECTED)) {
             return self::vProtected();
         } else {
             if ($token->is(Token::T_PRIVATE)) {
                 return self::vPrivate();
             }
         }
     }
     throw new \r8\Exception\Argument(0, "Token", "Invalid token source");
 }
コード例 #2
0
ファイル: Parser.php プロジェクト: Nycto/phpVocab
 public function testPopToken_CustomTokens()
 {
     $parser = new \vc\Tokens\Parser(new \r8\Stream\In\String('<?php if(!$$v[0]=1<5){' . "\n" . '~1%1*1+1-1/1&1^1|1>0?:`w`.@a("$a",1);' . "\n" . '}?>'));
     $result = array(array(Token::T_OPEN_TAG, '<?php ', 1), array(Token::T_IF, 'if', 1), array(Token::T_PARENS_OPEN, '(', 1), array(Token::T_LOGICAL_NOT, '!', 1), array(Token::T_VAR_VARIABLE, '$', 1), array(Token::T_VARIABLE, '$v', 1), array(Token::T_BRACKET_OPEN, '[', 1), array(Token::T_LNUMBER, '0', 1), array(Token::T_BRACKET_CLOSE, ']', 1), array(Token::T_EQUALS, '=', 1), array(Token::T_LNUMBER, '1', 1), array(Token::T_LESS_THAN, '<', 1), array(Token::T_LNUMBER, '5', 1), array(Token::T_PARENS_CLOSE, ')', 1), array(Token::T_CURLY_OPEN, '{', 1), array(Token::T_WHITESPACE, "\n", 1), array(Token::T_BIT_NOT, '~', 2), array(Token::T_LNUMBER, '1', 2), array(Token::T_MODULO, '%', 2), array(Token::T_LNUMBER, '1', 2), array(Token::T_MULTIPLY, '*', 2), array(Token::T_LNUMBER, '1', 2), array(Token::T_ADD, '+', 2), array(Token::T_LNUMBER, '1', 2), array(Token::T_MINUS, '-', 2), array(Token::T_LNUMBER, '1', 2), array(Token::T_DIVIDE, '/', 2), array(Token::T_LNUMBER, '1', 2), array(Token::T_AMPERSAND, '&', 2), array(Token::T_LNUMBER, '1', 2), array(Token::T_BIT_XOR, '^', 2), array(Token::T_LNUMBER, '1', 2), array(Token::T_BIT_OR, '|', 2), array(Token::T_LNUMBER, '1', 2), array(Token::T_GREATER_THAN, '>', 2), array(Token::T_LNUMBER, '0', 2), array(Token::T_TERNARY, '?', 2), array(Token::T_TERNARY_ELSE, ':', 2), array(Token::T_BACKTICK, '`', 2), array(Token::T_ENCAPSED_AND_WHITESPACE, 'w', 2), array(Token::T_BACKTICK, '`', 2), array(Token::T_CONCAT, '.', 2), array(Token::T_SUPPRESS, '@', 2), array(Token::T_STRING, 'a', 2), array(Token::T_PARENS_OPEN, '(', 2), array(Token::T_QUOTE, '"', 2), array(Token::T_VARIABLE, '$a', 2), array(Token::T_QUOTE, '"', 2), array(Token::T_COMMA, ',', 2), array(Token::T_LNUMBER, '1', 2), array(Token::T_PARENS_CLOSE, ')', 2), array(Token::T_SEMICOLON, ';', 2), array(Token::T_WHITESPACE, "\n", 2), array(Token::T_CURLY_CLOSE, '}', 3), array(Token::T_CLOSE_TAG, '?>', 3));
     foreach ($result as $offset => $token) {
         $this->assertTrue($parser->hasToken(), "Ran out of tokens at offset #{$offset}");
         $this->assertEquals(Token::fromArray($token), $parser->popToken(), "Token mismatch at offset #{$offset}");
     }
     $this->assertEndOfTokens($parser);
 }
コード例 #3
0
ファイル: UnexpectedToken.php プロジェクト: Nycto/phpVocab
 /**
  * Constructor...
  *
  * @param \vc\Tokens\Token $token The token that was encountered
  * @param Array $search The list of tokens being searched for
  * @param Array $allowed The list of allowed tokens
  */
 public function __construct(\vc\Tokens\Token $token, array $search, array $allowed = array())
 {
     parent::__construct(sprintf('Unexpected Token (%s) on line %d', $token->getName(), $token->getLine()));
     $this->addData("Encountered Token", $token->getName());
     $this->addData("Token Line", $token->getLine());
     $this->addData("Token Content", $token->getContent());
     $this->addData("Searching for Tokens", implode(", ", array_map(array('\\vc\\Tokens\\Token', 'getTokenName'), $search)));
     $this->addData("Allowed Tokens", implode(", ", array_map(array('\\vc\\Tokens\\Token', 'getTokenName'), $allowed)));
 }
コード例 #4
0
ファイル: Parser.php プロジェクト: Nycto/phpVocab
 /**
  * Builds a token from a mixed input
  *
  * @param Mixed $input
  * @return \vc\Tokens\Token
  */
 private function buildToken($input)
 {
     // In most cases, token_get_all represents a token as an array
     if (is_array($input)) {
         return \vc\Tokens\Token::fromArray($input);
     }
     // When a token is reinstated, its object gets shifted onto this list
     if ($input instanceof \vc\Tokens\Token) {
         return $input;
     }
     // For custom tokens, we need to derive the line number based on the
     // previous token. If the previous token contains a carriage return,
     // then we need to manually bump the value up
     $line = $this->current->getLine();
     if ($this->current->is(\vc\Tokens\Token::T_WHITESPACE)) {
         $content = $this->current->getContent();
         $line += substr_count($content, "\n") + substr_count($content, "\r");
     }
     return new \vc\Tokens\Token(self::lookupToken($input), $input, $line);
 }
コード例 #5
0
ファイル: Token.php プロジェクト: Nycto/phpVocab
 public function testToArray()
 {
     $token = new Token(Token::T_ECHO, "echo", 1);
     $this->assertEquals(array(Token::T_ECHO, "echo", 1), $token->toArray());
 }
コード例 #6
0
ファイル: TestCase.php プロジェクト: Nycto/phpVocab
 /**
  * Asserts that a value is a token of the given type
  */
 public function assertIsTokenOf($type, $token)
 {
     $this->assertThat($token, $this->isInstanceOf('\\vc\\Tokens\\Token'), "Value is not a Token");
     $this->assertEquals(\vc\Tokens\Token::getTokenName($type), $token->getName(), "Token is not of the correct type");
 }
コード例 #7
0
ファイル: Value.php プロジェクト: Nycto/phpVocab
 /**
  * Parses a number
  *
  * @param Boolean $positive Whether this value is positive
  * @param \vc\Tokens\Token $token The token to examine
  * @return \vc\Data\Value
  */
 private function parseNumber($positive, \vc\Tokens\Token $token)
 {
     $content = $token->getContent();
     if (!$positive) {
         $content = "-" . $content;
     }
     return new \vc\Data\Value($content, $token->getType() == Token::T_LNUMBER ? "int" : "float");
 }