@@ -422,13 +422,35 @@ impl fmt::Display for Whitespace {
422422}
423423
424424/// Location in input string
425+ ///
426+ /// # Create an "empty" (unknown) `Location`
427+ /// ```
428+ /// # use sqlparser::tokenizer::Location;
429+ /// let location = Location::empty();
430+ /// ```
431+ ///
432+ /// # Create a `Location` from a line and column
433+ /// ```
434+ /// # use sqlparser::tokenizer::Location;
435+ /// let location = Location::new(1, 1);
436+ /// ```
437+ ///
438+ /// # Create a `Location` from a pair
439+ /// ```
440+ /// # use sqlparser::tokenizer::Location;
441+ /// let location = Location::from((1, 1));
442+ /// ```
425443#[ derive( Eq , PartialEq , Hash , Clone , Copy , Ord , PartialOrd ) ]
426444#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
427445#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
428446pub struct Location {
429- /// Line number, starting from 1
447+ /// Line number, starting from 1.
448+ ///
449+ /// Line 0 is used for empty spans
430450 pub line : u64 ,
431- /// Line column, starting from 1
451+ /// Line column, starting from 1.
452+ ///
453+ /// Column 0 is used for empty spans
432454 pub column : u64 ,
433455}
434456
@@ -448,10 +470,24 @@ impl fmt::Debug for Location {
448470}
449471
450472impl Location {
451- pub fn of ( line : u64 , column : u64 ) -> Self {
473+ /// Return an "empty" / unknown location
474+ pub fn empty ( ) -> Self {
475+ Self { line : 0 , column : 0 }
476+ }
477+
478+ /// Create a new `Location` for a given line and column
479+ pub fn new ( line : u64 , column : u64 ) -> Self {
452480 Self { line, column }
453481 }
454482
483+ /// Create a new location for a given line and column
484+ ///
485+ // TODO: remove / deprecate in favor of` `new` for consistency?
486+ pub fn of ( line : u64 , column : u64 ) -> Self {
487+ Self :: new ( line, column)
488+ }
489+
490+ /// Combine self and `end` into a new `Span`
455491 pub fn span_to ( self , end : Self ) -> Span {
456492 Span { start : self , end }
457493 }
0 commit comments