classItemLayout
final class ItemLayout
Reads the layout of the expression of an unaliased select item as the server reads its text.
Rule: MYSQL-ITEM-LAYOUT-001. The server names such an item after the text of its expression in the preprocessed query buffer (8.0 and later: PTI_expr_with_alias::itemize copies @1.cpp; 5.6 and 5.7: select_item copies the text between remember_name and remember_end, both in the preprocessed buffer). The preprocessed buffer is the statement with its whitespace and ordinary comments, where the marker that opens an executed version comment (/*!, optionally with its version digits) is left out, the * / that closes it becomes one space when neither the character before nor the one after is a space, and a version comment for a later release is left out entirely. The layout keeps the tokens as written and the trivia between them as the preprocessed buffer holds it, so the rendered text holds no version comment marker. The lexer reads WITH ROLLUP and WITH CUBE as one lexeme, which the rendering writes as two keywords; the layout keeps the two words with the trivia between them. Version digits are five digits; from 8.1 on also six digits followed by a space. Source: sql/sql_lex.cc (MY_LEX_LONG_COMMENT, MY_LEX_END_LONG_COMMENT) and sql/parse_tree_items.cc of each release, https://dev.mysql.com/doc/refman/8.4/en/comments.html. Status: Implemented.
Methods§
public function __construct(private GrammarRelease $release)Parameters
$release | GrammarRelease | The release whose version decides which version comments are executed |
Answers the layout of an expression node with its trivia as the preprocessed buffer holds it.
Parameters
$expression | Node |
Returns
Throws
InvariantViolation When the node covers no tokenTest cases 2
Called from 1
Calls 6
- method-call Layouts::of() line 53
- new Layouts line 53
- method-call ItemLayout::words() line 57
- new Spelled line 58
- method-call ItemLayout::gap() line 58
- new Layout line 63
public function words(string $gap, string $text): non-empty-list<array{string, string}>Splits the one lexeme the lexer makes of WITH ROLLUP and WITH CUBE into its two words, which the rendering writes as two keywords.
Parameters
$gap | string | |
$text | string |
Returns
non-empty-list<array{string, string}> Each word with the trivia before itTest cases 1
Called from 1
Calls 1
- function-call
preg_matchline 73
public function gap(string $gap, string $before, string $after): stringAnswers the trivia between two tokens as the preprocessed buffer holds it.
Parameters
$gap | string | |
$before | string | |
$after | string |
Returns
stringCalled from 1
Calls 6
- function-call
strlenline 87 - function-call
substr_compareline 89 - method-call ItemLayout::opening() line 90
- function-call
ctype_spaceline 95 - method-call ItemLayout::trivia() line 97
- function-call
substrline 98
public function opening(string $gap, int $offset): intAnswers where the trivia after a version comment marker continues: after the marker when the comment is executed, after the whole comment otherwise.
Parameters
$gap | string | |
$offset | int |
Returns
intTest cases 1
Called from 1
Calls 4
- method-call ItemLayout::digits() line 111
- method-call ItemLayout::version() line 112
- function-call
strlenline 113 - function-call
substr_compareline 118
public function digits(string $gap, int $offset): stringAnswers the version digits written after a version comment marker, or an empty string when there are none.
Parameters
$gap | string | |
$offset | int |
Returns
stringTest cases 1
Called from 1
Calls 5
- class-const GrammarRelease::MySql5651() line 137
- class-const GrammarRelease::MySql5744() line 137
- class-const GrammarRelease::MySql8044() line 137
- function-call
preg_matchline 138 - function-call
substrline 139
public function trivia(string $gap, int $offset): intAnswers where the trivia element at an offset ends: one whitespace character, an ordinary comment, or a line comment without its line end.
Parameters
$gap | string | |
$offset | int |
Returns
intTest cases 1
Called from 1
public function version(): intAnswers the server version of the release as MYSQL_VERSION_ID writes it.
Returns
intTest cases 1
Called from 1
Private surface 1§
Implementation details, listed for orientation only.
private GrammarRelease $releaseTest cases 8§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 8
ItemLayoutTest::testDigitsReadsSixDigitsFromMySql81callsItemLayoutTest::testGapWritesTheClosingMarkerAsASpaceBetweenTwoCharacterscallsItemLayoutTest::testOfDropsTheMarkersOfAVersionCommentcallsItemLayoutTest::testOfKeepsTheTokensAndTheTriviaOfTheExpressioncallsItemLayoutTest::testOpeningSkipsAVersionCommentForALaterReleasecallsItemLayoutTest::testTriviaAnswersTheEndOfOneTriviaElementcallsItemLayoutTest::testVersionAnswersTheServerVersionNumbercallsItemLayoutTest::testWordsSplitsTheLexemeOfWithRollupcalls