# class EimXML::Parser

### Attributes

scanner[R]

### Public Class Methods

new(src) click to toggle source

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

### Public Instance Methods

parse() click to toggle source

       # File lib/eim_xml/parser.rb
    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

parse_empty_element() click to toggle source

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

parse_start_tag() click to toggle source

       # File lib/eim_xml/parser.rb
    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

parse_string() click to toggle source

       # File lib/eim_xml/parser.rb
    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

parse_tag() click to toggle source

       # File lib/eim_xml/parser.rb
    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