def each_block_string
rough_reg = /<(?:\!|c|\/c)/i
comment_reg = /<\!---[^-](.*?)[^-]--->/mi
cktag_reg = /<cgikit\s+[^>]*?\/>/i
start_cktag_reg = /<cgikit\s+[^>]*?>/mi
end_cktag_reg = /<\/cgikit\s*>/i
other_reg = /(?:.+?(?=<(?:\!|c|\/c))|.+)/mi
nest = 0
nested_cktag = ''
str = nil
while @scanner.rest?
if @scanner.match?(rough_reg)
if str = @scanner.scan(comment_reg)
yield str, :comment
next
end
if str = @scanner.scan(cktag_reg)
if nest > 0
nested_cktag << str
else
yield str, :cgikit_tag
end
next
end
if str = @scanner.scan(start_cktag_reg)
nested_cktag << str
nest += 1
next
end
if str = @scanner.scan(end_cktag_reg)
nested_cktag << str
nest -= 1
if nest == 0
yield nested_cktag, :cgikit_tag
nested_cktag = ''
elsif nest < 0
raise CKHTMLParseError, \
"too many end-tags(</cgikit>) in #{@parent.template_file}."
end
next
end
end
if str = @scanner.scan(other_reg)
if nest > 0
nested_cktag << str
else
yield str, :normal
end
next
end
raise CKHTMLParseError, "not match any rule in #{@parent.template_file}."
end
if nest != 0
raise CKHTMLParseError, \
"a cgikit tag is not closed in #{@parent.template_file}."
end
end