Example #1
0
def cmd_preprocess(filenames, *, raw=False, iter_filenames=None, **kwargs):
    if 'get_file_preprocessor' not in kwargs:
        kwargs['get_file_preprocessor'] = _get_preprocessor()
    if raw:

        def show_file(filename, lines):
            for line in lines:
                print(line)
                #print(line.raw)
    else:

        def show_file(filename, lines):
            for line in lines:
                linefile = ''
                if line.filename != filename:
                    linefile = f' ({line.filename})'
                text = line.data
                if line.kind == 'comment':
                    text = '/* ' + line.data.splitlines()[0]
                    text += ' */' if '\n' in line.data else r'\n... */'
                print(f' {line.lno:>4} {line.kind:10} | {text}')

    filenames = main_for_filenames(filenames, iter_filenames)
    for filename in filenames:
        lines = _iter_preprocessed(filename, **kwargs)
        show_file(filename, lines)
Example #2
0
def cmd_parse(filenames,
              *,
              fmt='summary',
              showfwd=None,
              iter_filenames=None,
              **kwargs):
    if 'get_file_preprocessor' not in kwargs:
        kwargs['get_file_preprocessor'] = _get_preprocessor()
    try:
        do_fmt = FORMATS[fmt]
    except KeyError:
        raise ValueError(f'unsupported fmt {fmt!r}')
    for filename in main_for_filenames(filenames, iter_filenames):
        for item in _iter_parsed(filename, **kwargs):
            for line in do_fmt(filename, item, showfwd=showfwd):
                print(line)