mirror of
https://github.com/fluencelabs/lalrpop
synced 2025-03-28 06:01:02 +00:00
feat: Accept slices as types (#507)
* fix: Avoid emitting redundant parentheses Fixes #493 * Update lrgrammar * feat: Accept slices as types * Update lrgrammar
This commit is contained in:
parent
3746d5e3b9
commit
c3e1cda5c3
@ -57,6 +57,7 @@ impl FreeVariables for repr::TypeRepr {
|
|||||||
fn free_variables(&self, type_parameters: &[TypeParameter]) -> Vec<TypeParameter> {
|
fn free_variables(&self, type_parameters: &[TypeParameter]) -> Vec<TypeParameter> {
|
||||||
match self {
|
match self {
|
||||||
repr::TypeRepr::Tuple(tys) => tys.free_variables(type_parameters),
|
repr::TypeRepr::Tuple(tys) => tys.free_variables(type_parameters),
|
||||||
|
repr::TypeRepr::Slice(ty) => ty.free_variables(type_parameters),
|
||||||
repr::TypeRepr::Nominal(data) | repr::TypeRepr::TraitObject(data) => {
|
repr::TypeRepr::Nominal(data) | repr::TypeRepr::TraitObject(data) => {
|
||||||
data.free_variables(type_parameters)
|
data.free_variables(type_parameters)
|
||||||
}
|
}
|
||||||
|
@ -200,6 +200,9 @@ pub enum TypeRef {
|
|||||||
// (T1, T2)
|
// (T1, T2)
|
||||||
Tuple(Vec<TypeRef>),
|
Tuple(Vec<TypeRef>),
|
||||||
|
|
||||||
|
// [T]
|
||||||
|
Slice(Box<TypeRef>),
|
||||||
|
|
||||||
// Foo<'a, 'b, T1, T2>, Foo::Bar, etc
|
// Foo<'a, 'b, T1, T2>, Foo::Bar, etc
|
||||||
Nominal {
|
Nominal {
|
||||||
path: Path,
|
path: Path,
|
||||||
@ -1008,6 +1011,7 @@ impl Display for TypeRef {
|
|||||||
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> {
|
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> {
|
||||||
match *self {
|
match *self {
|
||||||
TypeRef::Tuple(ref types) => write!(fmt, "({})", Sep(", ", types)),
|
TypeRef::Tuple(ref types) => write!(fmt, "({})", Sep(", ", types)),
|
||||||
|
TypeRef::Slice(ref ty) => write!(fmt, "[{}]", ty),
|
||||||
TypeRef::Nominal {
|
TypeRef::Nominal {
|
||||||
ref path,
|
ref path,
|
||||||
ref types,
|
ref types,
|
||||||
@ -1076,6 +1080,7 @@ impl TypeRef {
|
|||||||
TypeRef::Tuple(ref types) => {
|
TypeRef::Tuple(ref types) => {
|
||||||
TypeRepr::Tuple(types.iter().map(TypeRef::type_repr).collect())
|
TypeRepr::Tuple(types.iter().map(TypeRef::type_repr).collect())
|
||||||
}
|
}
|
||||||
|
TypeRef::Slice(ref ty) => TypeRepr::Slice(Box::new(ty.type_repr())),
|
||||||
TypeRef::Nominal {
|
TypeRef::Nominal {
|
||||||
ref path,
|
ref path,
|
||||||
ref types,
|
ref types,
|
||||||
|
@ -182,6 +182,7 @@ pub enum InlinedSymbol {
|
|||||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub enum TypeRepr {
|
pub enum TypeRepr {
|
||||||
Tuple(Vec<TypeRepr>),
|
Tuple(Vec<TypeRepr>),
|
||||||
|
Slice(Box<TypeRepr>),
|
||||||
Nominal(NominalTypeRepr),
|
Nominal(NominalTypeRepr),
|
||||||
Associated {
|
Associated {
|
||||||
type_parameter: Atom,
|
type_parameter: Atom,
|
||||||
@ -239,6 +240,7 @@ impl TypeRepr {
|
|||||||
TypeRepr::Tuple(types) => {
|
TypeRepr::Tuple(types) => {
|
||||||
TypeRepr::Tuple(types.iter().map(|t| t.bottom_up(op)).collect())
|
TypeRepr::Tuple(types.iter().map(|t| t.bottom_up(op)).collect())
|
||||||
}
|
}
|
||||||
|
TypeRepr::Slice(ty) => TypeRepr::Slice(Box::new(ty.bottom_up(op))),
|
||||||
TypeRepr::Nominal(NominalTypeRepr { path, types }) => {
|
TypeRepr::Nominal(NominalTypeRepr { path, types }) => {
|
||||||
TypeRepr::Nominal(NominalTypeRepr {
|
TypeRepr::Nominal(NominalTypeRepr {
|
||||||
path: path.clone(),
|
path: path.clone(),
|
||||||
@ -304,6 +306,7 @@ impl TypeRepr {
|
|||||||
|
|
||||||
self.bottom_up(&mut |t| match t {
|
self.bottom_up(&mut |t| match t {
|
||||||
TypeRepr::Tuple { .. }
|
TypeRepr::Tuple { .. }
|
||||||
|
| TypeRepr::Slice { .. }
|
||||||
| TypeRepr::Nominal { .. }
|
| TypeRepr::Nominal { .. }
|
||||||
| TypeRepr::Associated { .. }
|
| TypeRepr::Associated { .. }
|
||||||
| TypeRepr::TraitObject { .. }
|
| TypeRepr::TraitObject { .. }
|
||||||
@ -511,6 +514,7 @@ impl Display for TypeRepr {
|
|||||||
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> {
|
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> {
|
||||||
match *self {
|
match *self {
|
||||||
TypeRepr::Tuple(ref types) => write!(fmt, "({})", Sep(", ", types)),
|
TypeRepr::Tuple(ref types) => write!(fmt, "({})", Sep(", ", types)),
|
||||||
|
TypeRepr::Slice(ref ty) => write!(fmt, "[{}]", ty),
|
||||||
TypeRepr::Nominal(ref data) => write!(fmt, "{}", data),
|
TypeRepr::Nominal(ref data) => write!(fmt, "{}", data),
|
||||||
TypeRepr::Associated {
|
TypeRepr::Associated {
|
||||||
ref type_parameter,
|
ref type_parameter,
|
||||||
|
@ -233,6 +233,9 @@ impl MacroExpander {
|
|||||||
) -> TypeRef {
|
) -> TypeRef {
|
||||||
match *type_ref {
|
match *type_ref {
|
||||||
TypeRef::Tuple(ref trs) => TypeRef::Tuple(self.macro_expand_type_refs(args, trs)),
|
TypeRef::Tuple(ref trs) => TypeRef::Tuple(self.macro_expand_type_refs(args, trs)),
|
||||||
|
TypeRef::Slice(ref tr) => {
|
||||||
|
TypeRef::Slice(Box::new(self.macro_expand_type_ref(args, tr)))
|
||||||
|
}
|
||||||
TypeRef::Nominal {
|
TypeRef::Nominal {
|
||||||
ref path,
|
ref path,
|
||||||
ref types,
|
ref types,
|
||||||
|
@ -248,6 +248,7 @@ impl<'grammar> TypeInferencer<'grammar> {
|
|||||||
.collect::<Result<_, _>>()?;
|
.collect::<Result<_, _>>()?;
|
||||||
Ok(TypeRepr::Tuple(types))
|
Ok(TypeRepr::Tuple(types))
|
||||||
}
|
}
|
||||||
|
TypeRef::Slice(ref ty) => self.type_ref(ty).map(|ty| TypeRepr::Slice(Box::new(ty))),
|
||||||
TypeRef::Nominal {
|
TypeRef::Nominal {
|
||||||
ref path,
|
ref path,
|
||||||
ref types,
|
ref types,
|
||||||
|
@ -239,6 +239,9 @@ TypeRef: TypeRef = {
|
|||||||
"(" <Comma<TypeRef>> ")" =>
|
"(" <Comma<TypeRef>> ")" =>
|
||||||
TypeRef::Tuple(<>),
|
TypeRef::Tuple(<>),
|
||||||
|
|
||||||
|
"[" <TypeRef> "]" =>
|
||||||
|
TypeRef::Slice(Box::new(<>)),
|
||||||
|
|
||||||
"#" <Symbol> "#" => {
|
"#" <Symbol> "#" => {
|
||||||
TypeRef::OfSymbol(<>.kind)
|
TypeRef::OfSymbol(<>.kind)
|
||||||
},
|
},
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user