Change soft-fail to use the config, rather than env
[rbx.git] / lib / rexml / parsers / lightparser.rb
blob0f350349930b042f031af304ff347bcd7975f6cb
1 require 'rexml/parsers/streamparser'
2 require 'rexml/parsers/baseparser'
3 require 'rexml/light/node'
5 module REXML
6         module Parsers
7                 class LightParser
8                         def initialize stream
9                                 @stream = stream
10                                 @parser = REXML::Parsers::BaseParser.new( stream )
11                         end
13       def add_listener( listener )
14         @parser.add_listener( listener )
15       end
17       def rewind
18         @stream.rewind
19         @parser.stream = @stream
20       end
22                         def parse
23                                 root = context = [ :document ]
24                                 while true
25                                         event = @parser.pull
26                                         case event[0]
27                                         when :end_document
28                                                 break
29                                         when :end_doctype
30                                                 context = context[1]
31                                         when :start_element, :start_doctype
32                                                 new_node = event
33                                                 context << new_node
34                                                 new_node[1,0] = [context]
35                                                 context = new_node
36                                         when :end_element, :end_doctype
37                                                 context = context[1]
38                                         else
39                                                 new_node = event
40                                                 context << new_node
41                                                 new_node[1,0] = [context]
42                                         end
43                                 end
44                                 root
45                         end
46                 end
48                 # An element is an array.  The array contains:
49                 #  0                    The parent element
50                 #  1                    The tag name
51                 #  2                    A hash of attributes
52                 #  3..-1        The child elements
53                 # An element is an array of size > 3
54                 # Text is a String
55                 # PIs are [ :processing_instruction, target, data ]
56                 # Comments are [ :comment, data ]
57                 # DocTypes are DocType structs
58                 # The root is an array with XMLDecls, Text, DocType, Array, Text
59         end
60 end