Skip to content

Commit 3dc1869

Browse files
committed
Name lexer token constants after the MySQL grammar
The token constants kept the names of the MySQL Workbench lexer the package was ported from (OPEN_PAR_SYMBOL, INT_NUMBER, BACK_TICK_QUOTED_ID, ...), and generate-tokens.php mapped them to grammar terminals. Name them after their sql_yacc.yy terminals instead (IDENT, NUM, TEXT_STRING, GT_SYM, ...), the same source as the AST rule names. Single-character terminals have no usable Bison name, so they are named after the character (LEFT_PAREN, ASTERISK, ...). The old role names were often wrong, e.g., "*" is also the SELECT wildcard. The end marker is YYEOF, as in the C code that Bison generates. SINGLE_QUOTED_TEXT and DOUBLE_QUOTED_TEXT were aliases of one terminal, so they become a single TEXT_STRING constant. A new test guards against such aliases.
1 parent ca62f60 commit 3dc1869

6 files changed

Lines changed: 397 additions & 389 deletions

File tree

‎packages/mysql-parser/src/class-wp-mysql-lexer.php‎

Lines changed: 142 additions & 150 deletions
Large diffs are not rendered by default.

‎packages/mysql-parser/src/class-wp-mysql-token.php‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,7 @@ public function get_name(): string {
6262
*/
6363
public function get_value(): string {
6464
$value = $this->get_bytes();
65-
if (
66-
WP_MySQL_Lexer::SINGLE_QUOTED_TEXT === $this->id
67-
|| WP_MySQL_Lexer::DOUBLE_QUOTED_TEXT === $this->id
68-
|| WP_MySQL_Lexer::BACK_TICK_QUOTED_ID === $this->id
69-
) {
65+
if ( WP_MySQL_Lexer::TEXT_STRING === $this->id || WP_MySQL_Lexer::IDENT_QUOTED === $this->id ) {
7066
// Remove bounding quotes.
7167
$quote = $value[0];
7268
$value = substr( $value, 1, -1 );
@@ -79,7 +75,7 @@ public function get_value(): string {
7975
* See: https://dev.mysql.com/doc/refman/8.4/en/identifiers.html
8076
*/
8177
if (
82-
WP_MySQL_Lexer::BACK_TICK_QUOTED_ID === $this->id
78+
WP_MySQL_Lexer::IDENT_QUOTED === $this->id
8379
|| $this->sql_mode_no_backslash_escapes_enabled
8480
) {
8581
return str_replace( $quote . $quote, $quote, $value );

0 commit comments

Comments
 (0)