pub struct ParserContext { /* private fields */ }Expand description
A reusable parse context that keeps a bumpalo::Bump arena alive between
re-parses, resetting it (O(1)) instead of dropping and reallocating.
This is the preferred entry point for LSP servers or any tool that parses the same document repeatedly. Once the arena has grown to accommodate the largest document seen, subsequent parses reuse the backing memory without any new allocations.
The Rust lifetime system enforces safety: the returned ParseResult
borrows from self, so the borrow checker prevents calling reparse or
reparse_versioned again while the previous result is still alive.
§Example
let mut ctx = php_rs_parser::ParserContext::new();
let result = ctx.reparse("<?php echo 1;");
assert!(result.errors.is_empty());
drop(result); // must be dropped before the next reparse
let result = ctx.reparse("<?php echo 2;");
assert!(result.errors.is_empty());Implementations§
Source§impl ParserContext
impl ParserContext
Sourcepub fn reparse<'a, 'src>(
&'a mut self,
source: &'src str,
) -> ParseResult<'a, 'src>
pub fn reparse<'a, 'src>( &'a mut self, source: &'src str, ) -> ParseResult<'a, 'src>
Reset the arena and parse source using PHP 8.5 (the latest version).
The previous ParseResult must be dropped before calling this
method. The borrow checker enforces this: the returned result borrows
self for the duration of its lifetime, so a second call while the
first result is still live is a compile-time error.
Sourcepub fn reparse_versioned<'a, 'src>(
&'a mut self,
source: &'src str,
version: PhpVersion,
) -> ParseResult<'a, 'src>
pub fn reparse_versioned<'a, 'src>( &'a mut self, source: &'src str, version: PhpVersion, ) -> ParseResult<'a, 'src>
Reset the arena and parse source targeting the given PHP version.
See reparse for lifetime safety notes.