pub struct SourceLocation {
pub line: usize,
pub column: usize,
pub start_byte: usize,
pub end_byte: usize,
}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, ) -> Self
Sourcepub fn as_str<'a>(&self, source: &'a [u8]) -> Option<&'a str>
pub fn as_str<'a>(&self, source: &'a [u8]) -> Option<&'a str>
Extract the source text for this location
Sourcepub fn find_line_bounds(&self, source: &[u8]) -> (usize, usize)
pub fn find_line_bounds(&self, source: &[u8]) -> (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,
source: &[u8],
) -> (usize, usize)
pub fn find_line_bounds_with_following_blank( &self, source: &[u8], ) -> (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, source: &[u8]) -> String
pub fn extract_line_indentation(&self, source: &[u8]) -> 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, source: &[u8]) -> String
pub fn extract_indentation(&self, source: &[u8]) -> 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_semicolon_end(&self, source: &[u8]) -> usize
pub fn find_semicolon_end(&self, source: &[u8]) -> usize
Scan forward from end_byte through whitespace to find a ; and
return the byte position immediately after it. Returns end_byte
unchanged if no semicolon is found within a short distance.
Trait Implementations§
Source§impl Clone for SourceLocation
impl Clone for SourceLocation
Source§fn clone(&self) -> SourceLocation
fn clone(&self) -> SourceLocation
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more