mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-12-23 11:12:51 +00:00
refactor: Make Parser methods immutable using interior mutability
Changed all parsing methods to take '&self' instead of '\&mut self'. Mutable parser state (token index and parser state) now uses for interior mutability. This refactoring is preparation for the borrowed tokenizer work. When holding borrowed tokens from the parser (with lifetime tied to '\&self'), we cannot call methods requiring '\&mut self' due to Rust's borrowing rules. Using interior mutability resolves this conflict by allowing state mutations through shared references.
This commit is contained in:
parent
b098976cab
commit
650b1ca18f
13 changed files with 658 additions and 716 deletions
|
|
@ -39,7 +39,7 @@ fn custom_prefix_parser() -> Result<(), ParserError> {
|
|||
is_identifier_part(ch)
|
||||
}
|
||||
|
||||
fn parse_prefix(&self, parser: &mut Parser) -> Option<Result<Expr, ParserError>> {
|
||||
fn parse_prefix(&self, parser: &Parser) -> Option<Result<Expr, ParserError>> {
|
||||
if parser.consume_token(&Token::Number("1".to_string(), false)) {
|
||||
Some(Ok(Expr::Value(Value::Null.with_empty_span())))
|
||||
} else {
|
||||
|
|
@ -72,7 +72,7 @@ fn custom_infix_parser() -> Result<(), ParserError> {
|
|||
|
||||
fn parse_infix(
|
||||
&self,
|
||||
parser: &mut Parser,
|
||||
parser: &Parser,
|
||||
expr: &Expr,
|
||||
_precedence: u8,
|
||||
) -> Option<Result<Expr, ParserError>> {
|
||||
|
|
@ -110,7 +110,7 @@ fn custom_statement_parser() -> Result<(), ParserError> {
|
|||
is_identifier_part(ch)
|
||||
}
|
||||
|
||||
fn parse_statement(&self, parser: &mut Parser) -> Option<Result<Statement, ParserError>> {
|
||||
fn parse_statement(&self, parser: &Parser) -> Option<Result<Statement, ParserError>> {
|
||||
if parser.parse_keyword(Keyword::SELECT) {
|
||||
for _ in 0..3 {
|
||||
let _ = parser.next_token();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue