Fixed constructor args

This commit is contained in:
2026-06-04 10:39:41 +02:00
parent a4df59927e
commit 7a5e03afd6
6 changed files with 57 additions and 30 deletions
+1 -1
View File
@@ -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),
+5 -1
View File
@@ -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 = {
+8
View File
@@ -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)::+
};
+10 -1
View File
@@ -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())),