diff --git a/CMakeLists.txt b/CMakeLists.txt index 7748dc4f..0fb90c0c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,9 +19,12 @@ add_definitions(${PROJECT_CXX_FLAGS}) # ---------------------------------------------------------------- add_subdirectory(src/reader) +add_subdirectory(examples) add_subdirectory(utest) +xo_export_cmake_config(${PROJECT_NAME} ${PROJECT_VERSION} ${PROJECT_NAME}Targets) # ---------------------------------------------------------------- -# provide find_package() support - -xo_export_cmake_config(${PROJECT_NAME} ${PROJECT_VERSION} ${PROJECT_NAME}Targets) +# docs targets depends on other library/utest/exec targets, +# must come after them +# +add_subdirectory(docs) diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt new file mode 100644 index 00000000..9e5aca53 --- /dev/null +++ b/docs/CMakeLists.txt @@ -0,0 +1,7 @@ +# xo-reader/docs/CMakeLists.txt + +xo_doxygen_collect_deps() +xo_docdir_doxygen_config() +xo_docdir_sphinx_config( + index.rst +) diff --git a/docs/README b/docs/README new file mode 100644 index 00000000..ea8a9a25 --- /dev/null +++ b/docs/README @@ -0,0 +1,41 @@ +standalone build + + +-----------------------------------------------+ + | cmake | + | CMakeLists.txt | + | $PREFIX/share/cmake/xo_macros/xo_cxx.cmake | + +-----------------------------------------------+ + | + | +----------------------+ + +------------------------------------------------->| .build/docs/Doxyfile | + | +----------------------+ + | ^ + | (cmake | + | /------------/ + | | + | +---------------------------------------+ +-----------------+ + +---->| doxygen |--->| .build/docs/dox | + | | $PREFIX/share/xo-macros/Doxyfile.in | | +- html/ | + | +---------------------------------------+ | +- xml/ | + | +-----------------+ + | | + | /------------/ + | | + | v + | +---------------------------------------+ +--------------------+ + \---->| sphinx |--->| .build/docs/sphinx | + | +- conf.py | | +- html/ | + | +- _static/ | +--------------------+ + | +- *.rst | + +---------------------------------------+ + +umbrella build relies on top-level cmake macros + +files + + README this file + CMakeLists.txt build entry point + conf.py sphinx config + _static static files for sphinx + + index.rst toplevel sphinx document; entry point diff --git a/docs/_static/README b/docs/_static/README new file mode 100644 index 00000000..8230095c --- /dev/null +++ b/docs/_static/README @@ -0,0 +1 @@ +add any static {.html, .js, ..} files for sphinx to pickup here \ No newline at end of file diff --git a/docs/_static/img/favicon.ico b/docs/_static/img/favicon.ico new file mode 100644 index 00000000..15da2145 Binary files /dev/null and b/docs/_static/img/favicon.ico differ diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 00000000..a598d229 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,39 @@ +# Configuration file for the Sphinx documentation builder. +# +# For the full list of built-in configuration values, see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Project information ----------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information + +project = 'xo reader documentation' +copyright = '2024-2025, Roland Conybeare' +author = 'Roland Conybeare' + +# -- General configuration --------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration + +#extensions = [] +extensions = [ "breathe", + "sphinx.ext.mathjax", # inline math + "sphinx.ext.autodoc", # generate info from docstrings + "sphinxcontrib.ditaa", # diagrams-through-ascii-art + "sphinxcontrib.plantuml" # text -> uml diagrams + ] + +# note: breathe requires doxygen xml output -> must have GENERATE_XML = YES in Doxyfile.in +# match project name in Doxyfile.in +breathe_default_project = "xodoxxml" + +templates_path = ['_templates'] +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] + +pygments_style = 'sphinx' + +# -- Options for HTML output ------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output + +#html_theme = 'alabaster' +html_theme = 'sphinx_rtd_theme' +html_static_path = ['_static'] +html_favicon = '_static/img/favicon.ico' diff --git a/docs/example.rst b/docs/example.rst new file mode 100644 index 00000000..5ceddc4a --- /dev/null +++ b/docs/example.rst @@ -0,0 +1,45 @@ +.. _examples: + +.. toctree:: + :maxdepth: 2 + +Examples +======== + +See ``xo-reader/examples`` for built examples + +.. code-block:: cpp + :linenos: + + #include "xo/reader/reader.h" + + int + main() { + using namespace xo::scm; + using namespace std; + + reader rdr; + rdr.begin_translation_unit(); + + bool eof = false; + while (!eof) { + auto input = ins.read_some(); + + eof = ins.eof(); + + for (auto rem = input; !rem.empty();) { + // res: (parsed-expr, used) + auto [expr, rem2] = rdr.read_expr(rem, eof); + + if (expr) { + cout << expr << endl; + } + + rem = rem.suffix_after(rem2); + } + } + + if (rdr.has_prefix()) { + cout << "error: unparsed input after expression" << endl; + } + } diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 00000000..2c6a1b96 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,12 @@ +.. xo-reader documentation master file. + +xo-reader documentation +======================= + +xo-reader provides a parser for the Schematika language. + +.. toctree:: + :maxdepth: 2 + :caption: xo-reader contents + + example