@@ -16,10 +16,15 @@ class PreprocessorError(Exception):
16
16
17
17
18
18
class _CustomPreprocessor (Preprocessor ):
19
- def __init__ (self , encoding : typing .Optional [str ]):
19
+ def __init__ (
20
+ self ,
21
+ encoding : typing .Optional [str ],
22
+ passthru_includes : typing .Optional ["re.Pattern" ],
23
+ ):
20
24
Preprocessor .__init__ (self )
21
25
self .errors : typing .List [str ] = []
22
26
self .assume_encoding = encoding
27
+ self .passthru_includes = passthru_includes
23
28
24
29
def on_error (self , file , line , msg ):
25
30
self .errors .append (f"{ file } :{ line } error: { msg } " )
@@ -58,12 +63,15 @@ def make_pcpp_preprocessor(
58
63
include_paths : typing .List [str ] = [],
59
64
retain_all_content : bool = False ,
60
65
encoding : typing .Optional [str ] = None ,
66
+ passthru_includes : typing .Optional ["re.Pattern" ] = None ,
61
67
) -> PreprocessorFunction :
62
68
"""
63
69
Creates a preprocessor function that uses pcpp (which must be installed
64
70
separately) to preprocess the input text.
65
71
66
72
:param encoding: If specified any include files are opened with this encoding
73
+ :param passthru_includes: If specified any #include directives that match the
74
+ compiled regex pattern will be part of the output.
67
75
68
76
.. code-block:: python
69
77
@@ -75,7 +83,7 @@ def make_pcpp_preprocessor(
75
83
"""
76
84
77
85
def _preprocess_file (filename : str , content : str ) -> str :
78
- pp = _CustomPreprocessor (encoding )
86
+ pp = _CustomPreprocessor (encoding , passthru_includes )
79
87
if include_paths :
80
88
for p in include_paths :
81
89
pp .add_path (p )
0 commit comments