Croissant Runtime
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
crsn/crsn/src/asm/parse/parse_op.rs

31 lines
1.2 KiB

use crate::asm::data::literal::{Label, RoutineName};
use crate::asm::error::Error;
use crate::asm::instr::Op;
use crate::asm::instr::cond::parse_cond;
use crate::asm::instr::op::{AsmModule, ParseOpResult};
use crate::asm::parse::arg_parser::ArgParser;
use crate::asm::parse::parse_data::{parse_label, parse_rd};
use crate::asm::parse::sexp_expect::expect_string_atom;
use crate::builtin::parse::BuiltinOpParser;
pub fn parse_op(keyword: &str, mut arg_tokens: ArgParser, parsers: &[Box<dyn AsmModule>]) -> Result<Op, Error> {
// Include built-in instructions
let builtins = [BuiltinOpParser::new()];
for p in builtins.iter().chain(parsers) {
arg_tokens = match p.parse_op(keyword, arg_tokens) {
Ok(ParseOpResult::Parsed(op)) => return Ok(op),
Ok(ParseOpResult::Unknown(to_reuse)) => {
if to_reuse.parsing_started() {
panic!("Module \"{}\" started parsing {}, but returned Unknown!", p.name(), keyword);
}
to_reuse
}
Err(err) => {
return Err(err);
}
}
}
return Err(Error::Parse(format!("Unknown instruction: {}", keyword).into()));
}