File tree Expand file tree Collapse file tree 3 files changed +16
-2
lines changed Expand file tree Collapse file tree 3 files changed +16
-2
lines changed Original file line number Diff line number Diff line change 4
4
anonymous_funcs=0
5
5
6
6
getindent(){
7
+ [[ ! ${1:0:1} =~ ([ \t]) ]] && echo 0 && return 0
7
8
echo "$1" | sed "s/\n/ /g" | awk '{ match($0, /^ */); printf("%d", RLENGTH) }' | sed 's/00/0/g'
8
9
}
9
10
@@ -68,7 +69,7 @@ transpile_for(){
68
69
else
69
70
# iterate over indexed array
70
71
local key="$(echo "$code" | awk '{ print $2 }')"
71
- code="${code/ $arr/ \"\${$arr\[@\]\}\"}"
72
+ [[ ! "$arr" == "\$@" ]] && code="${code/ $arr/ \"\${$arr\[@\]\}\"}"
72
73
fi
73
74
echo -e "$code" | transpile_all
74
75
}
@@ -122,6 +123,11 @@ transpile_switch(){
122
123
echo "${1/switch/case} in"
123
124
}
124
125
126
+ transpile_while(){
127
+ push stack "done"
128
+ echo "$1""; do"
129
+ }
130
+
125
131
transpile_case(){
126
132
push stack " ;;"
127
133
echo "${1/case /})"
Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ stack=()
50
50
anonymous_funcs=0
51
51
52
52
getindent (){
53
+ [[ ! ${1: 0: 1} =~ ([ \t ]) ]] && echo 0 && return 0
53
54
echo " $1 " | sed " s/\n/ /g" | awk ' { match($0, /^ */); printf("%d", RLENGTH) }' | sed ' s/00/0/g'
54
55
}
55
56
@@ -114,7 +115,7 @@ transpile_for(){
114
115
else
115
116
# iterate over indexed array
116
117
local key=" $( echo " $code " | awk ' { print $2 }' ) "
117
- code=" ${code/ $arr / \"\$ {$arr \[ @ \]\}\" } "
118
+ [[ ! " $arr " == " \$ @ " ]] && code=" ${code/ $arr / \"\$ {$arr \[ @ \]\}\" } "
118
119
fi
119
120
echo -e " $code " | transpile_all
120
121
}
@@ -168,6 +169,11 @@ transpile_switch(){
168
169
echo " ${1/ switch/ case} in"
169
170
}
170
171
172
+ transpile_while (){
173
+ push stack " done"
174
+ echo " $1 " " ; do"
175
+ }
176
+
171
177
transpile_case (){
172
178
push stack " ;;"
173
179
echo " ${1/ case / } )"
@@ -389,6 +395,7 @@ transpile_sugar(){
389
395
[[ " $line " =~ (await .* then) ]] && transpile_then " $line " && continue
390
396
[[ " $line " =~ ^([ ]* if ) ]] && transpile_if " $line " && continue
391
397
[[ " $line " =~ ^([ ]* switch ) ]] && transpile_switch " $line " && continue
398
+ [[ " $line " =~ ^([ ]* while ) ]] && transpile_while " $line " && continue
392
399
[[ " $line " =~ ^([ ]* case ) ]] && transpile_case " $line " && continue
393
400
[[ " $line " =~ ([a-zA-Z_0-9]\+ =) ]] && transpile_array_push " $line " && continue
394
401
[[ " $line " =~ ^([a-zA-Z_0-9]* \( [a-zA-Z_0-9, ]* \) ) ]] && transpile_function " $line " && continue
Original file line number Diff line number Diff line change @@ -80,6 +80,7 @@ transpile_sugar(){
80
80
[[ " $line " =~ (await .* then) ]] && transpile_then " $line " && continue
81
81
[[ " $line " =~ ^([ ]* if ) ]] && transpile_if " $line " && continue
82
82
[[ " $line " =~ ^([ ]* switch ) ]] && transpile_switch " $line " && continue
83
+ [[ " $line " =~ ^([ ]* while ) ]] && transpile_while " $line " && continue
83
84
[[ " $line " =~ ^([ ]* case ) ]] && transpile_case " $line " && continue
84
85
[[ " $line " =~ ([a-zA-Z_0-9]\+ =) ]] && transpile_array_push " $line " && continue
85
86
[[ " $line " =~ ^([a-zA-Z_0-9]* \( [a-zA-Z_0-9, ]* \) ) ]] && transpile_function " $line " && continue
You can’t perform that action at this time.
0 commit comments