Sha256: 13778e97b1218b8daa3ed5dd7bfc0a91d10ee578617569f27f9a9d26c9b1235e

Contents?: true

Size: 1.92 KB

Versions: 221

Compression:

Stored size: 1.92 KB

Contents

# frozen_string_literal: false
require_relative "baseparser"

module REXML
  module Parsers
    class StreamParser
      def initialize source, listener
        @listener = listener
        @parser = BaseParser.new( source )
        @tag_stack = []
      end

      def add_listener( listener )
        @parser.add_listener( listener )
      end

      def parse
        # entity string
        while true
          event = @parser.pull
          case event[0]
          when :end_document
            unless @tag_stack.empty?
              tag_path = "/" + @tag_stack.join("/")
              raise ParseException.new("Missing end tag for '#{tag_path}'",
                                       @parser.source)
            end
            return
          when :start_element
            @tag_stack << event[1]
            attrs = event[2].each do |n, v|
              event[2][n] = @parser.unnormalize( v )
            end
            @listener.tag_start( event[1], attrs )
          when :end_element
            @listener.tag_end( event[1] )
            @tag_stack.pop
          when :text
            normalized = @parser.unnormalize( event[1] )
            @listener.text( normalized )
          when :processing_instruction
            @listener.instruction( *event[1,2] )
          when :start_doctype
            @listener.doctype( *event[1..-1] )
          when :end_doctype
            # FIXME: remove this condition for milestone:3.2
            @listener.doctype_end if @listener.respond_to? :doctype_end
          when :comment, :attlistdecl, :cdata, :xmldecl, :elementdecl
            @listener.send( event[0].to_s, *event[1..-1] )
          when :entitydecl, :notationdecl
            @listener.send( event[0].to_s, event[1..-1] )
          when :externalentity
            entity_reference = event[1]
            content = entity_reference.gsub(/\A%|;\z/, "")
            @listener.entity(content)
          end
        end
      end
    end
  end
end

Version data entries

221 entries across 214 versions & 33 rubygems

Version Path
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rexml-3.3.1/lib/rexml/parsers/streamparser.rb
rexml-3.3.1 lib/rexml/parsers/streamparser.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/rexml-3.2.5/lib/rexml/parsers/streamparser.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/rexml-3.2.5/lib/rexml/parsers/streamparser.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/rexml-3.2.5/lib/rexml/parsers/streamparser.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/rexml-3.3.0/lib/rexml/parsers/streamparser.rb
rexml-3.3.0 lib/rexml/parsers/streamparser.rb
rexml-3.2.9 lib/rexml/parsers/streamparser.rb
harbr-2.8.1 vendor/bundle/ruby/3.2.0/gems/rexml-3.2.6/lib/rexml/parsers/streamparser.rb
cloudsmith-api-2.0.13 vendor/bundle/ruby/2.6.0/gems/rexml-3.2.6/lib/rexml/parsers/streamparser.rb
bison-0.1.0 vendor/bundle/ruby/3.2.0/gems/rexml-3.2.6/lib/rexml/parsers/streamparser.rb
cloudsmith-api-2.0.12 vendor/bundle/ruby/2.6.0/gems/rexml-3.2.6/lib/rexml/parsers/streamparser.rb
cloudsmith-api-2.0.11 vendor/bundle/ruby/2.6.0/gems/rexml-3.2.6/lib/rexml/parsers/streamparser.rb
cloudsmith-api-2.0.10 vendor/bundle/ruby/2.6.0/gems/rexml-3.2.6/lib/rexml/parsers/streamparser.rb
cloudsmith-api-2.0.9 vendor/bundle/ruby/2.6.0/gems/rexml-3.2.6/lib/rexml/parsers/streamparser.rb
cloudsmith-api-2.0.8 vendor/bundle/ruby/2.6.0/gems/rexml-3.2.6/lib/rexml/parsers/streamparser.rb
mlh-rubocop-config-1.0.3 vendor/bundle/ruby/3.2.0/gems/rexml-3.2.6/lib/rexml/parsers/streamparser.rb
brakeman-6.1.2 bundle/ruby/3.3.0/gems/rexml-3.2.6/lib/rexml/parsers/streamparser.rb
study_line-0.2.7 vendor/bundle/ruby/3.2.0/gems/rexml-3.2.6/lib/rexml/parsers/streamparser.rb
study_line-0.2.6 vendor/bundle/ruby/3.2.0/gems/rexml-3.2.6/lib/rexml/parsers/streamparser.rb