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_cond.rs

20 lines
822 B

use sexp::Sexp;
use crate::asm::error::CrsnError;
use crate::asm::instr::{Cond, cond, Flatten};
use crate::asm::parse::parse_instr::parse_instructions;
use crate::asm::parse::ParserContext;
use crate::asm::parse::sexp_expect::{expect_list, expect_string_atom};
use crate::asm::patches::TryRemove;
pub fn parse_cond_branch(tok: Sexp, parsers: &ParserContext) -> Result<(Cond, Box<dyn Flatten>), CrsnError> {
let (mut list, pos) = expect_list(tok, false)?;
let (kw, kw_pos) = expect_string_atom(list.remove_or_err(0, &pos, "Missing \"cond?\" keyword in conditional branch")?)?;
if !kw.ends_with('?') {
return Err(CrsnError::Parse(format!("Condition must end with '?': {}", kw).into(), kw_pos));
}
Ok((cond::parse_cond(&kw, &kw_pos)?, parse_instructions(list.into_iter(), &pos, parsers)?))
}