oak_runtime::file_map_stream

Struct FileMap

Source
pub struct FileMap {
    pub name: String,
    pub abs_path: Option<String>,
    pub src: Option<Rc<String>>,
    pub start_pos: BytePos,
    pub end_pos: BytePos,
    pub lines: RefCell<Vec<BytePos>>,
    pub multibyte_chars: RefCell<Vec<MultiByteChar>>,
}
Expand description

A single source in the CodeMap.

Fields§

§name: String

The name of the file that the source came from, source that doesn’t originate from files has names between angle brackets by convention, e.g. <anon>

§abs_path: Option<String>

The absolute path of the file that the source came from.

§src: Option<Rc<String>>

The complete source code

§start_pos: BytePos

The start position of this source in the CodeMap

§end_pos: BytePos

The end position of this source in the CodeMap

§lines: RefCell<Vec<BytePos>>

Locations of lines beginnings in the source code

§multibyte_chars: RefCell<Vec<MultiByteChar>>

Locations of multi-byte characters in the source code

Implementations§

Source§

impl FileMap

Source

pub fn next_line(&self, pos: BytePos)

EFFECT: register a start-of-line offset in the table of line-beginnings. UNCHECKED INVARIANT: these offsets must be added in the right order and must be in the right places; there is shared knowledge about what ends a line between this file and parse.rs WARNING: pos param here is the offset relative to start of CodeMap, and CodeMap will append a newline when adding a filemap without a newline at the end, so the safe way to call this is with value calculated as filemap.start_pos + newline_offset_relative_to_the_start_of_filemap.

Source

pub fn get_line(&self, line_number: usize) -> Option<&str>

get a line from the list of pre-computed line-beginnings. line-number here is 0-based.

Source

pub fn record_multibyte_char(&self, pos: BytePos, bytes: usize)

Source

pub fn is_real_file(&self) -> bool

Source

pub fn is_imported(&self) -> bool

Source

pub fn byte_length(&self) -> u32

Source

pub fn count_lines(&self) -> usize

Source

pub fn lookup_line(&self, pos: BytePos) -> Option<usize>

Find the line containing the given position. The return value is the index into the lines array of this FileMap, not the 1-based line number. If the filemap is empty or the position is located before the first line, None is returned.

Source

pub fn line_bounds(&self, line_index: usize) -> (BytePos, BytePos)

Trait Implementations§

Source§

impl Debug for FileMap

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Decodable for FileMap

Source§

fn decode<D>(d: &mut D) -> Result<FileMap, <D as Decoder>::Error>
where D: Decoder,

Deserialize a value using a Decoder.
Source§

impl Encodable for FileMap

Source§

fn encode<S>(&self, s: &mut S) -> Result<(), <S as Encoder>::Error>
where S: Encoder,

Serialize a value using an Encoder.

Auto Trait Implementations§

§

impl !Freeze for FileMap

§

impl !RefUnwindSafe for FileMap

§

impl !Send for FileMap

§

impl !Sync for FileMap

§

impl Unpin for FileMap

§

impl UnwindSafe for FileMap

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.