Fixed constructor args
This commit is contained in:
@@ -33,7 +33,7 @@ pub enum Literal {
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub enum Pattern {
|
||||
NamedTuple(Path, Vec<Box<Pattern>>),
|
||||
Struct(Path, Vec<Box<Pattern>>),
|
||||
Struct(Path, Vec<(Identifier, Option<Box<Pattern>>)>),
|
||||
Tuple(Vec<Box<Pattern>>),
|
||||
Literal(Literal),
|
||||
Path(bool, Path),
|
||||
|
||||
@@ -146,8 +146,12 @@ named_tuple_pattern = {
|
||||
static_path ~ "[" ~ multi_pat_template ~ "]"
|
||||
}
|
||||
|
||||
struct_destruct = {
|
||||
identifier ~ (":" ~ pattern)?
|
||||
}
|
||||
|
||||
struct_pattern = {
|
||||
static_path ~ "{" ~ multi_pat_template ~ "}"
|
||||
static_path ~ "{" ~ (struct_destruct ~ ("," ~ struct_destruct)*)? ~ "}"
|
||||
}
|
||||
|
||||
path_pattern = {
|
||||
|
||||
@@ -77,6 +77,14 @@ macro_rules! ast_expr {
|
||||
analyzer.build(v)
|
||||
}};
|
||||
|
||||
(( $($v:expr),* $(,)? )) => {{
|
||||
let mut analyzer = $crate::error::AstErrorAnalyzer(None);
|
||||
|
||||
let v = ( $(analyzer.get($v).get()?),* );
|
||||
|
||||
analyzer.build(v)
|
||||
}};
|
||||
|
||||
($($item:ident)::+) => {
|
||||
$($item)::+
|
||||
};
|
||||
|
||||
@@ -71,7 +71,16 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Pattern {
|
||||
|
||||
Rule::struct_pattern => ast_expr!(Pattern::Struct(
|
||||
Path::try_from(inner.next().unwrap()),
|
||||
collect_recovered_map(inner, |v| Self::try_from(v).map(Box::new)),
|
||||
collect_recovered_map(inner, |v| {
|
||||
let mut inner = v.into_inner();
|
||||
ast_expr!((
|
||||
Identifier::try_from(inner.next().unwrap()),
|
||||
inner
|
||||
.next()
|
||||
.map(|v| Self::try_from(v).map(Box::new).get_map(Box::new))
|
||||
.transpose()
|
||||
))
|
||||
}),
|
||||
)),
|
||||
|
||||
Rule::literal => ast_expr!(Pattern::Literal(pair.try_into())),
|
||||
|
||||
Reference in New Issue
Block a user