[parser, types] Clean up obj parsers
- Define ListParser, SymParser in their own separate modules - Add some stuff to types to make working with them more ergonomic
This commit is contained in:
parent
b6a9b8a855
commit
929846152e
8 changed files with 129 additions and 56 deletions
27
parser/src/sym_parser.rs
Normal file
27
parser/src/sym_parser.rs
Normal file
|
@ -0,0 +1,27 @@
|
|||
/* parser/src/sym_parser.rs
|
||||
* Eryn Wells <eryn@erynwells.me>
|
||||
*/
|
||||
|
||||
use sibillexer::{Lex, Token};
|
||||
use sibiltypes::{Obj, Sym};
|
||||
use node_parser::{NodeParser, NodeParseResult};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct SymParser;
|
||||
|
||||
impl NodeParser for SymParser {
|
||||
fn parse(&mut self, lex: Lex) -> NodeParseResult {
|
||||
match lex.token() {
|
||||
Token::Id => {
|
||||
let value = String::from(lex.value());
|
||||
// Initializing with Sym(value) caused E0423. So use this isntead.
|
||||
let obj = Obj::new(Sym::new(value));
|
||||
NodeParseResult::Complete { obj: obj }
|
||||
}
|
||||
_ => {
|
||||
let msg = format!("Invalid token: {:?}", lex);
|
||||
NodeParseResult::error(msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue