# File lib/edi4r/edifact.rb, line 1398
    def Segment.parse (p, buf, tag_expected=nil)
      # Buffer contains a single segment
      obj_list = EDI::E::edi_split( buf, p.root.una.de_sep, p.root.una.esc_char )
      tag = obj_list.shift                # First entry must be the segment tag

      raise "Illegal tag: #{tag}" unless tag =~ /[A-Z]{3}/
        if tag_expected and tag_expected != tag
          raise "Wrong segment name! Expected: #{tag_expected}, found: #{tag}"
        end

      seg = p.new_segment(tag)
      seg.each {|obj| obj.parse( obj_list.shift ) }
      seg
      # Error handling needed here if obj_list is not exhausted now!
    end