Add documentation

This commit is contained in:
Dustin Spicuzza
2020-12-31 01:55:29 -05:00
parent e361d4443a
commit 1392fceeb5
16 changed files with 342 additions and 42 deletions

1
docs/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/_build

20
docs/Makefile Normal file
View File

@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

64
docs/conf.py Normal file
View File

@@ -0,0 +1,64 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Path setup --------------------------------------------------------------
import os
import pkg_resources
# -- Project information -----------------------------------------------------
project = "cxxheaderparser"
copyright = "2020-2021, Dustin Spicuzza"
author = "Dustin Spicuzza"
# The full version, including alpha/beta/rc tags
release = pkg_resources.get_distribution("cxxheaderparser").version
# -- RTD configuration ------------------------------------------------
# on_rtd is whether we are on readthedocs.org, this line of code grabbed from docs.readthedocs.org
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
# -- General configuration ---------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
"sphinx.ext.autodoc",
"sphinx_autodoc_typehints",
]
# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
if not on_rtd: # only import and set the theme if we're building docs locally
import sphinx_rtd_theme
html_theme = "sphinx_rtd_theme"
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
else:
html_theme = "default"
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ["_static"]
always_document_param_types = True

37
docs/custom.rst Normal file
View File

@@ -0,0 +1,37 @@
Custom parsing
==============
For many users, the data provided by the simple API is enough. In some advanced
cases you may find it necessary to use this more customizable parsing mechanism.
First, define a visitor that implements the :class:`CxxVisitor` protocol. Then
you can create an instance of it and pass it to the :class:`CxxParser`.
.. code-block:: python
visitor = MyVisitor()
parser = CxxParser(filename, content, visitor)
parser.parse()
# do something with the data collected by the visitor
Your visitor should do something with the data as the various callbacks are
called. See the :class:`SimpleCxxVisitor` for inspiration.
API
---
.. automodule:: cxxheaderparser.parser
:members:
:undoc-members:
.. automodule:: cxxheaderparser.visitor
:members:
:undoc-members:
Parser state
------------
.. automodule:: cxxheaderparser.parserstate
:members:
:undoc-members:

37
docs/index.rst Normal file
View File

@@ -0,0 +1,37 @@
.. cxxheaderparser documentation master file, created by
sphinx-quickstart on Thu Dec 31 00:46:02 2020.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
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.
.. warning:: cxxheaderparser intentionally does not have a C preprocessor
implementation! If you are parsing code with macros in it, use
a conforming preprocessor like the pure python preprocessor
`pcpp`_ or your favorite C++ compiler.
.. _pcpp: https://github.com/ned14/pcpp
.. toctree::
:maxdepth: 2
:caption: Contents:
tools
simple
custom
types
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

35
docs/make.bat Normal file
View File

@@ -0,0 +1,35 @@
@ECHO OFF
pushd %~dp0
REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build
if "%1" == "" goto help
%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end
:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
:end
popd

3
docs/requirements.txt Normal file
View File

@@ -0,0 +1,3 @@
sphinx >= 3.0
sphinx-rtd-theme
sphinx-autodoc-typehints

12
docs/simple.rst Normal file
View File

@@ -0,0 +1,12 @@
.. _simple:
Simple API
==========
.. automodule:: cxxheaderparser.simple
:members:
:undoc-members:
.. automodule:: cxxheaderparser.options
:members:
:undoc-members:

41
docs/tools.rst Normal file
View File

@@ -0,0 +1,41 @@
Tools
=====
There are a variety of command line tools provided by the cxxheaderparser
project.
dump tool
---------
Dump data from a header to stdout
.. code-block:: sh
# 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
Anything more than that and you should use the python API, start with the
:ref:`simple API <simple>` first.
test generator
--------------
To generate a unit test for cxxheaderparser:
* Put the C++ header content in a file
* Run the following:
.. code-block:: sh
python -m cxxheaderparser.gentest FILENAME.h TESTNAME
You can copy/paste the stdout to one of the test files in the tests directory.

16
docs/types.rst Normal file
View File

@@ -0,0 +1,16 @@
Types
=====
parser types
------------
.. automodule:: cxxheaderparser.types
:members:
:undoc-members:
exceptions
----------
.. automodule:: cxxheaderparser.errors
:members:
:undoc-members: