classNameRule
final class NameRule
Lowers the identifier productions of every release into decoded names.
Rule: MYSQL-NAME-001. Scope: ident, IDENT_sys, label_ident, role_ident, lvalue_ident, ident_or_text, role_ident_or_text, schema, the keyword-as-identifier rules, opt_ident, ident_or_empty, opt_component, storage_engines, known_storage_engines, table_ident, table_name, table_ident_nodb, table_ident_opt_wild, sp_name, table_list, opt_table_list, ident_string_list, simple_ident, simple_ident_nospvar, simple_ident_q, field_ident, table_wild. An identifier token is decoded by MYSQL-IDENTIFIER-DECODE-001; a keyword at a keyword-as-identifier production is the name it spells, letter case kept; a string or a host name at a name position is the name it holds. The leading dot of .table and .table.column names the default database and is not kept. Every name is recorded as an operand leaf. Constructs: Name, QualifiedName, ColumnUse, ColumnName, TableWildcard. Terminates: unit productions are followed in a loop over strict subtrees and lists are flattened iteratively. Source: https://dev.mysql.com/doc/refman/8.4/en/identifiers.html, https://dev.mysql.com/doc/refman/8.4/en/identifier-qualifiers.html, https://dev.mysql.com/doc/refman/8.4/en/keywords.html. Status: Implemented.
Methods§
public function __construct(private Lowering $lowering)Parameters
$lowering | Lowering | The lowering this rule belongs to |
Lowers a position that holds exactly one unqualified name.
Parameters
$name | Node |
Returns
Throws
ImplementationGap When the production has no ruleCalled from 10
- method-call SqlSemantics\Platform\MySql\Lowering\Leaf\NameRule::optional() packages/sql-semantics-mysql/src/Lowering/Leaf/NameRule.php:155
- method-call SqlSemantics\Platform\MySql\Lowering\Leaf\NameRule::qualified() packages/sql-semantics-mysql/src/Lowering/Leaf/NameRule.php:173
- method-call SqlSemantics\Platform\MySql\Lowering\Leaf\NameRule::qualified() packages/sql-semantics-mysql/src/Lowering/Leaf/NameRule.php:175
- method-call SqlSemantics\Platform\MySql\Lowering\Leaf\NameRule::identifiers() packages/sql-semantics-mysql/src/Lowering/Leaf/NameRule.php:226
- method-call SqlSemantics\Platform\MySql\Lowering\Leaf\NameRule::column() packages/sql-semantics-mysql/src/Lowering/Leaf/NameRule.php:250
- method-call SqlSemantics\Platform\MySql\Lowering\Leaf\NameRule::columnName() packages/sql-semantics-mysql/src/Lowering/Leaf/NameRule.php:266
- method-call SqlSemantics\Platform\MySql\Lowering\Leaf\NameRule::optionalColumnName() packages/sql-semantics-mysql/src/Lowering/Leaf/NameRule.php:281
- method-call SqlSemantics\Platform\MySql\Lowering\Leaf\NameRule::qualifier() packages/sql-semantics-mysql/src/Lowering/Leaf/NameRule.php:295
- method-call SqlSemantics\Platform\MySql\Lowering\Leaf\NameRule::wildcard() packages/sql-semantics-mysql/src/Lowering/Leaf/NameRule.php:308
- method-call SqlSemantics\Platform\MySql\Lowering\Leaf\NameRule::wildcard() packages/sql-semantics-mysql/src/Lowering/Leaf/NameRule.php:309
Calls 7
- class-const NameRule::FORWARD() line 118
- new Name line 122
- class-const NameRule::TOKENS() line 124
- method-call NameRule::keyword() line 124
- static-call ImplementationGap::production() line 126
- method-call Identifiers::decode() line 130
- new Identifiers line 130
public function keyword(string $signature): boolTells whether a production reads a keyword as the identifier it spells.
Parameters
$signature | string |
Returns
boolTest cases 1
Called from 1
Calls 4
- function-call
array_fill_keysline 138 - class-const LegacyKeywords::SIGNATURES() line 138
- class-const UnambiguousKeywords::SIGNATURES() line 138
- class-const AmbiguousKeywords::SIGNATURES() line 138
Lowers a position that holds a name or nothing.
Parameters
$name | Node |
Returns
?NameThrows
ImplementationGap When the production has no ruleCalls 2
- class-const NameRule::ABSENT() line 151
- method-call NameRule::identifier() line 155
public function qualified(Node $name): QualifiedNameLowers the name of a table, view or routine with its optional database qualifier.
Parameters
$name | Node |
Returns
Throws
ImplementationGap When the production has no ruleCalled from 1
Calls 5
- class-const NameRule::FORWARD() line 166
- class-const NameRule::QUALIFIED() line 169
- static-call ImplementationGap::production() line 171
- method-call NameRule::identifier() line 173
- new QualifiedName line 175
public function dotted(Node $name): boolTells whether a table name is written after a leading dot, .t (MySQL 5.6 and 5.7).
Parameters
$name | Node |
Returns
boolCalls 1
- class-const NameRule::FORWARD() line 184
public function qualifiedList(Node $list): list<QualifiedName>Lowers a comma-separated list of table names; an absent list is empty.
Parameters
$list | Node |
Returns
list<QualifiedName>Throws
ImplementationGap When a production has no ruleTest cases 1
Calls 4
- method-call Lists::items() line 205
- new Lists line 205
- method-call NameRule::qualified() line 206
- method-call NameRule::claimed() line 208
Lowers a comma-separated list of unqualified names.
Parameters
$list | Node |
Returns
list<Name>Throws
ImplementationGap When a production has no ruleTest cases 1
Calls 4
- method-call NameRule::claimed() line 223
- method-call Lists::items() line 225
- new Lists line 225
- method-call NameRule::identifier() line 226
Lowers a name used as a value into a column use.
Parameters
$column | Node |
Returns
Throws
ImplementationGap When the production has no ruleCalls 9
- class-const NameRule::FORWARD() line 240
- class-const NameRule::COLUMNS() line 243
- function-call
str_starts_withline 244 - static-call ImplementationGap::production() line 245
- class-const OptionalWords::Written() line 248
- class-const OptionalWords::Omitted() line 248
- new ColumnUse line 250
- method-call NameRule::identifier() line 250
- method-call NameRule::qualifier() line 250
public function columnName(Node $field): ColumnNameLowers the name of a column at a position that defines or alters it.
Parameters
$field | Node |
Returns
Throws
ImplementationGap When the production has no ruleTest cases 1
Called from 1
Calls 6
- class-const NameRule::COLUMNS() line 261
- function-call
str_starts_withline 262 - static-call ImplementationGap::production() line 263
- new ColumnName line 266
- method-call NameRule::identifier() line 266
- method-call NameRule::qualifier() line 266
public function optionalColumnName(Node $name): ?ColumnNameLowers the optional name of an index or constraint, which MySQL 5.x lets a table name qualify.
Parameters
$name | Node |
Returns
Throws
ImplementationGap When the production has no ruleTest cases 1
Calls 4
- method-call NameRule::columnName() line 280
- new ColumnName line 281
- method-call NameRule::identifier() line 281
- static-call ImplementationGap::production() line 282
public function qualifier(Form $form, ?int $table, ?int $schema): ?QualifiedNameLowers the table and database qualifier of a column production, when it has one.
Parameters
$form | Form | |
$table | ?int | |
$schema | ?int |
Returns
Test cases 1
Called from 2
Calls 3
- new QualifiedName line 295
- method-call NameRule::identifier() line 295
- method-call Form::node() line 295
public function wildcard(Node $wildcard): TableWildcardLowers a qualified star.
Parameters
$wildcard | Node |
Returns
Throws
ImplementationGap When the production has no ruleTest cases 1
Calls 4
- new TableWildcard line 308
- new QualifiedName line 308
- method-call NameRule::identifier() line 308
- static-call ImplementationGap::production() line 310
public function claimed(Form $form, list<string> $signatures): voidConfirms that a list production is one this rule flattens.
Parameters
$form | Form | |
$signatures | list<string> | The list productions of the rule |
Throws
ImplementationGap When the production has no ruleTest cases 1
Called from 2
Calls 2
- function-call
in_arrayline 322 - static-call ImplementationGap::production() line 323
Private surface 7§
Implementation details, listed for orientation only.
private const FORWARD = ['ident: IDENT_sys' => true, 'ident: keyword' => true, 'ident: ident_keyword' =…private const TOKENS = ['IDENT_sys: IDENT' => 'identifier', 'IDENT_sys: IDENT_QUOTED' => 'identifier',…private const QUALIFIED = ['table_ident: ident' => [0, null], 'table_ident: ident . ident' => [2, 0], 'ta…private const COLUMNS = ['simple_ident: ident' => [0, null, null], 'simple_ident_nospvar: ident' => [0,…private const ABSENT = ['opt_ident:' => true, 'ident_or_empty:' => true, 'opt_component:' => true]private static array<string, true>|null $keywords = nullprivate Lowering $loweringTest cases 8§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 8
NameRuleTest::testClaimedReportsAnUnexpectedListProductioncallsNameRuleTest::testColumnNameLowersADefinedColumnWithItsQualifierscallsNameRuleTest::testIdentifiersFlattensAnIdentifierListcallsNameRuleTest::testKeywordTellsTheKeywordAsIdentifierProductionscallsNameRuleTest::testOptionalColumnNameLowersAnIndexNamecallsNameRuleTest::testQualifiedListFlattensATableListcallsNameRuleTest::testQualifierLowersTheTableAndDatabaseOfAColumnProductioncallsNameRuleTest::testWildcardLowersAQualifiedStarcalls