Skip to content

Commit 2716348

Browse files
authored
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 -->
1 parent ca62f60 commit 2716348

11 files changed

Lines changed: 486 additions & 432 deletions

‎packages/mysql-parser/README.md‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ It outputs a compact parse table and a list of MySQL tokens for the lexer:
1414
mysql-server sources
1515
sql/sql_yacc.yy ──▶ Bison 3.8.2 ──▶ automaton.xml ─┬─▶ generate-parse-table.php ──▶ mysql-parse-table.php
1616
|
17-
sql/lex.h ─────────────────────────────────────────┴─▶ generate-tokens.php ───────▶ class-wp-mysql-tokens.php
17+
sql/lex.h ─────────────────────────────────────────┴─▶ generate-tokens.php ───────▶ class-wp-mysql-lexer.php
1818
```
1919

2020
The runtime ships only the compiled artifacts and a thin parser implementation.
@@ -37,6 +37,30 @@ $tokens = ( new WP_MySQL_Lexer( 'SELECT 1 + 2' ) )->remaining_tokens();
3737
$ast = $parser->parse( $tokens );
3838
```
3939

40+
## Tokens and AST nodes
41+
AST nodes and tokens use the names from the official MySQL grammar (`sql/sql_yacc.yy`):
42+
43+
- **Nodes** are named after grammar rules, such as `select_item` or `simple_expr`.
44+
- **Keywords** are looked up by their SQL spelling in `WP_MySQL_Lexer::KEYWORDS`,
45+
which is generated from the MySQL keyword list (`sql/lex.h`). Like MySQL, the lexer
46+
emits a few of them as other terminals: `||` as `OR2_SYM` (without `PIPES_AS_CONCAT`),
47+
`NOT` as `NOT2_SYM` (with `HIGH_NOT_PRECEDENCE`), and `WITH ROLLUP` as `WITH_ROLLUP_SYM`.
48+
- **Other tokens** are `WP_MySQL_Lexer` constants named after their grammar terminals,
49+
such as `IDENT`, `TEXT_STRING`, `NUM`, or `EQ` (`=`).
50+
- **Single-character terminals**, which the grammar writes as a quoted character
51+
like `'('`, are named after the character, such as `LEFT_PAREN`, `COMMA`, or `ASTERISK`.
52+
53+
```php
54+
$ast->get_descendant_nodes( 'select_item' ); // A grammar rule.
55+
$ast->get_first_descendant_token( WP_MySQL_Lexer::KEYWORDS['DISTINCT'] ); // A keyword.
56+
$ast->get_first_descendant_token( WP_MySQL_Lexer::IDENT ); // A grammar terminal.
57+
$ast->get_first_descendant_token( WP_MySQL_Lexer::ASTERISK ); // A single character.
58+
```
59+
60+
Token IDs are the grammar's own token numbers. Like in MySQL, the token stream of
61+
valid input ends with `END_OF_INPUT` and `YYEOF`. For debugging, `$token->get_name()`
62+
returns a readable token name.
63+
4064
## Development
4165
This package includes the full grammar compilation pipeline. The generated artifacts
4266
are committed to the repository, and they only need to be regenerated on grammar

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

Lines changed: 144 additions & 169 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 );

‎packages/mysql-parser/tests/WP_MySQL_Lexer_Tests.php‎

Lines changed: 190 additions & 158 deletions
Large diffs are not rendered by default.

