mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
make IdentIds expose an iterator of &str
This commit is contained in:
parent
b0c6cb4420
commit
5a5324f27e
4 changed files with 16 additions and 14 deletions
|
@ -129,8 +129,8 @@ impl<'a> Env<'a> {
|
||||||
region,
|
region,
|
||||||
},
|
},
|
||||||
self.ident_ids
|
self.ident_ids
|
||||||
.idents()
|
.ident_strs()
|
||||||
.map(|(_, string)| string.as_ref().into())
|
.map(|(_, string)| string.into())
|
||||||
.collect(),
|
.collect(),
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
|
@ -146,9 +146,9 @@ impl<'a> Env<'a> {
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let exposed_values = exposed_ids
|
let exposed_values = exposed_ids
|
||||||
.idents()
|
.ident_strs()
|
||||||
.filter(|(_, ident)| {
|
.filter(|(_, ident)| {
|
||||||
ident.as_ref().starts_with(|c: char| c.is_lowercase())
|
ident.starts_with(|c: char| c.is_lowercase())
|
||||||
})
|
})
|
||||||
.map(|(_, ident)| Lowercase::from(ident.as_ref()))
|
.map(|(_, ident)| Lowercase::from(ident.as_ref()))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
|
@ -327,9 +327,9 @@ impl Scope {
|
||||||
) -> ASTResult<()> {
|
) -> ASTResult<()> {
|
||||||
let ident_ids = get_module_ident_ids(all_ident_ids, &env.home)?.clone();
|
let ident_ids = get_module_ident_ids(all_ident_ids, &env.home)?.clone();
|
||||||
|
|
||||||
for (_, ident_ref) in ident_ids.idents() {
|
for (_, ident_ref) in ident_ids.ident_strs() {
|
||||||
self.introduce(
|
self.introduce(
|
||||||
ident_ref.as_inline_str().as_str().into(),
|
ident_ref.into(),
|
||||||
&env.exposed_ident_ids,
|
&env.exposed_ident_ids,
|
||||||
get_module_ident_ids_mut(all_ident_ids, &env.home)?,
|
get_module_ident_ids_mut(all_ident_ids, &env.home)?,
|
||||||
Region::zero(),
|
Region::zero(),
|
||||||
|
|
|
@ -104,8 +104,8 @@ impl<'a> Env<'a> {
|
||||||
region,
|
region,
|
||||||
},
|
},
|
||||||
self.ident_ids
|
self.ident_ids
|
||||||
.idents()
|
.ident_strs()
|
||||||
.map(|(_, string)| string.as_ref().into())
|
.map(|(_, string)| string.into())
|
||||||
.collect(),
|
.collect(),
|
||||||
);
|
);
|
||||||
Err(error)
|
Err(error)
|
||||||
|
@ -127,9 +127,9 @@ impl<'a> Env<'a> {
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let exposed_values = exposed_ids
|
let exposed_values = exposed_ids
|
||||||
.idents()
|
.ident_strs()
|
||||||
.filter(|(_, ident)| {
|
.filter(|(_, ident)| {
|
||||||
ident.as_ref().starts_with(|c: char| c.is_lowercase())
|
ident.starts_with(|c: char| c.is_lowercase())
|
||||||
})
|
})
|
||||||
.map(|(_, ident)| Lowercase::from(ident.as_ref()))
|
.map(|(_, ident)| Lowercase::from(ident.as_ref()))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
|
@ -542,11 +542,11 @@ pub struct IdentIds {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IdentIds {
|
impl IdentIds {
|
||||||
pub fn idents(&self) -> impl Iterator<Item = (IdentId, &Ident)> {
|
pub fn ident_strs(&self) -> impl Iterator<Item = (IdentId, &str)> {
|
||||||
self.by_id
|
self.by_id
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(index, ident)| (IdentId(index as u32), ident))
|
.map(|(index, ident)| (IdentId(index as u32), ident.as_inline_str().as_str()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add(&mut self, ident_name: Ident) -> IdentId {
|
pub fn add(&mut self, ident_name: Ident) -> IdentId {
|
||||||
|
@ -639,8 +639,10 @@ impl IdentIds {
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn get_id(&self, ident_name: &Ident) -> Option<IdentId> {
|
pub fn get_id(&self, ident_name: &Ident) -> Option<IdentId> {
|
||||||
for (id, ident) in self.idents() {
|
let ident_name = ident_name.as_inline_str().as_str();
|
||||||
if ident_name == ident {
|
|
||||||
|
for (id, ident_str) in self.ident_strs() {
|
||||||
|
if ident_name == ident_str {
|
||||||
return Some(id);
|
return Some(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue