Skip to content

Commit

Permalink
more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb committed Nov 25, 2024
1 parent 03b7486 commit b86dd41
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/ast/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,26 @@ fn union_spans<I: Iterator<Item = Span>>(iter: I) -> Span {
/// # use sqlparser::parser::{Parser, ParserError};
/// # use sqlparser::ast::Spanned;
/// # use sqlparser::dialect::GenericDialect;
/// # use sqlparser::tokenizer::Location;
/// # fn main() -> Result<(), ParserError> {
/// let dialect = GenericDialect {};
/// let sql = r#"SELECT *
/// FROM table_1"#;
/// let statements = Parser::new(&dialect)
/// .try_with_sql("SELECT * FROM table_1")?
/// .try_with_sql(sql)?
/// .parse_statements()?;
/// let span = statements[0].span();
/// assert!(span.
/// // statement starts at line 1, column 1 (1 based, not 0 based)
/// assert_eq!(span.start, Location::new(1, 1));
/// // statement ends on line 2, column 15
/// assert_eq!(span.end, Location::new(2, 15));
/// # Ok(())
/// # }
/// ```
///
pub trait Spanned {
/// Return the source [`Span`] for this AST node, by recursively
/// combining the spans of its children.
/// Return the [`Span`] (the minimum and maximum [`Location`]) for this AST
/// node, by recursively combining the spans of its children.
fn span(&self) -> Span;
}

Expand Down

0 comments on commit b86dd41

Please sign in to comment.