Generic lifetimes

This commit is contained in:
2026-05-08 20:08:03 +02:00
parent 0bf32b16cd
commit 020dd3b76b
5 changed files with 46 additions and 21 deletions
+7 -1
View File
@@ -98,7 +98,13 @@ pub enum TopLevelKind {
}
#[derive(Debug, Clone, Serialize, Default)]
pub struct Generics(pub Vec<(Identifier, Vec<Path>)>);
pub struct Generics(pub Vec<Generic>);
#[derive(Debug, Clone, Serialize)]
pub enum Generic {
Lifetime(Identifier),
Type(Identifier, Vec<TypeExpr>),
}
#[derive(Debug, Clone, Serialize)]
pub enum Pattern {
+11 -2
View File
@@ -55,7 +55,7 @@ var = { "var" }
// ======================================================
// GENERICS
// ======================================================
generic = { identifier ~ (":" ~ static_path ~ ("+" ~ static_path)*)? }
generic = { lifetime | (identifier ~ (":" ~ type_expr_param ~ ("+" ~ type_expr_param)*)?) }
generics = { "<" ~ (generic ~ ("," ~ generic)*)? ~ ">" }
// ======================================================
@@ -67,7 +67,7 @@ tuple_type = {
}
path_type = {
static_path ~ ("<" ~ (type_expr ~ ("," ~ type_expr)*)? ~ ">")?
static_path ~ ("<" ~ (type_expr_param ~ ("," ~ type_expr_param)*)? ~ ">")?
}
ref_type = {
@@ -78,6 +78,15 @@ type_expr = {
(path_type | tuple_type) ~ ref_type*
}
lifetime = {
"'" ~ identifier
}
type_expr_param = {
type_expr
| lifetime
}
// ======================================================
// LITERALS
// ======================================================
+8 -4
View File
@@ -238,10 +238,14 @@ impl From<pest::iterators::Pair<'_, Rule>> for Generics {
inner
.map(|pair| {
let mut inner = pair.into_inner();
(
Identifier::from(inner.next().unwrap()),
inner.map(Path::from).collect(),
)
if let Some(pair) = consume_rule(&mut inner, Rule::lifetime) {
Generic::Lifetime(Identifier::from(pair.into_inner().next().unwrap()))
} else {
Generic::Type(
Identifier::from(inner.next().unwrap()),
inner.map(TypeExpr::from).collect(),
)
}
})
.collect(),
),