xo-reader2 xo-expression2: pprint for DDefineExpr + DVariable
This commit is contained in:
parent
ca2be0172a
commit
480294ae05
21 changed files with 455 additions and 8 deletions
|
|
@ -56,6 +56,8 @@ xo_add_genfacetimpl(
|
|||
OUTPUT_CPP_DIR src/expression2
|
||||
)
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
# note: manual target; generated code committed to git
|
||||
xo_add_genfacetimpl(
|
||||
TARGET xo-expression2-facetimpl-expression-variable
|
||||
|
|
@ -68,6 +70,20 @@ xo_add_genfacetimpl(
|
|||
OUTPUT_CPP_DIR src/expression2
|
||||
)
|
||||
|
||||
# note: manual target; generated code committed to git
|
||||
xo_add_genfacetimpl(
|
||||
TARGET xo-expression2-facetimpl-printable-variable
|
||||
FACET_PKG xo_printable2
|
||||
FACET Printable
|
||||
REPR Variable
|
||||
INPUT idl/IPrintable_DVariable.json5
|
||||
OUTPUT_HPP_DIR include/xo/expression2
|
||||
OUTPUT_IMPL_SUBDIR detail
|
||||
OUTPUT_CPP_DIR src/expression2
|
||||
)
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
# note: manual target; generated code committed to git
|
||||
xo_add_genfacetimpl(
|
||||
TARGET xo-expression2-facetimpl-expression-defineexpr
|
||||
|
|
@ -80,6 +96,18 @@ xo_add_genfacetimpl(
|
|||
OUTPUT_CPP_DIR src/expression2
|
||||
)
|
||||
|
||||
# note: manual target; generated code committed to git
|
||||
xo_add_genfacetimpl(
|
||||
TARGET xo-expression2-facetimpl-printable-defineexpr
|
||||
FACET_PKG xo_printable2
|
||||
FACET Printable
|
||||
REPR DefineExpr
|
||||
INPUT idl/IPrintable_DDefineExpr.json5
|
||||
OUTPUT_HPP_DIR include/xo/expression2
|
||||
OUTPUT_IMPL_SUBDIR detail
|
||||
OUTPUT_CPP_DIR src/expression2
|
||||
)
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
# note: manual target; generated code committed to git
|
||||
|
|
|
|||
13
xo-expression2/idl/IPrintable_DDefineExpr.json5
Normal file
13
xo-expression2/idl/IPrintable_DDefineExpr.json5
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
mode: "implementation",
|
||||
includes: [ "<xo/printable2/Printable.hpp>",
|
||||
"<xo/printable2/detail/IPrintable_Xfer.hpp>" ],
|
||||
local_types: [ ],
|
||||
namespace1: "xo",
|
||||
namespace2: "scm",
|
||||
facet_idl: "idl/Printable.json5",
|
||||
brief: "provide APrintable interface for DDefineExpr",
|
||||
using_doxygen: true,
|
||||
repr: "DDefineExpr",
|
||||
doc: [ "implement APrintable for DDefineExpr" ],
|
||||
}
|
||||
13
xo-expression2/idl/IPrintable_DVariable.json5
Normal file
13
xo-expression2/idl/IPrintable_DVariable.json5
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
mode: "implementation",
|
||||
includes: [ "<xo/printable2/Printable.hpp>",
|
||||
"<xo/printable2/detail/IPrintable_Xfer.hpp>" ],
|
||||
local_types: [ ],
|
||||
namespace1: "xo",
|
||||
namespace2: "scm",
|
||||
facet_idl: "idl/Printable.json5",
|
||||
brief: "provide APrintable interface for DVariable",
|
||||
using_doxygen: true,
|
||||
repr: "DVariable",
|
||||
doc: [ "implement APrintable for DVariable" ],
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@
|
|||
#include "Expression.hpp"
|
||||
#include "DVariable.hpp"
|
||||
#include <xo/alloc2/Allocator.hpp>
|
||||
#include <xo/indentlog/print/pretty.hpp>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
|
@ -21,6 +22,7 @@ namespace xo {
|
|||
**/
|
||||
class DDefineExpr {
|
||||
public:
|
||||
using ppindentinfo = xo::print::ppindentinfo;
|
||||
using AAllocator = xo::mm::AAllocator;
|
||||
using TypeDescr = xo::reflect::TypeDescr;
|
||||
|
||||
|
|
@ -62,6 +64,12 @@ namespace xo {
|
|||
void assign_valuetype(TypeDescr td) noexcept;
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-defineexpr-printable-facet **/
|
||||
///@{
|
||||
|
||||
bool pretty(const ppindentinfo & ppii) const;
|
||||
|
||||
///@}
|
||||
|
||||
private:
|
||||
/** @defgrouop scm-defineexpr-instance-vars **/
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#include "TypeRef.hpp"
|
||||
#include "exprtype.hpp"
|
||||
#include <xo/reflect/TypeDescr.hpp>
|
||||
#include <xo/indentlog/print/pretty.hpp>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
|
@ -19,6 +20,7 @@ namespace xo {
|
|||
**/
|
||||
class DVariable {
|
||||
public:
|
||||
using ppindentinfo = xo::print::ppindentinfo;
|
||||
using AAllocator = xo::mm::AAllocator;
|
||||
using TypeDescr = xo::reflect::TypeDescr;
|
||||
|
||||
|
|
@ -46,7 +48,7 @@ namespace xo {
|
|||
|
||||
void assign_name(const DUniqueString * name) { this->name_ = name; }
|
||||
|
||||
/** @defgroup scm-variable-expression-facet**/
|
||||
/** @defgroup scm-variable-expression-facet **/
|
||||
///@{
|
||||
|
||||
exprtype extype() const noexcept { return exprtype::variable; }
|
||||
|
|
@ -55,6 +57,12 @@ namespace xo {
|
|||
void assign_valuetype(TypeDescr td) noexcept;
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-variable-printable-facet **/
|
||||
///@{
|
||||
|
||||
bool pretty(const ppindentinfo & ppii) const;
|
||||
|
||||
///@}
|
||||
|
||||
private:
|
||||
/** symbol name **/
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ namespace xo {
|
|||
static TypeDescr valuetype(const DVariable & self) noexcept;
|
||||
|
||||
// non-const methods
|
||||
/** assing to valuetype member. Useful when scaffolding expressions **/
|
||||
/** assign to valuetype member. Useful when scaffolding expressions **/
|
||||
static void assign_valuetype(DVariable & self, TypeDescr td) noexcept;
|
||||
///@}
|
||||
};
|
||||
|
|
@ -63,4 +63,4 @@ namespace xo {
|
|||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
/* end */
|
||||
|
|
|
|||
|
|
@ -0,0 +1,62 @@
|
|||
/** @file IPrintable_DDefineExpr.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DDefineExpr.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_repr.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IPrintable_DDefineExpr.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Printable.hpp"
|
||||
#include <xo/printable2/Printable.hpp>
|
||||
#include <xo/printable2/detail/IPrintable_Xfer.hpp>
|
||||
#include "DDefineExpr.hpp"
|
||||
|
||||
namespace xo { namespace scm { class IPrintable_DDefineExpr; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::print::APrintable,
|
||||
xo::scm::DDefineExpr>
|
||||
{
|
||||
using ImplType = xo::print::IPrintable_Xfer
|
||||
<xo::scm::DDefineExpr,
|
||||
xo::scm::IPrintable_DDefineExpr>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class IPrintable_DDefineExpr
|
||||
**/
|
||||
class IPrintable_DDefineExpr {
|
||||
public:
|
||||
/** @defgroup scm-printable-ddefineexpr-type-traits **/
|
||||
///@{
|
||||
using ppindentinfo = xo::print::APrintable::ppindentinfo;
|
||||
using Copaque = xo::print::APrintable::Copaque;
|
||||
using Opaque = xo::print::APrintable::Opaque;
|
||||
///@}
|
||||
/** @defgroup scm-printable-ddefineexpr-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
/** Pretty-printing support for this object.
|
||||
See [xo-indentlog/xo/indentlog/pretty.hpp] **/
|
||||
static bool pretty(const DDefineExpr & self, const ppindentinfo & ppii);
|
||||
|
||||
// non-const methods
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
/** @file IPrintable_DVariable.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DVariable.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_repr.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IPrintable_DVariable.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Printable.hpp"
|
||||
#include <xo/printable2/Printable.hpp>
|
||||
#include <xo/printable2/detail/IPrintable_Xfer.hpp>
|
||||
#include "DVariable.hpp"
|
||||
|
||||
namespace xo { namespace scm { class IPrintable_DVariable; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::print::APrintable,
|
||||
xo::scm::DVariable>
|
||||
{
|
||||
using ImplType = xo::print::IPrintable_Xfer
|
||||
<xo::scm::DVariable,
|
||||
xo::scm::IPrintable_DVariable>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class IPrintable_DVariable
|
||||
**/
|
||||
class IPrintable_DVariable {
|
||||
public:
|
||||
/** @defgroup scm-printable-dvariable-type-traits **/
|
||||
///@{
|
||||
using ppindentinfo = xo::print::APrintable::ppindentinfo;
|
||||
using Copaque = xo::print::APrintable::Copaque;
|
||||
using Opaque = xo::print::APrintable::Opaque;
|
||||
///@}
|
||||
/** @defgroup scm-printable-dvariable-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
/** Pretty-printing support for this object.
|
||||
See [xo-indentlog/xo/indentlog/pretty.hpp] **/
|
||||
static bool pretty(const DVariable & self, const ppindentinfo & ppii);
|
||||
|
||||
// non-const methods
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
|
|
@ -12,8 +12,12 @@ set(SELF_SRCS
|
|||
|
||||
IExpression_Any.cpp
|
||||
IExpression_DConstant.cpp
|
||||
|
||||
IExpression_DVariable.cpp
|
||||
IPrintable_DVariable.cpp
|
||||
|
||||
IExpression_DDefineExpr.cpp
|
||||
IPrintable_DDefineExpr.cpp
|
||||
|
||||
DLocalSymtab.cpp
|
||||
DGlobalSymtab.cpp
|
||||
|
|
|
|||
|
|
@ -4,9 +4,14 @@
|
|||
**/
|
||||
|
||||
#include "DDefineExpr.hpp"
|
||||
#include "detail/IPrintable_DVariable.hpp"
|
||||
#include <xo/printable2/Printable.hpp>
|
||||
#include <xo/facet/FacetRegistry.hpp>
|
||||
#include <xo/indentlog/scope.hpp>
|
||||
|
||||
namespace xo {
|
||||
using xo::print::APrintable;
|
||||
using xo::facet::FacetRegistry;
|
||||
using xo::facet::typeseq;
|
||||
|
||||
namespace scm {
|
||||
|
|
@ -60,6 +65,30 @@ namespace xo {
|
|||
{
|
||||
lhs_var_->assign_valuetype(td);
|
||||
}
|
||||
|
||||
bool
|
||||
DDefineExpr::pretty(const ppindentinfo & ppii) const
|
||||
{
|
||||
auto lhs = obj<APrintable,DVariable>(lhs_var_);
|
||||
auto rhs = FacetRegistry::instance().try_variant<APrintable,
|
||||
AExpression>(rhs_);
|
||||
|
||||
if (rhs_) {
|
||||
assert(rhs);
|
||||
|
||||
return ppii.pps()->pretty_struct
|
||||
(ppii,
|
||||
"DDefineExpr",
|
||||
refrtag("lhs", lhs),
|
||||
refrtag("rhs", rhs));
|
||||
} else {
|
||||
return ppii.pps()->pretty_struct
|
||||
(ppii,
|
||||
"DDefineExpr",
|
||||
refrtag("lhs", lhs));
|
||||
}
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,19 @@ namespace xo {
|
|||
typeref_.resolve(td);
|
||||
}
|
||||
|
||||
bool
|
||||
DVariable::pretty(const ppindentinfo & ppii) const
|
||||
{
|
||||
auto name = (name_
|
||||
? std::string_view(*name_)
|
||||
: std::string_view(""));
|
||||
|
||||
return ppii.pps()->pretty_struct
|
||||
(ppii,
|
||||
"DVariable",
|
||||
refrtag("name", name));
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
|
|
|||
28
xo-expression2/src/expression2/IPrintable_DDefineExpr.cpp
Normal file
28
xo-expression2/src/expression2/IPrintable_DDefineExpr.cpp
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/** @file IPrintable_DDefineExpr.cpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DDefineExpr.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IPrintable_DDefineExpr.json5]
|
||||
**/
|
||||
|
||||
#include "detail/IPrintable_DDefineExpr.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
auto
|
||||
IPrintable_DDefineExpr::pretty(const DDefineExpr & self, const ppindentinfo & ppii) -> bool
|
||||
{
|
||||
return self.pretty(ppii);
|
||||
}
|
||||
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IPrintable_DDefineExpr.cpp */
|
||||
28
xo-expression2/src/expression2/IPrintable_DVariable.cpp
Normal file
28
xo-expression2/src/expression2/IPrintable_DVariable.cpp
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/** @file IPrintable_DVariable.cpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DVariable.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IPrintable_DVariable.json5]
|
||||
**/
|
||||
|
||||
#include "detail/IPrintable_DVariable.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
auto
|
||||
IPrintable_DVariable::pretty(const DVariable & self, const ppindentinfo & ppii) -> bool
|
||||
{
|
||||
return self.pretty(ppii);
|
||||
}
|
||||
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IPrintable_DVariable.cpp */
|
||||
|
|
@ -8,6 +8,10 @@
|
|||
#include <xo/expression2/detail/IGCObject_DUniqueString.hpp>
|
||||
#include <xo/expression2/detail/IPrintable_DUniqueString.hpp>
|
||||
|
||||
#include <xo/expression2/detail/IPrintable_DDefineExpr.hpp>
|
||||
|
||||
#include <xo/expression2/detail/IPrintable_DVariable.hpp>
|
||||
|
||||
#include <xo/gc/detail/AGCObject.hpp>
|
||||
#include <xo/printable2/detail/APrintable.hpp>
|
||||
#include <xo/facet/FacetRegistry.hpp>
|
||||
|
|
@ -28,7 +32,15 @@ namespace xo {
|
|||
FacetRegistry::register_impl<AGCObject, DUniqueString>();
|
||||
FacetRegistry::register_impl<APrintable, DUniqueString>();
|
||||
|
||||
FacetRegistry::register_impl<APrintable, DDefineExpr>();
|
||||
|
||||
FacetRegistry::register_impl<APrintable, DVariable>();
|
||||
|
||||
log && log(xtag("DUniqueString.tseq", typeseq::id<DUniqueString>()));
|
||||
log && log(xtag("DDefineExpr.tseq", typeseq::id<DDefineExpr>()));
|
||||
log && log(xtag("DVariable.tseq", typeseq::id<DVariable>()));
|
||||
|
||||
log && log(xtag("AExpression.tqseq", typeseq::id<AExpression>()));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -6,6 +6,9 @@
|
|||
#include "DDefineSsm.hpp"
|
||||
#include "DExpectSymbolSsm.hpp"
|
||||
#include "ssm/ISyntaxStateMachine_DDefineSsm.hpp"
|
||||
#include "ssm/IPrintable_DDefineSsm.hpp"
|
||||
#include <xo/expression2/detail/IPrintable_DDefineExpr.hpp>
|
||||
#include <xo/printable2/Printable.hpp>
|
||||
|
||||
#ifdef NOT_YET
|
||||
#include "parserstatemachine.hpp"
|
||||
|
|
@ -16,6 +19,7 @@
|
|||
#endif
|
||||
|
||||
namespace xo {
|
||||
using xo::print::APrintable;
|
||||
using xo::facet::with_facet;
|
||||
using xo::facet::typeseq;
|
||||
|
||||
|
|
@ -497,10 +501,13 @@ namespace xo {
|
|||
bool
|
||||
DDefineSsm::pretty(const ppindentinfo & ppii) const
|
||||
{
|
||||
auto expr = with_facet<APrintable>::mkobj(def_expr_.data());
|
||||
|
||||
return ppii.pps()->pretty_struct
|
||||
(ppii,
|
||||
"DDefineSsm",
|
||||
refrtag("defstate", defstate_));
|
||||
refrtag("defstate", defstate_),
|
||||
refrtag("def_expr", expr));
|
||||
}
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
|
|
|||
|
|
@ -5,8 +5,12 @@
|
|||
|
||||
#include "ParserStack.hpp"
|
||||
#include "SyntaxStateMachine.hpp"
|
||||
#include <xo/printable2/Printable.hpp>
|
||||
#include <xo/facet/FacetRegistry.hpp>
|
||||
|
||||
namespace xo {
|
||||
using xo::print::APrintable;
|
||||
using xo::facet::FacetRegistry;
|
||||
using xo::facet::typeseq;
|
||||
|
||||
namespace scm {
|
||||
|
|
@ -41,6 +45,48 @@ namespace xo {
|
|||
return stack->parent();
|
||||
}
|
||||
|
||||
void
|
||||
ParserStack::print(std::ostream & os) const
|
||||
{
|
||||
os << "<ParserStack>";
|
||||
os << xtag("ssm", "*placeholder*");
|
||||
os << xtag("parent", "*placeholder*");
|
||||
os << ">";
|
||||
}
|
||||
|
||||
bool
|
||||
ParserStack::pretty(const ppindentinfo & ppii) const
|
||||
{
|
||||
auto * pps = ppii.pps();
|
||||
|
||||
/* always use multiple lines */
|
||||
|
||||
if (ppii.upto())
|
||||
return false;
|
||||
|
||||
pps->write("<ParserStack");
|
||||
|
||||
const ParserStack * frame = this;
|
||||
std::size_t i_frame = 0;
|
||||
|
||||
while (frame) {
|
||||
char buf[80];
|
||||
snprintf(buf, sizeof(buf), "[%lu]", i_frame);
|
||||
|
||||
auto ssm = FacetRegistry::instance().variant<APrintable,
|
||||
ASyntaxStateMachine> (frame->top());
|
||||
|
||||
pps->newline_pretty_tag(ppii.ci1(), buf, ssm);
|
||||
|
||||
++i_frame;
|
||||
frame = frame->parent_;
|
||||
}
|
||||
|
||||
pps->write(">");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
|
|
|||
|
|
@ -86,6 +86,28 @@ namespace xo {
|
|||
<< xtag("has_stack", (psm_.stack() != nullptr))
|
||||
<< ">" << std::endl;
|
||||
}
|
||||
|
||||
bool
|
||||
SchematikaParser::pretty(const ppindentinfo & ppii) const {
|
||||
auto * pps = ppii.pps();
|
||||
|
||||
if (ppii.upto())
|
||||
return false;
|
||||
|
||||
// TODO: consider printing:
|
||||
// psm.stringtable_
|
||||
// psm.parser_alloc_
|
||||
// psm.parser_alloc_ckp_
|
||||
// psm.expr_alloc_
|
||||
// psm.result_
|
||||
// psm.debug_flag_
|
||||
//
|
||||
|
||||
return pps->pretty_struct
|
||||
(ppii,
|
||||
"SchematikaParser",
|
||||
refrtag("stack", psm_.stack()));
|
||||
}
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
**/
|
||||
|
||||
#include <xo/reader2/SchematikaParser.hpp>
|
||||
#include <xo/reader2/init_reader2.hpp>
|
||||
#include <xo/alloc2/arena/IAllocator_DArena.hpp>
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
|
|
@ -17,6 +18,8 @@ namespace xo {
|
|||
using xo::mm::DArena;
|
||||
using xo::facet::with_facet;
|
||||
|
||||
static InitEvidence s_init = (InitSubsys<S_reader2_tag>::require());
|
||||
|
||||
namespace ut {
|
||||
TEST_CASE("SchematikaParser-ctor", "[reader2][SchematikaParser]")
|
||||
{
|
||||
|
|
@ -92,6 +95,10 @@ namespace xo {
|
|||
// but is still "at toplevel" in the sense of ready for input
|
||||
REQUIRE(parser.has_incomplete_expr() == true);
|
||||
REQUIRE(result.is_incomplete());
|
||||
|
||||
log && log("after def token:");
|
||||
log && log(xtag("parser", &parser));
|
||||
log && log(xtag("result", result));
|
||||
}
|
||||
|
||||
{
|
||||
|
|
@ -100,6 +107,8 @@ namespace xo {
|
|||
REQUIRE(parser.has_incomplete_expr() == true);
|
||||
REQUIRE(result.is_incomplete());
|
||||
|
||||
log && log("after lhs symbol token:");
|
||||
log && log(xtag("parser", &parser));
|
||||
log && log(xtag("result", result));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue