Skip to content

Commit 5eaef7a

Browse files
committed
Wire the SQLite driver to the wordpress/mysql-parser package
Replace the hand-written recursive parser with the table-driven LALR(1) parser generated from MySQL's official grammar, consumed as a Composer dependency: - Require wordpress/mysql-parser, resolved from the monorepo sibling package via a Composer path repository, and load it through the Composer autoloader in the driver loader. - Drop the old parser machinery (WP_Parser, WP_Parser_Grammar, the lexer, the parse tree classes, and mysql-grammar.php), all provided by the parser package now, and the native parser fork, which is bound to the old grammar contract. - Parse multi-statement input by splitting the token stream on top-level ';' separators, as the grammar parses a single statement (this is how MySQL clients split multi-statement input). - Re-key the statement dispatch to the sql_yacc.yy rule names and map keyword token constants to the grammar keyword table. The translation layer still needs to be ported to the new AST shapes.
1 parent 33cbf06 commit 5eaef7a

20 files changed

Lines changed: 477 additions & 4810 deletions
Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
{
2-
"name": "wordpress/mysql-on-sqlite",
3-
"type": "library",
2+
"name": "wordpress/mysql-on-sqlite",
3+
"type": "library",
4+
"require": {
5+
"wordpress/mysql-parser": "@dev"
6+
},
7+
"require-dev": {
8+
"phpunit/phpunit": "^8.5"
9+
},
10+
"repositories": [
11+
{
12+
"type": "path",
13+
"url": "../mysql-parser"
14+
}
15+
],
416
"scripts": {
517
"test": "phpunit",
618
"bench-lexer": [
719
"@php tests/tools/run-lexer-benchmark.php",
820
"@php -d opcache.enable_cli=1 -d opcache.jit_buffer_size=64M -d opcache.jit=tracing tests/tools/run-lexer-benchmark.php"
921
]
10-
},
11-
"require-dev": {
12-
"phpunit/phpunit": "^8.5"
13-
}
22+
}
1423
}

‎packages/mysql-on-sqlite/src/load.php‎

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,14 @@
44

55
/**
66
* Load the PDO MySQL-on-SQLite driver and its dependencies.
7+
*
8+
* The MySQL lexer and parser are provided by the "wordpress/mysql-parser"
9+
* Composer package and are loaded through the Composer autoloader.
710
*/
11+
require_once __DIR__ . '/../vendor/autoload.php';
12+
813
require_once __DIR__ . '/php-polyfills.php';
914
require_once __DIR__ . '/version.php';
10-
require_once __DIR__ . '/parser/class-wp-parser-grammar.php';
11-
require_once __DIR__ . '/parser/class-wp-parser.php';
12-
require_once __DIR__ . '/parser/class-wp-parser-node.php';
13-
require_once __DIR__ . '/parser/class-wp-parser-token.php';
14-
require_once __DIR__ . '/mysql/class-wp-mysql-token.php';
15-
16-
/*
17-
* The MySQL lexer and parser have an optional native (e.g. Rust) implementation.
18-
* When the native extension is loaded, it pre-declares WP_MySQL_Native_Lexer /
19-
* WP_MySQL_Native_Parser; otherwise we fall back to the pure-PHP classes shipped
20-
* here. WP_MySQL_Lexer / WP_MySQL_Parser is the public entrypoint either way.
21-
*/
22-
if ( class_exists( 'WP_MySQL_Native_Lexer', false ) ) {
23-
require_once __DIR__ . '/mysql/native/class-wp-mysql-lexer.php';
24-
} else {
25-
require_once __DIR__ . '/mysql/class-wp-mysql-lexer.php';
26-
}
27-
28-
if ( class_exists( 'WP_MySQL_Native_Parser', false ) ) {
29-
require_once __DIR__ . '/mysql/native/mysql-rust-bridge.php';
30-
require_once __DIR__ . '/mysql/native/class-wp-mysql-native-parser-node.php';
31-
require_once __DIR__ . '/mysql/native/trait-wp-mysql-native-parser-impl.php';
32-
require_once __DIR__ . '/mysql/native/class-wp-mysql-parser.php';
33-
} else {
34-
require_once __DIR__ . '/mysql/class-wp-mysql-parser.php';
35-
}
3615
require_once __DIR__ . '/sqlite/class-wp-sqlite-connection.php';
3716
require_once __DIR__ . '/sqlite/class-wp-sqlite-configurator.php';
3817
require_once __DIR__ . '/sqlite/class-wp-sqlite-driver.php';

‎packages/mysql-on-sqlite/src/mysql/class-wp-mysql-lexer.php‎

Lines changed: 0 additions & 3070 deletions
This file was deleted.

‎packages/mysql-on-sqlite/src/mysql/class-wp-mysql-parser.php‎

Lines changed: 0 additions & 63 deletions
This file was deleted.

‎packages/mysql-on-sqlite/src/mysql/class-wp-mysql-token.php‎

Lines changed: 0 additions & 187 deletions
This file was deleted.

‎packages/mysql-on-sqlite/src/mysql/mysql-grammar.php‎

Lines changed: 0 additions & 4 deletions
This file was deleted.

‎packages/mysql-on-sqlite/src/mysql/native/class-wp-mysql-lexer.php‎

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)