diff --git a/parser/src/parsers/bool.rs b/parser/src/parsers/bool.rs new file mode 100644 index 0000000..dd15f24 --- /dev/null +++ b/parser/src/parsers/bool.rs @@ -0,0 +1,33 @@ +/* parser/src/parsers/bool.rs + * Eryn Wells + */ + +use sibillexer::{Lex, Token}; +use sibiltypes::{Bool, Obj}; +use parsers::{NodeParser, NodeParseResult}; + +#[derive(Debug)] pub struct BoolParser; + +impl NodeParser for BoolParser { + fn parse(&mut self, lex: &Lex) -> NodeParseResult { + match lex.token() { + Token::Bool(value) => { + NodeParseResult::Complete { obj: Obj::new(Bool::from(value)) } + } + _ => { + let msg = format!("Expected bool, found {:?}", lex); + NodeParseResult::error(msg) + } + } + } + + fn none(&mut self) -> NodeParseResult { + let msg = format!("Expected bool, found EOF"); + NodeParseResult::error(msg) + } + + fn subparser_completed(&mut self, obj: Obj) -> NodeParseResult { + let msg = format!("Unexpected subparser result: {}", obj); + NodeParseResult::error(msg) + } +} diff --git a/parser/src/parsers/list.rs b/parser/src/parsers/list.rs index 93317a7..000d791 100644 --- a/parser/src/parsers/list.rs +++ b/parser/src/parsers/list.rs @@ -5,6 +5,7 @@ use sibillexer::{Lex, Token}; use sibiltypes::{Obj, Pair}; use parsers::{NodeParser, NodeParseResult}; +use parsers::bool::BoolParser; use parsers::sym::SymParser; #[derive(Debug)] @@ -23,6 +24,10 @@ impl ListParser { impl NodeParser for ListParser { fn parse(&mut self, lex: &Lex) -> NodeParseResult { match lex.token() { + Token::Bool(_) => { + let parser = BoolParser{}; + NodeParseResult::Push { next: Box::new(parser) } + } Token::LeftParen => { match self.list { None => { diff --git a/parser/src/parsers/mod.rs b/parser/src/parsers/mod.rs index e53d6ca..b983f78 100644 --- a/parser/src/parsers/mod.rs +++ b/parser/src/parsers/mod.rs @@ -2,6 +2,7 @@ * Eryn Wells */ +mod bool; mod list; mod program; mod sym; diff --git a/parser/src/parsers/program.rs b/parser/src/parsers/program.rs index b9822c5..6165468 100644 --- a/parser/src/parsers/program.rs +++ b/parser/src/parsers/program.rs @@ -5,6 +5,7 @@ use sibillexer::{Lex, Token}; use sibiltypes::Obj; use parsers::{NodeParser, NodeParseResult}; +use parsers::bool::BoolParser; use parsers::list::ListParser; use parsers::sym::SymParser; @@ -20,10 +21,13 @@ impl ProgramParser { impl NodeParser for ProgramParser { fn parse(&mut self, lex: &Lex) -> NodeParseResult { match lex.token() { + Token::Bool(_) => { + let next = Box::new(BoolParser{}); + NodeParseResult::Push { next } + }, Token::LeftParen => { - let parser = ListParser::new(); - let parser = Box::new(parser); - NodeParseResult::Push { next: parser } + let next = Box::new(ListParser::new()); + NodeParseResult::Push { next } }, Token::RightParen => { let msg = format!("Expected symbol found {:?}", lex); diff --git a/parser/src/parsers/sym.rs b/parser/src/parsers/sym.rs index 70d70f3..ece89d6 100644 --- a/parser/src/parsers/sym.rs +++ b/parser/src/parsers/sym.rs @@ -6,8 +6,7 @@ use sibillexer::{Lex, Token}; use sibiltypes::{Obj, Sym}; use parsers::{NodeParser, NodeParseResult}; -#[derive(Debug)] -pub struct SymParser; +#[derive(Debug)] pub struct SymParser; impl NodeParser for SymParser { fn parse(&mut self, lex: &Lex) -> NodeParseResult { @@ -31,7 +30,7 @@ impl NodeParser for SymParser { } fn subparser_completed(&mut self, obj: Obj) -> NodeParseResult { - let msg = format!("Unexpected parser result: {}", obj); + let msg = format!("Unexpected subparser result: {}", obj); NodeParseResult::error(msg) } }