Skip to content

Commit

Permalink
Improve parsing algorithm to handle spaces and comments #63
Browse files Browse the repository at this point in the history
  • Loading branch information
xonixx committed Oct 14, 2021
1 parent d8565ac commit 8e9d9a4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
14 changes: 11 additions & 3 deletions makesure.awk
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ body,goalBody,goalBodies,resolvedGoals,exitCode, t0,t1,t2, goalTimed, list) {
goalName = GoalNames[i]
if (list && GoalsByName[goalName]) # private
continue
if ((gnLen = length(goalName)) > gnMaxLen && gnLen <= 30)
if ((gnLen = length(quote2(goalName))) > gnMaxLen && gnLen <= 30)
gnMaxLen = gnLen
}
for (i = 0; i in GoalNames; i++) {
Expand All @@ -371,9 +371,9 @@ body,goalBody,goalBodies,resolvedGoals,exitCode, t0,t1,t2, goalTimed, list) {
continue
printf " "
if (goalName in Doc)
printf "%-" gnMaxLen "s : %s\n", goalName, Doc[goalName]
printf "%-" gnMaxLen "s : %s\n", quote2(goalName), Doc[goalName]
else
print goalName
print quote2(goalName)
}
} else {
if ("timing" in Options)
Expand Down Expand Up @@ -734,6 +734,14 @@ function reparseCli( res,i,err) {
for (i=NF=0; i in res; i++)
$(++NF)=res[i]
}
function quote2(s,force) {
if (index(s,"'")) {
gsub(/\\/,"\\\\",s)
gsub(/'/,"\\'",s)
return "$'" s "'"
} else
return force || s ~ /[ \t\\]/ ? "'" s "'" : s
}
function addLine(target, line) { target[0] = addL(target[0], line) }
function addL(s, l) { return s ? s "\n" l : l }
function arrPush(arr, elt) { arr[arr[-7]++] = elt }
Expand Down
14 changes: 7 additions & 7 deletions tests/21_parsing.tush
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

$ cd "$MYDIR"; ./$MAKESURE -f tests/21_parsing_spaces.sh -la
| Available goals:
| 21_parsing 1.txt
| 21_parsing 2.txt
| '21_parsing 1.txt'
| '21_parsing 2.txt'
| 21_parsing*.txt
| g1@21_parsing 1.txt
| g1@21_parsing 2.txt
| 'g1@21_parsing 1.txt'
| 'g1@21_parsing 2.txt'
| g1
| test2
| test3
Expand Down Expand Up @@ -34,9 +34,9 @@ $ cd "$MYDIR"; ./$MAKESURE -f tests/21_parsing_comments.sh test1

$ 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
| 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
Expand Down

0 comments on commit 8e9d9a4

Please sign in to comment.