-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshoop2.sh
159 lines (159 loc) · 3.88 KB
/
shoop2.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/bin/sh -e
SHOOP() {
class() {
local class=$1; shift
if eval [ \"\$_shoopclass_$class\" ]; then
echo "Class already defined!($class)" >&2
return 1
fi
eval _shoopclass_$class=1
_shoop_class_stack="$class $_shoop_class_stack"
_shoop_current_class=$class
_shoop_location=class
_shoopforward="${_shoopforward:+${_shoopforward}_}$class"
_shoopreverse="$class${_shoopreverse:+_$_shoopreverse}"
if [ "$abstract" ]; then
eval _shoopabstract_$class=1
fi
if [ "$1" = : ]; then
shift
eval "_shoopparents_$class=\"\$@\" _shoop_${class}_parent=\"echo -n '\$@'\""
fi
}
_part() {
local type=$1 name=$2; shift 2
if eval [ \"\$_shooptype_${_shoop_current_class}_$name\" ]; then
echo "Name already defined!($_shoop_current_class.$name)" >&2
return 1
fi
if eval [ -z \"\$_shoopabstract_${_shoop_current_class}\" -a \"\$abstract\" ]; then
echo "Can't create abstract $type $name on non-abstract class $_shoop_current_class!" >&2
return 1
fi
eval "_shoopflags_${_shoop_current_class}_$name=$flags\
_shooptype_${_shoop_current_class}_$name=$type\
_shoopparts_${_shoop_current_class}=\"\${_shoopparts_${_shoop_current_class}:+\$_shoopparts_${_shoop_current_class} }$name\""
if [ ! -z "$@" ]; then
if [ $type = variable ]; then
if [ $1 != = ]; then
echo "Syntax error! \`$1' not allowed."
return 1
fi
shift
eval "_shoop_${_shoopforward}_$name=\"echo -n '$@'\""
else
eval "_shoop_${_shoopforward}_$name=\"\$@\""
fi
fi
}
end() {
local IFS="_ "
case "$_shoop_location" in
class)
set -- $_shoop_class_stack
shift
_shoop_class_stack="$@"
_shooptest="${_shooptest}_$1"
set -- $_shoopreverse
current_class="$1"
shift
if [ "$_shoopreverse" = "$current_class" ]; then
_shoopreverse=
else
_shoopreverse=${_shoopreverse#${current_class}_}
fi
if [ "$_shoopforward" = "$current_class" ]; then
_shoopforward=
else
_shoopforward=${_shoopforward%_${current_class}}
fi
;;
method)
set -- $_shoop_method_stack
shift
_shoop_method_stack="$@"
;;
esac
}
_resolve() {
local class parent parents methods;
while [ $# -gt 0 ]; do
class=$1
if eval [ \"\$_shoopresolved_$class\" ]; then
continue;
fi
eval "parents=\$_shoopparents_$class"
if [ "$parents" ]; then
_resolve $parents
fi
for parent in $parents; do
eval methods=${methods:-$methods }\$_shoop
done
shift
done
}
new() {
local name=$1 cmd=$2 THIS=$1 class=$3; shift 2
if [ "$cmd" != ":" ]; then
echo "Syntax error in new.($name $cmd $@)" >&2
return 1
fi
if eval [ -z \"\$_shoopresolved_$class\" ]; then
_resolve "$@"
fi
if eval [ -z \"\$_shoopclass_$class\" ]; then
echo "$class not defined!" >&2
return 1
fi
if eval [ \"\$_shoopabstract_$class\" ]; then
echo "Can't create instance of abstract class $class!" >&2
return 1
fi
if eval [ \"\$_shoopdata_${class}_$class\" ];then
eval eval \$_shoopdata_${class}_$class
fi
eval _shoop_${name}_parent=\"echo -n '$@'\"
eval $name\(\) \{ local cmd=\"\$1\"\; shift\; _shoop $cmd $name $name '"$@"' \; \}
}
local abstract public flags
while :; do
case "$1" in
abstract|public)
eval $1=1
flags="${flags:+$flags }$1"
;;
*)
break
;;
esac
shift
done
case "$1" in
method|variable)
_part "$@"
;;
class|end|new)
"$@"
;;
*)
echo "Unknown SHOOP command($1)!"
exit 1
;;
esac
}
_shoop2() {
local cmd=$1 object=$2 class=$3 THIS=$2 entity=$4 type; shift 4
eval type=\$_shooptype_${class}_$entity
if eval [ "$type" = variable ]; then
if [ "$1" = = ]; then
shift;
eval "_shoop_${object}_$entity=\"$@\""
return 0
elif eval [ -z \"\$_shoop_${object}_$entity\" ]; then
eval "_shoop_${object}_$entity=\"\$_shoopdata_${class}_$entity\""
fi
eval echo -n \"\$_shoop_${object}_$entity\"
else
eval eval \$_shoop_${class}_$entity
fi
}