Ejemplo n.º 1
0
    def make(self, name, temp_file_h, temp_file_c, save_to, save_to_c):
        tags = self.tags.enum_list
        res = LXB.Res("lxb_html_tree_insertion_mode_f", "{}_{}_res".format(self.prefix, name), False)
        res_closed = LXB.Res("lxb_html_tree_insertion_mode_f", "{}_{}_closed_res".format(self.prefix, name), False)

        for entry in tags:
            res.append("{}_{}_{} /* {} */".format(self.prefix, name, self.anything_else, entry["c_name"]))
            res_closed.append("{}_{}_{} /* {} */".format(self.prefix, name, self.anything_else_closed, entry["c_name"]))

        res_data = res.create(1, True)
        res_closed_data = res_closed.create(1, True)

        lxb_temp = LXB.Temp(temp_file_h, save_to)

        lxb_temp.pattern_append("%%NAME%%", name.upper())
        lxb_temp.pattern_append("%%HASH%%", self.tags.enum_hash_ifdef())
        lxb_temp.pattern_append("%%BODY-OPEN%%", ''.join(res_data))
        lxb_temp.pattern_append("%%BODY-CLOSED%%", ''.join(res_closed_data))

        lxb_temp.build()
        lxb_temp.save()

        lxb_temp = LXB.Temp(temp_file_c, save_to_c)

        lxb_temp.pattern_append("%%NAME%%", name)

        lxb_temp.build()
        lxb_temp.save()
Ejemplo n.º 2
0
    def shs_create_and_save_html(self, temp_file, save_to, temp_file_interface,
                                 save_to_interface):
        data_list = self.tag_data_create_html()

        lxb_temp = LXB.Temp(temp_file, save_to)

        lxb_temp.pattern_append("%%CHECK_TAG_VERSION%%",
                                self.enum_hash_ifdef())
        lxb_temp.pattern_append("%%CHECK_NS_VERSION%%", self.ns_hash_ifdef())
        lxb_temp.pattern_append("%%TAG_DATA%%", ''.join(data_list[0]))
        lxb_temp.pattern_append("%%FIXNAME_SVG_DATA%%", ''.join(data_list[4]))

        lxb_temp.build()
        lxb_temp.save()

        lxb_temp = LXB.Temp(temp_file_interface, save_to_interface)

        lxb_temp.pattern_append("%%CHECK_TAG_VERSION%%",
                                self.enum_hash_ifdef())
        lxb_temp.pattern_append("%%CHECK_NS_VERSION%%", self.ns_hash_ifdef())
        lxb_temp.pattern_append("%%INCLUDES%%", '\n'.join(data_list[1]))
        lxb_temp.pattern_append("%%CONSTRUCTOR%%", ''.join(data_list[2]))
        lxb_temp.pattern_append("%%DESTRUCTOR%%", ''.join(data_list[3]))

        lxb_temp.build()
        lxb_temp.save()

        print(self.shs_stat(self.shs))
        print("Save to {}".format(save_to))
        print("Done")
Ejemplo n.º 3
0
    def save_res(self, temp_file_h, save_to_h, temp_file_c, save_to_c):
        res = self.make()

        lxb_temp = LXB.Temp(temp_file_h, save_to_h)
        lxb_temp.pattern_append("%%EXTERNS%%", '\n'.join(res[1]))
        lxb_temp.pattern_append("%%SIZES%%", '\n'.join(res[2]))
        lxb_temp.build()
        lxb_temp.save()

        lxb_temp = LXB.Temp(temp_file_c, save_to_c)
        lxb_temp.pattern_append("%%INDEX%%", '\n\n'.join(res[0]))
        lxb_temp.build()
        lxb_temp.save()
Ejemplo n.º 4
0
    def save_res(self, temp_file_h, save_to_h, temp_file_c, save_to_c):
        data = self.make_data('lxb_encoding_res_map')
        shs = self.make_shs('lxb_encoding_res_shs_entities',
                            'lxb_encoding_res_map')

        lxb_temp = LXB.Temp(temp_file_h, save_to_h)
        lxb_temp.pattern_append("%%MAX%%",
                                self.make_name_upper(self.last_entry_name))
        lxb_temp.build()
        lxb_temp.save()

        lxb_temp = LXB.Temp(temp_file_c, save_to_c)
        lxb_temp.pattern_append("%%DATA%%", ''.join(data))
        lxb_temp.pattern_append("%%SHS%%", ''.join(shs))
        lxb_temp.build()
        lxb_temp.save()
