|
|
|
use sexp::Sexp;
|
|
|
|
|
|
|
|
use crate::asm::error::CrsnError;
|
|
|
|
use crate::asm::instr::{Cond, cond, Instr, Flatten};
|
|
|
|
use crate::asm::parse::parse_instr::parse_instructions;
|
|
|
|
use crate::asm::parse::sexp_expect::{expect_list, expect_string_atom};
|
|
|
|
use crate::asm::patches::TryRemove;
|
|
|
|
use crate::module::CrsnExtension;
|
|
|
|
|
|
|
|
pub fn parse_cond_branch(tok: Sexp, parsers: &[Box<dyn CrsnExtension>]) -> Result<(Cond, Box<dyn Flatten>), CrsnError> {
|
|
|
|
let mut list = expect_list(Some(tok), false)?;
|
|
|
|
let kw = expect_string_atom(list.try_remove(0))?;
|
|
|
|
|
|
|
|
if !kw.ends_with('?') {
|
|
|
|
return Err(CrsnError::Parse(format!("Condition must end with '?': {}", kw).into()));
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok((cond::parse_cond(&kw)?, parse_instructions(list.into_iter(), parsers)?))
|
|
|
|
}
|
|
|
|
|