Function mlem_asm::parse::parse_line [] [src]

pub fn parse_line(line: &str) -> Result<Option<Instruction>, String>

Parse a line of the form instruction [operand1] [operand2] [operand3][;[comment text]]

The return value is a Result<Option<Instruction>, String>. An Ok(Some(_)) value means a valid instruction (for instance, the line move R:R0 R:R1). An Err(_) value means that there is unparsable about the line (like move R:R0 R:r1 garbage garbage); an Ok(None) value means that the line was legal but meant nothing (like ; comment only).

Examples

Simple single-line parsing:

use mlem_asm::Instruction;
use mlem_asm::parse::parse_line;
assert!(parse_line("noop") == parse_line("noop;"));
assert!(parse_line("noop") == Ok(Some(Instruction::NoOp)));
assert!(parse_line("") == Ok(None));