Function mlem_asm::parse::parse_program
[−]
[src]
pub fn parse_program(program: &str) -> Result<Program, Vec<(u64, String)>>
Parse an entire program, returning either a ready-to-execute MLeM program or a Vec of error messages, with line numbers, of all errors in the program.
Example
A valid program:
use mlem_asm::*; let valid_program = " noop move R:R0 R:SP; input R:R0; ; comment only "; let expected_program = Ok(vec![ Instruction::NoOp, Instruction::Move(Address::RegAbs(Register::R0), Address::RegAbs(Register::SP)), Instruction::Input(Address::RegAbs(Register::R0)) ]); let program = parse_program(valid_program); assert!(program == expected_program, "Program resulted in: {:?} not: {:?}", program, expected_program);
An invalid program:
use mlem_asm::*; let invalid_program = " noop move R:R0 R:xx; output invalid; ; comment only "; let expected_errors = Err(vec![(2, "Unknown register name: xx".into()), (3, "Malformed address.".into())]); let errors = parse_program(invalid_program); assert!(errors == expected_errors, "Program resulted in: {:?} not: {:?}", errors, expected_errors);