@@ -16,10 +16,15 @@ class PreprocessorError(Exception):
1616
1717
1818class _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+ ):
2024 Preprocessor .__init__ (self )
2125 self .errors : typing .List [str ] = []
2226 self .assume_encoding = encoding
27+ self .passthru_includes = passthru_includes
2328
2429 def on_error (self , file , line , msg ):
2530 self .errors .append (f"{ file } :{ line } error: { msg } " )
@@ -58,12 +63,15 @@ def make_pcpp_preprocessor(
5863 include_paths : typing .List [str ] = [],
5964 retain_all_content : bool = False ,
6065 encoding : typing .Optional [str ] = None ,
66+ passthru_includes : typing .Optional ["re.Pattern" ] = None ,
6167) -> PreprocessorFunction :
6268 """
6369 Creates a preprocessor function that uses pcpp (which must be installed
6470 separately) to preprocess the input text.
6571
6672 :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.
6775
6876 .. code-block:: python
6977
@@ -75,7 +83,7 @@ def make_pcpp_preprocessor(
7583 """
7684
7785 def _preprocess_file (filename : str , content : str ) -> str :
78- pp = _CustomPreprocessor (encoding )
86+ pp = _CustomPreprocessor (encoding , passthru_includes )
7987 if include_paths :
8088 for p in include_paths :
8189 pp .add_path (p )
0 commit comments