mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 23:04:49 +00:00
Add keep_shadowed_builtins
feature to roc_parse
This commit is contained in:
parent
0922c86352
commit
f3ee0bef40
2 changed files with 26 additions and 12 deletions
|
@ -5,6 +5,11 @@ authors = ["The Roc Contributors"]
|
||||||
license = "UPL-1.0"
|
license = "UPL-1.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
# If enabled, parser accepts `Dict.#hashTestOnly` etc.
|
||||||
|
# For development puporpse.
|
||||||
|
keep_shadowed_builtins = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
roc_collections = { path = "../collections" }
|
roc_collections = { path = "../collections" }
|
||||||
roc_region = { path = "../region" }
|
roc_region = { path = "../region" }
|
||||||
|
|
|
@ -220,6 +220,10 @@ pub enum BadIdent {
|
||||||
BadPrivateTag(Row, Col),
|
BadPrivateTag(Row, Col),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn chomp_lowercase_part_keep_shadowed_builtins(buffer: &[u8]) -> Result<&str, Progress> {
|
||||||
|
chomp_part(|c: char| c.is_lowercase() || c == '#', buffer)
|
||||||
|
}
|
||||||
|
|
||||||
fn chomp_lowercase_part(buffer: &[u8]) -> Result<&str, Progress> {
|
fn chomp_lowercase_part(buffer: &[u8]) -> Result<&str, Progress> {
|
||||||
chomp_part(|c: char| c.is_lowercase(), buffer)
|
chomp_part(|c: char| c.is_lowercase(), buffer)
|
||||||
}
|
}
|
||||||
|
@ -499,19 +503,24 @@ fn chomp_access_chain<'a>(buffer: &'a [u8], parts: &mut Vec<'a, &'a str>) -> Res
|
||||||
|
|
||||||
while let Some(b'.') = buffer.get(chomped) {
|
while let Some(b'.') = buffer.get(chomped) {
|
||||||
match &buffer.get(chomped + 1..) {
|
match &buffer.get(chomped + 1..) {
|
||||||
Some(slice) => match chomp_lowercase_part(slice) {
|
Some(slice) => {
|
||||||
Ok(name) => {
|
let res = match cfg!(feature = "keep_shadowed_builtins") {
|
||||||
let value = unsafe {
|
true => chomp_lowercase_part_keep_shadowed_builtins(slice),
|
||||||
std::str::from_utf8_unchecked(
|
false => chomp_lowercase_part(slice),
|
||||||
&buffer[chomped + 1..chomped + 1 + name.len()],
|
};
|
||||||
)
|
match res {
|
||||||
};
|
Ok(name) => {
|
||||||
parts.push(value);
|
let value = unsafe {
|
||||||
|
std::str::from_utf8_unchecked(
|
||||||
chomped += name.len() + 1;
|
&buffer[chomped + 1..chomped + 1 + name.len()],
|
||||||
|
)
|
||||||
|
};
|
||||||
|
parts.push(value);
|
||||||
|
chomped += name.len() + 1;
|
||||||
|
}
|
||||||
|
Err(_) => return Err(chomped as u16 + 1),
|
||||||
}
|
}
|
||||||
Err(_) => return Err(chomped as u16 + 1),
|
}
|
||||||
},
|
|
||||||
None => return Err(chomped as u16 + 1),
|
None => return Err(chomped as u16 + 1),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue