From 89911ee8d1744e695566d5a3fd2e6d51911e0f25 Mon Sep 17 00:00:00 2001 From: "Levy A." Date: Wed, 16 Jul 2025 12:26:59 -0300 Subject: [PATCH] remove `to_sql_string` from simulator --- simulator/model/query/select.rs | 6 +++--- vendored/sqlite3-parser/src/parser/ast/fmt.rs | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/simulator/model/query/select.rs b/simulator/model/query/select.rs index 17d0a6844..9cc9fc4b8 100644 --- a/simulator/model/query/select.rs +++ b/simulator/model/query/select.rs @@ -4,7 +4,7 @@ use anyhow::Context; pub use ast::Distinctness; use itertools::Itertools; use serde::{Deserialize, Serialize}; -use turso_sqlite3_parser::{ast, to_sql_string::ToSqlString}; +use turso_sqlite3_parser::ast::{self, fmt::ToTokens}; use crate::{ generation::Shadow, @@ -383,7 +383,7 @@ impl Shadow for SelectInner { } else { return Err(anyhow::anyhow!( "Failed to evaluate expression in free select ({})", - expr.0.to_sql_string(&EmptyContext {}) + expr.0.format_with_context(&EmptyContext {}).unwrap() )); } } @@ -508,7 +508,7 @@ impl Select { } impl Display for Select { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.to_sql_ast().to_sql_string(&EmptyContext {})) + self.to_sql_ast().to_fmt_with_context(f, &EmptyContext {}) } } diff --git a/vendored/sqlite3-parser/src/parser/ast/fmt.rs b/vendored/sqlite3-parser/src/parser/ast/fmt.rs index 17979443c..c95f062bb 100644 --- a/vendored/sqlite3-parser/src/parser/ast/fmt.rs +++ b/vendored/sqlite3-parser/src/parser/ast/fmt.rs @@ -129,15 +129,27 @@ pub trait ToTokens { s: &mut S, context: &C, ) -> Result<(), S::Error>; + /// Send token(s) to the specified stream fn to_tokens(&self, s: &mut S) -> Result<(), S::Error> { self.to_tokens_with_context(s, &BlankContext) } + /// Format AST node fn to_fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - let mut s = FmtTokenStream { f, spaced: true }; - self.to_tokens(&mut s) + self.to_fmt_with_context(f, &BlankContext) } + + /// Format AST node with context + fn to_fmt_with_context( + &self, + f: &mut Formatter<'_>, + context: &C, + ) -> fmt::Result { + let mut s = FmtTokenStream { f, spaced: true }; + self.to_tokens_with_context(&mut s, context) + } + /// Format AST node to string fn format(&self) -> Result { self.format_with_context(&BlankContext) @@ -146,7 +158,6 @@ pub trait ToTokens { /// Format AST node to string with context fn format_with_context(&self, context: &C) -> Result { let mut s = String::new(); - let mut w = WriteTokenStream { write: &mut s, spaced: true,