pretty printing -- copmlete for xo::ast::GeneralizedExpression
This commit is contained in:
parent
7ddb79fadd
commit
c2dcc84c2e
14 changed files with 572 additions and 292 deletions
|
|
@ -11,56 +11,47 @@
|
|||
|
||||
namespace xo {
|
||||
namespace print {
|
||||
template <typename T>
|
||||
struct ppdetail<std::vector<T>> {
|
||||
static bool print_upto(ppstate * pps, const std::vector<T> & x) {
|
||||
std::uint32_t saved = pps->pos();
|
||||
if (!pps->has_margin())
|
||||
template <typename Vector>
|
||||
struct ppdetail_vector {
|
||||
static bool print_pretty(const ppindentinfo & ppii, const Vector & x) {
|
||||
if (ppii.upto()) {
|
||||
ppii.pps()->write("[");
|
||||
for (size_t i = 0, z = x.size(); i < z; ++i) {
|
||||
if (i > 0)
|
||||
ppii.pps()->write(", ");
|
||||
|
||||
if (!ppii.pps()->print_upto(x[i]))
|
||||
return false;
|
||||
if (!ppii.pps()->has_margin())
|
||||
return false;
|
||||
}
|
||||
ppii.pps()->write("]");
|
||||
|
||||
return true;
|
||||
} else {
|
||||
ppii.pps()->write('[');
|
||||
|
||||
for (size_t i = 0, z = x.size(); i < z; ++i) {
|
||||
if (i == 0)
|
||||
ppii.pps()->indent(std::max(ppii.pps()->indent_width(), 1u) - 1);
|
||||
else
|
||||
ppii.pps()->newline_indent(ppii.ci1());
|
||||
ppii.pps()->pretty(x[i]);
|
||||
|
||||
if (i+1 < z)
|
||||
ppii.pps()->write(',');
|
||||
}
|
||||
|
||||
ppii.pps()->write(" ]");
|
||||
return false;
|
||||
|
||||
pps->write("[");
|
||||
for (size_t i = 0, z = x.size(); i < z; ++i) {
|
||||
if (i > 0)
|
||||
pps->write(", ");
|
||||
|
||||
if (!pps->print_upto(x[i]))
|
||||
return false;
|
||||
if (!pps->has_margin())
|
||||
return false;
|
||||
}
|
||||
pps->write("]");
|
||||
if (!pps->has_margin())
|
||||
return false;
|
||||
|
||||
return pps->scan_no_newline(saved);
|
||||
}
|
||||
|
||||
static void print_pretty(ppstate * pps, const std::vector<T> & x) {
|
||||
std::uint32_t ci0 = pps->lpos();
|
||||
|
||||
pps->write('[');
|
||||
|
||||
std::uint32_t ci1 = ci0 + pps->indent_width();
|
||||
for (size_t i = 0, z = x.size(); i < z; ++i) {
|
||||
pps->newline_indent(ci1);
|
||||
pps->pretty(x[i]);
|
||||
|
||||
if (i+1 < z)
|
||||
pps->write(',');
|
||||
}
|
||||
|
||||
pps->newline_indent(ci0);
|
||||
pps->write(']');
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct ppdetail<const std::vector<T>> {
|
||||
static bool print_upto(ppstate * pps, const std::vector<T> & x) {
|
||||
return ppdetail<std::vector<T>>::print_upto(pps, x);
|
||||
}
|
||||
static void print_pretty(ppstate * pps, const std::vector<T> & x) {
|
||||
ppdetail<std::vector<T>>::print_pretty(pps, x);
|
||||
struct ppdetail<std::vector<T>> {
|
||||
static bool print_pretty(const ppindentinfo & ppii, const std::vector<T> & x) {
|
||||
return ppdetail_vector<std::vector<T>>::print_pretty(ppii, x);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue