classLeafKeys
final class LeafKeys
implements LeafKeys
Keys MySQL tokens for the token correspondence check.
Rule: MYSQL-LEAF-KEYS-001. A keyword or punctuation token is keyed by its terminal: the server grammar sees only the terminal, so the words the lexer maps to one terminal (INT/INTEGER, DATABASE/SCHEMA, COLUMNS/FIELDS, <>/!=, DESCRIBE/EXPLAIN) are one request. An identifier token, a keyword at a keyword-as-identifier production, a string at a production that reads it as a name, and a host name are keyed by the decoded name. A string literal is keyed by its decoded bytes under the escape setting of the profile, a number by its exact text, a hexadecimal or bit literal by its digits whatever its spelling, an introducer by its character set, a parameter marker by its text. A position a family noise table lists has no key; a position a family synonym table lists has the key that table states, so two distinct terminals the manual defines as synonyms compare equal. The end marker has no text and no key. Status: Implemented.
Methods§
public function __construct(private LexicalSettings $lexical)Parameters
$lexical | LexicalSettings | The lexical settings strings are decoded under |
public function key(Token $token, string $signature, int $position): ?stringAnswers the comparison key of a token, or null for declared noise.
Parameters
$token | Token | |
$signature | string | |
$position | int |
Returns
?stringTest cases 6
LeafKeysTest::testKeyAnswersTheStatedKeyAtSynonymPositionscallsLeafKeysTest::testKeyDecodesLiteralsByTheirExactValuecallsLeafKeysTest::testKeyDecodesNamesAtNameProductionscallsLeafKeysTest::testKeyDecodesStringsUnderTheEscapeSettingcallsLeafKeysTest::testKeyIsNullAtNoisePositionsAndForTheEndMarkercallsLeafKeysTest::testKeyKeysKeywordsAndPunctuationByTerminalcalls
Calls 8
- function-call
in_arrayline 78 - static-call LeafKeys::noise() line 78
- static-call LeafKeys::synonyms() line 81
- class-const LeafKeys::NAME_RULES() line 85
- function-call
substrline 85 - function-call
strposline 85 - method-call LeafKeys::name() line 86
- method-call LeafKeys::terminal() line 89
public function name(Token $token): stringDecodes the name a token denotes at a name production.
Parameters
$token | Token |
Returns
stringTest cases 1
Called from 1
Calls 4
- method-call Identifiers::decode() line 98
- new Identifiers line 98
- method-call Strings::decode() line 99
- new Strings line 99
public function terminal(Token $token): stringKeys a token by what its terminal denotes outside the name productions.
Parameters
$token | Token |
Returns
stringTest cases 1
Called from 1
Calls 9
- method-call Identifiers::decode() line 110
- new Identifiers line 110
- method-call Strings::decode() line 112
- new Strings line 112
- method-call Introducers::charset() line 114
- new Introducers line 114
- function-call
strtrline 115 - method-call RadixSpelling::digits() line 115
- new RadixSpelling line 115
public static function noise(): array<string, list<int>>Answers the noise positions of every family by production signature.
Returns
array<string, list<int>>Test cases 1
Called from 1
Calls 14
- static-call DispatchNoise::positions() line 131
- static-call LeafNoise::positions() line 131
- static-call TypeNoise::positions() line 131
- static-call ExpressionNoise::positions() line 131
- static-call CallNoise::positions() line 132
- static-call QueryNoise::positions() line 132
- static-call DmlNoise::positions() line 132
- static-call TableDefinitionNoise::positions() line 132
- static-call TableChangeNoise::positions() line 133
- static-call RoutineNoise::positions() line 133
- static-call AccountNoise::positions() line 133
- static-call ReplicationNoise::positions() line 133
- static-call ServerNoise::positions() line 134
- static-call UtilityNoise::positions() line 134
public static function synonyms(): array<string, array<int, string>>Answers the synonym keys of every family by production signature and position.
Returns
array<string, array<int, string>>Test cases 1
Called from 1
Calls 14
- static-call DispatchNoise::synonyms() line 144
- static-call LeafNoise::synonyms() line 144
- static-call TypeNoise::synonyms() line 144
- static-call ExpressionNoise::synonyms() line 144
- static-call CallNoise::synonyms() line 145
- static-call QueryNoise::synonyms() line 145
- static-call DmlNoise::synonyms() line 145
- static-call TableDefinitionNoise::synonyms() line 145
- static-call TableChangeNoise::synonyms() line 146
- static-call RoutineNoise::synonyms() line 146
- static-call AccountNoise::synonyms() line 146
- static-call ReplicationNoise::synonyms() line 146
- static-call ServerNoise::synonyms() line 147
- static-call UtilityNoise::synonyms() line 147
Private surface 4§
Implementation details, listed for orientation only.
private const NAME_RULES = ['IDENT_sys' => true, 'keyword' => true, 'keyword_sp' => true, 'ident_keywords_…private static array<string, list<int>>|null $noise = nullprivate static array<string, array<int, string>>|null $synonyms = nullprivate LexicalSettings $lexicalTest cases 10§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 10
LeafKeysTest::testKeyAnswersTheStatedKeyAtSynonymPositionscallsLeafKeysTest::testKeyDecodesLiteralsByTheirExactValuecallsLeafKeysTest::testKeyDecodesNamesAtNameProductionscallsLeafKeysTest::testKeyDecodesStringsUnderTheEscapeSettingcallsLeafKeysTest::testKeyIsNullAtNoisePositionsAndForTheEndMarkercallsLeafKeysTest::testKeyKeysKeywordsAndPunctuationByTerminalcallsLeafKeysTest::testNameDecodesIdentifiersStringsAndKeywordsAsNamescallsLeafKeysTest::testNoiseMergesEveryFamilyTableKeyedBySignaturecallsLeafKeysTest::testSynonymsMergesEveryFamilyTableKeyedBySignaturecallsLeafKeysTest::testTerminalKeysEachTerminalByWhatItDenotescalls