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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
# File 'lib/rwd/sgml.rb', line 125
def buildobjects(string)
@objects = []
verwerk3 =
lambda do |string|
a = []
string[1..-2].splitblocks(["'", "'"], ['"', '"']).collect do |type, s|
case type
when 0
if self.class.to_s == "HTML"
s.splitwords.each do |w|
d = w.split("=", 2)
if d.length == 1
a << d[0]
else
a << d[0] if not d[0].nil? and not d[0].empty?
a << "="
a << d[1] if not d[1].nil? and not d[1].empty?
end
end
else
a.concat s.splitwords(["/", "="])
end
when 1, 2 then a << s
end
end
open = false
close = false
a = a[0].splitwords("/") + a[1..-1]
if a[0] == "/"
close = true
a.shift
else
open = true
end
if a[-1] == "/"
close = true
a.pop
end
tag = a.shift.downcase
args = {}
while not a.length.zero?
if a.length >= 3 and a[1] == "="
key = a.shift.downcase
dummy = a.shift
value = a.shift.noquotes
args[key] = value
else
key = a.shift.downcase
args[key] = ""
end
end
[tag, args, open, close]
end
verwerk2 =
lambda do |string|
if @tagcache.include? string
res = @tagcache[string]
else
res = verwerk3.call(string)
@tagcache[string] = res
end
res
end
verwerk1 =
lambda do |string|
tag, args, open, close = verwerk2.call(string)
@objects << OpenTag.new(tag.dup, args.dup) if open
@objects << CloseTag.new(tag.dup, args.dup) if close
end
string.splitblocks(["<!--", "-->"], ["<!", ">"], ["<?", "?>"], ["<", ">"]).each do |type, s|
case type
when 0 then @objects << Text.new(s)
when 1 then @objects << .new(s)
when 2 then @objects << Special.new(s)
when 3 then @objects << Instruction.new(s)
when 4 then verwerk1.call(s)
end
end
end
|