-
Notifications
You must be signed in to change notification settings - Fork 7
/
js_to_wakeobj.sh
executable file
·78 lines (71 loc) · 1.54 KB
/
js_to_wakeobj.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
################################################
# Source Code for the Original Compiler for the
# Programming Language Wake
#
# %filename
#
# Licensed under the MIT license
# See LICENSE.TXT for details
#
# Author: Michael Fairhurst
# Revised By:
#
#################################################
STATE=js
ClASSESOUT=
PROPERTIESOUT=
JSOUT=
JSOUTLOC=0
PRINTNEXT=false
BUILDINGSYMBOL='%'
while IFS= read -rn 1 i
do
if $PRINTNEXT
then
JSOUT="$JSOUT""$i"
JSOUTLOC=$(( $JSOUTLOC + 1 ))
PRINTNEXT=false
continue
fi
if [ "$i" == $'\0' ] ; then continue ; fi
if [ "$i" == $'\r' ] ; then continue ; fi
if [ "$i" == $'\n' ] ; then continue ; fi
if [ "$i" == $'\t' ] ; then continue ; fi
if [ "$i" == ' ' ] ; then continue ; fi
if [ "$i" == '$' ] ; then PRINTNEXT=true; continue ; fi
if [ "$STATE" == js ]
then
if [ "$i" == '`' ]
then
STATE="property"
elif [ "$i" == '~' ]
then
STATE="class"
else
JSOUT="$JSOUT""$i"
JSOUTLOC=$(( $JSOUTLOC + 1 ))
fi
elif [ "$STATE" == class ]
then
if [ "$i" == '~' ]
then
CLASSESOUT="$CLASSESOUT $JSOUTLOC $BUILDINGSYMBOL%"
BUILDINGSYMBOL='%'
STATE="js"
else
BUILDINGSYMBOL="$BUILDINGSYMBOL""$i"
fi
else # $STATE == property
if [ "$i" == '`' ]
then
PROPERTIESOUT="$PROPERTIESOUT $JSOUTLOC $BUILDINGSYMBOL%"
BUILDINGSYMBOL='%'
STATE="js"
else
BUILDINGSYMBOL="$BUILDINGSYMBOL""$i"
fi
fi
done
echo "%-CLASSES-% $CLASSESOUT %-PROPERTIES-% $PROPERTIESOUT %-END-%"
echo -n "$JSOUT"