Skip to content

Commit 1392fce

Browse files
committed
Add documentation
1 parent e361d44 commit 1392fce

16 files changed

+339
-39
lines changed

.github/workflows/dist.yml

+16-17
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ jobs:
1010
- uses: actions/checkout@v2
1111
- uses: psf/black@stable
1212

13-
# check-doc:
14-
# runs-on: ubuntu-18.04
13+
check-doc:
14+
runs-on: ubuntu-18.04
1515

16-
# steps:
17-
# - uses: actions/checkout@v2
18-
# with:
19-
# submodules: recursive
20-
# fetch-depth: 0
16+
steps:
17+
- uses: actions/checkout@v2
18+
with:
19+
submodules: recursive
20+
fetch-depth: 0
2121

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"
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"
3030
3131
test:
3232
runs-on: ${{ matrix.os }}
@@ -71,8 +71,7 @@ jobs:
7171
7272
publish:
7373
runs-on: ubuntu-latest
74-
#needs: [check, check-doc, test]
75-
needs: [check, test]
74+
needs: [check, check-doc, test]
7675
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
7776

7877
steps:

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ There are two APIs available:
4141
Documentation
4242
-------------
4343

44-
TODO: documentation site
44+
Documentation can be found at https://cxxheaderparser.readthedocs.io
4545

4646
Install
4747
-------

cxxheaderparser/errors.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import typing
22

3-
if typing.TYPE_CHECKING:
4-
from .lexer import LexToken
3+
from .lexer import LexToken
54

65

76
class CxxParseError(Exception):

cxxheaderparser/lexer.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import typing
55
import sys
66

7-
8-
from .errors import CxxParseError
97
from ._ply import lex
108

119

@@ -340,6 +338,8 @@ def get_doxygen(self) -> typing.Optional[str]:
340338
_discard_types = {"NEWLINE", "COMMENT_SINGLELINE", "COMMENT_MULTILINE"}
341339

342340
def _token_limit_exceeded(self):
341+
from .errors import CxxParseError
342+
343343
raise CxxParseError("no more tokens left in this group")
344344

345345
@contextlib.contextmanager

cxxheaderparser/simple.py

+52-16
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,21 @@
77
cxxheaderparser's unit tests predominantly use the simple API for parsing,
88
so you can expect it to be pretty stable.
99
10+
The :func:`parse_string` and :func:`parse_file` functions are a great place
11+
to start:
12+
13+
.. code-block:: python
14+
15+
from cxxheaderparser.simple import parse_string
16+
17+
content = '''
18+
int x;
19+
'''
20+
21+
parsed_data = parse_string(content)
22+
23+
See below for the contents of the returned :class:`ParsedData`.
24+
1025
"""
1126

1227
import inspect
@@ -46,7 +61,11 @@
4661

4762
@dataclass
4863
class ClassScope:
64+
"""
65+
Contains all data collected for a single C++ class
66+
"""
4967

68+
#: Information about the class declaration is here
5069
class_decl: ClassDecl
5170

5271
#: Nested classes
@@ -64,6 +83,10 @@ class ClassScope:
6483

6584
@dataclass
6685
class NamespaceScope:
86+
"""
87+
Contains all data collected for a single namespace. Content for child
88+
namespaces are found in the ``namespaces`` attribute.
89+
"""
6790

6891
name: str = ""
6992

@@ -108,11 +131,38 @@ class UsingNamespace:
108131

109132
@dataclass
110133
class ParsedData:
134+
"""
135+
Container for information parsed by the :func:`parse_file` and
136+
:func:`parse_string` functions.
111137
138+
.. warning:: Names are not resolved, so items are stored in the scope that
139+
they are found. For example:
140+
141+
.. code-block:: c++
142+
143+
namespace N {
144+
class C;
145+
}
146+
147+
class N::C {
148+
void fn();
149+
};
150+
151+
The 'C' class would be a forward declaration in the 'N' namespace,
152+
but the ClassDecl for 'C' would be stored in the global
153+
namespace instead of the 'N' namespace.
154+
"""
155+
156+
#: Global namespace
112157
namespace: NamespaceScope = field(default_factory=lambda: NamespaceScope())
113158

159+
#: Any ``#define`` preprocessor directives encountered
114160
defines: typing.List[Define] = field(default_factory=list)
161+
162+
#: Any ``#pragma`` directives encountered
115163
pragmas: typing.List[Pragma] = field(default_factory=list)
164+
165+
#: Any ``#include`` directives encountered
116166
includes: typing.List[Include] = field(default_factory=list)
117167

118168

@@ -126,22 +176,8 @@ class SimpleCxxVisitor:
126176
A simple visitor that stores all of the C++ elements passed to it
127177
in an "easy" to use data structure
128178
129-
.. warning:: Names are not resolved, so items are stored in the scope that
130-
they are found. For example:
131-
132-
.. code-block:: c++
133-
134-
namespace N {
135-
class C;
136-
}
137-
138-
class N::C {
139-
void fn();
140-
};
141-
142-
The 'C' class would be a forward declaration in the 'N' namespace,
143-
but the ClassDecl for 'C' would be stored in the global
144-
namespace instead of the 'N' namespace.
179+
You probably don't want to use this directly, use :func:`parse_file`
180+
or :func:`parse_string` instead.
145181
"""
146182

