classTriviaReader
final class TriviaReader
Reads the comments out of the whitespace and comments a lexer skipped.
Languages differ in how a block comment ends. Some nest block comments. Some have executable comments: a block comment opened by ! and a version number whose body the lexer reads as SQL when the number does not exceed the parsed release, so its opening and closing delimiters are found apart from each other; an ordinary block comment in such a language steps over /* pairs and nests only an executable comment. The rest end at the first * /. Whether the reader is inside an executable comment carries from one run of trivia to the next until a tree has been read.
Methods§
public function __construct(
private bool $nestedBlocks = false,
private int|null $executableVersion = null,
)Parameters
$nestedBlocks | bool | Whether a block comment inside a block comment must close before the outer one |
$executableVersion | int|null | The highest version number of an executable comment the lexer reads as SQL, or null when the language has none |
public function read(Node $root): SourceCommentsCollects every comment of a parse tree, by the token it was written before.
Parameters
$root | Node |
Returns
Throws
LogicException When the tree's trivia holds text that is not a commentTest cases 3
Called from 2
Calls 6
- method-call Node::tokens() line 44
- function-call
countline 45 - method-call TriviaReader::comments() line 53
- function-call
array_pushline 60 - function-call
spl_object_idline 62 - new SourceComments line 67
public function comments(string $trivia): list<string>Splits one run of trivia into its comments, in order, without their surrounding whitespace.
Parameters
$trivia | string |
Returns
list<string>Throws
LogicException When the trivia holds text that is not a commentTest cases 3
Called from 2
public function commentEnd(string $trivia, int $offset): intFinds where the comment at an offset ends, entering or leaving an executable comment on the way.
Parameters
$trivia | string | |
$offset | int |
Returns
intThrows
LogicException When the offset does not start a commentTest cases 1
Called from 1
public function blockEnd(string $trivia, int $start): intFinds the offset just past the block comment that starts at an offset, or the end of the trivia when it never closes.
Parameters
$trivia | string | |
$start | int |
Returns
intCalled from 1
Private surface 3§
Implementation details, listed for orientation only.
private bool $executable = falseprivate bool $nestedBlocks = falseprivate int|null $executableVersion = nullTest cases 10§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 7
TriviaReaderTest::testBlockEndStepsOverPairsOnlyInLanguagesWithExecutableCommentscallsTriviaReaderTest::testCommentEndFindsTheEndOfEachCommentKindcallsTriviaReaderTest::testCommentsKeepsExecutableCommentDelimitersApartAndOrdinaryVersionCommentsWholecallsTriviaReaderTest::testCommentsNestsBlockCommentsWhenTheLanguageDoescallsTriviaReaderTest::testCommentsSplitsBlockAndLineCommentsWithoutTheirWhitespacecallsTriviaReaderTest::testReadSeparatesLeadingTrailingAndTokenCommentsAndSkipsTokensThatSpellNothingcallsTriviaReaderTest::testReadStartsEachTreeOutsideAnExecutableCommentcalls
Other tests reaching this symbol 3
Relations§
Instantiated in 4
- new SqlSemantics\Platform\MySql\Platform::values() packages/sql-semantics-mysql/src/Platform.php:42
- new SqlSemantics\Platform\PostgreSql\Platform::values() packages/sql-semantics-postgres/src/Platform.php:41
- new SqlSemantics\Platform\Sqlite\Platform::values() packages/sql-semantics-sqlite/src/Platform.php:41
- new SqlSemantics\Core\Analysis\ValueReader::__construct() packages/sql-semantics/src/Core/Analysis/ValueReader.php:35