Add preprocessor-only mode to the dump command

This commit is contained in:
Dustin Spicuzza 2023-10-05 02:48:22 -04:00
parent 955214cef4
commit 93bdfee934

View File

@ -21,7 +21,9 @@ def dumpmain() -> None:
)
parser.add_argument("-v", "--verbose", default=False, action="store_true")
parser.add_argument(
"--mode", choices=["json", "pprint", "repr", "brepr"], default="pprint"
"--mode",
choices=["json", "pprint", "repr", "brepr", "pponly"],
default="pprint",
)
parser.add_argument(
"--pcpp", default=False, action="store_true", help="Use pcpp preprocessor"
@ -33,11 +35,17 @@ def dumpmain() -> None:
args = parser.parse_args()
preprocessor = None
if args.pcpp:
if args.pcpp or args.mode == "pponly":
from .preprocessor import make_pcpp_preprocessor
preprocessor = make_pcpp_preprocessor(encoding=args.encoding)
if args.mode == "pponly":
with open(args.header, "r", encoding=args.encoding) as fp:
pp_content = preprocessor(args.header, fp.read())
sys.stdout.write(pp_content)
sys.exit(0)
options = ParserOptions(verbose=args.verbose, preprocessor=preprocessor)
data = parse_file(args.header, encoding=args.encoding, options=options)