update validator
This commit is contained in:
parent
bbdab93cf0
commit
10692b4b41
|
@ -403,7 +403,7 @@ function __wbg_get_imports() {
|
||||||
_assertBoolean(ret);
|
_assertBoolean(ret);
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
imports.wbg.__wbindgen_closure_wrapper8087 = function() { return logError(function (arg0, arg1, arg2) {
|
imports.wbg.__wbindgen_closure_wrapper8088 = function() { return logError(function (arg0, arg1, arg2) {
|
||||||
const ret = makeMutClosure(arg0, arg1, 354, __wbg_adapter_20);
|
const ret = makeMutClosure(arg0, arg1, 354, __wbg_adapter_20);
|
||||||
return ret;
|
return ret;
|
||||||
}, arguments) };
|
}, arguments) };
|
||||||
|
|
Binary file not shown.
|
@ -1,12 +1,11 @@
|
||||||
// TODO:
|
// TODO:
|
||||||
// * [ ] ensure `or` and `and` never get passed by reference
|
|
||||||
// * [ ] ensure no placeholder in `or` and `and` args
|
|
||||||
// * [ ] ensure loops have fixed arity (no splats)
|
// * [ ] ensure loops have fixed arity (no splats)
|
||||||
// * [ ] ensure fn pattern splats are always highest (and same) arity
|
// * [ ] ensure fn pattern splats are always highest (and same) arity
|
||||||
|
|
||||||
use crate::ast::{Ast, StringPart};
|
use crate::ast::{Ast, StringPart};
|
||||||
use crate::spans::{Span, Spanned};
|
use crate::spans::{Span, Spanned};
|
||||||
use crate::value::{Key, Value};
|
use crate::value::{Key, Value};
|
||||||
|
use std::cmp::max;
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
@ -230,6 +229,9 @@ impl<'a> Validator<'a> {
|
||||||
if members.is_empty() {
|
if members.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if members.len() > 7 {
|
||||||
|
self.err("tuples may not have more than 7 members".to_string());
|
||||||
|
}
|
||||||
let tailpos = self.status.tail_position;
|
let tailpos = self.status.tail_position;
|
||||||
self.status.tail_position = false;
|
self.status.tail_position = false;
|
||||||
for member in members {
|
for member in members {
|
||||||
|
@ -242,6 +244,9 @@ impl<'a> Validator<'a> {
|
||||||
if args.is_empty() {
|
if args.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if args.len() > 7 {
|
||||||
|
self.err("tuples may not have more than 7 members".to_string());
|
||||||
|
}
|
||||||
let tailpos = self.status.tail_position;
|
let tailpos = self.status.tail_position;
|
||||||
self.status.tail_position = false;
|
self.status.tail_position = false;
|
||||||
for arg in args {
|
for arg in args {
|
||||||
|
@ -423,6 +428,43 @@ impl<'a> Validator<'a> {
|
||||||
self.validate();
|
self.validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut max_arity = 0;
|
||||||
|
let mut has_splat = false;
|
||||||
|
for arity in arities.iter() {
|
||||||
|
match arity {
|
||||||
|
Arity::Fixed(n) => {
|
||||||
|
max_arity = max(*n, max_arity);
|
||||||
|
}
|
||||||
|
Arity::Splat(n) => {
|
||||||
|
max_arity = max(*n, max_arity);
|
||||||
|
has_splat = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for arity in arities.iter() {
|
||||||
|
match arity {
|
||||||
|
Arity::Fixed(n) => {
|
||||||
|
if *n == max_arity && has_splat {
|
||||||
|
self.err(
|
||||||
|
"splats must be the longest arity in function clauses"
|
||||||
|
.to_string(),
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Arity::Splat(n) => {
|
||||||
|
if *n > max_arity {
|
||||||
|
self.err(
|
||||||
|
"splats must be the longest arity in function clauses"
|
||||||
|
.to_string(),
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// collect info about what the function closes over
|
// collect info about what the function closes over
|
||||||
let mut closed_over = HashSet::new();
|
let mut closed_over = HashSet::new();
|
||||||
for binding in self.status.used_bindings.iter().skip(from) {
|
for binding in self.status.used_bindings.iter().skip(from) {
|
||||||
|
@ -497,7 +539,7 @@ impl<'a> Validator<'a> {
|
||||||
}
|
}
|
||||||
Arity::Splat(clause_arity) => {
|
Arity::Splat(clause_arity) => {
|
||||||
if clause_arity > loop_arity {
|
if clause_arity > loop_arity {
|
||||||
self.err(format!("mismathced arity: expected {loop_arity} arguments in `loop` clause; this clause takes {clause_arity} or more"))
|
self.err("loop clauses may not have splats".to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -516,6 +558,9 @@ impl<'a> Validator<'a> {
|
||||||
if !self.status.tail_position {
|
if !self.status.tail_position {
|
||||||
self.err("you may only use `recur` in tail position".to_string());
|
self.err("you may only use `recur` in tail position".to_string());
|
||||||
}
|
}
|
||||||
|
if args.len() > 7 {
|
||||||
|
self.err("tuples may only have 7 members".to_string());
|
||||||
|
}
|
||||||
|
|
||||||
let num_args = args.len() as u8;
|
let num_args = args.len() as u8;
|
||||||
let loop_arity = self.status.loop_arity;
|
let loop_arity = self.status.loop_arity;
|
||||||
|
@ -583,7 +628,25 @@ impl<'a> Validator<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TuplePattern(terms) | ListPattern(terms) | DictPattern(terms) => {
|
TuplePattern(terms) => {
|
||||||
|
if terms.is_empty() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if terms.len() > 7 {
|
||||||
|
self.err("tuples may only have 7 arguments".to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
for term in terms.iter().take(terms.len() - 1) {
|
||||||
|
self.visit(term);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.status.last_term = true;
|
||||||
|
let last = terms.last().unwrap();
|
||||||
|
self.visit(last);
|
||||||
|
self.status.last_term = false;
|
||||||
|
}
|
||||||
|
ListPattern(terms) | DictPattern(terms) => {
|
||||||
if terms.is_empty() {
|
if terms.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user