first draft of synthetic validation

This commit is contained in:
Scott Richmond 2024-12-10 17:23:15 -05:00
parent ec38bcdc8c
commit 4c9659271b
2 changed files with 39 additions and 3 deletions

View File

@ -167,8 +167,10 @@ pub fn run(src: &'static str) {
pub fn main() { pub fn main() {
let src = " let src = "
box foo = 42 match foo with {
foo :a -> :b
:c -> :d
}
"; ";
run(src); run(src);
// struct_scalpel::print_dissection_info::<value::Value>() // struct_scalpel::print_dissection_info::<value::Value>()

View File

@ -256,7 +256,41 @@ impl<'a> Validator<'a> {
// check arity is 1 if first term is keyword // check arity is 1 if first term is keyword
// check arity against fn info if first term is word and second term is args // check arity against fn info if first term is word and second term is args
Ast::Synthetic(first, second, rest) => { 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) => { Ast::When(clauses) => {
// let tailpos = self.status.tail_position; // let tailpos = self.status.tail_position;