From 8e9fde7a9f1c36b3ae73089b6530326f38c90089 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Thu, 23 Aug 2018 18:04:04 -0700 Subject: [PATCH] [parser, types] Add Obj::take() and use it to take the Obj from the parser when it is done --- parser/src/list_parser.rs | 4 +++- types/src/object.rs | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/parser/src/list_parser.rs b/parser/src/list_parser.rs index 9997a32..ac3c51a 100644 --- a/parser/src/list_parser.rs +++ b/parser/src/list_parser.rs @@ -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() } } } } diff --git a/types/src/object.rs b/types/src/object.rs index 2212494..b599e4c 100644 --- a/types/src/object.rs +++ b/types/src/object.rs @@ -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(&self) -> Option<&T> { match self { Obj::Null => None,