xo-reader2 xo-expression2: pprint for DDefineExpr + DVariable

This commit is contained in:
Roland Conybeare 2026-01-20 15:06:58 -05:00
commit 480294ae05
21 changed files with 455 additions and 8 deletions

View file

@ -8,6 +8,7 @@
#include "SyntaxStateMachine.hpp"
#include <xo/arena/DArena.hpp>
#include <xo/facet/obj.hpp>
#include <xo/indentlog/print/pretty.hpp>
namespace xo {
namespace scm {
@ -21,6 +22,7 @@ namespace xo {
class ParserStack {
public:
using DArena = xo::mm::DArena;
using ppindentinfo = xo::print::ppindentinfo;
public:
ParserStack(DArena::Checkpoint ckp,
@ -42,6 +44,11 @@ namespace xo {
obj<ASyntaxStateMachine> top() const noexcept { return ssm_; }
ParserStack * parent() const noexcept { return parent_; }
/** regular printing **/
void print(std::ostream & os) const;
/** pretty-printer support **/
bool pretty(const ppindentinfo & ppii) const;
private:
/** stack pointer: top of stack just before this instance created **/
DArena::Checkpoint ckp_;
@ -51,7 +58,32 @@ namespace xo {
ParserStack * parent_ = nullptr;
};
inline std::ostream & operator<< (std::ostream & os, const ParserStack * x) {
if (x) {
x->print(os);
} else {
os << "nullptr";
}
return os;
}
} /*namespace scm*/
namespace print {
/** pretty printer in <xo/indentlog/print/pretty.hpp> relies on this specialization
* to handle ParserResult instances
**/
template <>
struct ppdetail<xo::scm::ParserStack*> {
static inline bool print_pretty(const ppindentinfo & ppii, const xo::scm::ParserStack * p) {
if (p)
return p->pretty(ppii);
else
return ppii.pps()->print_upto("nullptr");
}
};
}
} /*namespace xo*/
/* end ParserStack.hpp */

View file

@ -19,7 +19,8 @@ namespace xo {
//
class ASyntaxStateMachine;
// note: load-bearing to forward-declare ParserStack,
// note: it's load-bearing here to forward-declare ParserStack,
// see ParserStack.hpp for impl
// because ASyntaxStateMachine.hpp includes ParserStateMachine.hpp;
// before obj<SyntaxStateMachine> is defined.
class ParserStack;

View file

@ -153,9 +153,10 @@ namespace xo {
**/
class SchematikaParser {
public:
using token_type = Token;
using ArenaConfig = xo::mm::ArenaConfig;
using AAllocator = xo::mm::AAllocator;
using token_type = Token;
using ppindentinfo = xo::print::ppindentinfo;
public:
/** create parser in initial state;
@ -216,6 +217,8 @@ namespace xo {
/** print human-readable representation on stream @p os **/
void print(std::ostream & os) const;
/** pretty-printer support **/
bool pretty(const ppindentinfo & ppii) const;
private:
/** state machine **/
@ -227,12 +230,31 @@ namespace xo {
inline std::ostream &
operator<< (std::ostream & os,
const SchematikaParser & x) {
x.print(os);
const SchematikaParser * x) {
if (x) {
x->print(os);
} else {
os << "nullptr";
}
return os;
}
} /*namespace scm*/
namespace print {
/** pretty printer in <xo/indentlog/print/pretty.hpp> relies on this specialization
* to handle ParserResult instances
**/
template <>
struct ppdetail<xo::scm::SchematikaParser*> {
static inline bool print_pretty(const ppindentinfo & ppii, const xo::scm::SchematikaParser* p) {
if (p)
return p->pretty(ppii);
else
return ppii.pps()->print_upto("nullptr");
}
};
}
} /*namespace xo*/
/* end SchematikaParser.hpp */