Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update comments / docs for Spanned #1549

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Nov 25, 2024

I took a pass over the code in #1435 and found some places
I thought adding some more documentation would be helpful.

Changes

  1. Updates rustdocs, and adds a bunch of examples
  2. Adds links to [EPIC] Complete Span (source location) information / feature #1548

Follow on work (tickets)

@alamb alamb marked this pull request as draft November 25, 2024 12:24
@@ -1,52 +0,0 @@

Copy link
Contributor Author

@alamb alamb Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This content is great. However, I think it may be hard to find given it is in a separate file

I moved the content into two places:

  1. docs in lib.rs for stuff that is relevant to users
  2. The [EPIC] Complete Span (source location) information / feature #1548 for things that are related to contributors

I think that will make it more likely the documentation can be discovered

syntax from newer versions that have been explicitly requested, plus some MSSQL,
PostgreSQL, and other dialect-specific syntax. Whenever possible, the [online
SQL:2016 grammar][sql-2016-grammar] is used to guide what syntax to accept.
syntax from newer versions that have been explicitly requested, plus various
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drive by clarification

@@ -80,3 +128,9 @@ impl From<TokenWithLocation> for AttachedToken {
AttachedToken(value)
}
}

impl From<AttachedToken> for TokenWithLocation {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seemed to be an obvious gap so I just added it to avoid a papercut

///
/// [this ticket]: https://github.com/apache/datafusion-sqlparser-rs/issues/1548
///
/// # Example
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I felt an example will help people understand how to use the Spans

//! [sqlparser crates.io page]: https://crates.io/crates/sqlparser
//! [`Parser::parse_sql`]: crate::parser::Parser::parse_sql
//! [`Parser::new`]: crate::parser::Parser::new
//! [`AST`]: crate::ast
//! [`ast`]: crate::ast
//! [`Dialect`]: crate::dialect::Dialect
//!
//! # Source Spans
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This content is largely migrated from docs/source_spans.md

#[derive(Eq, PartialEq, Hash, Clone, Copy, Ord, PartialOrd)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub struct Location {
/// Line number, starting from 1
/// Line number, starting from 1.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/// means these comments show up in docs

/// Create a new location for a given line and column
///
/// Alias for [`Self::new`]
// TODO: remove / deprecate in favor of` `new` for consistency?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found the Location::of API kind of confusing -- I would expect that creating a new Rust object would be done via ::new() so I added a new()

I am thinking perhaps we can deprecate Location::of maybe to help downstream users

@@ -21,21 +21,51 @@ use super::{

/// Given an iterator of spans, return the [Span::union] of all spans.
fn union_spans<I: Iterator<Item = Span>>(iter: I) -> Span {
iter.reduce(|acc, item| acc.union(&item))
.unwrap_or(Span::empty())
Span::union_iter(iter)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was useful enough I felt making it a method in Span with more documentation and examples would make it easier to find

/// Span::union_iter(spans),
/// Span::new(Location::new(1, 1), Location::new(4, 2))
/// );
pub fn union_iter<I: IntoIterator<Item = Span>>(iter: I) -> Span {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a private function and I thought it was useful enough it should be its own API and have an example, so I pulled it into a method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants