Skip to content

Commit ef5c229

Browse files
committed
Initial commit
0 parents  commit ef5c229

37 files changed

+14826
-0
lines changed

Diff for: .github/workflows/dist.yml

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
name: dist
3+
4+
on: [push, pull_request]
5+
6+
jobs:
7+
check:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
- uses: psf/black@stable
12+
13+
# check-doc:
14+
# runs-on: ubuntu-18.04
15+
16+
# steps:
17+
# - uses: actions/checkout@v2
18+
# with:
19+
# submodules: recursive
20+
# fetch-depth: 0
21+
22+
# - uses: actions/setup-python@v2
23+
# with:
24+
# python-version: 3.8
25+
# - name: Sphinx
26+
# run: |
27+
# pip --disable-pip-version-check install -e .
28+
# pip --disable-pip-version-check install -r docs/requirements.txt
29+
# cd docs && make clean html SPHINXOPTS="-W --keep-going"
30+
31+
test:
32+
runs-on: ${{ matrix.os }}
33+
strategy:
34+
matrix:
35+
os: [windows-latest, macos-latest, ubuntu-18.04]
36+
python_version: [3.6, 3.7, 3.8, 3.9]
37+
architecture: [x86, x64]
38+
exclude:
39+
- os: macos-latest
40+
architecture: x86
41+
- os: ubuntu-18.04
42+
architecture: x86
43+
44+
steps:
45+
- uses: actions/checkout@v2
46+
with:
47+
submodules: recursive
48+
fetch-depth: 0
49+
50+
- uses: actions/setup-python@v2
51+
with:
52+
python-version: ${{ matrix.python_version }}
53+
architecture: ${{ matrix.architecture }}
54+
55+
- name: Install build dependencies
56+
run: python -m pip --disable-pip-version-check install wheel
57+
58+
- name: Build wheel
59+
run: python setup.py bdist_wheel
60+
61+
- name: Install test dependencies
62+
run: python -m pip --disable-pip-version-check install pytest
63+
64+
- name: Test wheel
65+
shell: bash
66+
run: |
67+
cd dist
68+
python -m pip --disable-pip-version-check install *.whl
69+
cd ../tests
70+
python -m pytest
71+
72+
publish:
73+
runs-on: ubuntu-latest
74+
needs: [check, check-doc, test]
75+
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
76+
77+
steps:
78+
- uses: actions/checkout@v2
79+
with:
80+
submodules: recursive
81+
fetch-depth: 0
82+
83+
- uses: actions/setup-python@v2
84+
with:
85+
python-version: 3.8
86+
- run: pip --disable-pip-version-check install wheel
87+
88+
- name: Build packages
89+
run: python setup.py sdist bdist_wheel
90+
- name: Publish to PyPI
91+
uses: pypa/gh-action-pypi-publish@master
92+
with:
93+
user: __token__
94+
password: ${{ secrets.PYPI_PASSWORD }}

Diff for: .gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.py[cod]
2+
*.egg-info
3+
/build
4+
/dist
5+
/cxxheaderparser/version.py
6+
/.vscode
7+
8+
.coverage
9+
.pytest_cache

Diff for: LICENSE.txt

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
cxxheaderparser license:
2+
3+
Copyright (c) 2020 Dustin Spicuzza <[email protected]>
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
1. Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
3. Neither the name of the copyright holder nor the names of its contributors
17+
may be used to endorse or promote products derived from this software
18+
without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30+
31+
-----------------------------------------------------------------------------
32+
33+
CppHeaderParser license:
34+
35+
Copyright (C) 2011, Jashua R. Cloutier
36+
All rights reserved.
37+
38+
Redistribution and use in source and binary forms, with or without
39+
modification, are permitted provided that the following conditions
40+
are met:
41+
42+
* Redistributions of source code must retain the above copyright
43+
notice, this list of conditions and the following disclaimer.
44+
45+
* Redistributions in binary form must reproduce the above copyright
46+
notice, this list of conditions and the following disclaimer in
47+
the documentation and/or other materials provided with the
48+
distribution.
49+
50+
* Neither the name of Jashua R. Cloutier nor the names of its
51+
contributors may be used to endorse or promote products derived from
52+
this software without specific prior written permission. Stories,
53+
blog entries etc making reference to this project may mention the
54+
name Jashua R. Cloutier in terms of project originator/creator etc.
55+
56+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
57+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
58+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
59+
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
60+
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
61+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
62+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
63+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
64+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
65+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
66+
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
67+
POSSIBILITY OF SUCH DAMAGE.
68+
69+
-----------------------------------------------------------------------------
70+
71+
PLY license:
72+
73+
Copyright (C) 2001-2020
74+
David M. Beazley (Dabeaz LLC)
75+
All rights reserved.
76+
77+
Latest version: https://github.com/dabeaz/ply
78+
79+
Redistribution and use in source and binary forms, with or without
80+
modification, are permitted provided that the following conditions are
81+
met:
82+
83+
* Redistributions of source code must retain the above copyright notice,
84+
this list of conditions and the following disclaimer.
85+
* Redistributions in binary form must reproduce the above copyright notice,
86+
this list of conditions and the following disclaimer in the documentation
87+
and/or other materials provided with the distribution.
88+
* Neither the name of David Beazley or Dabeaz LLC may be used to
89+
endorse or promote products derived from this software without
90+
specific prior written permission.
91+
92+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
93+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
94+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
95+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
96+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
98+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
99+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
100+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
101+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
102+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
103+
104+
-----------------------------------------------------------------------------

