You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 2716348
Browse filesBrowse the repository at this point in the historyBrowse files
Name lexer tokens after the MySQL grammar and default to MySQL 8.4.10 (#607)
The `mysql-parser` lexer still used the token names of the MySQL
Workbench lexer it was ported from, such as `OPEN_PAR_SYMBOL` or
`INT_NUMBER`. The AST nodes already use names from the MySQL grammar
(`sql_yacc.yy`), so code that uses the parser had to mix two naming
schemes.
**This PR names all lexer tokens after the MySQL grammar:**
- Tokens use their `sql_yacc.yy` names, such as `IDENT`, `TEXT_STRING`,
`NUM`, or `GT_SYM`.
- Single-character tokens have no usable grammar name, so they are named
after the character, such as `LEFT_PAREN`, `COMMA`, or `ASTERISK`.
- The end marker is `YYEOF`, as in the C code that Bison generates.
- `SINGLE_QUOTED_TEXT` and `DOUBLE_QUOTED_TEXT` were two names for one
token, so they are now one `TEXT_STRING`.
Keywords are still looked up by their SQL spelling in
`WP_MySQL_Lexer::KEYWORDS`. The README now explains how to refer to
grammar rules, keywords, and other tokens.
**The lexer now defaults to MySQL 8.4.10**, the version of its grammar
and query corpus. With the old 8.0.38 default, version comments like
`/*!80400 ... */` were skipped. Three corpus queries with six-digit
version comments now parse too.
The PR also fixes a few leftovers:
- The grammar generators now use the MySQL tag of the fetched sources.
Before, the build could write the old `mysql-8.4.3` tag into the parse
table header.
- The unused `WP_MySQL_Lexer::get_token_id()` is removed.
- The README no longer points to a token data file that doesn't exist.
- A `read_quoted_text()` call no longer passes an argument that the
method ignores.
<details>
<summary>All renamed token constants</summary>
| Old | New |
|---|---|
| `OPEN_PAR_SYMBOL`, `CLOSE_PAR_SYMBOL` | `LEFT_PAREN`, `RIGHT_PAREN` |
| `OPEN_CURLY_SYMBOL`, `CLOSE_CURLY_SYMBOL` | `LEFT_BRACE`,
`RIGHT_BRACE` |
| `COMMA_SYMBOL`, `DOT_SYMBOL`, `COLON_SYMBOL`, `SEMICOLON_SYMBOL`,
`AT_SIGN_SYMBOL` | `COMMA`, `DOT`, `COLON`, `SEMICOLON`, `AT_SIGN` |
| `PLUS_OPERATOR`, `MINUS_OPERATOR`, `MULT_OPERATOR`, `DIV_OPERATOR`,
`MOD_OPERATOR` | `PLUS`, `MINUS`, `ASTERISK`, `SLASH`, `PERCENT` |
| `BITWISE_AND_OPERATOR`, `BITWISE_OR_OPERATOR`, `BITWISE_XOR_OPERATOR`,
`BITWISE_NOT_OPERATOR`, `LOGICAL_NOT_OPERATOR` | `AMPERSAND`, `PIPE`,
`CARET`, `TILDE`, `EXCLAMATION` |
| `EQUAL_OPERATOR`, `NULL_SAFE_EQUAL_OPERATOR`, `NOT_EQUAL_OPERATOR` |
`EQ`, `EQUAL_SYM`, `NE` |
| `GREATER_OR_EQUAL_OPERATOR`, `GREATER_THAN_OPERATOR`,
`LESS_OR_EQUAL_OPERATOR`, `LESS_THAN_OPERATOR` | `GE`, `GT_SYM`, `LE`,
`LT` |
| `ASSIGN_OPERATOR`, `SHIFT_LEFT_OPERATOR`, `SHIFT_RIGHT_OPERATOR` |
`SET_VAR`, `SHIFT_LEFT`, `SHIFT_RIGHT` |
| `LOGICAL_AND_OPERATOR`, `LOGICAL_OR_OPERATOR`, `CONCAT_PIPES_SYMBOL` |
`AND_AND_SYM`, `OR2_SYM`, `OR_OR_SYM` |
| `JSON_SEPARATOR_SYMBOL`, `JSON_UNQUOTED_SEPARATOR_SYMBOL` |
`JSON_SEPARATOR_SYM`, `JSON_UNQUOTED_SEPARATOR_SYM` |
| `IDENTIFIER`, `BACK_TICK_QUOTED_ID` | `IDENT`, `IDENT_QUOTED` |
| `SINGLE_QUOTED_TEXT`, `DOUBLE_QUOTED_TEXT`, `NCHAR_TEXT` |
`TEXT_STRING`, `NCHAR_STRING` |
| `INT_NUMBER`, `LONG_NUMBER`, `ULONGLONG_NUMBER`, `DECIMAL_NUMBER`,
`FLOAT_NUMBER` | `NUM`, `LONG_NUM`, `ULONGLONG_NUM`, `DECIMAL_NUM`,
`FLOAT_NUM` |
| `BIN_NUMBER`, `HEX_NUMBER` | `BIN_NUM`, `HEX_NUM` |
| `NULL2_SYMBOL`, `NOT_SYMBOL`, `NOT2_SYMBOL` | `NULL_SYM`, `NOT_SYM`,
`NOT2_SYM` |
| `WITH_SYMBOL`, `ROLLUP_SYMBOL`, `WITH_ROLLUP_SYMBOL` | `WITH`,
`ROLLUP_SYM`, `WITH_ROLLUP_SYM` |
| `END_MARKER` | `YYEOF` |
`PARAM_MARKER`, `UNDERSCORE_CHARSET`, and `END_OF_INPUT` keep their
names.
</details>
## API changes
The package isn't published yet, and the driver still uses its own
lexer, so no released code is affected.
- **Renamed** token constants in `WP_MySQL_Lexer` (see the table above).
`get_name()` returns the new names too, except for tokens with a keyword
spelling, such as `=` for `EQ` or `NULL` for `NULL_SYM`.
- **Removed** `WP_MySQL_Lexer::get_token_id()`.
- **Changed** the default `mysql_version` from `80038` to `80410`.
## Merge notes
- #432 needs the new names when it's rebased.
- #596 merges without a Git conflict, but it adds four uses of
`NCHAR_TEXT` and merges the two `get_value()` conditions into one.
Whichever PR lands second must rename them to `NCHAR_STRING` and
reformat the condition.
Follows up on #429.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
## Summary by CodeRabbit
* **Updates**
* The MySQL parser now defaults to MySQL 8.4.10 and uses MySQL grammar
terminal names for its public tokens. Applications that use the previous
token names or the removed token-ID lookup method may need updates.
* **Documentation**
* Expanded guidance on token and AST naming, keyword handling, special
terminals, token constants and IDs, and end markers. Added examples for
querying descendant nodes and tokens.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
0 commit comments