From c271a9e62251f76e9798894346adcbfd3aa6dc8a Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 7 Mar 2022 22:58:22 -0500 Subject: allow empty strings --- src/parse/test_ast.rs | 3 +++ src/shell.pest | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/parse/test_ast.rs b/src/parse/test_ast.rs index 4ac75ec..fb3a4e3 100644 --- a/src/parse/test_ast.rs +++ b/src/parse/test_ast.rs @@ -233,6 +233,9 @@ fn test_basic() { ) )) ); + + parse_eq!("foo ''", cs!(p!((0, 6), e!(w!("foo"), w!())))); + parse_eq!("foo \"\"", cs!(p!((0, 6), e!(w!("foo"), w!())))); } #[test] diff --git a/src/shell.pest b/src/shell.pest index 0c63802..92b173a 100644 --- a/src/shell.pest +++ b/src/shell.pest @@ -23,8 +23,8 @@ alternation_bareword = @{ alternation_bareword_char+ } alternation_word_part = ${ var | alternation_bareword | - "'" ~ single_string ~ "'" | - "\"" ~ (var | double_string)+ ~ "\"" + "'" ~ single_string? ~ "'" | + "\"" ~ (var | double_string)* ~ "\"" } alternation_word = ${ alternation_word_part* } alternation = ${ "{" ~ alternation_word ~ ("," ~ alternation_word)* ~ "}" } @@ -36,8 +36,8 @@ word_part = ${ substitution | var | bareword | - "'" ~ single_string ~ "'" | - "\"" ~ (substitution | var | double_string)+ ~ "\"" + "'" ~ single_string? ~ "'" | + "\"" ~ (substitution | var | double_string)* ~ "\"" } word = ${ word_part+ } -- cgit v1.2.3-54-g00ecf