mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +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"
|
||||
edition = "2018"
|
||||
|
||||
[features]
|
||||
# If enabled, parser accepts `Dict.#hashTestOnly` etc.
|
||||
# For development puporpse.
|
||||
keep_shadowed_builtins = []
|
||||
|
||||
[dependencies]
|
||||
roc_collections = { path = "../collections" }
|
||||
roc_region = { path = "../region" }
|
||||
|
|
|
@ -220,6 +220,10 @@ pub enum BadIdent {
|
|||
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> {
|
||||
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) {
|
||||
match &buffer.get(chomped + 1..) {
|
||||
Some(slice) => match chomp_lowercase_part(slice) {
|
||||
Ok(name) => {
|
||||
let value = unsafe {
|
||||
std::str::from_utf8_unchecked(
|
||||
&buffer[chomped + 1..chomped + 1 + name.len()],
|
||||
)
|
||||
};
|
||||
parts.push(value);
|
||||
|
||||
chomped += name.len() + 1;
|
||||
Some(slice) => {
|
||||
let res = match cfg!(feature = "keep_shadowed_builtins") {
|
||||
true => chomp_lowercase_part_keep_shadowed_builtins(slice),
|
||||
false => chomp_lowercase_part(slice),
|
||||
};
|
||||
match res {
|
||||
Ok(name) => {
|
||||
let value = unsafe {
|
||||
std::str::from_utf8_unchecked(
|
||||
&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),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue