本文整理汇总了PHP中Token::getText方法的典型用法代码示例。如果您正苦于以下问题:PHP Token::getText方法的具体用法?PHP Token::getText怎么用?PHP Token::getText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Token
的用法示例。
在下文中一共展示了Token::getText方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: extract_potential_named_entities
/**
* Simply attempts to attract place names or names.
*/
private function extract_potential_named_entities()
{
for ($i = 0, $n = count($this->tokens); $i < $n; $i++) {
$entity = NULL;
$token = new Token($this->tokens[$i]);
// If the token is uppercase, maybe it is a name or a place.
if ($token->isUpperCase() && !$token->isStopWord() && !$token->isInitWord()) {
$entity = array($token->getText());
// Look two words ahead.
if (isset($this->tokens[$i + 2])) {
$next = new Token($this->tokens[$i + 2]);
while ($next->isUpperCase() || $next->isPrefixOrInfix()) {
// Jump two words.
$i += 2;
$entity[] = $next->getText();
if (isset($this->tokens[$i + 2])) {
$next = new Token($this->tokens[$i + 2]);
} else {
break;
}
}
}
$this->named_entities[] = $entity;
}
}
}
示例2: FromToken
public function FromToken(Token $oldToken)
{
$text = $oldToken->getText();
$type = $oldToken->getType();
$line = $oldToken->getLine();
$index = $oldToken->getTokenIndex();
$charPositionInLine = $oldToken->getCharPositionInLine();
$channel = $oldToken->getChannel();
if ($oldToken instanceof CommonToken) {
$start = $oldToken->start;
$stop = $oldToken->stop;
}
$token = new CommonToken(null, $type, $channel, $start, $stop);
$token->text = $text;
$token->line = $line;
$token->index = $index;
$token->charPositionInLine = $charPositionInLine;
return $token;
}
示例3: accept
function accept(Token $token)
{
if ($token->isA(T_DOC_COMMENT)) {
$this->last_doc_block = $token->getText();
$this->state = 1;
} elseif ($token->isA(T_INTERFACE) || $token->isA(T_CLASS) || $token->isA(T_FUNCTION) || $token->isA(T_VARIABLE) && !$this->parameters_scanner->isActive()) {
if ($this->state === 1) {
$this->state = 2;
} else {
$this->last_doc_block = null;
$this->state = 0;
}
}
}
示例4: testGetText
/**
* @covers spriebsch\PHPca\Token::__construct
* @covers spriebsch\PHPca\Token::getText
*/
public function testGetText()
{
$t = new Token(T_OPEN_TAG, '<?php');
$this->assertEquals('<?php', $t->getText());
}
示例5: tokenize
/**
* Tokenize a file
*
* @param string $fileName the file name
* @param string $sourceCode the source code
* @return File
*/
public static function tokenize($fileName, $sourceCode)
{
Constants::init();
$class = '';
$classFound = false;
$waitForClassBegin = false;
$classCurlyLevel = 0;
$interface = '';
$interfaceFound = false;
$waitForInterfaceBegin = false;
$interfaceCurlyLevel = 0;
$function = '';
$functionFound = false;
$waitForFunctionBegin = false;
$functionCurlyLevel = 0;
$namespace = '\\';
$newNamespace = '';
$namespaceFound = false;
$namespaceStarted = false;
$level = 0;
$line = 1;
$column = 1;
$file = new File($fileName, $sourceCode);
foreach (token_get_all($sourceCode) as $token) {
if (is_array($token)) {
$id = $token[0];
$text = $token[1];
$line = $token[2];
} else {
try {
// it's not a PHP token, so we use one we have defined
$id = Constants::getTokenId($token);
$text = $token;
} catch (UnkownTokenException $e) {
throw new TokenizerException('Unknown token ' . $e->getTokenName() . ' in file ' . $fileName);
}
// This exception is not testable, because we _have_ defined all
// tokens, hopefully. It's just a safeguard to provide a decent
// error message should we ever encounter an undefined token.
// @codeCoverageIgnoreEnd
}
$tokenObj = new Token($id, $text, $line, $column);
if ($tokenObj->hasNewline()) {
// a newline resets the column count
$line += $tokenObj->getNewLineCount();
$column = 1 + $tokenObj->getTrailingWhitespaceCount();
} else {
$column += $tokenObj->getLength();
}
// We have encountered a T_NAMESPACE token before (this is indicated
// by $namespaceFound being true, so the T_STRING contains the class
// name (there will be T_WHITESPACE between T_NAMESPACE and T_STRING).
// We remember the namespace name, but do not set it until we have
// encountered the next opening brace or semicolon. We set
// $waitForNamespaceBegin to true so that we can wait for one of these.
if ($namespaceFound && $tokenObj->getId() == T_STRING || $namespaceFound && $tokenObj->getId() == T_NS_SEPARATOR) {
$newNamespace .= $tokenObj->getText();
}
// We have encountered a T_CLASS token before (this is indicated
// by $classFound being true, so the T_STRING contains the class
// name (there will be T_WHITESPACE between T_CLASS and T_STRING).
// We remember the class name, but do not set it until we have
// encountered the next opening brace. We set $waitForClassBegin
// to true so that we can wait for the next opening curly brace.
if ($classFound && $tokenObj->getId() == T_STRING) {
$class = $tokenObj->getText();
$waitForClassBegin = true;
$classFound = false;
}
// We have encountered a T_INTERFACE token before (this is indicated
// by $interfaceFound being true, so the T_STRING contains the class
// name (there will be T_WHITESPACE between T_INTERFACE and T_STRING).
// We remember the interface name, but do not set it until we have
// encountered the next opening brace. We set $waitForInterfaceBegin
// to true so that we can wait for the next opening curly brace.
if ($interfaceFound && $tokenObj->getId() == T_STRING) {
$interface = $tokenObj->getText();
$waitForInterfaceBegin = true;
$interfaceFound = false;
}
// We have encountered a T_FUNCTION token before (this is indicated
// by $functionFound being true, so the T_STRING contains the class
// name (there will be T_WHITESPACE between T_FUNCTION and T_STRING).
// We remember the function name, but do not set it until we have
// encountered the next opening brace. We set $waitForFunctionBegin
// to true so that we can wait for the next opening curly brace.
if ($functionFound && $tokenObj->getId() == T_STRING) {
$function = $tokenObj->getText();
$waitForFunctionBegin = true;
$functionFound = false;
}
// T_NAMESPACE token starts a namespace. We set $namespaceFound
// to true so that we can watch out for the namespace name (see above).
//.........这里部分代码省略.........
示例6: accept
function accept(Token $token)
{
$this->output .= $token->getText();
}