From 9edc745a45c772ba20ce089deb720d2439189a43 Mon Sep 17 00:00:00 2001 From: xonix Date: Fri, 15 Oct 2021 15:51:29 +0300 Subject: [PATCH] Improve parsing algorithm to handle spaces and comments #63 --- makesure.awk | 7 ++++--- tests/21_parsing.tush | 10 ++++++++++ tests/21_parsing_err1.sh | 4 ++++ tests/21_parsing_err2.sh | 5 +++++ 4 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 tests/21_parsing_err1.sh create mode 100644 tests/21_parsing_err2.sh diff --git a/makesure.awk b/makesure.awk index 17d073c..1def565 100755 --- a/makesure.awk +++ b/makesure.awk @@ -724,9 +724,10 @@ function parseCli(line, res, pos,c,last,is_doll,c1) { } function reparseCli( res,i,err) { err = parseCli($0, res) - if (err) - die("syntax error at line " NR ": " err) - else + if (err) { + addError("Syntax error: " err) + die(Error) + } else for (i=NF=0; i in res; i++) $(++NF)=res[i] } diff --git a/tests/21_parsing.tush b/tests/21_parsing.tush index f757476..49c1117 100644 --- a/tests/21_parsing.tush +++ b/tests/21_parsing.tush @@ -75,3 +75,13 @@ $ cd "$MYDIR"; ./$MAKESURE -f tests/21_parsing_quoting.sh | goal 'goal;b' [empty]. | goal 'goal&c' [empty]. | goal 'default' [empty]. + +$ cd "$MYDIR"; ./$MAKESURE -f tests/21_parsing_err1.sh +@ Syntax error: unterminated argument: +@ tests/21_parsing_err1.sh:3: @goal 'goal name +? 1 + +$ cd "$MYDIR"; ./$MAKESURE -f tests/21_parsing_err2.sh +@ Syntax error: joined arguments: +@ tests/21_parsing_err2.sh:4: @doc doc'text +? 1 diff --git a/tests/21_parsing_err1.sh b/tests/21_parsing_err1.sh new file mode 100644 index 0000000..e2b720c --- /dev/null +++ b/tests/21_parsing_err1.sh @@ -0,0 +1,4 @@ + + +@goal 'goal name +echo 123 \ No newline at end of file diff --git a/tests/21_parsing_err2.sh b/tests/21_parsing_err2.sh new file mode 100644 index 0000000..902d15c --- /dev/null +++ b/tests/21_parsing_err2.sh @@ -0,0 +1,5 @@ + + +@goal 'goal name' +@doc doc'text +echo 123 \ No newline at end of file