Struct leo_span::source_map::SourceFile
source · pub struct SourceFile {
pub name: FileName,
pub src: String,
pub start_pos: BytePos,
pub end_pos: BytePos,
lines: Vec<BytePos>,
multibyte_chars: Vec<MultiByteChar>,
}
Expand description
A single source in the SourceMap
.
Fields§
§name: FileName
The name of the file that the source came from.
src: String
The complete source code.
start_pos: BytePos
The start position of this source in the SourceMap
.
end_pos: BytePos
The end position of this source in the SourceMap
.
lines: Vec<BytePos>
Locations of line beginnings in the source code.
multibyte_chars: Vec<MultiByteChar>
Locations of multi-byte characters in the source code.
Implementations§
source§impl SourceFile
impl SourceFile
sourcefn new(name: FileName, src: String, start_pos: BytePos) -> Self
fn new(name: FileName, src: String, start_pos: BytePos) -> Self
Creates a new SourceFile
given the file name
,
source contents, and the start_pos
ition.
This position is used for analysis purposes.
sourcefn bytepos_to_file_charpos(&self, bpos: BytePos) -> CharPos
fn bytepos_to_file_charpos(&self, bpos: BytePos) -> CharPos
Converts an absolute BytePos
to a CharPos
relative to the SourceFile
.
sourcefn lookup_line(&self, pos: BytePos) -> Option<usize>
fn lookup_line(&self, pos: BytePos) -> Option<usize>
Finds the line containing the given position. The return value is the
index into the lines
array of this SourceFile
, not the 1-based line
number. If the source file is empty or the position is located before the
first line, None
is returned.
sourcefn lookup_file_pos(&self, pos: BytePos) -> (usize, CharPos)
fn lookup_file_pos(&self, pos: BytePos) -> (usize, CharPos)
Looks up the file’s (1-based) line number and (0-based CharPos
) column offset, for a
given BytePos
.
sourcefn contents_of_span(&self, span: Span) -> String
fn contents_of_span(&self, span: Span) -> String
Returns contents of a span
assumed to be within the given file.