本文整理汇总了PHP中SqlParser\Context::isComment方法的典型用法代码示例。如果您正苦于以下问题:PHP Context::isComment方法的具体用法?PHP Context::isComment怎么用?PHP Context::isComment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SqlParser\Context
的用法示例。
在下文中一共展示了Context::isComment方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testIsComment
public function testIsComment()
{
$this->assertEquals(Token::FLAG_COMMENT_BASH, Context::isComment('#'));
$this->assertEquals(Token::FLAG_COMMENT_C, Context::isComment('/*'));
$this->assertEquals(Token::FLAG_COMMENT_C, Context::isComment('*/'));
$this->assertEquals(Token::FLAG_COMMENT_SQL, Context::isComment('-- '));
$this->assertEquals(Token::FLAG_COMMENT_SQL, Context::isComment("--\t"));
$this->assertEquals(Token::FLAG_COMMENT_SQL, Context::isComment("--\n"));
$this->assertEquals(Token::FLAG_COMMENT_BASH, Context::isComment('# a comment'));
$this->assertEquals(Token::FLAG_COMMENT_C, Context::isComment('/*comment */'));
$this->assertEquals(Token::FLAG_COMMENT_SQL, Context::isComment('-- my comment'));
$this->assertEquals(null, Context::isComment('--not a comment'));
}
示例2: parseComment
/**
* Parses a comment.
*
* @return Token
*/
public function parseComment()
{
$iBak = $this->last;
$token = $this->str[$this->last];
// Bash style comments. (#comment\n)
if (Context::isComment($token)) {
while (++$this->last < $this->len && $this->str[$this->last] !== "\n") {
$token .= $this->str[$this->last];
}
$token .= $this->str[$this->last];
return new Token($token, Token::TYPE_COMMENT, Token::FLAG_COMMENT_BASH);
}
// C style comments. (/*comment*\/)
if (++$this->last < $this->len) {
$token .= $this->str[$this->last];
if (Context::isComment($token)) {
$flags = Token::FLAG_COMMENT_C;
if ($this->last + 1 < $this->len && $this->str[$this->last + 1] === '!') {
// It is a MySQL-specific command.
$flags |= Token::FLAG_COMMENT_MYSQL_CMD;
}
while (++$this->last < $this->len && ($this->str[$this->last - 1] !== '*' || $this->str[$this->last] !== '/')) {
$token .= $this->str[$this->last];
}
$token .= $this->str[$this->last];
return new Token($token, Token::TYPE_COMMENT, $flags);
}
}
// SQL style comments. (-- comment\n)
if (++$this->last < $this->len) {
$token .= $this->str[$this->last];
if (Context::isComment($token)) {
if ($this->str[$this->last] !== "\n") {
// Checking if this comment did not end already (```--\n```).
while (++$this->last < $this->len && $this->str[$this->last] !== "\n") {
$token .= $this->str[$this->last];
}
if ($this->last < $this->len) {
$token .= $this->str[$this->last];
}
}
return new Token($token, Token::TYPE_COMMENT, Token::FLAG_COMMENT_SQL);
}
}
$this->last = $iBak;
return null;
}
示例3: parseComment
/**
* Parses a comment.
*
* @return Token
*/
public function parseComment()
{
$iBak = $this->last;
$token = $this->str[$this->last];
// Bash style comments. (#comment\n)
if (Context::isComment($token)) {
while (++$this->last < $this->len && $this->str[$this->last] !== "\n") {
$token .= $this->str[$this->last];
}
$token .= "\n";
// Adding the line ending.
return new Token($token, Token::TYPE_COMMENT, Token::FLAG_COMMENT_BASH);
}
// C style comments. (/*comment*\/)
if (++$this->last < $this->len) {
$token .= $this->str[$this->last];
if (Context::isComment($token)) {
$flags = Token::FLAG_COMMENT_C;
// This comment already ended. It may be a part of a
// previous MySQL specific command.
if ($token === '*/') {
return new Token($token, Token::TYPE_COMMENT, $flags);
}
// Checking if this is a MySQL-specific command.
if ($this->last + 1 < $this->len && $this->str[$this->last + 1] === '!') {
$flags |= Token::FLAG_COMMENT_MYSQL_CMD;
$token .= $this->str[++$this->last];
while (++$this->last < $this->len && '0' <= $this->str[$this->last] && $this->str[$this->last] <= '9') {
$token .= $this->str[$this->last];
}
--$this->last;
// We split this comment and parse only its beginning
// here.
return new Token($token, Token::TYPE_COMMENT, $flags);
}
// Parsing the comment.
while (++$this->last < $this->len && ($this->str[$this->last - 1] !== '*' || $this->str[$this->last] !== '/')) {
$token .= $this->str[$this->last];
}
// Adding the ending.
if ($this->last < $this->len) {
$token .= $this->str[$this->last];
}
return new Token($token, Token::TYPE_COMMENT, $flags);
}
}
// SQL style comments. (-- comment\n)
if (++$this->last < $this->len) {
$token .= $this->str[$this->last];
if (Context::isComment($token)) {
// Checking if this comment did not end already (```--\n```).
if ($this->str[$this->last] !== "\n") {
while (++$this->last < $this->len && $this->str[$this->last] !== "\n") {
$token .= $this->str[$this->last];
}
$token .= "\n";
// Adding the line ending.
}
return new Token($token, Token::TYPE_COMMENT, Token::FLAG_COMMENT_SQL);
}
}
$this->last = $iBak;
return null;
}