How to use the pcpp.Preprocessor function in pcpp

To help you get started, we’ve selected a few pcpp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ned14 / pcpp / tests / cstd.py View on Github external
def runTest(self):
        from pcpp import Preprocessor
        import os, sys

        start = clock()
        p = Preprocessor()
        p.parse(self.input)
        oh = StringIO()
        p.write(oh)
        end = clock()
        print("Preprocessed test in", end-start, "seconds")
        if oh.getvalue() != self.output:
            print("Should be:\n" + self.output, file = sys.stderr)
            print("\n\nWas:\n" + oh.getvalue(), file = sys.stderr)
        self.assertEqual(p.return_code, 0)
        self.assertEqual(oh.getvalue(), self.output)
github ned14 / pcpp / tests / passthru.py View on Github external
def runTest(self):
        from pcpp import Preprocessor, OutputDirective
        import os, sys

        class PassThruPreprocessor(Preprocessor):
            def on_include_not_found(self,is_system_include,curdir,includepath):
                raise OutputDirective()

            def on_unknown_macro_in_defined_expr(self,tok):
                return None  # Pass through as expanded as possible
                
            def on_unknown_macro_in_expr(self,tok):
                return None  # Pass through as expanded as possible
                
            def on_directive_handle(self,directive,toks,ifpassthru,precedingtoks):
                super(PassThruPreprocessor, self).on_directive_handle(directive,toks,ifpassthru,precedingtoks)
                return None  # Pass through where possible

            def on_directive_unknown(self,directive,toks,ifpassthru,precedingtoks):
                if directive.value == 'error' or directive.value == 'warning':
                    super(PassThruPreprocessor, self).on_directive_unknown(directive,toks,ifpassthru,precedingtoks)
github ned14 / pcpp / tests / n_std.py View on Github external
def runTest(self):
        from pcpp import Preprocessor
        import os

        start = clock()
        p = Preprocessor()
        p.compress = 1
        p.line_directive = '#'
        p.define('__STDC__ 1')
        p.define('__STDC_VERSION__ 199901L')
        p.define('__DATE__ "Jan 13 2020"')
        p.define('__TIME__ "10:47:38"')
        p.define('NO_SYSTEM_HEADERS')
        path = 'tests/test-c/n_std.c'
        with open(path, 'rt') as ih:
            p.parse(ih.read(), path)
        with open('tests/n_std.i', 'w') as oh:
            p.write(oh)
        end = clock()
        print("Preprocessed", path, "in", end-start, "seconds")
        self.assertEqual(p.return_code, 0)
github ZedThree / fort_depend.py / fortdepend / preprocessor.py View on Github external
import io
import pcpp


class FortranPreprocessor(pcpp.Preprocessor):
    def __init__(self):
        super().__init__()
        self.add_path('.')

    def parse_to_string(self, text, source):
        with io.StringIO() as f:
            self.parse(text, source=source)
            self.write(f)
            return f.getvalue()