Skip to content

Commit 6c17f23

Browse files
committed
Add optional native parser routing
1 parent 91e6d80 commit 6c17f23

5 files changed

Lines changed: 44 additions & 2 deletions

File tree

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,9 @@
22

33
require_once __DIR__ . '/class-wp-mysql-polyfill-lexer.php';
44

5-
class WP_MySQL_Lexer extends WP_MySQL_Polyfill_Lexer {
5+
if ( ! class_exists( 'WP_MySQL_Native_Lexer', false ) ) {
6+
require_once __DIR__ . '/class-wp-mysql-native-lexer.php';
7+
}
8+
9+
class WP_MySQL_Lexer extends WP_MySQL_Native_Lexer {
610
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
3+
class WP_MySQL_Native_Lexer extends WP_MySQL_Polyfill_Lexer {
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
3+
class WP_MySQL_Native_Parser extends WP_MySQL_Polyfill_Parser {
4+
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,13 @@
22

33
require_once __DIR__ . '/class-wp-mysql-polyfill-parser.php';
44

5-
class WP_MySQL_Parser extends WP_MySQL_Polyfill_Parser {
5+
if ( class_exists( 'WP_MySQL_Native_Parser', false ) ) {
6+
if ( ! function_exists( 'wp_sqlite_mysql_native_export_grammar' ) ) {
7+
require_once __DIR__ . '/mysql-rust-bridge.php';
8+
}
9+
} else {
10+
require_once __DIR__ . '/class-wp-mysql-native-parser.php';
11+
}
12+
13+
class WP_MySQL_Parser extends WP_MySQL_Native_Parser {
614
}
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)