pub struct SourceLocation {
pub line: usize,
pub column: usize,
pub start_byte: usize,
pub end_byte: usize,
/* private fields */
}Expand description
Source location information for AST nodes
Fields§
§line: usize§column: usize§start_byte: usize§end_byte: usizeImplementations§
Source§impl SourceLocation
impl SourceLocation
pub fn new( line: usize, column: usize, start_byte: usize, end_byte: usize, source: Arc<Vec<u8>>, ) -> Self
Sourcepub fn with_byte_range(&self, start_byte: usize, end_byte: usize) -> Self
pub fn with_byte_range(&self, start_byte: usize, end_byte: usize) -> Self
Create a new SourceLocation sharing the same source but pointing at
a different byte range. Line/column are zeroed since they are only used
for display and these synthetic locations are used for fix generation.
Sourcepub fn find_line_range(&self) -> (usize, usize)
pub fn find_line_range(&self) -> (usize, usize)
Return (start, end) covering the full line from its first byte to just past the trailing newline — no blank-line absorption.
Sourcepub fn find_line_bounds(&self) -> (usize, usize)
pub fn find_line_bounds(&self) -> (usize, usize)
Find the start and end byte positions of the line containing this location Returns (line_start_byte, line_end_byte) including the newline If the previous line is empty (only whitespace), includes it too
Sourcepub fn find_line_bounds_with_following_blank(&self) -> (usize, usize)
pub fn find_line_bounds_with_following_blank(&self) -> (usize, usize)
Find the start and end byte positions of the line containing this location, including any following blank line Returns (line_start_byte, line_end_byte) including newlines
Sourcepub fn extract_line_indentation(&self) -> String
pub fn extract_line_indentation(&self) -> String
Extract indentation (leading whitespace) from the line containing this location. Returns all leading spaces/tabs from the start of the line.
Sourcepub fn extract_indentation(&self) -> String
pub fn extract_indentation(&self) -> String
Extract indentation (leading whitespace) up to this location Returns the spaces/tabs from line start up to (but not past) the location
Sourcepub fn find_after(&self, target: u8) -> usize
pub fn find_after(&self, target: u8) -> usize
Scan forward from end_byte through whitespace to find target and
return the byte position immediately after it. Returns end_byte
unchanged if the target is not found before a non-whitespace byte.
Sourcepub fn find_before(&self, target: u8) -> usize
pub fn find_before(&self, target: u8) -> usize
Scan backward from start_byte through whitespace to find target and
return the byte position of the target. Returns start_byte
unchanged if the target is not found before a non-whitespace byte.
Sourcepub fn find_semicolon_end(&self) -> usize
pub fn find_semicolon_end(&self) -> usize
Convenience: scan forward for ; — equivalent to find_after(b';')
Sourcepub fn count_trailing_newlines(&self) -> usize
pub fn count_trailing_newlines(&self) -> usize
Count consecutive newlines immediately after end_byte.
Sourcepub fn find_braces_around(&self) -> (usize, usize)
pub fn find_braces_around(&self) -> (usize, usize)
Find braces surrounding this location in the source. Returns (opening_brace_pos, closing_brace_pos) using depth tracking to find matching braces.