parent
3a7fe94b32
commit
4fab810d1f
5 changed files with 48 additions and 6 deletions
33
parser/src/parsers/bool.rs
Normal file
33
parser/src/parsers/bool.rs
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
/* parser/src/parsers/bool.rs
|
||||||
|
* Eryn Wells <eryn@erynwells.me>
|
||||||
|
*/
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,6 +5,7 @@
|
||||||
use sibillexer::{Lex, Token};
|
use sibillexer::{Lex, Token};
|
||||||
use sibiltypes::{Obj, Pair};
|
use sibiltypes::{Obj, Pair};
|
||||||
use parsers::{NodeParser, NodeParseResult};
|
use parsers::{NodeParser, NodeParseResult};
|
||||||
|
use parsers::bool::BoolParser;
|
||||||
use parsers::sym::SymParser;
|
use parsers::sym::SymParser;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -23,6 +24,10 @@ impl ListParser {
|
||||||
impl NodeParser for ListParser {
|
impl NodeParser for ListParser {
|
||||||
fn parse(&mut self, lex: &Lex) -> NodeParseResult {
|
fn parse(&mut self, lex: &Lex) -> NodeParseResult {
|
||||||
match lex.token() {
|
match lex.token() {
|
||||||
|
Token::Bool(_) => {
|
||||||
|
let parser = BoolParser{};
|
||||||
|
NodeParseResult::Push { next: Box::new(parser) }
|
||||||
|
}
|
||||||
Token::LeftParen => {
|
Token::LeftParen => {
|
||||||
match self.list {
|
match self.list {
|
||||||
None => {
|
None => {
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
* Eryn Wells <eryn@erynwells.me>
|
* Eryn Wells <eryn@erynwells.me>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
mod bool;
|
||||||
mod list;
|
mod list;
|
||||||
mod program;
|
mod program;
|
||||||
mod sym;
|
mod sym;
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
use sibillexer::{Lex, Token};
|
use sibillexer::{Lex, Token};
|
||||||
use sibiltypes::Obj;
|
use sibiltypes::Obj;
|
||||||
use parsers::{NodeParser, NodeParseResult};
|
use parsers::{NodeParser, NodeParseResult};
|
||||||
|
use parsers::bool::BoolParser;
|
||||||
use parsers::list::ListParser;
|
use parsers::list::ListParser;
|
||||||
use parsers::sym::SymParser;
|
use parsers::sym::SymParser;
|
||||||
|
|
||||||
|
@ -20,10 +21,13 @@ impl ProgramParser {
|
||||||
impl NodeParser for ProgramParser {
|
impl NodeParser for ProgramParser {
|
||||||
fn parse(&mut self, lex: &Lex) -> NodeParseResult {
|
fn parse(&mut self, lex: &Lex) -> NodeParseResult {
|
||||||
match lex.token() {
|
match lex.token() {
|
||||||
|
Token::Bool(_) => {
|
||||||
|
let next = Box::new(BoolParser{});
|
||||||
|
NodeParseResult::Push { next }
|
||||||
|
},
|
||||||
Token::LeftParen => {
|
Token::LeftParen => {
|
||||||
let parser = ListParser::new();
|
let next = Box::new(ListParser::new());
|
||||||
let parser = Box::new(parser);
|
NodeParseResult::Push { next }
|
||||||
NodeParseResult::Push { next: parser }
|
|
||||||
},
|
},
|
||||||
Token::RightParen => {
|
Token::RightParen => {
|
||||||
let msg = format!("Expected symbol found {:?}", lex);
|
let msg = format!("Expected symbol found {:?}", lex);
|
||||||
|
|
|
@ -6,8 +6,7 @@ use sibillexer::{Lex, Token};
|
||||||
use sibiltypes::{Obj, Sym};
|
use sibiltypes::{Obj, Sym};
|
||||||
use parsers::{NodeParser, NodeParseResult};
|
use parsers::{NodeParser, NodeParseResult};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)] pub struct SymParser;
|
||||||
pub struct SymParser;
|
|
||||||
|
|
||||||
impl NodeParser for SymParser {
|
impl NodeParser for SymParser {
|
||||||
fn parse(&mut self, lex: &Lex) -> NodeParseResult {
|
fn parse(&mut self, lex: &Lex) -> NodeParseResult {
|
||||||
|
@ -31,7 +30,7 @@ impl NodeParser for SymParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn subparser_completed(&mut self, obj: Obj) -> NodeParseResult {
|
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)
|
NodeParseResult::error(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue