[parser, types] Add Obj::take() and use it to take the Obj from the parser when it is done

This commit is contained in:
Eryn Wells 2018-08-23 18:04:04 -07:00
parent 929846152e
commit 8e9fde7a9f
2 changed files with 8 additions and 1 deletions

View file

@ -30,8 +30,10 @@ impl NodeParser for ListParser {
Token::Id => { Token::Id => {
let parser = SymParser{}; let parser = SymParser{};
NodeParseResult::Push { next: Box::new(parser) } NodeParseResult::Push { next: Box::new(parser) }
},
Token::RightParen => {
NodeParseResult::Complete { obj: self.list.take() }
} }
_ => NodeParseResult::Error { msg: "womp".to_string() }
} }
} }
} }

View file

@ -13,6 +13,7 @@
//! available types in Scheme. These predicates are implemented as `is_*` //! available types in Scheme. These predicates are implemented as `is_*`
//! methods in a bunch of `Is*` traits defined below. //! methods in a bunch of `Is*` traits defined below.
use std::mem;
use std::any::Any; use std::any::Any;
use std::fmt; use std::fmt;
use super::*; use super::*;
@ -36,6 +37,10 @@ impl Obj {
Obj::Ptr(Box::new(obj)) Obj::Ptr(Box::new(obj))
} }
pub fn take(&mut self) -> Obj {
mem::replace(self, Obj::Null)
}
pub fn unbox_as<T: 'static + Object>(&self) -> Option<&T> { pub fn unbox_as<T: 'static + Object>(&self) -> Option<&T> {
match self { match self {
Obj::Null => None, Obj::Null => None,