本文整理汇总了PHP中Token::getLine方法的典型用法代码示例。如果您正苦于以下问题:PHP Token::getLine方法的具体用法?PHP Token::getLine怎么用?PHP Token::getLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Token
的用法示例。
在下文中一共展示了Token::getLine方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetters
public function testGetters()
{
$token = new Token(Token::IDENTIFIER, 'foobar', 7);
$this->assertNotEquals(Token::TEXT, $token->getType());
$this->assertEquals(Token::IDENTIFIER, $token->getType());
$this->assertNotEquals('foo', $token->getValue());
$this->assertEquals('foobar', $token->getValue());
$this->assertNotEquals(6, $token->getLine());
$this->assertEquals(7, $token->getLine());
}
示例2: _getParseTokenFromToken
protected function _getParseTokenFromToken(Token $token)
{
$code = $token->getCode();
if ($code === "WHILE_START") {
$code = "WHILE";
}
return new ParseToken($code, $token->getContent(), $token->getChar(), $token->getLine());
}
示例3: getLine
/**
* Returns the line in the source file the message refers to.
* If this error message does not refer to a token (lint error),
* the line number is 0.
*
* @returns integer
*/
public function getLine()
{
// Explicitly set line overrides token start line
if ($this->line !== null) {
return $this->line;
}
if (!$this->token instanceof Token) {
return 0;
}
return $this->token->getLine();
}
示例4: 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;
}
示例5: testGetLineReturnsCorrectLineWhenWhitespaceTokenHasNoLeadingNewline
/**
* @covers spriebsch\PHPca\Token::__construct
* @covers spriebsch\PHPca\Token::getLine
*/
public function testGetLineReturnsCorrectLineWhenWhitespaceTokenHasNoLeadingNewline()
{
$t = new Token(T_WHITESPACE, " ", 3, 7);
$this->assertEquals(3, $t->getLine());
}
示例6: procAssignment
protected function procAssignment(Token $token)
{
$this->debug(__METHOD__, __LINE__, "identifier: {$token->getValue()}");
// Validate the leftside
if ($token->getType() != TokenType::IDENTIFIER) {
throw new SyntaxException($token->getLine(), $token->getColumn() - mb_strlen($token->getValue()) + 1, "Invalid assignment identifier: '{$token->getValue()}'", __FILE__, __LINE__);
}
$name = $token->getValue();
$token = $this->getToken();
// Validate the operator
switch ($token->getType()) {
case TokenType::SYMBOL:
switch ($token->getValue()) {
case ';':
if (!$this->memory->hasVar($name)) {
throw new SyntaxException($token->getLine(), $token->getColumn() - mb_strlen($name) + 1, "Unknown identifier: '{$name}'", __FILE__, __LINE__);
}
// Do nothing :\
return;
break;
case '=':
// allow =
break;
case '++':
case '--':
// allow ++ and --
break;
default:
throw new SyntaxException($token->getLine(), $token->getColumn() - mb_strlen($token->getValue()) + 1, "Invalid assignment operator: '{$token->getValue()}'", __FILE__, __LINE__);
}
break;
default:
throw new SyntaxException($token->getLine(), $token->getColumn() - mb_strlen($token->getValue()) + 1, "Invalid assignment operator: '{$token->getValue()}'", __FILE__, __LINE__);
}
$operator = $token->getValue();
// Evaluate the rightside
$type = $this->evalExp($value);
// Perform action
switch ($operator) {
case '=':
$this->memory->setVar($name, $value, $type);
break;
case '++':
// number only
// number only
case '--':
if (!$this->memory->hasVar($name)) {
throw new SyntaxException($token->getLine(), $token->getColumn(), "Unknown identifier: '{$name}'", __FILE__, __LINE__);
}
$value = $this->memory->getVar($name);
if ($operator == '++') {
$newval = intval($value + 1);
} else {
$newval = intval($value - 1);
}
$this->memory->setVar($name, $newval, $type);
break;
default:
throw new SyntaxException($token->getLine(), $token->getColumn() - mb_strlen($operator) + 1, "Unknown operator: '{$operator}'", __FILE__, __LINE__);
break;
}
}
示例7: buildNumberToken
protected function buildNumberToken(Token $token, Character $char)
{
$token->setType(TokenType::INTEGER);
$buffer = '';
do {
$buffer .= $char->getValue();
try {
$char = $this->getCharacter();
} catch (EofException $e) {
throw new SyntaxException($char->getLine(), $char->getColumn() - mb_strlen($buffer) + 1, "Found EOF reading number: '{$buffer}'", __FILE__, __LINE__);
}
} while ($char->isNumber() || $char->getValue() == '.');
$this->ungetCharacter();
// If number contains a period, is a FLOAT
if (mb_strpos($buffer, '.') !== FALSE) {
$token->setType(TokenType::FLOAT);
// If period is not followed by numbers
if (mb_substr($buffer, -1) == '.') {
throw new SyntaxException($token->getLine(), $token->getColumn(), "Invalid FLOAT value: '{$buffer}'", __FILE__, __LINE__);
}
}
switch ($token->getType()) {
case TokenType::FLOAT:
$token->setValue(floatval($buffer));
break;
case TokenType::INTEGER:
$token->setValue(intval($buffer));
break;
default:
throw new SyntaxException($char->getLine(), $char->getColumn(), 'Unknown number token type: "' . $buffer . '"', __FILE__, __LINE__);
break;
}
return $token;
}