pub struct CodeWriter(_);
Expand description

A helper to emit code. Supports indentation and maintains source to target location information.

Implementations§

source§

impl CodeWriter

source

pub fn new(loc: Loc) -> CodeWriter

Creates new code writer, with the given default location.

source

pub fn create_label(&self) -> CodeWriterLabel

Creates a label at which code can be inserted later.

source

pub fn insert_at_label(&self, label: CodeWriterLabel, s: &str)

Inserts code at the previously created label.

source

pub fn process_result<T, F: FnMut(&str) -> T>(&self, f: F) -> T

Calls a function to process the code written so far. This is embedded into a function so we ensure correct scoping of borrowed RefCell content.

source

pub fn extract_result(&self) -> String

Extracts the output as a string. Leaves the writers data empty.

source

pub fn set_location(&self, loc: &Loc)

Sets the current location. This location will be associated with all subsequently written code so we can map back from the generated code to this location. If current loc is already the passed one, nothing will be updated, so it is ok to call this method repeatedly with the same value.

source

pub fn get_source_location(&self, output_index: ByteIndex) -> Option<Loc>

Given a byte index in the written output, return the best approximation of the source which generated this output.

source

pub fn get_output_byte_index( &self, line: LineIndex, column: ColumnIndex ) -> Option<ByteIndex>

Given line/column location, determine ByteIndex of that location.

source

pub fn indent(&self)

Indents any subsequently written output. The current line of output and any subsequent ones will be indented. Note this works after the last output was \n but the line is still empty.

source

pub fn unindent(&self)

Undo previously done indentation.

source

pub fn with_indent<F>(&self, f: F)where F: FnMut(),

Emit some code with indentation

source

pub fn emit(&self, s: &str)

Emit a string. The string will be broken down into lines to apply current indentation.

source

pub fn emit_line(&self, s: &str)

Emits a string and then terminates the line.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V