Skip to content

Commit c265cf5

Browse files
committed
Add Rust parser bridge helpers
When a native MySQL parser extension declares WP_MySQL_Native_Parser, load a small bridge file that exposes WP_Parser_Grammar internals to the extension. The native parser needs the grammar's terminal table, rules, and lookahead map, but those live on a PHP object — the bridge function hands them out as a plain array the extension can consume.
1 parent 97c3ebd commit c265cf5

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)