'Process one line containing the GENERATE statement from a DNS
master file.'

def _generate_line(self):

    if (self.current_origin is None):
        raise UnknownOrigin
    token = self.tok.get()
    try:
        (start, stop, step) = dns.grange.from_text(token.value)
        token = self.tok.get()
        if (not token.is_identifier()):
            raise dns.exception.SyntaxError
    except:
        raise dns.exception.SyntaxError
    try:
        lhs = token.value
        token = self.tok.get()
        if (not token.is_identifier()):
            raise dns.exception.SyntaxError
    except:
        raise dns.exception.SyntaxError
    try:
        ttl = dns.ttl.from_text(token.value)
        token = self.tok.get()
        if (not token.is_identifier()):
            raise dns.exception.SyntaxError
    except dns.ttl.BadTTL:
        ttl = self.ttl
    try:
        rdclass = dns.rdataclass.from_text(token.value)
        token = self.tok.get()
        if (not token.is_identifier()):
            raise dns.exception.SyntaxError
    except dns.exception.SyntaxError:
        raise dns.exception.SyntaxError
    except:
        rdclass = self.zone.rdclass
    if (rdclass != self.zone.rdclass):
        raise dns.exception.SyntaxError("RR    class    is    not    zone's    class")
    try:
        rdtype = dns.rdatatype.from_text(token.value)
        token = self.tok.get()
        if (not token.is_identifier()):
            raise dns.exception.SyntaxError
    except:
        raise dns.exception.SyntaxError(("unknown    rdatatype    '%s'" % token.value))
    try:
        rhs = token.value
    except:
        raise dns.exception.SyntaxError
    (lmod, lsign, loffset, lwidth, lbase) = self._parse_modify(lhs)
    (rmod, rsign, roffset, rwidth, rbase) = self._parse_modify(rhs)
    for i in range(start, (stop + 1), step):
        if (lsign == u'+'):
            lindex = (i + int(loffset))
        elif (lsign == u'-'):
            lindex = (i - int(loffset))
        if (rsign == u'-'):
            rindex = (i - int(roffset))
        elif (rsign == u'+'):
            rindex = (i + int(roffset))
        lzfindex = str(lindex).zfill(int(lwidth))
        rzfindex = str(rindex).zfill(int(rwidth))
        name = lhs.replace((u'$%s' % lmod), lzfindex)
        rdata = rhs.replace((u'$%s' % rmod), rzfindex)
        self.last_name = dns.name.from_text(name, self.current_origin)
        name = self.last_name
        if (not name.is_subdomain(self.zone.origin)):
            self._eat_line()
            return
        if self.relativize:
            name = name.relativize(self.zone.origin)
        n = self.zone.nodes.get(name)
        if (n is None):
            n = self.zone.node_factory()
            self.zone.nodes[name] = n
        try:
            rd = dns.rdata.from_text(rdclass, rdtype, rdata, self.current_origin, False)
        except dns.exception.SyntaxError:
            (ty, va) = sys.exc_info()[:2]
            raise va
        except:
            (ty, va) = sys.exc_info()[:2]
            raise dns.exception.SyntaxError(('caught    exception    %s:    %s' % (str(ty), str(va))))
        rd.choose_relativity(self.zone.origin, self.relativize)
        covers = rd.covers()
        rds = n.find_rdataset(rdclass, rdtype, covers, True)
        rds.add(rd, ttl)
