xo-reader: + pretty-printing support [WIP]

This commit is contained in:
Roland Conybeare 2025-07-13 21:21:20 -05:00
commit 495d8cd44a
18 changed files with 84 additions and 21 deletions

View file

@ -12,7 +12,7 @@ xo_cxx_toplevel_options3()
# ----------------------------------------------------------------
# c++ settings
set(PROJECT_CXX_FLAGS "")
set(PROJECT_CXX_FLAGS "-ftemplate-backtrace-limit=0")
#set(PROJECT_CXX_FLAGS "-fconcepts-diagnostics-depth=2")
add_definitions(${PROJECT_CXX_FLAGS})
@ -28,3 +28,5 @@ xo_export_cmake_config(${PROJECT_NAME} ${PROJECT_VERSION} ${PROJECT_NAME}Targets
# must come after them
#
add_subdirectory(docs)
# end CMakeLists.txt

View file

@ -10,22 +10,22 @@ standalone build
+------------------------------------------------->| .build/docs/Doxyfile |
| +----------------------+
| ^
| (cmake |
| (cmake) |
| /------------/
| |
| +---------------------------------------+ +-----------------+
+---->| doxygen |--->| .build/docs/dox |
| | $PREFIX/share/xo-macros/Doxyfile.in | | +- html/ |
| +---------------------------------------+ | +- xml/ |
| +-----------------+
| |
| /------------/
| |
| v
| +---------------------------------------+ +--------------------+
\---->| sphinx |--->| .build/docs/sphinx |
| +- conf.py | | +- html/ |
| +- _static/ | +--------------------+
| +---------------------------------------+ +-----------------+
+---->| doxygen |--------->| .build/docs/dox |
| | $PREFIX/share/xo-macros/Doxyfile.in | (doxygen)| +- html/ |
| +---------------------------------------+ | +- xml/ |
| +-----------------+
| |
| |(sphinx)
| |
| v
| +---------------------------------------+ +--------------------+
\---->| sphinx |------->| .build/docs/sphinx |
| +- conf.py | | +- html/ |
| +- _static/ | +--------------------+
| +- *.rst |
+---------------------------------------+

View file

@ -49,8 +49,8 @@ Minimal Dependencies
.. _xo-subsys source: https://github.com/rconybea/subsys
.. _xo-cmake source: https://github.com/rconybea/xo-cmake
Installing from source
----------------------
Building from source
--------------------
Install scripts for XO libraries depend on helper scripts installed from `xo-cmake`.
@ -135,12 +135,11 @@ CMake Support
To use built-in cmake support, when using ``xo-reader`` from another project:
Make sure ``PREFIX/lib/cmake`` is searched by cmake (if necessary, include it in ``CMAKE_PREFIX_PATH``)
Make sure ``PREFIX/lib/cmake`` is searched by cmake (for example include it in ``CMAKE_PREFIX_PATH``)
Add to your ``CMakeLists.txt``:
.. code-block:: cmake
FindPackage(xo_reader CONFIG REQUIRED)
target_link_libraries(mytarget INTERFACE xo_reader)

View file

@ -61,6 +61,10 @@ int
main() {
using namespace replxx;
using namespace xo::scm;
using xo::ast::Expression;
using xo::print::ppconfig;
using xo::print::ppstate_standalone;
using xo::rp;
using namespace std;
using span_type = xo::scm::span<const char>;
@ -92,7 +96,10 @@ main() {
auto [expr, consumed, psz] = rdr.read_expr(input, eof);
if (expr) {
cout << expr << endl;
ppconfig ppc;
ppstate_standalone pps(&cout, 0, &ppc);
pps.prettyn(expr);
}
input = input.after_prefix(consumed);
@ -103,7 +110,10 @@ main() {
auto [expr, _1, _2] = rdr.read_expr(input, true /*eof*/);
if (expr) {
cout << expr << endl;
ppconfig ppc;
ppstate_standalone pps(&cout, 0, &ppc);
pps.prettyn<rp<Expression>>(rp<Expression>(expr));
}
rx.history_save("repl_history.txt");

View file

@ -8,6 +8,7 @@
#include "xo/expression/DefineExpr.hpp"
#include "xo/expression/ConvertExpr.hpp"
#include "exprstate.hpp"
#include "xo/indentlog/print/ppdetail_atomic.hpp"
//#include <cstdint>
namespace xo {
@ -117,6 +118,12 @@ namespace xo {
rp<ConvertExprAccess> cvt_expr_;
};
} /*namespace scm*/
#ifndef ppdetail_atomic
namespace print {
PPDETAIL_ATOMIC(xo::scm::defexprstatetype);
}
#endif
} /*namespace xo*/

View file

@ -214,6 +214,13 @@ namespace xo {
return os;
};
} /*namespace scm*/
#ifndef ppdetail_atomic
namespace print {
PPDETAIL_ATOMIC(xo::scm::exprstatetype);
PPDETAIL_ATOMIC(xo::scm::exprstate);
} /*namespace print*/
#endif
} /*namespace xo*/
/** end exprstate.hpp **/

View file

@ -7,6 +7,7 @@
#include "exprstate.hpp"
#include "xo/indentlog/print/vector.hpp"
#include "xo/indentlog/print/pretty.hpp"
namespace xo {
namespace scm {
@ -64,6 +65,21 @@ namespace xo {
return os;
}
} /*namespace scm*/
#ifndef ppdetail_atomic
namespace print {
template <>
struct ppdetail<xo::scm::exprstatestack *> {
static bool print_upto(ppstate * pps, const xo::scm::exprstatestack * x) {
return ppdetail_atomic<const xo::scm::exprstatestack *>::print_upto(pps, x);
}
static void print_pretty(ppstate * pps, const xo::scm::exprstatestack * x) {
ppdetail_atomic<const xo::scm::exprstatestack *>::print_pretty(pps, x);
}
};
}
#endif
} /*namespace xo*/

View file

@ -87,6 +87,12 @@ namespace xo {
return os;
}
} /*namespace scm*/
#ifndef ppdetail_atomic
namespace print {
PPDETAIL_ATOMIC(xo::scm::parserstatemachine);
}
#endif
} /*namespace xo*/

