Generic lifetimes
This commit is contained in:
+7
-1
@@ -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
@@ -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
@@ -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(),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user