classToken
final class Token
Public API: explicitly declared with
@visibility public.One terminal as the lexer read it from the SQL text.
A token carries the whitespace and comments written before it, so a run of tokens spells the text it was read from, byte for byte. The end marker and other tokens a lexer synthesises have no text and stand at the offset where the lexer produced them, which is how the trivia before them still has an owner.
$token = new \SqlParser\Lexer\Token(7, 'SELECT_SYM', 'SELECT', 0);
$token->end() // => 6$token = new \SqlParser\Lexer\Token(7, 'NUM', '1', 9, ' ');
$token->toString() // => ' 1'Properties§
public int $symbolpublic string $namepublic string $textpublic int $offsetpublic string $leading = ''Methods§
public function __construct(
public int $symbol,
public string $name,
public string $text,
public int $offset,
public string $leading = '',
)Parameters
$symbol | int | Terminal number in the grammar's symbol table |
$name | string | Terminal name as the grammar spells it |
$text | string | Text as written in the SQL |
$offset | int | Byte offset of the first character |
$leading | string | Whitespace and comments written before the token |
public function end(): intAnswers the byte offset just past the token.
Returns
int End offsetTest cases 1
TokenTest::testEndcalls
Calls 1
- function-call
strlenline 50
public function is(string $name): boolReports whether the token is a given terminal.
Parameters
$name | string | Terminal name |
Returns
bool True when the names matchTest cases 1
TokenTest::testIscalls
public function toString(): stringAnswers the text the token was read from, the trivia before it included.
Returns
string The trivia written before the token followed by its textTest cases 1
Test cases 63§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 3
Other tests reaching this symbol 60
SourceCommentsTest::testBeforeAnswersTheCommentsOfTheTokenTheyPrecedecallsSourceCommentsTest::testFirstFindsTheFirstTokenBelowANodeAndNullForAnEmptyNodecallsTriviaReaderTest::testReadSeparatesLeadingTrailingAndTokenCommentsAndSkipsTokensThatSpellNothingcallsTriviaReaderTest::testReadStartsEachTreeOutsideAnExecutableCommentcallsIdentifiersTest::testNameUnquotesEscapedDelimiterscallsTreeTest::testSignificantRemovesEmptyProductionscallsTreeTest::testTextKeepsTerminalSpellingscallsExpressionBinderTest::testQualifiedRejectsNonNameOperandscallsExpressionBinderTest::testTokenRejectsUnmodeledTerminalscallsLiteralBinderTest::testTypeNameRetainsLiteralCategoriesAndRejectsIdentifierscallsKeywordsTest::testFallbackPreservesSqliteIdentifierSpellingcallsKeywordsTest::testTextPreservesKeywordIdentifiersAndLiteralBytescallsRendererTest::testWriteRetainsDirectiveOwnershipAndRequiredSeparatorscallsRulesTest::testApplyRemovesOnlyDefaultsOwnedByTheSelectedGrammarRulecallsSettingsTest::testInjectedSeparatorPrecedesLexerProbingcallsShapeTest::testOfRetainsOperandNestingButIgnoresTransparentWrapperscallsSpacingTest::testBetweenDoesNotMergeQuotedTokensOrOperatorTokenscallsSpacingTest::testBetweenProtectsNumberExponentAndCommentBoundariescallsVisitorTest::testTokensPreservesIdentifierRolesAndExecutableBodiescallsDialectTest::testCompactRulesCanProvideAnIndependentGrammarcallsDialectTest::testSyntaxRulesCanProvideAnIndependentGrammarcallsFormatterTest::testFormatUsesInjectedParserAndGrammarRolescallsSpacingTest::testBetweenPreservesFunctionAdjacencycallsSpacingTest::testBetweenSeparatesTokenscallsWriterTest::testFinishDropsOnlyWhitespaceTriviacallsWriterTest::testTokenPreservesCommentsAndLiteralNewlinescallsPlatformTest::testNamesDecodeQuotedIdentifierscallsNameRulesTest::testNameHonorsAnInjectedPolicycallsTypeRulesTest::testTypeNameClassifiesIntegerTokencallsBracketsTest::testMarkPairsNestedParenthesescallsFingerprintTest::testOfDetectsChangedGrammarAndLiteralContentcallsFingerprintTest::testOfIgnoresWhitespaceAndPositionscallsHeadersTest::testMarkDoesNotTreatIdentifierAsClausecallsHeadersTest::testMarkRecognizesLongestHeadercallsTerminalIndexTest::testTokenscallsTerminalIndexTest::testTokensGivesTheSkippedTextToTheTokenThatFollowsItcallsMySqlParserTest::testTokenizecallsNameRulesTest::testNameDecodesEscapedQuotescallsLrParserTest::testParseBuildsATreeNamedAfterTheRulescallsLrParserTest::testParseGivesTheTreeTheTextThatFollowsTheLastTokencallsLrParserTest::testParseLeavesMidRuleActionsOutOfTheTreecallsLrParserTest::testParseRejectsAnUnexpectedTokencallsLrParserTest::testParseSuppliesTheEndMarkerWhenTheStreamLacksItcallsNodeTest::testFindcallsNodeTest::testIsEmptycallsNodeTest::testSpancallsNodeTest::testTextcallsNodeTest::testTokenscallsNodeTest::testToStringWritesBackTheTextTheTreeWasParsedFromcallsSqlParserTest::testTokenizePreservesSourceThroughTheContractcallsSyntaxExceptionTest::testMessageNamesTheTokenAndTheExpectationcallsSyntaxExceptionTest::testMessageShortensALongExpectationcallsSyntaxExceptionTest::testMessageWithoutExpectationcallsDialectTest::testCompactRulesNormalizeDeclaredTerminalAliasescallsDialectTest::testCompactRulesNormalizeDeclaredTerminalAliasescallsDialectTest::testCompactRulesNormalizeDeclaredTerminalAliasescallsPlatformTest::testNamesDecodeQuotedIdentifierscallsPostgreSqlParserTest::testTokenizecallsSqliteParserTest::testTokenizecallsTypeRulesTest::testTypeNameClassifiesIntegerTokencalls
Relations§
Instantiated in 6
- new SqlFormatter\Core\Compact\Document::__construct() packages/sql-formatter/src/Core/Compact/Document.php:52
- new SqlFormatter\Core\Compact\Visitor::tokens() packages/sql-formatter/src/Core/Compact/Visitor.php:37
- new SqlParser\Lexer\TerminalIndex::tokens() packages/sql-parser/src/Lexer/TerminalIndex.php:46
- new SqlParser\Lexer\TerminalIndex::token() packages/sql-parser/src/Lexer/TerminalIndex.php:69
- new SqlParser\Parser\LrParser::parse() packages/sql-parser/src/Parser/LrParser.php:48
- new SqlParser\Parser\LrParser::parse() packages/sql-parser/src/Parser/LrParser.php:58
Type checks 19
- instanceof SqlFormatter\Core\Compact\Grouping::pairs() packages/sql-formatter/src/Core/Compact/Grouping.php:37
- instanceof SqlFormatter\Core\Compact\Grouping::pairs() packages/sql-formatter/src/Core/Compact/Grouping.php:39
- instanceof SqlFormatter\Core\Compact\Grouping::pairs() packages/sql-formatter/src/Core/Compact/Grouping.php:41
- instanceof SqlFormatter\Core\Compact\Shape::of() packages/sql-formatter/src/Core/Compact/Shape.php:30
- instanceof SqlFormatter\Core\Compact\Visitor::tokens() packages/sql-formatter/src/Core/Compact/Visitor.php:31
- instanceof SqlFormatter\Core\Syntax\Analyzer::visit() packages/sql-formatter/src/Core/Syntax/Analyzer.php:33
- instanceof SqlFormatter\Core\Syntax\Fingerprint::of() packages/sql-formatter/src/Core/Syntax/Fingerprint.php:22
- instanceof SqlParser\Parser\LrParser::parse() packages/sql-parser/src/Parser/LrParser.php:69
- instanceof SqlParser\Parser\Node::tokens() packages/sql-parser/src/Parser/Node.php:71
- instanceof SqlSemantics\Core\Analysis\SourceComments::first() packages/sql-semantics/src/Core/Analysis/SourceComments.php:48
- instanceof SqlSemantics\Core\Analysis\ValueReader::lower() packages/sql-semantics/src/Core/Analysis/ValueReader.php:127
- instanceof SqlSemantics\Core\Analysis\ValueReader::lower() packages/sql-semantics/src/Core/Analysis/ValueReader.php:147
- instanceof SqlSemantics\Core\Ast\ColumnProperties::generation() packages/sql-semantics/src/Core/Ast/ColumnProperties.php:39
- instanceof SqlSemantics\Core\Ast\ColumnProperties::generation() packages/sql-semantics/src/Core/Ast/ColumnProperties.php:51
- instanceof SqlSemantics\Core\Ast\ColumnProperties::autoIncrement() packages/sql-semantics/src/Core/Ast/ColumnProperties.php:85
- instanceof SqlSemantics\Core\Ast\Tree::assertChildren() packages/sql-semantics/src/Core/Ast/Tree.php:28
- instanceof SqlSemantics\Core\Ast\Tree::significant() packages/sql-semantics/src/Core/Ast/Tree.php:72
- instanceof SqlSemantics\Core\Ast\Tree::text() packages/sql-semantics/src/Core/Ast/Tree.php:80
- instanceof SqlSemantics\Core\Binding\ExpressionBinder::bind() packages/sql-semantics/src/Core/Binding/ExpressionBinder.php:24
Type declarations 47
- type SqlFormatter\Core\Compact\Grouping::pairs() packages/sql-formatter/src/Core/Compact/Grouping.php:37
- type SqlFormatter\Core\Compact\Keywords packages/sql-formatter/src/Core/Compact/Keywords.php:44
- type SqlFormatter\Core\Compact\Keywords packages/sql-formatter/src/Core/Compact/Keywords.php:53
- type SqlFormatter\Core\Compact\Renderer::render() packages/sql-formatter/src/Core/Compact/Renderer.php:54
- type SqlFormatter\Core\Compact\Rules::apply() packages/sql-formatter/src/Core/Compact/Rules.php:39
- type SqlFormatter\Core\Compact\Rules::apply() packages/sql-formatter/src/Core/Compact/Rules.php:44
- type SqlFormatter\Core\Compact\Rules::apply() packages/sql-formatter/src/Core/Compact/Rules.php:48
- type SqlFormatter\Core\Compact\Shape packages/sql-formatter/src/Core/Compact/Shape.php:28
- type SqlFormatter\Core\Compact\Spacing packages/sql-formatter/src/Core/Compact/Spacing.php:28
- type SqlFormatter\Core\Compact\Spacing::signature() packages/sql-formatter/src/Core/Compact/Spacing.php:56
- type SqlFormatter\Core\Compact\Visitor packages/sql-formatter/src/Core/Compact/Visitor.php:29
- type SqlFormatter\Core\Layout\Spacing packages/sql-formatter/src/Core/Layout/Spacing.php:19
- type SqlFormatter\Core\Layout\Writer packages/sql-formatter/src/Core/Layout/Writer.php:21
- type SqlFormatter\Core\Syntax\Fingerprint packages/sql-formatter/src/Core/Syntax/Fingerprint.php:20
- type SqlFormatter\Platform\MySql\Dialect::compactRules() packages/sql-formatter/src/Platform/MySql/Dialect.php:52
- type SqlFormatter\Platform\PostgreSql\Dialect::compactRules() packages/sql-formatter/src/Platform/PostgreSql/Dialect.php:52
- type SqlFormatter\Platform\Sqlite\Dialect::compactRules() packages/sql-formatter/src/Platform/Sqlite/Dialect.php:52
- type SqlParser\Lexer\TerminalIndex packages/sql-parser/src/Lexer/TerminalIndex.php:62
- type SqlParser\Parser\SyntaxException packages/sql-parser/src/Parser/SyntaxException.php:30
- type SqlSemantics\Platform\MySql\NameRules packages/sql-semantics-mysql/src/NameRules.php:21
- type SqlSemantics\Platform\MySql\TypeRules packages/sql-semantics-mysql/src/TypeRules.php:104
- type SqlSemantics\Platform\MySql\TypeRules packages/sql-semantics-mysql/src/TypeRules.php:139
- type SqlSemantics\Platform\PostgreSql\NameRules packages/sql-semantics-postgres/src/NameRules.php:21
- type SqlSemantics\Platform\PostgreSql\TypeRules packages/sql-semantics-postgres/src/TypeRules.php:106
- type SqlSemantics\Platform\PostgreSql\TypeRules packages/sql-semantics-postgres/src/TypeRules.php:144
- type SqlSemantics\Platform\Sqlite\NameRules packages/sql-semantics-sqlite/src/NameRules.php:21
- type SqlSemantics\Platform\Sqlite\TypeRules packages/sql-semantics-sqlite/src/TypeRules.php:109
- type SqlSemantics\Platform\Sqlite\TypeRules packages/sql-semantics-sqlite/src/TypeRules.php:143
- type SqlSemantics\Core\Analysis\SourceComments packages/sql-semantics/src/Core/Analysis/SourceComments.php:37
- type SqlSemantics\Core\Analysis\SourceComments packages/sql-semantics/src/Core/Analysis/SourceComments.php:45
- type SqlSemantics\Core\Ast\Identifiers packages/sql-semantics/src/Core/Ast/Identifiers.php:28
- type SqlSemantics\Core\Ast\TokenGroups::names() packages/sql-semantics/src/Core/Ast/TokenGroups.php:99
- type SqlSemantics\Core\Ast\Tree::significant() packages/sql-semantics/src/Core/Ast/Tree.php:72
- type SqlSemantics\Core\Ast\Tree packages/sql-semantics/src/Core/Ast/Tree.php:78
- type SqlSemantics\Core\Ast\Tree::text() packages/sql-semantics/src/Core/Ast/Tree.php:80
- type SqlSemantics\Core\Ast\Tree packages/sql-semantics/src/Core/Ast/Tree.php:86
- type SqlSemantics\Core\Binding\ExpressionBinder packages/sql-semantics/src/Core/Binding/ExpressionBinder.php:22
- type SqlSemantics\Core\Binding\ExpressionBinder packages/sql-semantics/src/Core/Binding/ExpressionBinder.php:54
- type SqlSemantics\Core\Binding\LiteralBinder packages/sql-semantics/src/Core/Binding/LiteralBinder.php:31
- type SqlSemantics\Core\Binding\LiteralBinder packages/sql-semantics/src/Core/Binding/LiteralBinder.php:49
- type SqlSemantics\Core\Binding\Scope packages/sql-semantics/src/Core/Binding/Scope.php:39
- type SqlSemantics\Core\Binding\TypeResolution packages/sql-semantics/src/Core/Binding/TypeResolution.php:32
- type SqlSemantics\Core\Model\Expression packages/sql-semantics/src/Core/Model/Expression.php:37
- type SqlSemantics\Core\Policy\NameRules packages/sql-semantics/src/Core/Policy/NameRules.php:19
- type SqlSemantics\Core\Policy\TypeRules packages/sql-semantics/src/Core/Policy/TypeRules.php:38
- type SqlSemantics\Core\Policy\TypeRules packages/sql-semantics/src/Core/Policy/TypeRules.php:49
- type SqlSemantics\Core\SemanticException packages/sql-semantics/src/Core/SemanticException.php:32