diff --git a/crates/nu-cli/src/util.rs b/crates/nu-cli/src/util.rs index bc227643b5..74101a36f4 100644 --- a/crates/nu-cli/src/util.rs +++ b/crates/nu-cli/src/util.rs @@ -109,19 +109,14 @@ pub fn gather_parent_env_vars(engine_state: &mut EngineState) { ); } - fn escape(input: &str) -> String { - let output = input.replace('\\', "\\\\"); - output.replace('"', "\\\"") - } - fn put_env_to_fake_file(name: &str, val: &str, fake_env_file: &mut String) { - fake_env_file.push('"'); - fake_env_file.push_str(&escape(name)); - fake_env_file.push('"'); + fake_env_file.push('`'); + fake_env_file.push_str(name); + fake_env_file.push('`'); fake_env_file.push('='); - fake_env_file.push('"'); - fake_env_file.push_str(&escape(val)); - fake_env_file.push('"'); + fake_env_file.push('`'); + fake_env_file.push_str(val); + fake_env_file.push('`'); fake_env_file.push('\n'); } diff --git a/crates/nu-parser/src/lex.rs b/crates/nu-parser/src/lex.rs index c8a5aa8f93..c4fa1612ee 100644 --- a/crates/nu-parser/src/lex.rs +++ b/crates/nu-parser/src/lex.rs @@ -147,7 +147,7 @@ pub fn lex_item( } else if is_special_item(&block_level, c, special_tokens) && token_start == *curr_offset { *curr_offset += 1; break; - } else if c == b'\'' || c == b'"' { + } else if c == b'\'' || c == b'"' || c == b'`' { // We encountered the opening quote of a string literal. quote_start = Some(c); } else if c == b'[' { diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index 859d464197..7d59222c2c 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -71,6 +71,7 @@ pub fn is_math_expression_like(bytes: &[u8]) -> bool { || b == b'$' || b == b'"' || b == b'\'' + || b == b'`' || b == b'-' } @@ -89,6 +90,7 @@ fn is_variable(bytes: &[u8]) -> bool { pub fn trim_quotes(bytes: &[u8]) -> &[u8] { if (bytes.starts_with(b"\"") && bytes.ends_with(b"\"") && bytes.len() > 1) || (bytes.starts_with(b"\'") && bytes.ends_with(b"\'") && bytes.len() > 1) + || (bytes.starts_with(b"`") && bytes.ends_with(b"`") && bytes.len() > 1) { &bytes[1..(bytes.len() - 1)] } else { @@ -1482,10 +1484,16 @@ pub fn parse_string_interpolation( if byte == b'"' { delimiter_stack.pop(); } + } else if let Some(b'`') = delimiter_stack.last() { + if byte == b'`' { + delimiter_stack.pop(); + } } else if byte == b'\'' { delimiter_stack.push(b'\'') } else if byte == b'"' { delimiter_stack.push(b'"'); + } else if byte == b'`' { + delimiter_stack.push(b'`') } else if byte == b'(' { delimiter_stack.push(b')'); } else if byte == b')' { @@ -2681,7 +2689,11 @@ pub fn parse_var_with_opt_type( ) -> (Expression, Option) { let bytes = working_set.get_span_contents(spans[*spans_idx]).to_vec(); - if bytes.contains(&b' ') || bytes.contains(&b'"') || bytes.contains(&b'\'') { + if bytes.contains(&b' ') + || bytes.contains(&b'"') + || bytes.contains(&b'\'') + || bytes.contains(&b'`') + { return ( garbage(spans[*spans_idx]), Some(ParseError::VariableNotValid(spans[*spans_idx])),