pretty printing -- copmlete for xo::ast::GeneralizedExpression
This commit is contained in:
parent
adc0ca287e
commit
c0587aa4fb
14 changed files with 206 additions and 29 deletions
|
|
@ -1,4 +1,4 @@
|
|||
# parser/CMakeLists.txt
|
||||
# reader/CMakeLists.txt
|
||||
|
||||
set(SELF_LIB xo_reader)
|
||||
set(SELF_SRCS
|
||||
|
|
@ -19,7 +19,9 @@ set(SELF_SRCS
|
|||
expect_type_xs.cpp
|
||||
lambda_xs.cpp
|
||||
let1_xs.cpp
|
||||
envframestack.cpp)
|
||||
envframestack.cpp
|
||||
pretty_parserstatemachine.cpp
|
||||
)
|
||||
|
||||
xo_add_shared_library4(${SELF_LIB} ${PROJECT_NAME}Targets ${PROJECT_VERSION} 1 ${SELF_SRCS})
|
||||
xo_dependency(${SELF_LIB} xo_expression)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
*/
|
||||
|
||||
#include "envframestack.hpp"
|
||||
#include "pretty_envframestack.hpp"
|
||||
#include "pretty_localenv.hpp"
|
||||
|
||||
namespace xo {
|
||||
using xo::ast::LocalEnv;
|
||||
|
|
@ -92,6 +94,45 @@ namespace xo {
|
|||
|
||||
os << ">" << std::endl;
|
||||
}
|
||||
|
||||
bool
|
||||
envframestack::pretty_print(const ppindentinfo & ppii) const
|
||||
{
|
||||
ppstate * pps = ppii.pps();
|
||||
|
||||
if (ppii.upto()) {
|
||||
if (stack_.size() > 1)
|
||||
return false;
|
||||
|
||||
if (!pps->print_upto("<envframestack"))
|
||||
return false;
|
||||
|
||||
if (!pps->print_upto_tag("size", stack_.size()))
|
||||
return false;
|
||||
|
||||
if ((stack_.size() > 0)
|
||||
&& !pps->print_upto_tag("[0]", stack_[0]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
pps->write(">");
|
||||
|
||||
return true;
|
||||
} else {
|
||||
pps->write("<envframestack");
|
||||
|
||||
pps->newline_pretty_tag(ppii.ci1(), "size", stack_.size());
|
||||
|
||||
for (std::size_t i = 0, z = stack_.size(); i < z; ++i) {
|
||||
std::string i_str = tostr("[", z-i-1, "]");
|
||||
pps->newline_pretty_tag(ppii.ci1(), i_str, stack_[i]);
|
||||
}
|
||||
pps->write(">");
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#include "exprstate.hpp"
|
||||
#include "exprstatestack.hpp"
|
||||
#include "parserstatemachine.hpp"
|
||||
#include "pretty_parserstatemachine.hpp"
|
||||
#include "pretty_expression.hpp"
|
||||
//#include "formal_arg.hpp"
|
||||
#include "xo/expression/Variable.hpp"
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
*/
|
||||
|
||||
#include "exprstatestack.hpp"
|
||||
#include <cstdint>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
|
@ -65,6 +66,48 @@ namespace xo {
|
|||
|
||||
os << ">" << std::endl;
|
||||
}
|
||||
|
||||
bool
|
||||
exprstatestack::pretty_print(const ppindentinfo & ppii) const
|
||||
{
|
||||
ppstate * pps = ppii.pps();
|
||||
|
||||
if (ppii.upto()) {
|
||||
if (stack_.size() > 1)
|
||||
return false;
|
||||
|
||||
if (!pps->print_upto("<exprstatestack"))
|
||||
return false;
|
||||
|
||||
if (!pps->print_upto_tag("size", stack_.size()))
|
||||
return false;
|
||||
|
||||
/** always multiple lines if more than one element in stack **/
|
||||
if ((stack_.size() > 0)
|
||||
&& !pps->print_upto_tag("[0]", *stack_[0].get()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
pps->write(">");
|
||||
|
||||
return true;
|
||||
} else {
|
||||
pps->write("<exprstatestack");
|
||||
|
||||
pps->newline_pretty_tag(ppii.ci1(), "size", stack_.size());
|
||||
|
||||
for (std::size_t i = 0, z = stack_.size(); i < z; ++i) {
|
||||
std::string i_str = tostr("[", z-i-1, "]");
|
||||
|
||||
pps->newline_pretty_tag(ppii.ci1(), i_str, *stack_[i].get());
|
||||
}
|
||||
|
||||
pps->write(">");
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@
|
|||
|
||||
#include "parserstatemachine.hpp"
|
||||
#include "exprstatestack.hpp"
|
||||
#include "pretty_parserstatemachine.hpp"
|
||||
#include "pretty_envframestack.hpp"
|
||||
#include "pretty_localenv.hpp"
|
||||
#include "xo/expression/pretty_expression.hpp"
|
||||
|
||||
namespace xo {
|
||||
|
|
|
|||
44
src/reader/pretty_parserstatemachine.cpp
Normal file
44
src/reader/pretty_parserstatemachine.cpp
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/* file pretty_parserstatemachine.cpp
|
||||
*
|
||||
* author: Roland Conybeare, Jul 2025
|
||||
*/
|
||||
|
||||
#include "pretty_parserstatemachine.hpp"
|
||||
#include "pretty_exprstatestack.hpp"
|
||||
#include "pretty_envframestack.hpp"
|
||||
#include "exprstatestack.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace print {
|
||||
bool
|
||||
ppdetail<xo::scm::parserstatemachine>::print_pretty(const ppindentinfo & ppii, const xo::scm::parserstatemachine & x)
|
||||
{
|
||||
ppstate * pps = ppii.pps();
|
||||
|
||||
if (ppii.upto()) {
|
||||
if (!pps->print_upto("<psm"))
|
||||
return false;
|
||||
|
||||
if (!pps->print_upto_tag("stack", x.p_stack_))
|
||||
return false;
|
||||
|
||||
if (!pps->print_upto_tag("env_stack", x.p_env_stack_))
|
||||
return false;
|
||||
|
||||
if (!pps->print_upto_tag("emit_expr", (void*)x.p_emit_expr_))
|
||||
return false;
|
||||
|
||||
return pps->print_upto(">");
|
||||
} else {
|
||||
pps->write("<psm");
|
||||
pps->newline_pretty_tag(ppii.ci1(), "stack", x.p_stack_);
|
||||
pps->newline_pretty_tag(ppii.ci1(), "env_stack", x.p_env_stack_);
|
||||
pps->newline_pretty_tag(ppii.ci1(), "emit_expr", (void*)x.p_emit_expr_);
|
||||
pps->write(">");
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
} /*namespace print*/
|
||||
} /*namespace xo*/
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
#include "exprstatestack.hpp"
|
||||
#include "expect_expr_xs.hpp"
|
||||
#include "parserstatemachine.hpp"
|
||||
#include "pretty_exprstatestack.hpp"
|
||||
#include "xo/expression/AssignExpr.hpp"
|
||||
#include "xo/expression/Apply.hpp"
|
||||
#include "xo/expression/pretty_expression.hpp"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue