Skip to main content

parse_streaming

Function parse_streaming 

Source
pub fn parse_streaming<F>(
    tokens: &[Token<'_>],
    arch: Arch,
    syntax: Syntax,
    sink: F,
) -> Result<(), AsmError>
where F: FnMut(Statement) -> Result<(), AsmError>,
Expand description

Parse statements one at a time, handing each to sink as it is produced.

This is the streaming counterpart to parse_with_syntax, and the form the assembler uses. Statement is a large value — the operand list is stored inline to keep encoding allocation-free — so collecting a whole program into a Vec costs hundreds of bytes per instruction and makes peak memory proportional to the source rather than to the output. Consuming each statement immediately keeps that at one statement.

sink may return an error to abort parsing early.

§Errors

Returns AsmError on a syntax error, or whatever sink returns.