Ejemplo n.º 5
0
    def save(self, const_temp_file, const_save_to, res_temp_file, res_save_to):
        res_class = ps.make("pseudo_class", pseudo_classes)
        res_class_function = ps.make("pseudo_class_function", pseudo_class_functions, pseudo_class_functions_dict)
        res_element = ps.make("pseudo_element", pseudo_elements)
        res_element_function = ps.make("pseudo_element_function", pseudo_element_functions, pseudo_element_functions_dict)

        # const
        lxb_temp = LXB.Temp(const_temp_file, const_save_to)

        lxb_temp.pattern_append("%%BODY%%",
                                "{}\n\n{}\n\n{}\n\n{}".format('\n'.join(res_class[0]),
                                                        '\n'.join(res_class_function[0]),
                                                        '\n'.join(res_element[0]),
                                                        '\n'.join(res_element_function[0])))

        lxb_temp.build()
        lxb_temp.save()

        print("Const saved to {}".format(const_save_to))

        # res
        lxb_temp = LXB.Temp(res_temp_file, res_save_to)

        lxb_temp.pattern_append("%%SHS_DATA%%",
                                "{}\n\n{}\n\n{}\n\n{}".format(''.join(res_class[1]),
                                                        ''.join(res_class_function[1]),
                                                        ''.join(res_element[1]),
                                                        ''.join(res_element_function[1])))
        lxb_temp.pattern_append("%%SHS%%",
                                "{}\n\n{}\n\n{}\n\n{}".format(''.join(res_class[2]),
                                                        ''.join(res_class_function[2]),
                                                        ''.join(res_element[2]),
                                                        ''.join(res_element_function[2])))

        lxb_temp.build()
        lxb_temp.save()

        print("Res saved to {}".format(res_save_to))
        print("Done")

        yn = input("Print declarations? (y - yes, n - no): ")
        if yn.lower() == 'y':
            print('LXB_API ', ';\n\nLXB_API '.join(res_class_function[3]), ';', sep='')
            print('LXB_API ', ';\n\nLXB_API '.join(res_element_function[3]), ';', sep='')
            print('\n\n'.join(res_class_function[4]))
            print('\n\n'.join(res_element_function[4]))
Ejemplo n.º 6
0
    def save_const(self, temp_file, save_to):
        buf = self.make_const()
        lxb_temp = LXB.Temp(temp_file, save_to)

        lxb_temp.pattern_append("%%CONST%%", '\n'.join(buf))

        lxb_temp.build()
        lxb_temp.save()
Ejemplo n.º 7
0
    def save_test(self, data, const_name, name):
        save_to_c = os.path.join(self.save_to, name + ".c")

        lxb_temp = LXB.Temp(self.temp_file_c, save_to_c)
        lxb_temp.pattern_append("%%DATA%%", data)
        lxb_temp.pattern_append("%%CONST_NAME%%", const_name)
        lxb_temp.pattern_append("%%NAME%%", name)
        lxb_temp.build()
        lxb_temp.save()
Ejemplo n.º 8
0
    def tag_test_create_and_save(self, temp_file, save_to):
        lxb_temp = LXB.Temp(temp_file, save_to)

        lxb_temp.pattern_append("%%TEST_NAMES%%", "\n".join(self.tag_test_name_create()))

        lxb_temp.build()
        lxb_temp.save()

        print("Test saved to {}".format(save_to))
Ejemplo n.º 9
0
    def save_res(self, filename, buf, hash_buf):
        save_to_c = os.path.join(self.save_to, filename + ".c")

        print("Save to:", save_to_c)

        lxb_temp = LXB.Temp(self.temp_file_c, save_to_c)
        lxb_temp.pattern_append("%%INDEX%%", buf)
        lxb_temp.pattern_append("%%HASH%%", hash_buf)
        lxb_temp.build()
        lxb_temp.save()
