packages/sql-semantics-mysql/src/Rules/Noise/DmlNoise.php
1<?php
2
3declare(strict_types=1);
4
5namespace SqlSemantics\Platform\MySql\Rules\Noise;
6
7/**
8 * The noise and synonym token positions of the productions of data manipulation statements.
9 *
10 * Only a token with no influence on meaning in its production may be listed
11 * as noise, and only terminals the manual defines as synonyms may share a
12 * key. Every entry is listed in the method documentation with its reason and
13 * the manual page that states it. Nothing else is skipped or merged by the
14 * token correspondence check.
15 *
16 * @visibility SqlSemantics\Platform\MySql
17 */
18final class DmlNoise
19{
20 /**
21 * Answers the noise positions by production signature.
22 *
23 * - `opt_INTO: INTO` and `insert2: INTO insert_table`, position 0: INTO is
24 * optional (https://dev.mysql.com/doc/refman/8.4/en/insert.html:
25 * "INSERT ... [INTO] tbl_name"; https://dev.mysql.com/doc/refman/8.4/en/replace.html).
26 * - `opt_from_keyword: FROM`: `LOAD DATA [FROM] [LOCAL] INFILE`, the word
27 * is optional (https://dev.mysql.com/doc/refman/8.4/en/load-data.html;
28 * the grammar action of sql/sql_yacc.yy 8.4 stores nothing).
29 * - `opt_field_or_var_spec: ( )`: an empty column list of LOAD DATA is no
30 * list; the grammar action yields the same null value as an absent
31 * list, and the server then loads every column
32 * (https://dev.mysql.com/doc/refman/8.4/en/load-data.html, sql/sql_yacc.yy 8.4).
33 * - `opt_sp_cparam_list: ( opt_sp_cparams )` and `opt_paren_expr_list: (
34 * opt_expr_list )`, positions 0 and 2: the parentheses of CALL;
35 * without arguments they may be omitted
36 * (https://dev.mysql.com/doc/refman/8.4/en/call.html: "CALL p() and
37 * CALL p are equivalent"). The writer adds them exactly when there are
38 * arguments.
39 *
40 * @return array<string, list<int>>
41 */
42 public static function positions(): array
43 {
44 return [
45 'opt_INTO: INTO' => [0],
46 'insert2: INTO insert_table' => [0],
47 'opt_from_keyword: FROM' => [0],
48 'opt_field_or_var_spec: ( )' => [0, 1],
49 'opt_sp_cparam_list: ( opt_sp_cparams )' => [0, 2],
50 'opt_paren_expr_list: ( opt_expr_list )' => [0, 2],
51 ];
52 }
53
54 /**
55 * Answers the key of each synonym position by production signature.
56 *
57 * - `insert_values: VALUE_SYM values_list` and `value_or_values: VALUE_SYM`:
58 * VALUE is a synonym for VALUES
59 * (https://dev.mysql.com/doc/refman/8.4/en/insert.html: "VALUE is a synonym for VALUES in this context").
60 * - `deallocate_or_drop: DROP`: `{DEALLOCATE | DROP} PREPARE stmt_name`
61 * (https://dev.mysql.com/doc/refman/8.4/en/deallocate-prepare.html).
62 * - `lines_or_rows: ROWS_SYM`: `IGNORE number {LINES | ROWS}` skips that
63 * many lines or rows at the start of the file; both set the same count
64 * (https://dev.mysql.com/doc/refman/8.4/en/load-data.html,
65 * https://dev.mysql.com/doc/refman/8.4/en/load-xml.html).
66 *
67 * @return array<string, array<int, string>>
68 */
69 public static function synonyms(): array
70 {
71 return [
72 'insert_values: VALUE_SYM values_list' => [0 => 'VALUES'],
73 'value_or_values: VALUE_SYM' => [0 => 'VALUES'],
74 'deallocate_or_drop: DROP' => [0 => 'DEALLOCATE_SYM'],
75 'lines_or_rows: ROWS_SYM' => [0 => 'LINES'],
76 ];
77 }
78}
79