lib/x12/loop.rb
def parse(str)
      #puts "Parsing loop #{name}: "+str
      s = str
      nodes.each{|i|
        m = i.parse(s)
        s = m if m
      } 
      if str == s
        return nil
      else
        self.parsed_str = str[0..-s.length-1]
        s = do_repeats(s)
      end
      #puts 'Parsed loop '+self.inspect
      return s
    end
def parse(str)
      #puts "Parsing loop #{name}: "+str
      s = str
      nodes.each{|i|
        m = i.parse(s)
        s = m if m
      } 
      if str == s
        return nil
      else
        self.parsed_str = str[0..-s.length-1]
        s = do_repeats(s)
      end
      #puts 'Parsed loop '+self.inspect
      return s
    end
def regexp
       @regexp ||=
         Regexp.new(inject(''){|s, i|
                      puts i.class
                      s += case i
                           when X12::Segment: "(#{i.regexp.source}){#{i.repeats.begin},#{i.repeats.end}}"
                           when X12::Loop:    "(.*?)"
                           else
                             ''
                           end
                    })
     end
 Parse a string and fill out internal structures with the pieces of it. Returns
 an unparsed portion of the string or the original string if nothing was parsed out.