Starting on macro work

This commit is contained in:
greg 2018-03-10 22:10:13 -08:00
parent 7afb9d47fc
commit c0289f238f
1 changed files with 21 additions and 10 deletions

View File

@ -37,21 +37,32 @@ impl AutoParser {
let ast = self.program();
(ast, vec![])
}
}
impl AutoParser {
fn program(&mut self) -> ParseResult<AST> {
let etype = self.literal()?;
Ok(AST(vec![Statement::ExpressionStatement(Expression(etype, None))]))
}
}
fn literal(&mut self) -> ParseResult<ExpressionType> {
Ok(match self.next() {
Keyword(Kw::True) => ExpressionType::BoolLiteral(true),
Keyword(Kw::False) => ExpressionType::BoolLiteral(false),
_ => return ParseError::new("bad!")
})
}
macro_rules! bnf_rule {
($self:ident, $type:ty, $rule:ident := $( ($pat:pat => $e:expr) )|*) => {
fn $rule(&mut $self) -> ParseResult<$type> {
Ok(match $self.next() {
$(
$pat => $e,
)*
_ => return ParseError::new("Not found"),
})
}
};
}
macro_rules! expand_match_arm {
(($pat:pat => $e:expr)) => { $pat => $e };
}
impl AutoParser {
bnf_rule!(self, ExpressionType, literal :=
(Keyword(Kw::True) => ExpressionType::BoolLiteral(true)) | (Keyword(Kw::False) => ExpressionType::BoolLiteral(false)));
}