@@ -43,20 +43,26 @@ fn union_spans<I: Iterator<Item = Span>>(iter: I) -> Span {
4343/// # use sqlparser::parser::{Parser, ParserError};
4444/// # use sqlparser::ast::Spanned;
4545/// # use sqlparser::dialect::GenericDialect;
46+ /// # use sqlparser::tokenizer::Location;
4647/// # fn main() -> Result<(), ParserError> {
4748/// let dialect = GenericDialect {};
49+ /// let sql = r#"SELECT *
50+ /// FROM table_1"#;
4851/// let statements = Parser::new(&dialect)
49- /// .try_with_sql("SELECT * FROM table_1" )?
52+ /// .try_with_sql(sql )?
5053/// .parse_statements()?;
5154/// let span = statements[0].span();
52- /// assert!(span.
55+ /// // statement starts at line 1, column 1 (1 based, not 0 based)
56+ /// assert_eq!(span.start, Location::new(1, 1));
57+ /// // statement ends on line 2, column 15
58+ /// assert_eq!(span.end, Location::new(2, 15));
5359/// # Ok(())
5460/// # }
5561/// ```
5662///
5763pub trait Spanned {
58- /// Return the source [`Span`] for this AST node, by recursively
59- /// combining the spans of its children.
64+ /// Return the [`Span`] (the minimum and maximum [`Location`]) for this AST
65+ /// node, by recursively combining the spans of its children.
6066 fn span ( & self ) -> Span ;
6167}
6268
0 commit comments