Broken structure now gets through syntax evaluator.

This commit is contained in:
2024-03-08 18:39:13 -07:00
parent 77c4277625
commit b0cc2fc26b
12 changed files with 389 additions and 50 deletions

View File

@@ -68,7 +68,7 @@ impl Program {
/// actually a problem.
pub fn validate(&self) -> (Vec<Error>, Vec<Warning>) {
let mut bound_variables = ScopedMap::new();
println!("validate: {}", self);
println!("validate:\n{}", self);
self.validate_with_bindings(&mut bound_variables)
}
@@ -85,7 +85,7 @@ impl Program {
let mut warnings = vec![];
for stmt in self.items.iter() {
if let TopLevel::Function(Some(name), _, _) = stmt {
if let TopLevel::Function(Some(name), _, _, _) = stmt {
bound_variables.insert(name.to_string(), name.location.clone());
}
let (mut new_errors, mut new_warnings) = stmt.validate_with_bindings(bound_variables);
@@ -120,12 +120,12 @@ impl TopLevel {
bound_variables: &mut ScopedMap<String, Location>,
) -> (Vec<Error>, Vec<Warning>) {
match self {
TopLevel::Function(name, arguments, body) => {
TopLevel::Function(name, arguments, _, body) => {
bound_variables.new_scope();
if let Some(name) = name {
bound_variables.insert(name.name.clone(), name.location.clone());
}
for arg in arguments.iter() {
for (arg, _) in arguments.iter() {
bound_variables.insert(arg.name.clone(), arg.location.clone());
}
let result = body.validate(bound_variables);
@@ -133,6 +133,7 @@ impl TopLevel {
result
}
TopLevel::Statement(stmt) => stmt.validate(bound_variables),
TopLevel::Structure(_, _, _) => (vec![], vec![]),
}
}
}
@@ -198,11 +199,24 @@ impl Expression {
) -> (Vec<Error>, Vec<Warning>) {
match self {
Expression::Value(_, _) => (vec![], vec![]),
Expression::Constructor(_, _, fields) => {
let mut errors = vec![];
let mut warnings = vec![];
for (_, expr) in fields.iter() {
let (mut e, mut w) = expr.validate(variable_map);
errors.append(&mut e);
warnings.append(&mut w);
}
(errors, warnings)
}
Expression::Reference(_, var) if variable_map.contains_key(var) => (vec![], vec![]),
Expression::Reference(loc, var) => (
vec![Error::UnboundVariable(loc.clone(), var.clone())],
vec![],
),
Expression::FieldRef(_, exp, _) => exp.validate(variable_map),
Expression::Cast(location, t, expr) => {
let (mut errs, warns) = expr.validate(variable_map);