summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2022-01-11 11:18:30 -0500
committerJesse Luehrs <doy@tozt.net>2022-01-11 11:18:30 -0500
commit40cfe6a3c6691b0049986783f1d4e4402ee25843 (patch)
treef158acf2dc4d2c5c850795a434530b9205c80fc8
parent21035ea723f2a85328fc1b7b50f9488097346ab4 (diff)
downloadnbsh-40cfe6a3c6691b0049986783f1d4e4402ee25843.tar.gz
nbsh-40cfe6a3c6691b0049986783f1d4e4402ee25843.zip
fix parsing variables in double quoted strings
-rw-r--r--src/parse/test_ast.rs7
-rw-r--r--src/shell.pest2
2 files changed, 8 insertions, 1 deletions
diff --git a/src/parse/test_ast.rs b/src/parse/test_ast.rs
index 456684b..3142928 100644
--- a/src/parse/test_ast.rs
+++ b/src/parse/test_ast.rs
@@ -305,6 +305,13 @@ fn test_parts() {
cs!(p!((0, 16), e!(w!("echo"), w!(wpv!("HOME"), wpd!("/bin")))))
);
parse_eq!(
+ "echo \"dir: $HOME/bin\"",
+ cs!(p!(
+ (0, 21),
+ e!(w!("echo"), w!(wpd!("dir: "), wpv!("HOME"), wpd!("/bin")))
+ ))
+ );
+ parse_eq!(
"echo $HOME/bin",
cs!(p!((0, 14), e!(w!("echo"), w!(wpv!("HOME"), wpb!("/bin")))))
);
diff --git a/src/shell.pest b/src/shell.pest
index d09ccbc..8a51070 100644
--- a/src/shell.pest
+++ b/src/shell.pest
@@ -6,7 +6,7 @@ bareword_char = @{
!("|" | ";" | "\"" | "'" | "$" | "{" | WHITESPACE | COMMENT) ~ ANY
}
single_string_char = @{ basic_escape_char | (!"'" ~ ANY) }
-double_string_char = @{ escape_char | (!"\"" ~ ANY) }
+double_string_char = @{ escape_char | (!("\"" | "$") ~ ANY) }
redir_prefix = @{
("in" | "out" | "err" | ASCII_DIGIT*) ~ (">>" | ">" | "<") ~ WHITESPACE*