diff --git a/src/ast/spans.rs b/src/ast/spans.rs index 0300b29f4..8d68a6e2a 100644 --- a/src/ast/spans.rs +++ b/src/ast/spans.rs @@ -43,20 +43,26 @@ fn union_spans>(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; }