Diff for: README.md

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
cxxheaderparser
2+
===============
3+
4+
**Note**: This is still a work in progress, but should be stable in a few weeks
5+
once I port robotpy-build over to use it
6+
7+
A pure python C++ header parser that parses C++ headers in a mildly naive
8+
manner that allows it to handle many C++ constructs, including many modern
9+
(C++11 and beyond) features.
10+
11+
This is a complete rewrite of the `CppHeaderParser` library. `CppHeaderParser`
12+
is really useful for some tasks, but it's implementation is a truly terrible
13+
ugly hack built on top of other terrible hacks. This rewrite tries to learn
14+
from `CppHeaderParser` and leave its ugly baggage behind.
15+
16+
Goals:
17+
18+
* Parse syntatically valid C++ and provide a useful (and documented!) pure
19+
python API to work with the parsed data
20+
* Process incomplete headers (doesn't need to process includes)
21+
* Provide enough information for binding generators to wrap C++ code
22+
* Handle common C++ features, but it may struggle with obscure or overly
23+
complex things (feel free to make a PR to fix it!)
24+
25+
Non-goals:
26+
27+
* **Does not produce a full AST**, use Clang if you need that
28+
* **Not intended to validate C++**, which means this will not reject all
29+
invalid C++ headers! Use a compiler if you need that
30+
* **No C preprocessor substitution support implemented**. If you are parsing
31+
headers that contain macros, you should preprocess your code using the
32+
excellent pure python preprocessor [pcpp](https://github.com/ned14/pcpp)
33+
or your favorite compiler
34+
* Probably won't be able to parse most IOCCC entries
35+
36+
There are two APIs available:
37+
38+
* A visitor-style interface to build up your own custom data structures
39+
* A simple visitor that stores everything in a giant data structure
40+
41+
Documentation
42+
-------------
43+
44+
TODO: documentation site
45+
46+
Install
47+
-------
48+
49+
Requires Python 3.6+, no non-stdlib dependencies if using Python 3.7+.
50+
51+
TODO: distribute on pip
52+
53+
Usage
54+
-----
55+
56+
To see a dump of the data parsed from a header:
57+
58+
```
59+
# pprint format
60+
python -m cxxheaderparser myheader.h
61+
62+
# JSON format
63+
python -m cxxheaderparser --mode=json myheader.h
64+
65+
# dataclasses repr format
66+
python -m cxxheaderparser --mode=repr myheader.h
67+
68+
# dataclasses repr format (formatted with black)
69+
python -m cxxheaderparser --mode=brepr myheader.h
70+
```
71+
72+
See the documentation for anything more complex.
73+
74+
Bugs
75+
----
76+
77+
This should handle even complex C++ code with few problems, but there are
78+
almost certainly weird edge cases that it doesn't handle. Additionally,
79+
not all C++17/20 constructs are supported yet (but contributions welcome!).
80+
81+
If you find an bug, we encourage you to submit a pull request! New
82+
changes will only be accepted if there are tests to cover the change you
83+
made (and if they don’t break existing tests).
84+
85+
Author
86+
------
87+
88+
cxxheaderparser was created by Dustin Spicuzza
89+
90+
Credit
91+
------
92+
93+
* Partially derived from and inspired by the `CppHeaderParser` project
94+
originally developed by Jashua Cloutier
95+
* An embedded version of PLY is used for lexing tokens
96+
* Portions of the lexer grammar and other ideas were derived from pycparser
97+
* The source code is liberally sprinkled with comments containing C++ parsing
98+
grammar mostly derived from the [Hyperlinked C++ BNF Grammar](https://www.nongnu.org/hcb/)
99+
* cppreference.com has been invaluable for understanding many of the weird
100+
quirks of C++, and some of the unit tests use examples from there
101+
* [Compiler Explorer](godbolt.org) has been invaluable for validating my
102+
understanding of C++ by allowing me to quickly type in quirky C++
103+
constructs to see if they actually compile
104+
105+
License
106+
-------
107+
108+
BSD License

Diff for: cxxheaderparser/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
try:
2+
from .version import __version__
3+
except ImportError:
4+
__version__ = "master"

Diff for: cxxheaderparser/__main__.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from cxxheaderparser.dump import dumpmain
2+
3+
if __name__ == "__main__":
4+
dumpmain()

Diff for: cxxheaderparser/_ply/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)