|
25 | 25 | //! 1. [`Parser::parse_sql`] and [`Parser::new`] for the Parsing API
|
26 | 26 | //! 2. [`ast`] for the AST structure
|
27 | 27 | //! 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) |
29 | 29 | //!
|
30 | 30 | //! [`Spanned`]: ast::Spanned
|
31 | 31 | //!
|
|
64 | 64 | //! // The original SQL text can be generated from the AST
|
65 | 65 | //! assert_eq!(ast[0].to_string(), sql);
|
66 | 66 | //! ```
|
67 |
| -//! |
68 | 67 | //! [sqlparser crates.io page]: https://crates.io/crates/sqlparser
|
69 | 68 | //! [`Parser::parse_sql`]: crate::parser::Parser::parse_sql
|
70 | 69 | //! [`Parser::new`]: crate::parser::Parser::new
|
71 | 70 | //! [`AST`]: crate::ast
|
72 | 71 | //! [`ast`]: crate::ast
|
73 | 72 | //! [`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 |
74 | 123 |
|
75 | 124 | #![cfg_attr(not(feature = "std"), no_std)]
|
76 | 125 | #![allow(clippy::upper_case_acronyms)]
|
|
0 commit comments