Skip to content

Commit

Permalink
auto-format using the latest intellij-awk : adjust minify.awk
Browse files Browse the repository at this point in the history
  • Loading branch information
xonixx committed Dec 20, 2023
1 parent 12c34cc commit e29a77e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
10 changes: 5 additions & 5 deletions makesure_candidate
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ function checkBeforeRun(i,j,dep,depCnt,goalName){
if(!((dep=Dependencies[goalName,j])in GoalsByName))
addError("Goal " quote2(goalName,1)" has unknown dependency '\''" dep "'\''",DependenciesLineNo[goalName,j])
if(goalName in GoalToLib&&!(GoalToLib[goalName]in Lib))
addError("Goal " quote2(goalName,1)" uses unknown lib '\''" GoalToLib[goalName] "'\''",UseLibLineNo[goalName])}}
addError("Goal " quote2(goalName,1)" uses unknown lib '\''" GoalToLib[goalName]"'\''",UseLibLineNo[goalName])}}
function getPreludeCode(a,k){
addLine(a,MyDirScript)
for(k in Vars)
Expand Down Expand Up @@ -345,7 +345,7 @@ function topologicalSort(includeReachedIf,requestedGoals,result,reachedGoals,i,j
die("Goal not found: " goalName)
topologicalSortPerform(includeReachedIf,reachedGoals,goalName,result,loop)}
if(loop[0]==1)
die("There is a loop in goal dependencies via " loop[1] " -> " loop[2])}
die("There is a loop in goal dependencies via " loop[1]" -> " loop[2])}
function isCodeAllowed(){return "goal"==Mode||"goal_glob"==Mode||"lib"==Mode}
function isPrelude(){return "prelude"==Mode}
function checkPreludeOnly(){if(!isPrelude())addError("Only use " $1 " in prelude")}
Expand All @@ -354,7 +354,7 @@ function currentGoalName(){return arrLast(GoalNames)}
function currentLibName(){return arrLast(LibNames)}
function realExit(code){
exit code}
function addError(err,n){if(!n)n=NR;Error=addL(Error,err ":\n" ARGV[1] ":" n ": " Lines[n])}
function addError(err,n){if(!n)n=NR;Error=addL(Error,err ":\n" ARGV[1]":" n ": " Lines[n])}
function addErrorDedup(err,n){if((err,n)in AddedErrors)return;AddedErrors[err,n];addError(err,n)}
function die(msg,out){
out="cat 1>&2"
Expand Down Expand Up @@ -654,6 +654,6 @@ function commandExists(cmd){return ok("command -v " cmd " >/dev/null")}
function ok(cmd){return system(cmd)==0}
function isFile(path){return ok("test -f " quoteArg(path))}
function rm(f){system("rm " quoteArg(f))}
function quoteArg(a){gsub("'\''", "'\''\\'\'''\''", a);return "'\''" a "'\''"}
function trim(s){sub(/^[ \t\r\n]+/,"", s);sub(/[ \t\r\n]+$/, "",s);return s}
function quoteArg(a){gsub("'\''","'\''\\'\'''\''",a);return "'\''" a "'\''"}
function trim(s){sub(/^[ \t\r\n]+/,"",s);sub(/[ \t\r\n]+$/,"",s);return s}
function copyKey(keySrc,keyDst,arr){if(keySrc in arr)arr[keyDst]=arr[keySrc]}' Makesurefile "$@"
41 changes: 27 additions & 14 deletions minify.awk
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,40 @@ in_begin && $1 ~ /^delete/{ next }
gsub(/} +/, "}")
gsub(/[)] +/, ")")
gsubKeepStrings("] +", "]")
gsub(/print +"/,"print\"")
gsub(/printf +"/,"printf\"")
gsub(/print +"/, "print\"")
gsub(/printf +"/, "printf\"")
if (!/^ +}/) gsub(/ +}/, "}")
##gsub(/" in/, "\"in")
gsub(Q, Q "\\" Q Q)
if (l = trim($0)) { decreaseIndent(); printf "%s", (l == "}" ? l : (NR == 1 ? "" : "\n") $0) }
}
function decreaseIndent() {
match($0,/^ */)
$0 = sprintf("%" (RLENGTH-1)/2 "s","") substr($0,RLENGTH)
match($0, /^ */)
$0 = sprintf("%" (RLENGTH - 1) / 2 "s", "") substr($0, RLENGTH)
}
function gsubKeepStrings(regex, replacement, cnt,parts,i,s) {
if ((cnt = split($0,parts,"\"")) == 1) {
gsub(regex,replacement)
return
function gsubKeepStrings(regex, replacement, nonString,s,isString,i,c) {
nonString = ""
s = ""
isString = 0
for (i=1;(c=substr($0,i,1))!="";i++) {
# print "> " i " " c
if ("\"" == c) {
# TODO escaped "
if (!isString) {
gsub(regex, replacement, nonString)
s = s nonString
nonString = ""
}
s = s c # append this "
isString = !isString
} else if (isString) {
s = s c
} else {
nonString = nonString c
}
}
gsub(regex,replacement,parts[1])
gsub(regex,replacement,parts[cnt])
for (i = 1; i < cnt; i++)
s = s parts[i] "\""
s = s parts[cnt]
gsub(regex, replacement, nonString)
s = s nonString
$0 = s
}
#BEGIN { $0 = "aaa\"aaa\"bbb"; gsubKeepStrings("aaa","AAA"); print }
#BEGIN { $0 = "aaa\"aaa\"bbbaaa"; gsubKeepStrings("aaa","AAA"); print }

0 comments on commit e29a77e

Please sign in to comment.