xo-reader2: + pretty-printing for ParserResult + use in utest
This commit is contained in:
parent
0a7e8468ae
commit
3bdbb61eba
3 changed files with 121 additions and 1 deletions
|
|
@ -4,9 +4,28 @@
|
|||
**/
|
||||
|
||||
#include "ParserResult.hpp"
|
||||
#include <xo/printable2/Printable.hpp>
|
||||
#include <xo/facet/FacetRegistry.hpp>
|
||||
|
||||
namespace xo {
|
||||
using xo::print::APrintable;
|
||||
using xo::facet::FacetRegistry;
|
||||
|
||||
namespace scm {
|
||||
|
||||
const char *
|
||||
parser_result_type_descr(parser_result_type x)
|
||||
{
|
||||
switch (x) {
|
||||
case parser_result_type::none: return "none";
|
||||
case parser_result_type::expression: return "expression";
|
||||
case parser_result_type::error: return "error";
|
||||
case parser_result_type::N: break;
|
||||
}
|
||||
|
||||
return "parser_result_type?";
|
||||
}
|
||||
|
||||
ParserResult::ParserResult(parser_result_type type,
|
||||
obj<AExpression> expr,
|
||||
std::string_view error_src_fn,
|
||||
|
|
@ -26,6 +45,53 @@ namespace xo {
|
|||
ssm_name,
|
||||
errmsg);
|
||||
}
|
||||
|
||||
void
|
||||
ParserResult::print(std::ostream & os) const
|
||||
{
|
||||
os << "<ParserResult" ;
|
||||
os << xtag("type", result_type_);
|
||||
os << xtag("expr", result_expr_);
|
||||
os << xtag("src_fn", error_src_fn_);
|
||||
if (error_description_)
|
||||
os << xtag("error", error_description_);
|
||||
os << ">";
|
||||
}
|
||||
|
||||
bool
|
||||
ParserResult::pretty(const ppindentinfo & ppii) const
|
||||
{
|
||||
switch (result_type_) {
|
||||
case parser_result_type::none:
|
||||
return ppii.pps()->pretty_struct
|
||||
(ppii,
|
||||
"ParserResult",
|
||||
refrtag("type", result_type_));
|
||||
case parser_result_type::expression:
|
||||
{
|
||||
auto expr = FacetRegistry::instance().variant<APrintable,AExpression>(result_expr_);
|
||||
|
||||
return ppii.pps()->pretty_struct
|
||||
(ppii,
|
||||
"ParserResult",
|
||||
refrtag("type", result_type_),
|
||||
refrtag("expr", expr));
|
||||
}
|
||||
break;
|
||||
case parser_result_type::error:
|
||||
return ppii.pps()->pretty_struct
|
||||
(ppii,
|
||||
"ParserResult",
|
||||
refrtag("type", result_type_),
|
||||
refrtag("src_fn", error_src_fn_),
|
||||
refrtag("error", error_description_));
|
||||
case parser_result_type::N:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue