Package: cxxheaderparser
cxxheaderparserA pure python C++ header parser that parses C++ headers in a mildly naive
manner that allows it to handle many C++ constructs, including many modern
(C++11 and beyond) features.This is a complete rewrite of theCppHeaderParserlibrary.CppHeaderParseris really useful for some tasks, but it's implementation is a truly terrible
ugly hack built on top of other terrible hacks. This rewrite tries to learn
fromCppHeaderParserand leave its ugly baggage behind.Goals:Parse syntatically valid C++ and provide a useful (and documented!) pure
python API to work with the parsed dataProcess incomplete headers (doesn't need to process includes)Provide enough information for binding generators to wrap C++ codeHandle common C++ features, but it may struggle with obscure or overly
complex things (feel free to make a PR to fix it!)Non-goals:Does not produce a full AST, use Clang if you need thatNot intended to validate C++, which means this will not reject all
invalid C++ headers! Use a compiler if you need thatNo C preprocessor substitution support implemented. If you are parsing
headers that contain macros, you should preprocess your code using the
excellent pure python preprocessorpcppor your favorite compilerSeecxxheaderparser.preprocessorfor how to useProbably won't be able to parse most IOCCC entriesThere are two APIs available:A visitor-style interface to build up your own custom data structuresA simple visitor that stores everything in a giant data structureLive DemoA pyodide-powered interactive demo is athttps://robotpy.github.io/cxxheaderparser/DocumentationDocumentation can be found athttps://cxxheaderparser.readthedocs.ioInstallRequires Python 3.6+, no non-stdlib dependencies if using Python 3.7+.pip install cxxheaderparserUsageTo see a dump of the data parsed from a header:# pprint format
python -m cxxheaderparser myheader.h

# JSON format
python -m cxxheaderparser --mode=json myheader.h

# dataclasses repr format
python -m cxxheaderparser --mode=repr myheader.h

# dataclasses repr format (formatted with black)
python -m cxxheaderparser --mode=brepr myheader.hSee the documentation for anything more complex.BugsThis should handle even complex C++ code with few problems, but there are
almost certainly weird edge cases that it doesn't handle. Additionally,
not all C++17/20 constructs are supported yet (but contributions welcome!).If you find an bug, we encourage you to submit a pull request! New
changes will only be accepted if there are tests to cover the change you
made (and if they don’t break existing tests).Authorcxxheaderparser was created by Dustin SpicuzzaCreditPartially derived from and inspired by theCppHeaderParserproject
originally developed by Jashua CloutierAn embedded version of PLY is used for lexing tokensPortions of the lexer grammar and other ideas were derived from pycparserThe source code is liberally sprinkled with comments containing C++ parsing
grammar mostly derived from theHyperlinked C++ BNF Grammarcppreference.com has been invaluable for understanding many of the weird
quirks of C++, and some of the unit tests use examples from thereCompiler Explorerhas been invaluable for validating my
understanding of C++ by allowing me to quickly type in quirky C++
constructs to see if they actually compileLicenseBSD License