summaryrefslogtreecommitdiffstats
path: root/crates/rebel-lang/src/scope.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/rebel-lang/src/scope.rs')
-rw-r--r--crates/rebel-lang/src/scope.rs21
1 files changed, 13 insertions, 8 deletions
diff --git a/crates/rebel-lang/src/scope.rs b/crates/rebel-lang/src/scope.rs
index 3f2e682..bb3f2e9 100644
--- a/crates/rebel-lang/src/scope.rs
+++ b/crates/rebel-lang/src/scope.rs
@@ -15,6 +15,11 @@ pub struct Var {
pub value: Option<Value>,
}
+#[derive(Debug)]
+pub struct LookupError;
+
+pub type Result<T> = std::result::Result<T, LookupError>;
+
#[derive(Debug, Clone)]
pub struct Context {
pub vars: Module<Var>,
@@ -60,28 +65,28 @@ impl Context {
Some(ident)
}
- pub fn lookup_var(&self, path: &ast::Path) -> Option<&Var> {
+ pub fn lookup_var(&self, path: &ast::Path) -> Result<&Var> {
if path.root != ast::PathRoot::Relative {
- return None;
+ return Err(LookupError);
}
if path.components == [ast::Ident { name: "_" }] {
- return None;
+ return Err(LookupError);
}
- self.vars.lookup(&path.components)
+ self.vars.lookup(&path.components).ok_or(LookupError)
}
- pub fn lookup_type(&self, path: &ast::Path) -> Option<&Type> {
+ pub fn lookup_type(&self, path: &ast::Path) -> Result<&Type> {
if path.root != ast::PathRoot::Relative {
- return None;
+ return Err(LookupError);
}
if path.components == [ast::Ident { name: "_" }] {
- return Some(&Type::Free);
+ return Ok(&Type::Free);
}
- self.types.lookup(&path.components)
+ self.types.lookup(&path.components).ok_or(LookupError)
}
pub fn record_type(&mut self, stmt: &ast::BlockStmt) -> typing::Result<Type> {