xo-expression: + GeneralizedExpression pretty-printing [WIP]

This commit is contained in:
Roland Conybeare 2025-07-13 21:20:19 -05:00
commit 0b0d8ffdc0
11 changed files with 204 additions and 1 deletions

View file

@ -101,6 +101,7 @@ namespace xo {
virtual void attach_envs(bp<Environment> p) override;
virtual void display(std::ostream & os) const override;
virtual std::uint32_t pretty_print(ppstate * pps, bool upto) const override;
private:
Apply(TypeDescr apply_valuetype,

View file

@ -76,6 +76,7 @@ namespace xo {
}
virtual void display(std::ostream & os) const override;
virtual std::uint32_t pretty_print(ppstate * pps, bool upto) const override;
protected:
/**

View file

@ -8,7 +8,6 @@
#include "xo/refcnt/Refcounted.hpp"
#include "xo/reflect/TypeDescr.hpp"
#include "exprtype.hpp"
//#include <cstdint>
namespace xo {
namespace ast {
@ -22,6 +21,7 @@ namespace xo {
class GeneralizedExpression : public ref::Refcount {
public:
using TypeDescr = xo::reflect::TypeDescr;
using ppstate = xo::print::ppstate;
public:
GeneralizedExpression(exprtype extype, TypeDescr valuetype)
@ -34,6 +34,8 @@ namespace xo {
virtual void display(std::ostream & os) const = 0;
/** human-readable string representation **/
virtual std::string display_string() const;
/** pretty printing support. See [xo-indentlog/xo/indentlog/pretty.hpp] **/
virtual std::uint32_t pretty_print(ppstate * pps, bool upto) const;
protected:
/** useful when scaffolding expressions in a parser **/

View file

@ -98,6 +98,7 @@ namespace xo {
virtual void attach_envs(bp<Environment> p) override;
virtual void display(std::ostream & os) const override;
virtual std::uint32_t pretty_print(ppstate * pps, bool upto) const override;
protected:
/** create type description for lambda with arguments @p argv

View file

@ -103,6 +103,12 @@ namespace xo {
};
} /*namespace ast*/
#ifndef ppdetail_atomic
namespace print {
PPDETAIL_ATOMIC(xo::ast::LocalEnv);
}
#endif
} /*namespace xo*/

View file

@ -38,6 +38,7 @@ namespace xo {
// ----- from GeneralizedExpression ----
virtual void display(std::ostream & os) const override;
virtual std::uint32_t pretty_print(ppstate * pps, bool upto) const override;
private:
/** sequence of expressions; evaluate in left-to-right order.