Ejemplo n.º 10
0
    def enum_save(self, data, temp_file, save_to):
        lxb_temp = LXB.Temp(temp_file, save_to)
        lxb_temp.pattern_append("%%HASH%%", self.enum_hash)
        lxb_temp.pattern_append("%%BODY%%", "\n".join(data))

        lxb_temp.build()
        lxb_temp.save()

        print("\n".join(data))
        print("Save to {}".format(save_to))
        print("Done")
Ejemplo n.º 11
0
    def const_save(self, temp_file, save_to):
        res = self.const_create()

        lxb_temp = LXB.Temp(temp_file, save_to)

        lxb_temp.pattern_append("%%BODY%%", '\n'.join(res))

        lxb_temp.build()
        lxb_temp.save()

        print("\n".join(res))
        print("Save to {}".format(save_to))
        print("Done")
Ejemplo n.º 12
0
    def shs_save(self, data, temp_file, save_to):
        lxb_temp = LXB.Temp(temp_file, save_to)

        lxb_temp.pattern_append("%%CHECK_TAG_VERSION%%", self.enum_hash_ifdef())
        lxb_temp.pattern_append("%%TAG_DATA%%", ''.join(self.tag_data_create_default()))
        lxb_temp.pattern_append("%%SHS_DATA%%", ''.join(data))

        lxb_temp.build()
        lxb_temp.save()

        print("".join(data))
        print(self.shs_stat(self.shs))
        print("Save to {}".format(save_to))
        print("Done")
Ejemplo n.º 13
0
    def ns_shs_save(self, data, data_link, temp_file, save_to):
        lxb_temp = LXB.Temp(temp_file, save_to)

        lxb_temp.pattern_append("%%CHECK_NS_VERSION%%", self.ns_hash_ifdef())
        lxb_temp.pattern_append("%%NS_DATA%%", ''.join(self.ns_data_create()))
        # lxb_temp.pattern_append("%%SHS_DATA%%", ''.join(data))
        lxb_temp.pattern_append("%%SHS_DATA_LINK%%", ''.join(data_link))

        lxb_temp.build()
        lxb_temp.save()

        print("".join(data))
        print(self.shs_stat(self.ns_shs))
        print("Save to {}".format(save_to))
        print("Done")
Ejemplo n.º 14
0
    def shs_save(self, temp_file, save_to):
        res = self.shs_create()
        data = self.data_create()

        lxb_temp = LXB.Temp(temp_file, save_to)

        lxb_temp.pattern_append("%%SHS_DATA%%", ''.join(data))
        lxb_temp.pattern_append("%%SHS%%", ''.join(res))

        lxb_temp.build()
        lxb_temp.save()

        print("".join(data))
        print("".join(res))
        print("Save to {}".format(save_to))
        print("Done")
Ejemplo n.º 15
0
def entities_bst(tmp_name, save_name, json_filename):
    print(ABS_PATH)
    index = entities_bst_load(os.path.join(ABS_PATH, json_filename))
    bst = entities_bst_create(index)
    result = entities_bst_result("lxb_html_tokenizer_res_entities_sbst", bst)

    lxb_temp = LXB.Temp(os.path.join(ABS_PATH, tmp_name),
                        os.path.join(ABS_PATH, save_name))
    lxb_temp.pattern_append("%%BODY%%", ''.join(result))

    lxb_temp.build()
    lxb_temp.save()

    # entities_bst_print(bst)
    print(''.join(lxb_temp.buffer))

    print("Saved to {}".format(lxb_temp.fn_to_save))
    print("Done!")
