8000 added support for while · coderofsalvation/powscript@38a4a93 · GitHub
[go: up one dir, main page]

Skip to content

Commit 38a4a93

Browse files
added support for while
1 parent 3ed71af commit 38a4a93

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

lang/bash/.transpile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ stack=()
44
anonymous_funcs=0
55

66
getindent(){
7+
[[ ! ${1:0:1} =~ ([ \t]) ]] && echo 0 && return 0
78
echo "$1" | sed "s/\n/ /g" | awk '{ match($0, /^ */); printf("%d", RLENGTH) }' | sed 's/00/0/g'
89
}
910

@@ -68,7 +69,7 @@ transpile_for(){
6869
else
6970
# iterate over indexed array
7071
local key="$(echo "$code" | awk '{ print $2 }')"
71-
code="${code/ $arr/ \"\${$arr\[@\]\}\"}"
72+
[[ ! "$arr" == "\$@" ]] && code="${code/ $arr/ \"\${$arr\[@\]\}\"}"
7273
fi
7374
echo -e "$code" | transpile_all
7475
}
@@ -122,6 +123,11 @@ transpile_switch(){
122123
echo "${1/switch/case} in"
123124
}
124125

126+
transpile_while(){
127+
push stack "done"
128+
echo "$1""; do"
129+
}
130+
125131
transpile_case(){
126132
push stack " ;;"
127133
echo "${1/case /})"

powscript

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ stack=()
5050
anonymous_funcs=0
5151

5252
getindent(){
53+
[[ ! ${1:0:1} =~ ([ \t]) ]] && echo 0 && return 0
5354
echo "$1" | sed "s/\n/ /g" | awk '{ match($0, /^ */); printf("%d", RLENGTH) }' | sed 's/00/0/g'
5455
}
5556

@@ -114,7 +115,7 @@ transpile_for(){
114115
else
115116
# iterate over indexed array
116117
local key="$(echo "$code" | awk '{ print $2 }')"
117-
code="${code/ $arr/ \"\${$arr\[@\]\}\"}"
118+
[[ ! "$arr" == "\$@" ]] && code="${code/ $arr/ \"\${$arr\[@\]\}\"}"
118119
fi
119120
echo -e "$code" | transpile_all
120121
}
@@ -168,6 +169,11 @@ transpile_switch(){
168169
echo "${1/switch/case} in"
169170
}
170171

172+
transpile_while(){
173+
push stack "done"
174+
echo "$1""; do"
175+
}
176+
171177
transpile_case(){
172178
push stack " ;;"
173179
echo "${1/case /})"
@@ -389,6 +395,7 @@ transpile_sugar(){
389395
[[ "$line" =~ (await .* then) ]] && transpile_then "$line" && continue
390396
[[ "$line" =~ ^([ ]*if ) ]] && transpile_if "$line" && continue
391397
[[ "$line" =~ ^([ ]*switch ) ]] && transpile_switch "$line" && continue
398+
[[ "$line" =~ ^([ ]*while ) ]] && transpile_while "$line" && continue
392399
[[ "$line" =~ ^([ ]*case ) ]] && transpile_case "$line" && continue
393400
[[ "$line" =~ ([a-zA-Z_0-9]\+=) ]] && transpile_array_push "$line" && continue
394401
[[ "$line" =~ ^([a-zA-Z_0-9]*\([a-zA-Z_0-9, ]*\)) ]] && transpile_function "$line" && continue

src/powscript.bash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ transpile_sugar(){
8080
[[ "$line" =~ (await .* then) ]] && transpile_then "$line" && continue
8181
[[ "$line" =~ ^([ ]*if ) ]] && transpile_if "$line" && continue
8282
[[ "$line" =~ ^([ ]*switch ) ]] && transpile_switch "$line" && continue
83+
[[ "$line" =~ ^([ ]*while ) ]] && transpile_while "$line" && continue
8384
[[ "$line" =~ ^([ ]*case ) ]] && transpile_case "$line" && continue
8485
[[ "$line" =~ ([a-zA-Z_0-9]\+=) ]] && transpile_array_push "$line" && continue
8586
[[ "$line" =~ ^([a-zA-Z_0-9]*\([a-zA-Z_0-9, ]*\)) ]] && transpile_function "$line" && continue

0 commit comments

Comments
 (0)
0