View file

@ -132,6 +132,12 @@ namespace xo {
rp<Expression> rhs_;
};
} /*namespace scm*/
#ifndef ppdetail_atomic
namespace print {
PPDETAIL_ATOMIC(xo::scm::optype);
}
#endif
} /*namespace xo*/

View file

@ -7,6 +7,7 @@
#include "parser.hpp"
#include "xo/expression/Expression.hpp"
#include "xo/expression/pretty_expression.hpp"
#include "xo/tokenizer/tokenizer.hpp"
namespace xo {

View file

@ -6,6 +6,7 @@
#include "expect_symbol_xs.hpp"
#include "expect_expr_xs.hpp"
#include "expect_type_xs.hpp"
#include "pretty_expression.hpp"
namespace xo {
namespace scm {

View file

@ -13,6 +13,7 @@
#include "progress_xs.hpp"
#include "xo/expression/Lambda.hpp"
#include "xo/expression/Constant.hpp"
#include "xo/expression/pretty_expression.hpp"
namespace xo {
using xo::ast::Constant;

View file

@ -3,9 +3,11 @@
#include "exprstate.hpp"
#include "exprstatestack.hpp"
#include "parserstatemachine.hpp"
#include "pretty_expression.hpp"
//#include "formal_arg.hpp"
#include "xo/expression/Variable.hpp"
#include "xo/indentlog/print/vector.hpp"
#include "xo/indentlog/print/pretty_vector.hpp"
#include <stdexcept>
//#include "define_xs.hpp"
//#include "progress_xs.hpp"

View file

@ -5,6 +5,7 @@
#include "exprstatestack.hpp"
#include "progress_xs.hpp"
#include "expect_expr_xs.hpp"
#include "xo/expression/pretty_expression.hpp"
namespace xo {
namespace scm {

View file

@ -7,6 +7,7 @@
#include "parserstatemachine.hpp"
#include "define_xs.hpp"
#include "exprseq_xs.hpp"
#include "pretty_expression.hpp"
#include "xo/expression/DefineExpr.hpp"
#include "xo/expression/Constant.hpp"
#include "xo/expression/ConvertExpr.hpp"

View file

@ -5,6 +5,7 @@
#include "parserstatemachine.hpp"
#include "exprstatestack.hpp"
#include "xo/expression/pretty_expression.hpp"
namespace xo {
using xo::ast::LocalEnv;

View file

@ -6,6 +6,7 @@
#include "parserstatemachine.hpp"
#include "xo/expression/AssignExpr.hpp"
#include "xo/expression/Apply.hpp"
#include "xo/expression/pretty_expression.hpp"
namespace xo {
using xo::ast::Expression;

View file

@ -6,6 +6,7 @@
#include "let1_xs.hpp"
#include "xo/expression/DefineExpr.hpp"
#include "xo/expression/Sequence.hpp"
#include "xo/expression/pretty_expression.hpp"
namespace xo {
using xo::ast::DefineExpr;