def gen_name(name, name_list): i = 0 tname = name + '_' + str(i) while util.attrsearch(tname, 'i_xsd_name', name_list): i = i + 1 tname = name + '_' + str(i) return tname
def gen_new_typedef(module, new_type): i = 0 name = "t" + str(i) all_typedefs = module.search('typedef') + module.i_local_typedefs + \ module.i_gen_typedef while util.attrsearch(name, 'arg', all_typedefs): i = i + 1 name = "t" + str(i) typedef = statements.Statement(module, module, new_type.pos, 'typedef', name) typedef.substmts.append(new_type) module.i_gen_typedef.append(typedef) return name
def print_augment(ctx, module, fd, indent, augment): i = module.i_gen_augment_idx name = "a" + str(i) while util.attrsearch(name, 'arg', module.search('grouping')) != None: i = i + 1 name = "a" + str(i) module.i_gen_augment_idx = i + 1 fd.write(indent + '<xs:group name="%s">\n' % name) print_description(fd, indent + ' ', augment.search_one('description')) fd.write(indent + ' <xs:sequence>\n') print_children(ctx, module, fd, augment.i_children, indent + ' ', []) fd.write(indent + ' </xs:sequence>\n') fd.write(indent + '</xs:group>\n')
def v_reference_complex_type(ctx, stmt): """Validate the key of the complex type""" key = stmt.search_one('key') if key is not None: # check that the key has not been defined in the base type basetype = stmt.i_base_type while basetype is not None: basekey = basetype.search_one('key') if basekey is not None: err_add(ctx.errors, key.pos, "REDEFINED_KEY", (stmt.arg, basetype.arg, basekey.pos)) return basetype = basetype.i_base_type # check the references to the leafs # this part is based on the source code for the list's key validation stmt.i_key = [] if key is not None: found = [] for x in key.arg.split(): if x == '': continue if x.find(":") == -1: name = x else: [prefix, name] = x.split(':', 1) if prefix != stmt.i_module.i_prefix: err_add(ctx.errors, key.pos, 'BAD_KEY', x) return ptr = attrsearch(name, 'arg', stmt.i_children) if x in found: err_add(ctx.errors, key.pos, 'DUPLICATE_KEY', x) return elif ((ptr is None) or (ptr.keyword != 'leaf')): err_add(ctx.errors, key.pos, 'BAD_KEY', x) return type = ptr.search_one('type') if type is not None: t = statements.has_type(type, ['empty']) if t is not None: err_add(ctx.errors, key.pos, 'BAD_TYPE_IN_KEY', (t.arg, x)) return default = ptr.search_one('default') if default is not None: err_add(ctx.errors, default.pos, 'KEY_HAS_DEFAULT', ()) stmt.i_key.append(ptr) found.append(x)