def output_filename(base_dir, obj, suffix="h"): if base_dir is not None: base_dir = os.path.join(base_dir, *get_package_names_of_obj(obj)) output_file = os.path.join(base_dir, "{}.{}".format(obj.name, suffix)) output_file = os.path.abspath(output_file) else: base_dir = os.path.join(*get_package_names_of_obj(obj)) output_file = os.path.join(base_dir, "{}.{}".format(obj.name, suffix)) return output_file
def fqn(t): mm = get_metamodel(t) if textx_isinstance(t, mm["RawType"]): if t.name in _m: return _m[t.name] else: return t.name else: return "::".join(get_package_names_of_obj(t)) + "::" + t.name
def fqn(t): if t.is_enum(): t = t.type if t.is_rawtype(): if t.name in _m: return _m[t.name] else: return t.name else: return ".".join(get_package_names_of_obj(t)) + "." + t.name
def output_filename(base_dir, obj, suffix="lua"): if obj.__class__.__name__ == "Dissector": if base_dir is not None: base_dir = os.path.join(base_dir) output_file = os.path.join(base_dir, "{}.{}".format(obj.name, suffix)) output_file = os.path.abspath(output_file) else: base_dir = "." output_file = os.path.join(base_dir, "{}.{}".format(obj.name, suffix)) return output_file else: if base_dir is not None: base_dir = os.path.join(base_dir, *get_package_names_of_obj(obj)) output_file = os.path.join(base_dir, "{}.{}".format(obj.name, suffix)) output_file = os.path.abspath(output_file) else: base_dir = os.path.join(*get_package_names_of_obj(obj)) output_file = os.path.join(base_dir, "{}.{}".format(obj.name, suffix)) return output_file
def create_folder_and_return_output_filename(obj, base_dir, overwrite): """ :param obj: a struct, enum or constants object :return: filename or None (if the file already exists and has not be overriden """ concrete_dir = os.path.join(base_dir, *get_package_names_of_obj(obj)) if not os.path.exists(concrete_dir): os.makedirs(concrete_dir) output_file = output_filename(base_dir, obj) if overwrite or not os.path.exists(output_file): click.echo("-> {}".format(output_file)) return output_file else: click.echo("-- Skipping: {}".format(output_file)) return None
def render_ref( ref, separator=".", postfix="", prefix="", const_separator="::", enum_separator=None, repeat_type_name_for_enums=False, inhibit_fqn_for_parent=None, compute_constants=False, ): from textx import textx_isinstance, get_metamodel from item_lang.common import get_package_names_of_obj if enum_separator is None: enum_separator = const_separator mm = get_metamodel(ref) if ref.parent is inhibit_fqn_for_parent: fqn_parts = [] else: fqn_parts = get_package_names_of_obj(ref) + [ref.parent.name] if textx_isinstance(ref, mm["ScalarAttribute"]): return prefix + separator.join(map(lambda x: x.name, ref._tx_path)) + postfix elif textx_isinstance(ref, mm["Constant"]): if compute_constants: return ref.value.compute_formula() else: return const_separator.join(fqn_parts + [ref.name]) elif textx_isinstance(ref, mm["EnumEntry"]): if repeat_type_name_for_enums: return enum_separator.join(fqn_parts + [ref.parent.name, ref.name]) else: return enum_separator.join(fqn_parts + [ref.name]) else: from textx.exceptions import TextXSemanticError raise TextXSemanticError("unexpected type " + ref._tx_obj.__class__.__name__)
def get_open_namespace_for_obj(obj): return "namespace " + "::".join(get_package_names_of_obj(obj)) + "{\n"
def fqn(a): return ".".join(get_package_names_of_obj(a)) + "." + a.name + "." + a.name
def module_name(obj): return ".".join(get_package_names_of_obj(obj) + [obj.name])