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