diff --git a/src/main.rs b/src/main.rs index 7e686ea..01c2d7b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -167,8 +167,10 @@ pub fn run(src: &'static str) { pub fn main() { let src = " -box foo = 42 -foo +match foo with { + :a -> :b + :c -> :d +} "; run(src); // struct_scalpel::print_dissection_info::() diff --git a/src/validator.rs b/src/validator.rs index 0f30a9f..d9e737e 100644 --- a/src/validator.rs +++ b/src/validator.rs @@ -256,7 +256,41 @@ impl<'a> Validator<'a> { // check arity is 1 if first term is keyword // check arity against fn info if first term is word and second term is args Ast::Synthetic(first, second, rest) => { - todo!() + match (&first.0, &second.0) { + (Ast::Word(_), Ast::Keyword(_)) => { + let (expr, span) = first.as_ref(); + self.ast = expr; + self.span = *span; + self.validate(); + } + (Ast::Keyword(_), Ast::Arguments(args)) => { + if args.len() != 1 { + self.err("called keywords may only take one argument".to_string()) + } + let (expr, span) = second.as_ref(); + self.ast = expr; + self.span = *span; + self.validate(); + } + (Ast::Word(_), Ast::Arguments(_)) => { + let (expr, span) = first.as_ref(); + self.ast = expr; + self.span = *span; + self.validate(); + + let (expr, span) = second.as_ref(); + self.ast = expr; + self.span = *span; + self.validate(); + } + _ => unreachable!(), + } + for term in rest { + let (expr, span) = term; + self.ast = expr; + self.span = *span; + self.validate(); + } } Ast::When(clauses) => { // let tailpos = self.status.tail_position;