More work

This commit is contained in:
greg 2018-03-10 22:56:16 -08:00
parent c0289f238f
commit fb26293157

View File

@ -43,26 +43,38 @@ impl AutoParser {
}
}
macro_rules! expand_match_var {
(($pat:pat => $e:expr)) => { $pat };
(nonterm ($pat:pat => $e:expr)) => { $pat };
}
macro_rules! expand_match_expr {
($self:ident, ($pat:pat => $e:expr)) => {
{ $self.next(); $e }
};
($self:ident, nonterm ($pat:pat => $e:expr)) => {
{ $self.next(); $e }
};
}
macro_rules! bnf_rule {
($self:ident, $type:ty, $rule:ident := $( ($pat:pat => $e:expr) )|*) => {
($self:ident, $type:ty, $rule:ident := $( $rule_clauses:tt )|*) => {
fn $rule(&mut $self) -> ParseResult<$type> {
Ok(match $self.next() {
$(
$pat => $e,
)*
Ok(match $self.peek() {
$(
expand_match_var!($rule_clauses) => expand_match_expr!($self, $rule_clauses),
)*
_ => 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)));
(Keyword(Kw::True) => ExpressionType::BoolLiteral(true)) |
(Keyword(Kw::False) => ExpressionType::BoolLiteral(false))
);
}