cxxheaderparser
===============
A 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 the `CppHeaderParser` library. `CppHeaderParser`
is 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
from `CppHeaderParser` and leave its ugly baggage behind.
Goals:
* Parse syntatically valid C++ and provide a useful (and documented!) pure
python API to work with the parsed data
* Process incomplete headers (doesn't need to process includes)
* Provide enough information for binding generators to wrap C++ code
* Handle 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 that
* **Not intended to validate C++**, which means this will not reject all
invalid C++ headers! Use a compiler if you need that
* **No C preprocessor substitution support implemented**. If you are parsing
headers that contain macros, you should preprocess your code using the
excellent pure python preprocessor [pcpp](https://github.com/ned14/pcpp)
or your favorite compiler
* See `cxxheaderparser.preprocessor` for how to use
* Probably won't be able to parse most IOCCC entries
There are two APIs available:
* A visitor-style interface to build up your own custom data structures
* A simple visitor that stores everything in a giant data structure
Live Demo
---------
A pyodide-powered interactive demo is at https://robotpy.github.io/cxxheaderparser/
Documentation
-------------
Documentation can be found at https://cxxheaderparser.readthedocs.io
Install
-------
Requires Python 3.6+, no non-stdlib dependencies if using Python 3.7+.
```
pip install cxxheaderparser
```
Usage
-----
To 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.h
```
See the documentation for anything more complex.
Bugs
----
This 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).
Author
------
cxxheaderparser was created by Dustin Spicuzza
Credit
------
* Partially derived from and inspired by the `CppHeaderParser` project
originally developed by Jashua Cloutier
* An embedded version of PLY is used for lexing tokens
* Portions of the lexer grammar and other ideas were derived from pycparser
* The source code is liberally sprinkled with comments containing C++ parsing
grammar mostly derived from the [Hyperlinked C++ BNF Grammar](https://www.nongnu.org/hcb/)
* cppreference.com has been invaluable for understanding many of the weird
quirks of C++, and some of the unit tests use examples from there
* [Compiler Explorer](godbolt.org) has been invaluable for validating my
understanding of C++ by allowing me to quickly type in quirky C++
constructs to see if they actually compile
License
-------
BSD License
Raw data
{
"_id": null,
"home_page": "https://github.com/robotpy/cxxheaderparser",
"name": "cxxheaderparser",
"maintainer": "RobotPy Development Team",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "robotpy@googlegroups.com",
"keywords": "c++ header parser ply",
"author": "Dustin Spicuzza",
"author_email": "dustin@virtualroadside.com",
"download_url": "https://files.pythonhosted.org/packages/7b/4e/ffbbf1d192e27835359eac21af1e8aebb3a9edfdcb7fe14ece25c14e7d59/cxxheaderparser-1.4.1.tar.gz",
"platform": "Platform Independent",
"description": "cxxheaderparser\n===============\n\nA pure python C++ header parser that parses C++ headers in a mildly naive\nmanner that allows it to handle many C++ constructs, including many modern\n(C++11 and beyond) features.\n\nThis is a complete rewrite of the `CppHeaderParser` library. `CppHeaderParser`\nis really useful for some tasks, but it's implementation is a truly terrible\nugly hack built on top of other terrible hacks. This rewrite tries to learn\nfrom `CppHeaderParser` and leave its ugly baggage behind.\n\nGoals:\n\n* Parse syntatically valid C++ and provide a useful (and documented!) pure\n python API to work with the parsed data\n* Process incomplete headers (doesn't need to process includes)\n* Provide enough information for binding generators to wrap C++ code\n* Handle common C++ features, but it may struggle with obscure or overly\n complex things (feel free to make a PR to fix it!)\n\nNon-goals:\n\n* **Does not produce a full AST**, use Clang if you need that\n* **Not intended to validate C++**, which means this will not reject all\n invalid C++ headers! Use a compiler if you need that\n* **No C preprocessor substitution support implemented**. If you are parsing\n headers that contain macros, you should preprocess your code using the\n excellent pure python preprocessor [pcpp](https://github.com/ned14/pcpp)\n or your favorite compiler\n * See `cxxheaderparser.preprocessor` for how to use\n* Probably won't be able to parse most IOCCC entries\n\nThere are two APIs available:\n\n* A visitor-style interface to build up your own custom data structures \n* A simple visitor that stores everything in a giant data structure\n\nLive Demo\n---------\n\nA pyodide-powered interactive demo is at https://robotpy.github.io/cxxheaderparser/\n\nDocumentation\n-------------\n\nDocumentation can be found at https://cxxheaderparser.readthedocs.io\n\nInstall\n-------\n\nRequires Python 3.6+, no non-stdlib dependencies if using Python 3.7+.\n\n```\npip install cxxheaderparser\n```\n\nUsage\n-----\n\nTo see a dump of the data parsed from a header:\n\n```\n# pprint format\npython -m cxxheaderparser myheader.h\n\n# JSON format\npython -m cxxheaderparser --mode=json myheader.h\n\n# dataclasses repr format\npython -m cxxheaderparser --mode=repr myheader.h\n\n# dataclasses repr format (formatted with black)\npython -m cxxheaderparser --mode=brepr myheader.h\n```\n\nSee the documentation for anything more complex.\n\nBugs\n----\n\nThis should handle even complex C++ code with few problems, but there are\nalmost certainly weird edge cases that it doesn't handle. Additionally,\nnot all C++17/20 constructs are supported yet (but contributions welcome!).\n\nIf you find an bug, we encourage you to submit a pull request! New\nchanges will only be accepted if there are tests to cover the change you\nmade (and if they don\u2019t break existing tests).\n\nAuthor\n------\n\ncxxheaderparser was created by Dustin Spicuzza\n\nCredit\n------\n\n* Partially derived from and inspired by the `CppHeaderParser` project\n originally developed by Jashua Cloutier\n* An embedded version of PLY is used for lexing tokens\n* Portions of the lexer grammar and other ideas were derived from pycparser\n* The source code is liberally sprinkled with comments containing C++ parsing\n grammar mostly derived from the [Hyperlinked C++ BNF Grammar](https://www.nongnu.org/hcb/)\n* cppreference.com has been invaluable for understanding many of the weird\n quirks of C++, and some of the unit tests use examples from there\n* [Compiler Explorer](godbolt.org) has been invaluable for validating my \n understanding of C++ by allowing me to quickly type in quirky C++\n constructs to see if they actually compile\n\nLicense\n-------\n\nBSD License\n",
"bugtrack_url": null,
"license": "BSD",
"summary": "Parse C++ header files and generate a data structure representing the class",
"version": "1.4.1",
"project_urls": {
"Homepage": "https://github.com/robotpy/cxxheaderparser"
},
"split_keywords": [
"c++",
"header",
"parser",
"ply"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "62e60823c5d98adda565f92c00d3dccfda31fbc98ebba41aeeaababc2e3fc0d8",
"md5": "11530da73bddb6f61879fdaeab04e1da",
"sha256": "a75b78e598b168cefb9cdbcddb0ed3d868110d82319a37ff595792f4303e7eb1"
},
"downloads": -1,
"filename": "cxxheaderparser-1.4.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "11530da73bddb6f61879fdaeab04e1da",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 58196,
"upload_time": "2024-10-26T05:43:10",
"upload_time_iso_8601": "2024-10-26T05:43:10.247825Z",
"url": "https://files.pythonhosted.org/packages/62/e6/0823c5d98adda565f92c00d3dccfda31fbc98ebba41aeeaababc2e3fc0d8/cxxheaderparser-1.4.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "7b4effbbf1d192e27835359eac21af1e8aebb3a9edfdcb7fe14ece25c14e7d59",
"md5": "0fab70b2e67587f869ade363c371713d",
"sha256": "77f95679f42b376b09fc33a36c4b701ea0d2e8b0060b07ca514d4e090c0396ce"
},
"downloads": -1,
"filename": "cxxheaderparser-1.4.1.tar.gz",
"has_sig": false,
"md5_digest": "0fab70b2e67587f869ade363c371713d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 91809,
"upload_time": "2024-10-26T05:43:11",
"upload_time_iso_8601": "2024-10-26T05:43:11.332086Z",
"url": "https://files.pythonhosted.org/packages/7b/4e/ffbbf1d192e27835359eac21af1e8aebb3a9edfdcb7fe14ece25c14e7d59/cxxheaderparser-1.4.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-26 05:43:11",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "robotpy",
"github_project": "cxxheaderparser",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "cxxheaderparser"
}