147183
data: ParsedData

cxxheaderparser/types.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ class TemplateSpecialization:
202202
"""
203203
Contains the arguments of a template specialization
204204
205-
.. code-block:: c++s
205+
.. code-block:: c++
206206
207207
Foo<int, Bar...>
208208
~~~~~~~~~~~

docs/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/_build

docs/Makefile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = .
9+
BUILDDIR = _build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/conf.py

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Configuration file for the Sphinx documentation builder.
2+
#
3+
# This file only contains a selection of the most common options. For a full
4+
# list see the documentation:
5+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
6+
7+
# -- Path setup --------------------------------------------------------------
8+
9+
import os
10+
import pkg_resources
11+
12+
# -- Project information -----------------------------------------------------
13+
14+
project = "cxxheaderparser"
15+
copyright = "2020-2021, Dustin Spicuzza"
16+
author = "Dustin Spicuzza"
17+
18+
# The full version, including alpha/beta/rc tags
19+
release = pkg_resources.get_distribution("cxxheaderparser").version
20+
21+
# -- RTD configuration ------------------------------------------------
22+
23+
# on_rtd is whether we are on readthedocs.org, this line of code grabbed from docs.readthedocs.org
24+
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
25+
26+
27+
# -- General configuration ---------------------------------------------------
28+
29+
# Add any Sphinx extension module names here, as strings. They can be
30+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
31+
# ones.
32+
extensions = [
33+
"sphinx.ext.autodoc",
34+
"sphinx_autodoc_typehints",
35+
]
36+
37+
# Add any paths that contain templates here, relative to this directory.
38+
templates_path = ["_templates"]
39+
40+
# List of patterns, relative to source directory, that match files and
41+
# directories to ignore when looking for source files.
42+
# This pattern also affects html_static_path and html_extra_path.
43+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
44+
45+
46+
# -- Options for HTML output -------------------------------------------------
47+
48+
# The theme to use for HTML and HTML Help pages. See the documentation for
49+
# a list of builtin themes.
50+
#
51+
if not on_rtd: # only import and set the theme if we're building docs locally
52+
import sphinx_rtd_theme
53+
54+
html_theme = "sphinx_rtd_theme"
55+
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
56+
else:
57+
html_theme = "default"
58+
59+
# Add any paths that contain custom static files (such as style sheets) here,
60+
# relative to this directory. They are copied after the builtin static files,
61+
# so a file named "default.css" will overwrite the builtin "default.css".
62+
html_static_path = ["_static"]
63+
64+
always_document_param_types = True

docs/custom.rst

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Custom parsing
2+
==============
3+
4+
For many users, the data provided by the simple API is enough. In some advanced
5+
cases you may find it necessary to use this more customizable parsing mechanism.
6+
7+
First, define a visitor that implements the :class:`CxxVisitor` protocol. Then
8+
you can create an instance of it and pass it to the :class:`CxxParser`.
9+
10+
.. code-block:: python
11+
12+
visitor = MyVisitor()
13+
parser = CxxParser(filename, content, visitor)
14+
parser.parse()
15+
16+
# do something with the data collected by the visitor
17+
18+
Your visitor should do something with the data as the various callbacks are
19+
called. See the :class:`SimpleCxxVisitor` for inspiration.
20+
21+
API
22+
---
23+
24+
.. automodule:: cxxheaderparser.parser
25+
:members:
26+
:undoc-members:
27+
28+
.. automodule:: cxxheaderparser.visitor
29+
:members:
30+
:undoc-members:
31+
32+
Parser state
33+
------------
34+
35+
.. automodule:: cxxheaderparser.parserstate
36+
:members:
37+
:undoc-members:

docs/index.rst

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
.. cxxheaderparser documentation master file, created by
2+
sphinx-quickstart on Thu Dec 31 00:46:02 2020.
3+
You can adapt this file completely to your liking, but it should at least
4+
contain the root `toctree` directive.
5+
6+
cxxheaderparser
7+
===============
8+
9+
A pure python C++ header parser that parses C++ headers in a mildly naive
10+
manner that allows it to handle many C++ constructs, including many modern
11+
(C++11 and beyond) features.
12+
13+
.. warning:: cxxheaderparser intentionally does not have a C preprocessor
14+
implementation! If you are parsing code with macros in it, use
15+
a conforming preprocessor like the pure python preprocessor
16+
`pcpp`_ or your favorite C++ compiler.
17+
18+
.. _pcpp: https://github.com/ned14/pcpp
19+
20+
.. toctree::
21+
:maxdepth: 2
22+
:caption: Contents:
23+
24+
tools
25+
simple
26+
custom
27+
types
28+
29+
30+
31+
Indices and tables
32+
==================
33+
34+
* :ref:`genindex`
35+
* :ref:`modindex`
36+
* :ref:`search`
37+

0 commit comments

Comments
 (0)