Decl using the ast macro
This commit is contained in:
@@ -66,6 +66,10 @@ macro_rules! _ast_ti {
|
||||
$val::try_from($inner.next().unwrap())
|
||||
};
|
||||
|
||||
($inner:ident, ? $val:ident) => {
|
||||
$inner.next().map($val::try_from).transpose()
|
||||
};
|
||||
|
||||
($inner:ident, ? ($rule:path)) => {
|
||||
$crate::parser::listen_rule(&mut $inner, $rule)
|
||||
};
|
||||
|
||||
@@ -13,11 +13,12 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for VarDeclStmt {
|
||||
Rule::var_decl_statement => {
|
||||
let mut inner = pair.into_inner();
|
||||
|
||||
let decl = VarDecl::try_from(inner.next().unwrap()).get()?;
|
||||
|
||||
let init = inner.next().map(Expression::try_from).transpose().get()?;
|
||||
|
||||
Ok(VarDeclStmt { decl, init })
|
||||
Ok(ast_expr!(
|
||||
inner@VarDeclStmt {
|
||||
decl: @VarDecl,
|
||||
init: ?Expression
|
||||
}
|
||||
))
|
||||
}
|
||||
|
||||
_ => unimplemented!(),
|
||||
@@ -33,11 +34,12 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for FieldDeclStmt {
|
||||
Rule::class_field => {
|
||||
let mut inner = pair.into_inner();
|
||||
|
||||
let decl = FieldDecl::try_from(inner.next().unwrap()).get()?;
|
||||
|
||||
let init = inner.next().map(Expression::try_from).transpose().get()?;
|
||||
|
||||
Ok(FieldDeclStmt { decl, init })
|
||||
Ok(ast_expr!(
|
||||
inner@FieldDeclStmt {
|
||||
decl: @FieldDecl,
|
||||
init: ?Expression
|
||||
}
|
||||
))
|
||||
}
|
||||
|
||||
_ => unimplemented!(),
|
||||
@@ -53,7 +55,8 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for VarDecl {
|
||||
Rule::var_decl => {
|
||||
let mut inner = pair.into_inner();
|
||||
|
||||
Ok(ast_expr!(inner@VarDecl {
|
||||
Ok(ast_expr!(
|
||||
inner@VarDecl {
|
||||
type_: & (inner
|
||||
.next()
|
||||
.and_then(|pair| {
|
||||
@@ -68,7 +71,8 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for VarDecl {
|
||||
mutable: ?(Rule::mutable),
|
||||
|
||||
name: @Pattern
|
||||
}))
|
||||
}
|
||||
))
|
||||
}
|
||||
|
||||
_ => unimplemented!("{:?}", pair.as_rule()),
|
||||
@@ -84,11 +88,13 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for FieldDecl {
|
||||
Rule::field => {
|
||||
let mut inner = pair.into_inner();
|
||||
|
||||
Ok(ast_expr!(inner@FieldDecl {
|
||||
Ok(ast_expr!(
|
||||
inner@FieldDecl {
|
||||
visibility: !Visibility,
|
||||
type_: @TypeExpr,
|
||||
name: @Identifier
|
||||
}))
|
||||
}
|
||||
))
|
||||
}
|
||||
|
||||
_ => unimplemented!("{:?}", pair.as_rule()),
|
||||
|
||||
Reference in New Issue
Block a user