# File TagTreeScanner.rb, line 738
        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?
                        # Keep popping off the current tag until we get to the root,
                        # as long as the end criteria is met
                        while ( current != @root ) && (!current.close_requires_bol? || ss.bol?) && ss.scan( current.close_match )
                                current = current.parent_tag || @root
                        end

                        # No point in continuing if closing out tags consumed the rest of the string
                        break if ss.eos?

                        # Look for a tag to open
                        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
                                }
                                #start at the top of the loop if we found one
                                next if tag
                        end

                        # Couldn't find a valid tag at this spot
                        # so we need to eat some characters
                        consumed = ss.scan( text_match )
                        current << consumed if current.allows_text?
                end
        end