‎packages/mysql-parser/tests/WP_MySQL_Server_Suite_Parser_Tests.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class WP_MySQL_Server_Suite_Parser_Tests extends TestCase {
2020
* legitimately changes.
2121
*/
2222
const EXPECTED_QUERIES = 69158;
23-
const EXPECTED_FAILURES = 170;
23+
const EXPECTED_FAILURES = 167;
2424

2525
public function test_corpus_acceptance_rate(): void {
2626
$parser = WP_MySQL_Parser_Factory::create_parser();
@@ -36,7 +36,7 @@ public function test_corpus_acceptance_rate(): void {
3636
++$total;
3737

3838
// Pin the MySQL version. The failure set in FAILURES_PATH depends on it.
39-
$tokens = ( new WP_MySQL_Lexer( $query, 80038 ) )->remaining_tokens();
39+
$tokens = ( new WP_MySQL_Lexer( $query, 80410 ) )->remaining_tokens();
4040
if ( null === $parser->parse( $tokens ) ) {
4141
$failures[] = $query;
4242
}

‎packages/mysql-parser/tests/WP_MySQL_Token_Data_Tests.php‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ public function test_every_emittable_token_has_a_derived_name(): void {
2929
}
3030
}
3131

32+
public function test_token_constants_have_distinct_numbers(): void {
33+
// Each token constant names one grammar terminal; none is an alias.
34+
$numbers = array();
35+
foreach ( ( new ReflectionClass( WP_MySQL_Lexer::class ) )->getConstants() as $name => $value ) {
36+
if ( is_int( $value ) && $value >= 0 && 0 !== strpos( $name, 'SQL_MODE_' ) ) {
37+
$this->assertArrayNotHasKey( $value, $numbers, "Constant $name shares token $value with another constant" );
38+
$numbers[ $value ] = $name;
39+
}
40+
}
41+
$this->assertNotEmpty( $numbers );
42+
}
43+
3244
public function test_function_keywords_are_a_subset_of_keywords(): void {
3345
$this->assertNotEmpty( WP_MySQL_Lexer::FUNCTIONS );
3446
foreach ( array_keys( WP_MySQL_Lexer::FUNCTIONS ) as $keyword ) {
@@ -64,12 +76,12 @@ public function test_derived_names_prefer_plain_keywords_and_constants(): void {
6476
$this->assertSame( 'CURRENT_DATE', WP_MySQL_Lexer::get_token_name( WP_MySQL_Lexer::KEYWORDS['CURDATE'] ) );
6577

6678
// Constant name for non-keyword tokens.
67-
$this->assertSame( 'IDENTIFIER', WP_MySQL_Lexer::get_token_name( WP_MySQL_Lexer::IDENTIFIER ) );
68-
$this->assertSame( 'SINGLE_QUOTED_TEXT', WP_MySQL_Lexer::get_token_name( WP_MySQL_Lexer::SINGLE_QUOTED_TEXT ) );
69-
$this->assertSame( 'AT_SIGN_SYMBOL', WP_MySQL_Lexer::get_token_name( WP_MySQL_Lexer::AT_SIGN_SYMBOL ) );
70-
$this->assertSame( 'WITH_ROLLUP_SYMBOL', WP_MySQL_Lexer::get_token_name( WP_MySQL_Lexer::WITH_ROLLUP_SYMBOL ) );
79+
$this->assertSame( 'IDENT', WP_MySQL_Lexer::get_token_name( WP_MySQL_Lexer::IDENT ) );
80+
$this->assertSame( 'TEXT_STRING', WP_MySQL_Lexer::get_token_name( WP_MySQL_Lexer::TEXT_STRING ) );
81+
$this->assertSame( 'AT_SIGN', WP_MySQL_Lexer::get_token_name( WP_MySQL_Lexer::AT_SIGN ) );
82+
$this->assertSame( 'WITH_ROLLUP_SYM', WP_MySQL_Lexer::get_token_name( WP_MySQL_Lexer::WITH_ROLLUP_SYM ) );
7183
$this->assertSame( 'END_OF_INPUT', WP_MySQL_Lexer::get_token_name( WP_MySQL_Lexer::END_OF_INPUT ) );
72-
$this->assertSame( 'END_MARKER', WP_MySQL_Lexer::get_token_name( WP_MySQL_Lexer::END_MARKER ) );
84+
$this->assertSame( 'YYEOF', WP_MySQL_Lexer::get_token_name( WP_MySQL_Lexer::YYEOF ) );
7385
}
7486

7587
public function test_internal_scanner_sentinels_cannot_collide_with_grammar_tokens(): void {

‎packages/mysql-parser/tests/WP_MySQL_Token_Tests.php‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class WP_MySQL_Token_Tests extends TestCase {
1515
* @return WP_MySQL_Token The first matching token.
1616
*/
1717
private static function first_token( string $sql, string $name, array $sql_modes = array() ): WP_MySQL_Token {
18-
foreach ( ( new WP_MySQL_Lexer( $sql, 80400, $sql_modes ) )->remaining_tokens() as $token ) {
18+
foreach ( ( new WP_MySQL_Lexer( $sql, 80410, $sql_modes ) )->remaining_tokens() as $token ) {
1919
if ( $token->get_name() === $name ) {
2020
return $token;
2121
}
@@ -24,13 +24,13 @@ private static function first_token( string $sql, string $name, array $sql_modes
2424
}
2525

2626
public function test_get_value_unquotes_string_literals(): void {
27-
$this->assertSame( "a'b", self::first_token( "SELECT 'a''b'", 'SINGLE_QUOTED_TEXT' )->get_value() );
28-
$this->assertSame( 'a"b', self::first_token( 'SELECT "a""b"', 'SINGLE_QUOTED_TEXT' )->get_value() );
29-
$this->assertSame( "new\nline", self::first_token( "SELECT 'new\\nline'", 'SINGLE_QUOTED_TEXT' )->get_value() );
27+
$this->assertSame( "a'b", self::first_token( "SELECT 'a''b'", 'TEXT_STRING' )->get_value() );
28+
$this->assertSame( 'a"b', self::first_token( 'SELECT "a""b"', 'TEXT_STRING' )->get_value() );
29+
$this->assertSame( "new\nline", self::first_token( "SELECT 'new\\nline'", 'TEXT_STRING' )->get_value() );
3030
}
3131

3232
public function test_get_value_honors_no_backslash_escapes_mode(): void {
33-
$token = self::first_token( "SELECT 'a\\nb'", 'SINGLE_QUOTED_TEXT', array( 'NO_BACKSLASH_ESCAPES' ) );
33+
$token = self::first_token( "SELECT 'a\\nb'", 'TEXT_STRING', array( 'NO_BACKSLASH_ESCAPES' ) );
3434
$this->assertSame( 'a\\nb', $token->get_value() );
3535
}
3636

@@ -40,41 +40,41 @@ public function test_get_value_preserves_non_utf8_bytes_in_string_literals(): vo
4040
$raw = chr( 0xFF ) . chr( 0xFE );
4141
$this->assertSame(
4242
$raw,
43-
self::first_token( "SELECT '$raw'", 'SINGLE_QUOTED_TEXT' )->get_value()
43+
self::first_token( "SELECT '$raw'", 'TEXT_STRING' )->get_value()
4444
);
4545

4646
// A backslash escape strips the backslash and preserves the following non-UTF-8 byte.
4747
$this->assertSame(
4848
chr( 0xE9 ),
49-
self::first_token( "SELECT '\\" . chr( 0xE9 ) . "'", 'SINGLE_QUOTED_TEXT' )->get_value()
49+
self::first_token( "SELECT '\\" . chr( 0xE9 ) . "'", 'TEXT_STRING' )->get_value()
5050
);
5151

5252
// Valid multibyte UTF-8 still round-trips.
5353
$this->assertSame(
5454
'café 🙂',
55-
self::first_token( "SELECT 'café 🙂'", 'SINGLE_QUOTED_TEXT' )->get_value()
55+
self::first_token( "SELECT 'café 🙂'", 'TEXT_STRING' )->get_value()
5656
);
5757
}
5858

5959
public function test_get_value_unescapes_newlines_and_multibyte_characters(): void {
6060
$this->assertSame(
6161
"\n",
62-
self::first_token( "SELECT '\\\n'", 'SINGLE_QUOTED_TEXT' )->get_value()
62+
self::first_token( "SELECT '\\\n'", 'TEXT_STRING' )->get_value()
6363
);
6464
$this->assertSame(
6565
'🙂',
66-
self::first_token( "SELECT '\\🙂'", 'SINGLE_QUOTED_TEXT' )->get_value()
66+
self::first_token( "SELECT '\\🙂'", 'TEXT_STRING' )->get_value()
6767
);
6868
}
6969

7070
public function test_get_value_unquotes_backtick_identifiers(): void {
71-
$this->assertSame( 'col name', self::first_token( 'SELECT `col name` FROM t', 'BACK_TICK_QUOTED_ID' )->get_value() );
71+
$this->assertSame( 'col name', self::first_token( 'SELECT `col name` FROM t', 'IDENT_QUOTED' )->get_value() );
7272
}
7373

7474
public function test_get_value_unquotes_ansi_identifiers(): void {
7575
$this->assertSame(
7676
'a"b',
77-
self::first_token( 'SELECT "a""b"', 'BACK_TICK_QUOTED_ID', array( 'ANSI_QUOTES' ) )->get_value()
77+
self::first_token( 'SELECT "a""b"', 'IDENT_QUOTED', array( 'ANSI_QUOTES' ) )->get_value()
7878
);
7979
}
8080

@@ -84,7 +84,7 @@ public function test_get_value_does_not_unquote_unquoted_tokens(): void {
8484
// by token ids and must return keyword bytes as-is.
8585
$this->assertSame( 'SSL', self::first_token( 'CREATE USER u REQUIRE SSL', 'SSL' )->get_value() );
8686
$this->assertSame( 'SELECT', self::first_token( 'SELECT 1', 'SELECT' )->get_value() );
87-
$this->assertSame( '42', self::first_token( 'SELECT 42', 'INT_NUMBER' )->get_value() );
87+
$this->assertSame( '42', self::first_token( 'SELECT 42', 'NUM' )->get_value() );
8888
}
8989

9090
public function test_get_name_resolves_bison_terminal_names(): void {
@@ -94,7 +94,7 @@ public function test_get_name_resolves_bison_terminal_names(): void {
9494
$names[] = $token->get_name();
9595
}
9696
$this->assertSame(
97-
array( 'SELECT', 'SINGLE_QUOTED_TEXT', 'COMMA_SYMBOL', 'OPEN_PAR_SYMBOL', 'INT_NUMBER', 'CLOSE_PAR_SYMBOL', 'END_OF_INPUT', 'END_MARKER' ),
97+
array( 'SELECT', 'TEXT_STRING', 'COMMA', 'LEFT_PAREN', 'NUM', 'RIGHT_PAREN', 'END_OF_INPUT', 'YYEOF' ),
9898
$names
9999
);
100100
}

‎packages/mysql-parser/tests/data/corpus-failures.csv‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -653,10 +653,6 @@ UNLOCK TABLES"
653653
"SELECT 'a%' NOT LIKE 'a!%' ESCAPE '!', 'a%' NOT LIKE 'a!' || '%' ESCAPE '!'"
654654
"SELECT 'a%' NOT LIKE 'a!%' ESCAPE '$', 'a%' NOT LIKE 'a!' || '%' ESCAPE '$'"
655655
"SELECT * from ""full"""
656-
"SELECT 1 /*!080100 +1*/ AS should_return_2"
657-
"SELECT 1 /*!080100
658-
+1*/ AS should_return_2"
659-
"SELECT 1 /*!080100 +1*/ AS should_return_2"
660656
"SELECT 1 /*!99999 /* */ */"
661657
"SET sql_mode = 'NO_ENGINE_SUBSTITUTION';
662658
create procedure test_resignal()

‎packages/mysql-parser/tools/fetch-mysql-grammar.sh‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,8 @@ else
4242
sha256 "$build_dir/sql_yacc.yy" "$build_dir/lex.h" | sed 's/^/ /'
4343
fi
4444

45+
# Record the tag for the generators, so the generated files name the right source.
46+
echo "$MYSQL_TAG" > "$build_dir/mysql-tag"
47+
4548
echo " -> $build_dir/sql_yacc.yy ($(wc -l < "$build_dir/sql_yacc.yy" | tr -d ' ') lines)"
4649
echo " -> $build_dir/lex.h ($(wc -l < "$build_dir/lex.h" | tr -d ' ') lines)"

‎packages/mysql-parser/tools/generate-parse-table.php‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,13 @@
4545
}
4646
$xml_path = $argv[1];
4747
$output_path = $argv[2];
48-
$mysql_tag = getenv( 'MYSQL_TAG' );
49-
if ( false === $mysql_tag || '' === $mysql_tag ) {
50-
$mysql_tag = 'mysql-8.4.3';
48+
49+
// The tag of the grammar sources, recorded next to the automaton by fetch-mysql-grammar.sh.
50+
$tag_path = dirname( $xml_path ) . '/mysql-tag';
51+
$mysql_tag = is_file( $tag_path ) ? trim( file_get_contents( $tag_path ) ) : '';
52+
if ( '' === $mysql_tag ) {
53+
fwrite( STDERR, "error: MySQL tag not found in $tag_path; run fetch-mysql-grammar.sh first.\n" );
54+
exit( 1 );
5155
}
5256

5357
ini_set( 'memory_limit', '3G' );

0 commit comments

Comments
 (0)