Automattic\WooCommerce\Vendor\GraphQL\Language
Lexer::readBlockString
Reads a block string token from the source file.
"""("?"?(\"""|\(?!=""")|[^"\]))*"""
Method of the class: Lexer{}
No Hooks.
Returns
null. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->readBlockString( $line, $col, $prev ): Token;
- $line(int) (required)
- .
- $col(int) (required)
- .
- $prev(Token) (required)
- .
Lexer::readBlockString() Lexer::readBlockString code WC 10.9.1
private function readBlockString(int $line, int $col, Token $prev): Token
{
$start = $this->position;
// Skip leading quotes and read first string char:
[$char, $code, $bytes] = $this->moveStringCursor(3, 3)->readChar();
$chunk = '';
$value = '';
while ($code !== null) {
// Closing Triple-Quote (""")
if ($code === 34) {
// Move 2 quotes
[, $nextCode] = $this->moveStringCursor(1, 1)->readChar();
[, $nextNextCode] = $this->moveStringCursor(1, 1)->readChar();
if ($nextCode === 34 && $nextNextCode === 34) {
$value .= $chunk;
$this->moveStringCursor(1, 1);
return new Token(
Token::BLOCK_STRING,
$start,
$this->position,
$line,
$col,
$prev,
BlockString::dedentBlockStringLines($value)
);
}
// move cursor back to before the first quote
$this->moveStringCursor(-2, -2);
}
$this->assertValidBlockStringCharacterCode($code, $this->position);
$this->moveStringCursor(1, $bytes);
[, $nextCode] = $this->readChar();
[, $nextNextCode] = $this->moveStringCursor(1, 1)->readChar();
[, $nextNextNextCode] = $this->moveStringCursor(1, 1)->readChar();
// Escape Triple-Quote (\""")
if (
$code === 92
&& $nextCode === 34
&& $nextNextCode === 34
&& $nextNextNextCode === 34
) {
$this->moveStringCursor(1, 1);
$value .= $chunk . '"""';
$chunk = '';
} else {
// move cursor back to before the first quote
$this->moveStringCursor(-2, -2);
if ($code === 10) { // new line
++$this->line;
$this->lineStart = $this->position;
}
$chunk .= $char;
}
[$char, $code, $bytes] = $this->readChar();
}
throw new SyntaxError($this->source, $this->position, 'Unterminated string.');
}