Starting on macro work
This commit is contained in:
parent
7afb9d47fc
commit
c0289f238f
@ -37,21 +37,32 @@ impl AutoParser {
|
|||||||
let ast = self.program();
|
let ast = self.program();
|
||||||
(ast, vec![])
|
(ast, vec![])
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl AutoParser {
|
|
||||||
fn program(&mut self) -> ParseResult<AST> {
|
fn program(&mut self) -> ParseResult<AST> {
|
||||||
let etype = self.literal()?;
|
let etype = self.literal()?;
|
||||||
Ok(AST(vec![Statement::ExpressionStatement(Expression(etype, None))]))
|
Ok(AST(vec![Statement::ExpressionStatement(Expression(etype, None))]))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn literal(&mut self) -> ParseResult<ExpressionType> {
|
macro_rules! bnf_rule {
|
||||||
Ok(match self.next() {
|
($self:ident, $type:ty, $rule:ident := $( ($pat:pat => $e:expr) )|*) => {
|
||||||
Keyword(Kw::True) => ExpressionType::BoolLiteral(true),
|
fn $rule(&mut $self) -> ParseResult<$type> {
|
||||||
Keyword(Kw::False) => ExpressionType::BoolLiteral(false),
|
Ok(match $self.next() {
|
||||||
_ => return ParseError::new("bad!")
|
$(
|
||||||
|
$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)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user