Class EimXML::Parser
In: lib/eim_xml/parser.rb
Parent: Object

Methods

Classes and Modules

Module EimXML::Parser::RE

Attributes

scanner  [R] 

Public Class methods

[Source]

    # File lib/eim_xml/parser.rb, line 24
24:                 def initialize(src)
25:                         @scanner = StringScanner.new(src)
26:                         @scanner.scan(/\s*<\?.*?\?>\s*/)
27:                 end

Public Instance methods

[Source]

    # File lib/eim_xml/parser.rb, line 29
29:                 def parse
30:                         if @scanner.scan(RE::EMPTY_ELEMENT)
31:                                 parse_empty_element
32:                         elsif @scanner.scan(RE::START_TAG)
33:                                 parse_start_tag
34:                         elsif @scanner.scan(RE::STRING)
35:                                 parse_string
36:                         else
37:                                 nil
38:                         end
39:                 end

Protected Instance methods

[Source]

    # File lib/eim_xml/parser.rb, line 49
49:                 def parse_empty_element
50:                         parse_tag
51:                 end

[Source]

    # File lib/eim_xml/parser.rb, line 54
54:                 def parse_start_tag
55:                         e = parse_tag
56: 
57:                         until @scanner.scan(RE::END_TAG)
58:                                 c = parse
59:                                 raise ParseError.new("Syntax error.") unless c
60:                                 e << c
61:                         end
62:                         raise ParseError.new("End tag mismatched.") unless @scanner[1].to_sym==e.name
63:                         e
64:                 end

[Source]

    # File lib/eim_xml/parser.rb, line 67
67:                 def parse_string
68:                         s = @scanner[0]
69:                         s = s.gsub(/&(amp|quot|apos|lt|gt);/) do
70:                                 case $1
71:                                 when "amp"
72:                                         "&"
73:                                 when "quot"
74:                                         '"'
75:                                 when "apos"
76:                                         "'"
77:                                 when "lt"
78:                                         "<"
79:                                 when "gt"
80:                                         ">"
81:                                 end
82:                         end
83:                         PCString.new(s)
84:                 end

[Source]

    # File lib/eim_xml/parser.rb, line 41
41:                 def parse_tag
42:                         s = StringScanner.new(@scanner[1])
43:                         e = Element.new(s.scan(/\S+/))
44:                         e[s[1]] = s[3] ? s[3] : s[4] while s.scan(RE::ATTRIBUTE)
45:                         e
46:                 end

[Validate]