def initialize( string_to_parse )
current = @root = self.class.root_factory.create
tag_genres = self.class.tag_genres
text_match = self.class.text_match
ss = StringScanner.new( string_to_parse )
while !ss.eos?
while ( current != @root ) && (!current.close_requires_bol? || ss.bol?) && ss.scan( current.close_match )
current = current.parent_tag || @root
end
break if ss.eos?
if factories = tag_genres[ current.allowed_genre ]
tag = nil
factories.each{ |factory|
if tag = factory.match( ss, self )
current.append_child( tag )
current = tag unless tag.autoclose?
break
end
}
next if tag
end
consumed = ss.scan( text_match )
current << consumed if current.allows_text?
end
end