Skip to content

Commit

Permalink
Merge branch 'master' into validity-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mte90 committed Jul 11, 2024
2 parents 5ecb85c + 5b7cb7b commit f992157
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ repository = "https://github.com/Ph0enixKM/Amber"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
heraclitus-compiler = "1.5.8"
heraclitus-compiler = "1.6.1"
similar-string = "1.4.2"
colored = "2.0.0"
itertools = "0.11.0"
Expand Down
30 changes: 21 additions & 9 deletions src/modules/expression/literal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ pub fn parse_interpolated_region(meta: &mut ParserMetadata, letter: char) -> Res
let mut strings = vec![];
let mut interps = vec![];
// Handle full string
if let Ok(word) = token_by(meta, |word| word.starts_with(letter) && (word.ends_with(letter) && !word.ends_with(format!("\\{}", letter).as_str())) && word.len() > 1) {
if let Ok(word) = token_by(meta, |word| {
let is_escaped =
!word.ends_with(format!("\\\\{}", letter).as_str())
&& word.ends_with(format!("\\{}", letter).as_str());
word.starts_with(letter) && word.ends_with(letter) && word.len() > 1 && !is_escaped
}) {
let stripped = word.chars().take(word.chars().count() - 1).skip(1).collect::<String>();
strings.push(stripped);
Ok((strings, interps))
Expand All @@ -40,7 +45,10 @@ pub fn parse_interpolated_region(meta: &mut ParserMetadata, letter: char) -> Res
}
else {
strings.push(tok.word.clone());
if tok.word.ends_with(letter) && !tok.word.ends_with(format!("\\{}", letter).as_str()) {
let is_escaped =
!tok.word.ends_with(format!("\\\\{}", letter).as_str())
&& tok.word.ends_with(format!("\\{}", letter).as_str());
if tok.word.ends_with(letter) && !is_escaped {
meta.increment_index();
// Right trim the symbol
let trimmed = strings.last().unwrap()
Expand Down Expand Up @@ -72,16 +80,19 @@ fn translate_escaped_string(string: String, is_str: bool) -> String {
result.push('"');
}
},
'`' => {
// Escape backticks if in a string
symbol @ ('$' | '`') => {
if is_str {
result.push('\\');
result.push('`');
}
else {
result.push('`');
}
result.push(symbol);
},
'!' => {
if is_str {
result += "\"'!'\"";
} else {
result.push('!')
}
}
'\\' => {
// Escape symbols
match chars.peek() {
Expand Down Expand Up @@ -126,6 +137,7 @@ fn translate_escaped_string(string: String, is_str: bool) -> String {
chars.next();
},
Some('\\') => {
result.push('\\');
result.push('\\');
chars.next();
},
Expand Down Expand Up @@ -170,4 +182,4 @@ pub fn translate_interpolated_region(strings: Vec<String>, interps: Vec<String>,
is_even = !is_even;
}
result.join("")
}
}
2 changes: 1 addition & 1 deletion src/std/main.ab
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub fun input(prompt: Text): Text {
unsafe $printf "\${nameof prompt}"$
unsafe $read$
return "$REPLY"
return unsafe $echo \$REPLY$
}

pub fun replace_once(source, pattern, replacement) {
Expand Down

0 comments on commit f992157

Please sign in to comment.