Skip to main content

BlockVisitor

Trait BlockVisitor 

Source
pub trait BlockVisitor: HasDiagnostics + Sized {
    // Provided methods
    fn line_number(&mut self, n: u32, span: Span) { ... }
    fn comment(&mut self, value: &str, span: Span) { ... }
    fn program_number(&mut self, number: u32, span: Span) { ... }
    fn program_delimiter(&mut self, _span: Span) { ... }
    fn word_address(&mut self, _letter: char, _value: Value<'_>, _span: Span) { ... }
    fn start_general_code(
        &mut self,
        number: Number,
    ) -> ControlFlow<impl CommandVisitor + '_> { ... }
    fn start_miscellaneous_code(
        &mut self,
        number: Number,
    ) -> ControlFlow<impl CommandVisitor + '_> { ... }
    fn start_tool_change_code(
        &mut self,
        number: Number,
    ) -> ControlFlow<impl CommandVisitor + '_> { ... }
    fn end_line(self, span: Span) { ... }
}
Expand description

Visitor for a single block (line) of g-code.

The parser creates a block visitor from ProgramVisitor::start_block and then calls the methods below in order. Terminals (line number, comment, program number) are reported with a single call; each G/M/O/T command on the line is entered via one of the start_*_code methods, which return a CommandVisitor for that command. When the line ends, the parser calls end_line, consuming this visitor.

§Call order

Provided Methods§

Source

fn line_number(&mut self, n: u32, span: Span)

Optional N line number (e.g. N100). Called at most once per block.

Source

fn comment(&mut self, value: &str, span: Span)

Comment content (excluding parentheses). Called for each comment on the line.

Source

fn program_number(&mut self, number: u32, span: Span)

Optional O program number (e.g. O0001). Called at most once per block.

Source

fn program_delimiter(&mut self, _span: Span)

Program delimiter % (RS-274 / ISO 6983). Called once per % token.

Source

fn word_address(&mut self, _letter: char, _value: Value<'_>, _span: Span)

Modal bare word address (e.g. X5.0, S12000 at block level without a G/M/T prefix).

Source

fn start_general_code( &mut self, number: Number, ) -> ControlFlow<impl CommandVisitor + '_>

Start of a G (general) command. Return a CommandVisitor to handle this command, or use the default to ignore it.

Source

fn start_miscellaneous_code( &mut self, number: Number, ) -> ControlFlow<impl CommandVisitor + '_>

Start of an M (miscellaneous) command. Return a CommandVisitor to handle this command, or use the default to ignore it.

Source

fn start_tool_change_code( &mut self, number: Number, ) -> ControlFlow<impl CommandVisitor + '_>

Start of a T (tool change) command. Return a CommandVisitor to handle this command, or use the default to ignore it.

Source

fn end_line(self, span: Span)

Called once at the end of the block. The parser consumes this visitor after this call; use it to finalize per-block state.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§