diff --git a/makesure.awk b/makesure.awk index 130f979..4bad310 100755 --- a/makesure.awk +++ b/makesure.awk @@ -693,31 +693,35 @@ function join(arr, startIncl, endExcl, sep, result, i) { result = result sep arr[i] return result } -function parseCli(line, res, pos,c,last) { +function parseCli(line, res, pos,c,last,is_doll,c1) { for(pos=1;;) { while((c = substr(line,pos,1))==" " || c == "\t") pos++ # consume spaces if ((c = substr(line,pos,1))=="#" || c=="") return - else if (c == "'") { # start of string - # consume quoted string - res[last = res[-7]++] = "" - while((c = substr(line,++pos,1)) != "'") { # closing ' - if (c=="") - return "unterminated argument" - else if (c=="\\" && substr(line,pos+1,1)=="'") { # escaped ' - c = "'"; pos++ + else { + if ((is_doll = c == "$") && substr(line,pos+1,1)=="'" || c == "'") { # start of string + if(is_doll) + pos++ + # consume quoted string + res[last = res[-7]++] = "" + while((c = substr(line,++pos,1)) != "'") { # closing ' + if (c=="") + return "unterminated argument" + else if (is_doll && c=="\\" && ((c1=substr(line,pos+1,1))=="'" || c1==c)) { # escaped ' or \ + c = c1; pos++ + } + res[last] = res[last] c } - res[last] = res[last] c - } - if((c = substr(line,++pos,1)) != "" && c != " " && c != "\t") - return "joined arguments" - } else { - # consume unquoted argument - res[last = res[-7]++] = c - while((c = substr(line,++pos,1)) != "" && c != " " && c != "\t") { # whitespace denotes end of arg - if(c=="'") + if((c = substr(line,++pos,1)) != "" && c != " " && c != "\t") return "joined arguments" - res[last] = res[last] c + } else { + # consume unquoted argument + res[last = res[-7]++] = c + while((c = substr(line,++pos,1)) != "" && c != " " && c != "\t") { # whitespace denotes end of arg + if(c=="'") + return "joined arguments" + res[last] = res[last] c + } } } } diff --git a/tests/21_parsing.tush b/tests/21_parsing.tush index 54806a2..368ff94 100644 --- a/tests/21_parsing.tush +++ b/tests/21_parsing.tush @@ -24,10 +24,26 @@ $ cd "$MYDIR"; ./$MAKESURE -f tests/21_parsing_spaces.sh test3 $ cd "$MYDIR"; ./$MAKESURE -f tests/21_parsing_comments.sh -la | Available goals: -| goal_with_comment -| test1 +| goal_with_comment : doc with comment +| test1 : doc with comment $ cd "$MYDIR"; ./$MAKESURE -f tests/21_parsing_comments.sh test1 | goal 'goal_with_comment' ... | goal_with_comment | goal 'test1' [empty]. + +$ cd "$MYDIR"; ./$MAKESURE -f tests/21_parsing_quoting.sh -l +| Available goals: +| no_space : no_space +| name with spaces : name with spaces +| name with ' quote : name with ' quote +| default + +$ cd "$MYDIR"; ./$MAKESURE -f tests/21_parsing_quoting.sh +| goal 'no_space' ... +| no_space +| goal 'name with spaces' ... +| name with spaces +| goal 'name with ' quote' ... +| name with ' quote +| goal 'default' [empty]. diff --git a/tests/21_parsing_comments.sh b/tests/21_parsing_comments.sh index 3064e47..c68ab5e 100644 --- a/tests/21_parsing_comments.sh +++ b/tests/21_parsing_comments.sh @@ -1,7 +1,9 @@ @goal goal_with_comment # comment +@doc doc with comment # comment echo goal_with_comment @goal test1 +@doc 'doc with comment' # comment @depends_on goal_with_comment \ No newline at end of file diff --git a/tests/21_parsing_quoting.sh b/tests/21_parsing_quoting.sh new file mode 100644 index 0000000..6c44a3e --- /dev/null +++ b/tests/21_parsing_quoting.sh @@ -0,0 +1,15 @@ + +@goal no_space +@doc no_space +echo no_space + +@goal 'name with spaces' # no single quote allowed between single quotes +@doc 'name with spaces' # no single quote allowed between single quotes +echo 'name with spaces' # no single quote allowed between single quotes + +@goal $'name with \' quote' # $'strings' allow quote escaping +@doc $'name with \' quote' # $'strings' allow quote escaping +echo $'name with \' quote' # $'strings' allow quote escaping + +@goal default +@depends_on no_space 'name with spaces' $'name with \' quote' \ No newline at end of file