mirror of
https://github.com/fluencelabs/lalrpop
synced 2025-03-16 17:00:53 +00:00
refactor how forall
is represented in the AST
This commit is contained in:
parent
60751e68c3
commit
a9d8937fa9
@ -231,7 +231,7 @@ pub enum WhereClause<T> {
|
||||
},
|
||||
// where for<'a> &'a T: Debug + Into<usize>
|
||||
Type {
|
||||
forall: Option<Vec<Atom>>,
|
||||
forall: Vec<TypeParameter>,
|
||||
ty: T,
|
||||
bounds: Vec<TypeBound<T>>,
|
||||
},
|
||||
@ -269,7 +269,7 @@ pub enum TypeBound<T> {
|
||||
Lifetime(Atom),
|
||||
// `for<'a> FnMut(&'a usize)`
|
||||
Fn {
|
||||
forall: Option<Vec<Atom>>,
|
||||
forall: Vec<TypeParameter>,
|
||||
path: Path,
|
||||
parameters: Vec<T>,
|
||||
ret: Option<T>,
|
||||
@ -277,7 +277,7 @@ pub enum TypeBound<T> {
|
||||
// `some::Trait` or `some::Trait<Param, ...>` or `some::Trait<Item = Assoc>`
|
||||
// or `for<'a> Trait<'a, T>`
|
||||
Trait {
|
||||
forall: Option<Vec<Atom>>,
|
||||
forall: Vec<TypeParameter>,
|
||||
path: Path,
|
||||
parameters: Vec<TypeBoundParameter<T>>,
|
||||
},
|
||||
@ -712,7 +712,7 @@ impl<T: Display> Display for WhereClause<T> {
|
||||
ref ty,
|
||||
ref bounds,
|
||||
} => {
|
||||
if let Some(ref forall) = *forall {
|
||||
if !forall.is_empty() {
|
||||
write!(fmt, "for<")?;
|
||||
for (i, l) in forall.iter().enumerate() {
|
||||
if i != 0 {
|
||||
@ -746,7 +746,7 @@ impl<T: Display> Display for TypeBound<T> {
|
||||
ref parameters,
|
||||
ref ret,
|
||||
} => {
|
||||
if let Some(ref forall) = *forall {
|
||||
if !forall.is_empty() {
|
||||
write!(fmt, "for<")?;
|
||||
for (i, l) in forall.iter().enumerate() {
|
||||
if i != 0 {
|
||||
@ -777,7 +777,7 @@ impl<T: Display> Display for TypeBound<T> {
|
||||
ref path,
|
||||
ref parameters,
|
||||
} => {
|
||||
if let Some(ref forall) = *forall {
|
||||
if !forall.is_empty() {
|
||||
write!(fmt, "for<")?;
|
||||
for (i, l) in forall.iter().enumerate() {
|
||||
if i != 0 {
|
||||
|
@ -52,12 +52,14 @@ GrammarWhereClauses: Vec<WhereClause<TypeRef>> =
|
||||
GrammarWhereClause: WhereClause<TypeRef> = {
|
||||
<l:Lifetime> ":" <bounds:Plus<Lifetime>> =>
|
||||
WhereClause::Lifetime { lifetime: l, bounds: bounds },
|
||||
<f:ForAll?> <ty:TypeRef> ":" <bounds:TypeBounds> =>
|
||||
<f:ForAll> <ty:TypeRef> ":" <bounds:TypeBounds> =>
|
||||
WhereClause::Type { forall: f, ty: ty, bounds: bounds }
|
||||
};
|
||||
|
||||
ForAll: Vec<Atom> =
|
||||
"for" "<" <Comma<Lifetime>> ">";
|
||||
ForAll: Vec<TypeParameter> = {
|
||||
"for" "<" <Comma<TypeParameter>> ">",
|
||||
() => vec![],
|
||||
};
|
||||
|
||||
TypeBounds: Vec<TypeBound<TypeRef>> =
|
||||
<Plus<TypeBound>>;
|
||||
@ -65,9 +67,9 @@ TypeBounds: Vec<TypeBound<TypeRef>> =
|
||||
TypeBound: TypeBound<TypeRef> = {
|
||||
<l:Lifetime> =>
|
||||
TypeBound::Lifetime(l),
|
||||
<f:ForAll?> <p:Path> "(" <params:Comma<TypeRef>> ")" <ret:("->" <TypeRef>)?> =>
|
||||
<f:ForAll> <p:Path> "(" <params:Comma<TypeRef>> ")" <ret:("->" <TypeRef>)?> =>
|
||||
TypeBound::Fn { forall: f, path: p, parameters: params, ret: ret },
|
||||
<f:ForAll?> <p:Path> <params:("<" <Comma<TypeBoundParameter>> ">")?> =>
|
||||
<f:ForAll> <p:Path> <params:("<" <Comma<TypeBoundParameter>> ">")?> =>
|
||||
TypeBound::Trait { forall: f, path: p, parameters: params.unwrap_or(vec![]) }
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user