More work
This commit is contained in:
parent
c0289f238f
commit
fb26293157
@ -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 {
|
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> {
|
fn $rule(&mut $self) -> ParseResult<$type> {
|
||||||
Ok(match $self.next() {
|
Ok(match $self.peek() {
|
||||||
$(
|
$(
|
||||||
$pat => $e,
|
expand_match_var!($rule_clauses) => expand_match_expr!($self, $rule_clauses),
|
||||||
)*
|
)*
|
||||||
_ => return ParseError::new("Not found"),
|
_ => return ParseError::new("Not found"),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! expand_match_arm {
|
|
||||||
(($pat:pat => $e:expr)) => { $pat => $e };
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AutoParser {
|
impl AutoParser {
|
||||||
bnf_rule!(self, ExpressionType, literal :=
|
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))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user