Skip to content

Commit c19a42d

Browse files
authored
Add optional native parser routing (#385)
## Summary - add fallback `WP_MySQL_Native_*` classes that extend the PHP polyfills - route public MySQL lexer/parser classes through native classes when the extension preloads them - add the minimal PHP bridge that exports grammar data for native parser setup ## Testing - `php -l` on changed PHP files - parser smoke: lex and parse `SELECT 1` through `WP_MySQL_Lexer` and `WP_MySQL_Parser` This PR is intentionally stacked after the polyfill extraction PR so the native routing diff is small and reviewable.
1 parent 97c3ebd commit c19a42d

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
}
2727

2828
if ( class_exists( 'WP_MySQL_Native_Parser', false ) ) {
29+
require_once __DIR__ . '/mysql/native/mysql-rust-bridge.php';
2930
require_once __DIR__ . '/mysql/native/class-wp-mysql-parser.php';
3031
} else {
3132
require_once __DIR__ . '/mysql/class-wp-mysql-parser.php';
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/**
4+
* Bridge helpers for the optional Rust MySQL lexer/parser extension.
5+
* PHP keeps the grammar object, while Rust owns the exported parser state.
6+
*/
7+
8+
/**
9+
* Export grammar internals for the native parser.
10+
*
11+
* @param WP_Parser_Grammar $grammar Parser grammar.
12+
* @return array<string, mixed>
13+
*/
14+
function wp_sqlite_mysql_native_export_grammar( WP_Parser_Grammar $grammar ): array {
15+
return array(
16+
'highest_terminal_id' => $grammar->highest_terminal_id,
17+
'rules' => $grammar->rules,
18+
'lookahead_is_match_possible' => $grammar->lookahead_is_match_possible,
19+
'rule_names' => $grammar->rule_names,
20+
'fragment_ids' => $grammar->fragment_ids,
21+
);
22+
}

0 commit comments

Comments
 (0)