Skip to content

Commit 48ffc55

Browse files
committed
migrate content to issue
1 parent bb7ad71 commit 48ffc55

File tree

4 files changed

+60
-58
lines changed

4 files changed

+60
-58
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ issues and distinguish different syntaxes in the AST.
105105
This crate allows recovering source locations from AST nodes via the [Spanned]
106106
trait, which can be used for advanced diagnostics tooling. Note that this
107107
feature is a work in progress and many nodes report missing or inaccurate spans.
108-
Please see [this document] for information on how to contribute missing
108+
Please see [this ticket] for information on how to contribute missing
109109
improvements.
110110

111111
[Spanned]: https://docs.rs/sqlparser/latest/sqlparser/ast/trait.Spanned.html
112-
[this document]: ./docs/source_spans.md#source-span-contributing-guidelines
112+
[this ticket]: https://github.com/apache/datafusion-sqlparser-rs/issues/1548
113113

114114
```rust
115115
// Parse SQL

docs/source_spans.md

-52
This file was deleted.

src/ast/helpers/attached_token.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,13 @@ use sqlparser_derive::{Visit, VisitMut};
7878
/// assert_eq!(AttachedToken(tok1), AttachedToken(tok2)); // attached tokens are
7979
/// ```
8080
/// // period @ line 2, column 20
81-
82-
/// ```
8381
#[derive(Clone)]
8482
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8583
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8684
pub struct AttachedToken(pub TokenWithLocation);
8785

8886
impl AttachedToken {
87+
/// Return a new Empty AttachedToken
8988
pub fn empty() -> Self {
9089
AttachedToken(TokenWithLocation::wrap(Token::EOF))
9190
}
@@ -130,3 +129,9 @@ impl From<TokenWithLocation> for AttachedToken {
130129
AttachedToken(value)
131130
}
132131
}
132+
133+
impl From<AttachedToken> for TokenWithLocation {
134+
fn from(value: AttachedToken) -> Self {
135+
value.0
136+
}
137+
}

src/lib.rs

+51-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
//! 1. [`Parser::parse_sql`] and [`Parser::new`] for the Parsing API
2626
//! 2. [`ast`] for the AST structure
2727
//! 3. [`Dialect`] for supported SQL dialects
28-
//! 4. [`Spanned`] for source text locations
28+
//! 4. [`Spanned`] for source text locations (see "Source Spans" below for details)
2929
//!
3030
//! [`Spanned`]: ast::Spanned
3131
//!
@@ -64,13 +64,62 @@
6464
//! // The original SQL text can be generated from the AST
6565
//! assert_eq!(ast[0].to_string(), sql);
6666
//! ```
67-
//!
6867
//! [sqlparser crates.io page]: https://crates.io/crates/sqlparser
6968
//! [`Parser::parse_sql`]: crate::parser::Parser::parse_sql
7069
//! [`Parser::new`]: crate::parser::Parser::new
7170
//! [`AST`]: crate::ast
7271
//! [`ast`]: crate::ast
7372
//! [`Dialect`]: crate::dialect::Dialect
73+
//!
74+
//! # Source Spans
75+
//!
76+
//! Starting with version `0.53.0` sqlparser is introducing source spans to the
77+
//! AST. This feature is intended to provide more accurate source locations for
78+
//! syntax errors and to enable better error messages. See [issue #1548] for more
79+
//! information.
80+
//!
81+
//! [issue #1548]: https://github.com/apache/datafusion-sqlparser-rs/issues/1548
82+
//!
83+
//! ## Migration Guide
84+
//!
85+
//! For the next few releases, we will be incrementally adding source spans to the
86+
//! AST, trying to minimizes the impact on existing users, though some breaking
87+
//! changes are inevitable. The following is a summary of the changes:
88+
//!
89+
//! #### New fields for spans (must be added to any existing pattern matches)
90+
//!
91+
//! The primary change is that new fields will be added to AST nodes to store the source `Span` or `TokenWithLocation`.
92+
//!
93+
//! This will require
94+
//! 1. Adding new fields to existing pattern matches.
95+
//! 2. Filling in the proper span information when constructing AST nodes.
96+
//!
97+
//! For example, since `Ident` now stores a `Span`, so to construct an `Ident` you
98+
//! must provide a `Span` when constructing one:
99+
//!
100+
//! Previously:
101+
//! ```rust
102+
//! # use sqlparser::ast::Ident;
103+
//! Ident {
104+
//! value: "name".into(),
105+
//! quote_style: None,
106+
//! }
107+
//! ```
108+
//! Now
109+
//! ```rust
110+
//! # use sqlparser::ast::Ident;
111+
//! # use sqlparser::ast::Span;
112+
//! Ident {
113+
//! value: "name".into(),
114+
//! quote_style: None,
115+
//! span: Span::empty(),
116+
//! }
117+
//! ```
118+
//! #### Misc.
119+
//! - [`TokenWithLocation`] stores a full `Span`, rather than just a source location.
120+
//! Users relying on `token.location` should use `token.location.start` instead.
121+
//!
122+
//![`TokenWithLocation`]: tokenizer::TokenWithLocation
74123
75124
#![cfg_attr(not(feature = "std"), no_std)]
76125
#![allow(clippy::upper_case_acronyms)]

0 commit comments

Comments
 (0)