Ejemplo n.º 16
0
    def make(self):
        buf = []
        externs = []
        hash_externs = []
        hash_buf = []
        hash_sizes = []
        dir_path = self.dir_path

        for f in sorted(os.listdir(dir_path)):
            f_path = os.path.join(dir_path, f)
            if not os.path.isfile(f_path):
                continue

            print('File: {}'.format(f_path))

            idx = 0
            values = {'buffer_size': idx, 'max_size': 0}

            fo = open(f_path, "rb")

            for lineno, line in enumerate(fo):
                line = line.rstrip()
                if not line or line[:1] == b'#':
                    continue

                entries = line.split(b'\t')
                captions = entries[-1].split(b' ', maxsplit=1)

                if not captions[0]:
                    raise Exception(
                        'Failed to get chars variant on line {}'.format(
                            lineno))

                entries.append(captions[0])
                entries.append(captions[1] if captions[1] else b'')

                entries[2] = entries[3]
                entries[3] = len(entries[2])

                idx = int(entries[0].decode('utf-8'))
                values[idx] = entries

                if values['max_size'] < idx:
                    values['max_size'] = idx

            values['buffer_len'] = len(values)

            flat_name = self.make_name(f)
            res = self.make_flat_index(flat_name, values)
            hash_index = self.make_hash_index(flat_name, values)

            buf.append(''.join(res))
            externs.append('{};'.format(
                self.make_extern_name(flat_name, self.buffer_size(values))))
            hash_buf.append(''.join(hash_index[0]))
            hash_sizes.append(hash_index[1])
            hash_externs.append(hash_index[2])

            self.save_res(flat_name, ''.join(res), ''.join(hash_index[0]))

            fo.close()

        externs.append('')
        externs += hash_externs

        save_to_h = os.path.join(self.save_to, "multi.h")

        lxb_temp = LXB.Temp(self.temp_file_h, save_to_h)
        lxb_temp.pattern_append("%%EXTERNS%%", '\n'.join(externs))
        lxb_temp.pattern_append("%%SIZES%%", '\n'.join(hash_sizes))
        lxb_temp.build()
        lxb_temp.save()

        return [buf, externs, hash_buf, hash_sizes]
Ejemplo n.º 17
0
    def make(self, temp_file_h, temp_file_c, save_path):
        interfaces = self.interfaces
        typedefs_list = []
        interfaces_list = []

        for type in interfaces:
            path = os.path.abspath(save_path)
            full_path = "{}/{}".format(path, type.lower())

            if not os.path.exists(full_path):
                os.makedirs(full_path)

            interface = interfaces[type]
            names = list(interface.keys())
            names.sort()

            for name in names:
                inter_obj = interface[name]
                save_to_h = "{}/{}.h".format(full_path, inter_obj["c_name"])
                save_to_c = "{}/{}.c".format(full_path, inter_obj["c_name"])

                # Make and Save *.h
                lxb_temp_h = LXB.Temp(temp_file_h, save_to_h)

                if type == "DOM":
                    lxb_temp_h.pattern_append("%%mraw%%", "document->mraw")
                else:
                    lxb_temp_h.pattern_append("%%mraw%%",
                                              "document->mem->mraw")

                lxb_temp_h.pattern_append("%%M_PREFIX%%", type.upper())
                lxb_temp_h.pattern_append("%%M_NAME%%",
                                          inter_obj["c_name"].upper())
                lxb_temp_h.pattern_append("%%prefix%%", type.lower())
                lxb_temp_h.pattern_append("%%name%%", inter_obj["c_name"])

                typedef_name = self.make_type_name(type, inter_obj)
                lxb_temp_h.pattern_append("%%type%%", typedef_name)

                def_name = inter_obj["c_name"]
                def_name = def_name.replace('_element', '')

                interfaces_list.append(
                    "#define {}_{}_interface_{}(obj) (({} *) obj)".format(
                        self.prefix, type.lower(), def_name, typedef_name))

                vars = self.make_vars(type, inter_obj)
                lxb_temp_h.pattern_append("%%vars%%", "\n    ".join(vars))

                includes = self.make_inherit_includes(type, inter_obj)
                lxb_temp_h.pattern_append("%%includes%%",
                                          "\n".join(includes) + "\n")

                lxb_temp_h.build()
                lxb_temp_h.save()

                # Make and Save *.c
                lxb_temp_c = LXB.Temp(temp_file_c, save_to_c)

                if type == "DOM":
                    lxb_temp_c.pattern_append("%%mraw%%", "document->mraw")
                else:
                    lxb_temp_c.pattern_append("%%mraw%%",
                                              "document->mem->mraw")

                lxb_temp_c.pattern_append("%%prefix%%", type.lower())
                lxb_temp_c.pattern_append("%%name%%", inter_obj["c_name"])
                lxb_temp_c.pattern_append("%%type%%", typedef_name)

                lxb_temp_c.build()
                lxb_temp_c.save()

                # Print typedefs
                struct = "struct {}_{}_{}".format(self.prefix, type.lower(),
                                                  inter_obj["c_name"])
                typedefs_list.append("typedef {} {};".format(
                    struct, typedef_name))

        print("\n".join(typedefs_list))
        print("\n".join(interfaces_list))