Struct move_model::code_writer::CodeWriter
source · pub struct CodeWriter(_);
Expand description
A helper to emit code. Supports indentation and maintains source to target location information.
Implementations§
source§impl CodeWriter
impl CodeWriter
sourcepub fn new(loc: Loc) -> CodeWriter
pub fn new(loc: Loc) -> CodeWriter
Creates new code writer, with the given default location.
sourcepub fn create_label(&self) -> CodeWriterLabel
pub fn create_label(&self) -> CodeWriterLabel
Creates a label at which code can be inserted later.
sourcepub fn insert_at_label(&self, label: CodeWriterLabel, s: &str)
pub fn insert_at_label(&self, label: CodeWriterLabel, s: &str)
Inserts code at the previously created label.
sourcepub fn process_result<T, F: FnMut(&str) -> T>(&self, f: F) -> T
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.
sourcepub fn extract_result(&self) -> String
pub fn extract_result(&self) -> String
Extracts the output as a string. Leaves the writers data empty.
sourcepub fn set_location(&self, loc: &Loc)
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.
sourcepub fn get_source_location(&self, output_index: ByteIndex) -> Option<Loc>
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.
sourcepub fn get_output_byte_index(
&self,
line: LineIndex,
column: ColumnIndex
) -> Option<ByteIndex>
pub fn get_output_byte_index( &self, line: LineIndex, column: ColumnIndex ) -> Option<ByteIndex>
Given line/column location, determine ByteIndex of that location.
sourcepub fn indent(&self)
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.
sourcepub fn with_indent<F>(&self, f: F)where
F: FnMut(),
pub fn with_indent<F>(&self, f: F)where F: FnMut(),
Emit some code with indentation