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