Skip to content

Commit

Permalink
Move to a separate feature
Browse files Browse the repository at this point in the history
  • Loading branch information
blaginin committed Dec 2, 2024
1 parent 78effdf commit 34acb8b
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ name = "sqlparser"
path = "src/lib.rs"

[features]
default = ["std"]
std = ["recursive"]
default = ["std", "recursive-protection"]
std = []
recursive-protection = ["std", "recursive"]
# Enable JSON output in the `cli` example:
json_example = ["serde_json", "serde"]
visitor = ["sqlparser_derive"]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ The following optional [crate features](https://doc.rust-lang.org/cargo/referen

* `serde`: Adds [Serde](https://serde.rs/) support by implementing `Serialize` and `Deserialize` for all AST nodes.
* `visitor`: Adds a `Visitor` capable of recursively walking the AST tree.

* `recursive-protection` (enabled by default), uses [recursive](https://docs.rs/recursive/latest/recursive/) for stack overflow protection.

## Syntax vs Semantics

This crate provides only a syntax parser, and tries to avoid applying
any SQL semantics, and accepts queries that specific databases would
any SQL semantics, and accepts queries that specific databases wouldc
reject, even when using that Database's specific `Dialect`. For
example, `CREATE TABLE(x int, x int)` is accepted by this crate, even
though most SQL engines will reject this statement due to the repeated
Expand Down
2 changes: 1 addition & 1 deletion derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn derive_visit(input: proc_macro::TokenStream, visit_type: &VisitType) -> proc_
// Note that it uses [`recursive::recursive`] to protect from stack overflow.
// See tests in https://github.com/apache/datafusion-sqlparser-rs/pull/1522/ for more info.
impl #impl_generics sqlparser::ast::#visit_trait for #name #ty_generics #where_clause {
#[cfg_attr(feature = "std", recursive::recursive)]
#[cfg_attr(feature = "recursive-protection", recursive::recursive)]
fn visit<V: sqlparser::ast::#visitor_trait>(
&#modifier self,
visitor: &mut V
Expand Down
2 changes: 1 addition & 1 deletion src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1285,7 +1285,7 @@ impl fmt::Display for CastFormat {
}

impl fmt::Display for Expr {
#[cfg_attr(feature = "std", recursive::recursive)]
#[cfg_attr(feature = "recursive-protection", recursive::recursive)]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Expr::Identifier(s) => write!(f, "{s}"),
Expand Down
4 changes: 2 additions & 2 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ mod recursion {
/// borrow checker so the automatic [`DepthGuard`] decrement a
/// reference to the counter.
///
/// Note: when "std" feature is enabled, this crate uses additional stack overflow protection
/// Note: when "recursive-protection" feature is enabled, this crate uses additional stack overflow protection
/// for some of its recursive methods. See [`recursive::recursive`] for more information.
pub(crate) struct RecursionCounter {
remaining_depth: Rc<Cell<usize>>,
Expand Down Expand Up @@ -330,7 +330,7 @@ impl<'a> Parser<'a> {
/// # }
/// ```
///
/// Note: when "std" feature is enabled, this crate uses additional stack overflow protection
/// Note: when "recursive-protection" feature is enabled, this crate uses additional stack overflow protection
// for some of its recursive methods. See [`recursive::recursive`] for more information.
pub fn with_recursion_limit(mut self, recursion_limit: usize) -> Self {
self.recursion_counter = RecursionCounter::new(recursion_limit);
Expand Down

0 comments on commit 34acb8b

Please sign in to comment.