[parser, types] Add Obj::take() and use it to take the Obj from the parser when it is done
This commit is contained in:
parent
929846152e
commit
8e9fde7a9f
2 changed files with 8 additions and 1 deletions
|
@ -30,8 +30,10 @@ impl NodeParser for ListParser {
|
|||
Token::Id => {
|
||||
let parser = SymParser{};
|
||||
NodeParseResult::Push { next: Box::new(parser) }
|
||||
},
|
||||
Token::RightParen => {
|
||||
NodeParseResult::Complete { obj: self.list.take() }
|
||||
}
|
||||
_ => NodeParseResult::Error { msg: "womp".to_string() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
//! available types in Scheme. These predicates are implemented as `is_*`
|
||||
//! methods in a bunch of `Is*` traits defined below.
|
||||
|
||||
use std::mem;
|
||||
use std::any::Any;
|
||||
use std::fmt;
|
||||
use super::*;
|
||||
|
@ -36,6 +37,10 @@ impl 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> {
|
||||
match self {
|
||||
Obj::Null => None,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue