Start work on scope resolver

This commit is contained in:
greg 2019-09-03 02:19:37 -07:00
parent 0f7f5cb416
commit 724237545f
3 changed files with 22 additions and 1 deletions

View File

@ -1,5 +1,8 @@
# TODO items
## General code cleanup
- standardize on an error type that isn't String
## Reduction
- make a good type for actual language builtins to avoid string comparisons

View File

@ -27,6 +27,10 @@ impl<T> Meta<T> {
pub fn node(&self) -> &T {
&self.n
}
pub fn mut_node(&mut self) -> &mut T {
&mut self.n
}
}
//TODO this PartialEq is here to make tests work - find a way to make it not necessary
@ -46,7 +50,7 @@ pub struct AST(pub Vec<Meta<Statement>>);
#[derive(Debug, PartialEq, Clone)]
pub enum Statement {
ExpressionStatement(Meta<Expression>),
Declaration(Declaration),
Declaration(Declaration), //TODO Declaration should also be Meta-wrapped; only Expression and Declaration are Meta-wrapped maybe?
}
pub type Block = Vec<Meta<Statement>>;

View File

@ -2,5 +2,19 @@ use crate::ast::*;
pub fn resolve_scopes(ast: &mut AST) -> Result<(), String> {
println!("Resolving scopes - nothing so far!");
for statement in ast.0.iter_mut() {
match statement.mut_node() {
Statement::Declaration(ref mut decl) => resolve_decl(decl),
Statement::ExpressionStatement(ref mut expr) => resolve_expr(expr),
}?;
}
Ok(())
}
fn resolve_decl(decl: &mut Declaration) -> Result<(), String> {
Ok(())
}
fn resolve_expr(expr: &mut Meta<Expression>) -> Result<(), String> {
Ok(())
}