-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented parsing for generically named trait implementations
- Loading branch information
1 parent
20de27c
commit 4705e27
Showing
23 changed files
with
191 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use derive_more::IsVariant; | ||
|
||
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, IsVariant)] | ||
pub enum Privacy { | ||
#[default] | ||
Public, | ||
Private, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
use super::{Type, TypeArg}; | ||
use crate::source_files::Source; | ||
use indexmap::IndexMap; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct TypeParam { | ||
pub constraints: Vec<Type>, | ||
} | ||
|
||
impl TypeParam { | ||
pub fn new(constraints: Vec<Type>) -> Self { | ||
Self { constraints } | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug, Default)] | ||
pub struct TypeParams { | ||
pub params: IndexMap<String, TypeParam>, | ||
} | ||
|
||
impl TypeParams { | ||
pub fn iter(&self) -> impl Iterator<Item = (&String, &TypeParam)> { | ||
self.params.iter() | ||
} | ||
|
||
pub fn keys(&self) -> impl Iterator<Item = &String> { | ||
self.params.keys() | ||
} | ||
|
||
pub fn values(&self) -> impl Iterator<Item = &TypeParam> { | ||
self.params.values() | ||
} | ||
} | ||
|
||
impl From<IndexMap<String, TypeParam>> for TypeParams { | ||
fn from(params: IndexMap<String, TypeParam>) -> Self { | ||
Self { params } | ||
} | ||
} | ||
|
||
impl TryFrom<Vec<TypeArg>> for TypeParams { | ||
type Error = (String, Source); | ||
|
||
fn try_from(mut args: Vec<TypeArg>) -> Result<Self, Self::Error> { | ||
let mut params = IndexMap::<String, TypeParam>::new(); | ||
|
||
for arg in args.drain(..) { | ||
match arg { | ||
TypeArg::Type(ty) => match ty.kind { | ||
super::TypeKind::Polymorph(name, constraints) => { | ||
if let Some(existing) = params.get_mut(&name) { | ||
existing.constraints.extend(constraints); | ||
} else { | ||
params.insert(name, TypeParam { constraints }); | ||
} | ||
} | ||
_ => { | ||
return Err(( | ||
"Cannot use non-polymorph as type parameter".into(), | ||
ty.source, | ||
)) | ||
} | ||
}, | ||
TypeArg::Expr(expr) => { | ||
return Err(( | ||
"Cannot use expression as type parameter".into(), | ||
expr.source, | ||
)) | ||
} | ||
} | ||
} | ||
|
||
Ok(params.into()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.