eyalsatori commented on issue #2036:
URL:
https://github.com/apache/datafusion-sqlparser-rs/issues/2036#issuecomment-3514033061
Opened PR #2098 (rebased on #2075 and #2073) to use interior mutability
in the Parser.
## The Problem
Adding lifetimes to tokens (`TokenWithSpan<'a>`) creates a borrowing issue:
```rust
pub fn parse_statement(&mut self) -> Result {
let next_token = self.next_token(); // Immutably borrows self via
lifetime 'a
match &next_token.token {
Token::Word(w) => match w.keyword {
Keyword::KILL => self.parse_kill(), // ❌ Can't borrow as &mut
self
```
When `next_token` holds a reference with lifetime tied to `self`, we can't
call methods requiring `&mut self`.
## Solution
This PR converts all parsing methods from `&mut self` to `&self`. Mutable
parser state (token index and parser state) is wrapped in `Cell<T>`, which
provides interior mutability - allowing mutation through shared references.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]