Ejemplo n.º 1
0
def sanity_test(mh, filename, _):
    # pylint: disable=import-outside-toplevel
    from miss_hit_core import m_lexer
    # pylint: enable=import-outside-toplevel

    print("=== Parsing %s ===" % filename)

    mh.register_file(filename)
    slp = Simulink_SLX_Parser(mh, filename, Config())

    if slp.is_external_harness:
        print("   > Ignored external harness")
        return

    n_container = slp.parse_file()

    # Dump lexing of matlab blocks
    for n_block in n_container.iter_all_blocks():
        if not isinstance(n_block, Matlab_Function):
            continue

        mh.info(
            n_block.loc(), "block contains %u lines of MATLAB" %
            len(n_block.get_text().splitlines()))
        lexer = m_lexer.MATLAB_Lexer(mh, n_block.get_text(), filename,
                                     n_block.local_name())
        while True:
            token = lexer.token()
            if token is None:
                break
            mh.info(token.location, token.kind)
    mh.finalize_file(filename)

    # Dump model hierarchy
    n_container.dump_hierarchy()
Ejemplo n.º 2
0
    def __init__(self, mh, config_file):
        assert isinstance(mh, Message_Handler)
        assert isinstance(config_file, str)

        self.filename = config_file
        self.dirname = os.path.dirname(os.path.abspath(config_file))
        self.mh = mh

        self.mh.register_file(self.filename)
        with open(config_file, "r") as fd:
            content = fd.read()
        self.lexer = m_lexer.MATLAB_Lexer(mh, content, self.filename)
        self.lexer.set_config_file_mode()

        # pylint: disable=invalid-name
        self.ct = None
        self.nt = None
        # pylint: enable=invalid-name

        self.skip()