Vcsn
2.4
Be Rational
|
Pretty-printer for rational expressions. More...
#include <fwd.hh>
Classes | |
struct | visit_tuple |
Public Types | |
using | expressionset_t = ExpSet |
using | super_t = typename expressionset_t::const_visitor |
using | self_t = printer |
using | context_t = context_t_of< expressionset_t > |
using | identities_t = typename expressionset_t::identities_t |
using | labelset_t = labelset_t_of< context_t > |
using | label_t = label_t_of< context_t > |
using | weight_t = weight_t_of< context_t > |
using | node_t = typename super_t::node_t |
Actual node, without indirection. More... | |
using | value_t = typename node_t::value_t |
A shared_ptr to node_t. More... | |
using | inner_t = typename super_t::inner_t |
template<type_t Type> | |
using | unary_t = typename super_t::template unary_t< Type > |
template<type_t Type> | |
using | variadic_t = typename super_t::template variadic_t< Type > |
using | leaf_t = typename super_t::leaf_t |
Public Member Functions | |
printer (const expressionset_t &rs, std::ostream &out) | |
A printer. More... | |
void | format (format fmt) |
Set output format. More... | |
std::ostream & | operator() (const value_t &v) |
Entry point: print v. More... | |
void | print_child (const node_t &child, precedence_t parent) |
Print a child node, given its parent's precedence. More... | |
template<type_t Type> | |
auto | print_ (const unary_t< Type > &v, const char *op) -> void |
template<type_t Type> | |
auto | print_ (const variadic_t< Type > &n, const char *op) -> void |
Static Public Member Functions | |
static constexpr const char * | me () |
Name of this algorithm, for error messages. More... | |
Private Types | |
using | tuple_t = typename super_t::tuple_t |
Private Member Functions | |
std::ostream & | print_ (const node_t &v) |
Print v. More... | |
void | print_ (const weight_t &w) |
Print a weight. More... | |
VCSN_RAT_VISIT (atom, v) | |
VCSN_RAT_VISIT (compose, v) | |
VCSN_RAT_VISIT (complement, v) | |
VCSN_RAT_VISIT (conjunction, v) | |
VCSN_RAT_VISIT (infiltrate, v) | |
VCSN_RAT_VISIT (ldivide, v) | |
VCSN_RAT_VISIT (lweight, v) | |
VCSN_RAT_VISIT (one, v) | |
VCSN_RAT_VISIT (mul, v) | |
VCSN_RAT_VISIT (rweight, v) | |
VCSN_RAT_VISIT (shuffle, v) | |
VCSN_RAT_VISIT (star, v) | |
VCSN_RAT_VISIT (add, v) | |
VCSN_RAT_VISIT (transposition, v) | |
VCSN_RAT_VISIT (zero, v) | |
void | visit (const tuple_t &v, std::true_type) override |
Specific handling to using exponents as syntactic sugar. More... | |
bool | is_letter_ (const node_t &v) const |
Whether v is an atom whose label is a letter. More... | |
bool | is_word_ (const node_t &v) const |
Whether v is an atom whose label is not a letter. More... | |
bool | is_braced_ (const node_t &v) const |
Whether is naturally braced. More... | |
precedence_t | precedence_ (const node_t &v) const |
The precedence of v (to decide when to print parens). More... | |
void | print_child_ (const node_t &child, const node_t &parent) |
Print a child node, given its parent. More... | |
template<rat::exp::type_t Type> | |
void | print_ (const unary_t< Type > &n, const char *op) |
Print a unary node. More... | |
template<rat::exp::type_t Type> | |
void | print_ (const variadic_t< Type > &n, const char *op) |
Print an n-ary node. More... | |
ATTRIBUTE_PURE bool | shows_left_weight_ (const node_t &n) |
Whether the left weight shows. More... | |
template<typename Iterator > | |
auto | letter_range (Iterator i, Iterator end) const -> boost::iterator_range< Iterator > |
Return the longest range of expressions that are letters, in strictly increasing order. More... | |
template<typename LS = labelset_t> | |
auto | print_add_ (const add_t &v) -> std::enable_if_t< detail::has_generators_mem_fn< LS > |
Print a sum, when the labelset has a genset() function. More... | |
for (auto i=std::begin(v), end=std::end(v);i!=end;) | |
template<typename LS = labelset_t> | |
auto | print_add_ (const add_t &v) -> std::enable_if_t<!detail::has_generators_mem_fn< LS > |
Print a sum, when the labelset does not have a genset() function. More... | |
Private Attributes | |
void | |
std::ostream & | out_ |
Output stream. More... | |
class format | fmt_ |
Output format. More... | |
const expressionset_t & | rs_ |
The expressionset. More... | |
const bool | debug_ = !!getenv("VCSN_PARENS") |
Whether to be overly verbose. More... | |
const char * | lgroup_ = nullptr |
Left and right boundaries (typically braces for LaTeX). More... | |
const char * | rgroup_ = nullptr |
const char * | langle_ = nullptr |
Left and right angle brackets for weights. More... | |
const char * | rangle_ = nullptr |
const char * | lparen_ = nullptr |
Left and right parentheses. More... | |
const char * | rparen_ = nullptr |
const char * | lexponent_ = nullptr |
Left and right braces for exponents. More... | |
const char * | rexponent_ = nullptr |
const char * | lweight_ = nullptr |
External product. More... | |
const char * | rweight_ = nullptr |
const char * | ldivide_ = nullptr |
Left-quotient. More... | |
const char * | star_ = nullptr |
The expression operators. More... | |
const char * | complement_ = nullptr |
const char * | compose_ = nullptr |
Operator for composition: @ . More... | |
const char * | transposition_ = nullptr |
const char * | conjunction_ = nullptr |
const char * | infiltrate_ = nullptr |
const char * | shuffle_ = nullptr |
const char * | product_ = nullptr |
const char * | add_ = nullptr |
const char * | tuple_left = nullptr |
Left tuple delimiter. More... | |
const char * | tuple_middle = nullptr |
Tuple tape separator. More... | |
const char * | tuple_right = nullptr |
Right tuple delimiter. More... | |
const char * | zero_ = nullptr |
The constants. More... | |
const char * | one_ = nullptr |
unsigned int | exponent_threshold_ = 0 |
Pretty-printer for rational expressions.
using vcsn::rat::printer< ExpSet >::context_t = context_t_of<expressionset_t> |
Definition at line 74 of file printer.hh.
using vcsn::rat::printer< ExpSet >::expressionset_t = ExpSet |
Definition at line 70 of file printer.hh.
using vcsn::rat::printer< ExpSet >::identities_t = typename expressionset_t::identities_t |
Definition at line 75 of file printer.hh.
using vcsn::rat::printer< ExpSet >::inner_t = typename super_t::inner_t |
Definition at line 84 of file printer.hh.
using vcsn::rat::printer< ExpSet >::label_t = label_t_of<context_t> |
Definition at line 77 of file printer.hh.
using vcsn::rat::printer< ExpSet >::labelset_t = labelset_t_of<context_t> |
Definition at line 76 of file printer.hh.
using vcsn::rat::printer< ExpSet >::leaf_t = typename super_t::leaf_t |
Definition at line 89 of file printer.hh.
using vcsn::rat::printer< ExpSet >::node_t = typename super_t::node_t |
Actual node, without indirection.
Definition at line 81 of file printer.hh.
using vcsn::rat::printer< ExpSet >::self_t = printer |
Definition at line 72 of file printer.hh.
using vcsn::rat::printer< ExpSet >::super_t = typename expressionset_t::const_visitor |
Definition at line 71 of file printer.hh.
|
private |
Definition at line 138 of file printer.hh.
using vcsn::rat::printer< ExpSet >::unary_t = typename super_t::template unary_t<Type> |
Definition at line 86 of file printer.hh.
using vcsn::rat::printer< ExpSet >::value_t = typename node_t::value_t |
A shared_ptr to node_t.
Definition at line 83 of file printer.hh.
using vcsn::rat::printer< ExpSet >::variadic_t = typename super_t::template variadic_t<Type> |
Definition at line 88 of file printer.hh.
using vcsn::rat::printer< ExpSet >::weight_t = weight_t_of<context_t> |
Definition at line 78 of file printer.hh.
vcsn::rat::printer< ExpSet >::printer | ( | const expressionset_t & | rs, |
std::ostream & | out | ||
) |
A printer.
Definition at line 40 of file printer.hxx.
|
inlineprivate |
Definition at line 280 of file printer.hh.
References vcsn::rat::printer< ExpSet >::add_, vcsn::rat::printer< ExpSet >::fmt_, vcsn::rat::printer< ExpSet >::letter_range(), vcsn::rat::printer< ExpSet >::out_, vcsn::rat::printer< ExpSet >::print_child_(), vcsn::detail::print_label_class(), vcsn::rat::printer< ExpSet >::rs_, and vcsn::v.
auto vcsn::rat::printer< ExpSet >::format | ( | format | fmt | ) |
Set output format.
Definition at line 69 of file printer.hxx.
References vcsn::dyn::detail::conjunction_(), vcsn::dyn::detail::infiltrate_(), vcsn::format::latex, vcsn::dyn::detail::shuffle_(), vcsn::format::text, and vcsn::format::utf8.
|
inlineprivate |
Whether is naturally braced.
This is the case of sums of letters printed as range: we want to print [a-z]*
, not ([a-z])*
.
Definition at line 221 of file printer.hh.
References vcsn::rat::printer< ExpSet >::letter_range().
|
inlineprivate |
Whether v is an atom whose label is a letter.
Used to know if we can print a sum of expressions as a letter range.
Definition at line 189 of file printer.hh.
References vcsn::rat::printer< ExpSet >::rs_, vcsn::v, and vcsn::rat::atom< Context >::value().
Referenced by vcsn::rat::printer< ExpSet >::letter_range().
|
inlineprivate |
Whether v is an atom whose label is not a letter.
Used to decide when to issues parens via precedence ("letter" and "word" have different precedence). Actually, this routine checks whether this node is a self-delimited atom. Letters are of course self-delimited, so we don't add parens to "a" in "a*". Tuples printed as labels are not, so we need to add parens to "a|x" in "(a|x)*".
Note that 1-tape tuple are self-delimited (well, if what they contain is self-delimited). But then visually there is no difference between a lal and a lat<lal>. I think there should be one, so let's keep it this way. Likewise for 0-tape tuples.
Definition at line 209 of file printer.hh.
References vcsn::rat::printer< ExpSet >::rs_, vcsn::v, and vcsn::rat::atom< Context >::value().
|
inlineprivate |
Return the longest range of expressions that are letters, in strictly increasing order.
Definition at line 257 of file printer.hh.
References vcsn::detail::initial_sorted_range(), vcsn::rat::printer< ExpSet >::is_letter_(), and vcsn::rat::printer< ExpSet >::rs_.
Referenced by vcsn::rat::printer< ExpSet >::for(), and vcsn::rat::printer< ExpSet >::is_braced_().
|
inlinestatic |
Name of this algorithm, for error messages.
Definition at line 92 of file printer.hh.
|
inline |
Entry point: print v.
Definition at line 102 of file printer.hh.
References vcsn::rat::printer< ExpSet >::print_().
|
private |
The precedence of v (to decide when to print parens).
Definition at line 163 of file printer.hxx.
References CASE, vcsn::v, and vcsn::rat::word.
|
private |
Print v.
Definition at line 52 of file printer.hxx.
References vcsn::address(), vcsn::decendl(), vcsn::incendl(), vcsn::format::latex, vcsn::print(), and vcsn::v.
Referenced by vcsn::rat::printer< ExpSet >::operator()(), and vcsn::rat::printer< ExpSet >::VCSN_RAT_VISIT().
|
inlineprivate |
Print a weight.
Definition at line 117 of file printer.hh.
References vcsn::rat::printer< ExpSet >::fmt_, vcsn::format::for_weights(), vcsn::rat::printer< ExpSet >::out_, and vcsn::rat::printer< ExpSet >::rs_.
|
private |
Print a unary node.
|
private |
Print an n-ary node.
auto vcsn::rat::printer< ExpSet >::print_ | ( | const unary_t< Type > & | v, |
const char * | op | ||
) | -> void |
Definition at line 311 of file printer.hxx.
References vcsn::v.
auto vcsn::rat::printer< ExpSet >::print_ | ( | const variadic_t< Type > & | n, |
const char * | op | ||
) | -> void |
Definition at line 321 of file printer.hxx.
|
inlineprivate |
Print a sum, when the labelset has a genset() function.
Definition at line 275 of file printer.hh.
Referenced by vcsn::rat::printer< ExpSet >::VCSN_RAT_VISIT().
|
inlineprivate |
Print a sum, when the labelset does not have a genset() function.
Definition at line 311 of file printer.hh.
auto vcsn::rat::printer< ExpSet >::print_child | ( | const node_t & | child, |
precedence_t | parent | ||
) |
Print a child node, given its parent's precedence.
Public function, to support tuples.
Definition at line 281 of file printer.hxx.
References vcsn::detail::print_(), and vcsn::rat::unary.
|
private |
Print a child node, given its parent.
Definition at line 302 of file printer.hxx.
Referenced by vcsn::rat::printer< ExpSet >::for().
|
inlineprivate |
Whether the left weight shows.
Definition at line 249 of file printer.hh.
References vcsn::rat::lweight.
|
private |
|
inlineprivate |
Definition at line 123 of file printer.hh.
References vcsn::rat::printer< ExpSet >::compose_, vcsn::rat::printer< ExpSet >::print_(), and vcsn::v.
|
inlineprivate |
Definition at line 124 of file printer.hh.
References vcsn::rat::printer< ExpSet >::complement_, vcsn::rat::printer< ExpSet >::print_(), and vcsn::v.
|
inlineprivate |
Definition at line 125 of file printer.hh.
References vcsn::rat::printer< ExpSet >::conjunction_, vcsn::rat::printer< ExpSet >::print_(), and vcsn::v.
|
inlineprivate |
Definition at line 126 of file printer.hh.
References vcsn::rat::printer< ExpSet >::infiltrate_, vcsn::rat::printer< ExpSet >::print_(), and vcsn::v.
|
inlineprivate |
Definition at line 127 of file printer.hh.
References vcsn::rat::printer< ExpSet >::ldivide_, vcsn::rat::printer< ExpSet >::print_(), and vcsn::v.
|
private |
|
private |
|
private |
|
private |
|
inlineprivate |
Definition at line 132 of file printer.hh.
References vcsn::rat::printer< ExpSet >::print_(), vcsn::rat::printer< ExpSet >::shuffle_, and vcsn::v.
|
inlineprivate |
Definition at line 133 of file printer.hh.
References vcsn::rat::printer< ExpSet >::print_(), vcsn::rat::printer< ExpSet >::star_, and vcsn::v.
|
inlineprivate |
Definition at line 134 of file printer.hh.
References vcsn::rat::printer< ExpSet >::print_add_(), and vcsn::v.
|
inlineprivate |
Definition at line 135 of file printer.hh.
References vcsn::rat::printer< ExpSet >::print_(), vcsn::rat::printer< ExpSet >::transposition_, and vcsn::v.
|
private |
|
inlineoverrideprivate |
Specific handling to using exponents as syntactic sugar.
Definition at line 177 of file printer.hh.
References vcsn::v.
|
private |
Definition at line 356 of file printer.hh.
Referenced by vcsn::rat::printer< ExpSet >::for().
|
private |
Definition at line 348 of file printer.hh.
Referenced by vcsn::rat::printer< ExpSet >::VCSN_RAT_VISIT().
|
private |
Operator for composition: @
.
Definition at line 350 of file printer.hh.
Referenced by vcsn::rat::printer< ExpSet >::VCSN_RAT_VISIT().
|
private |
Definition at line 352 of file printer.hh.
Referenced by vcsn::rat::printer< ExpSet >::VCSN_RAT_VISIT().
|
private |
Whether to be overly verbose.
Definition at line 324 of file printer.hh.
|
private |
Definition at line 368 of file printer.hh.
|
private |
Output format.
Definition at line 320 of file printer.hh.
Referenced by vcsn::rat::printer< ExpSet >::for(), vcsn::rat::printer< ExpSet >::print_(), and vcsn::rat::printer< ExpSet >::visit_tuple< Dummy >::print_().
|
private |
Definition at line 353 of file printer.hh.
Referenced by vcsn::rat::printer< ExpSet >::VCSN_RAT_VISIT().
|
private |
Left and right angle brackets for weights.
Definition at line 333 of file printer.hh.
|
private |
Left-quotient.
Definition at line 345 of file printer.hh.
Referenced by vcsn::rat::printer< ExpSet >::VCSN_RAT_VISIT().
|
private |
Left and right braces for exponents.
Definition at line 339 of file printer.hh.
|
private |
Left and right boundaries (typically braces for LaTeX).
Used to group operand of unary operators, e.g. "a" -> "a", "a*" -> "{a}^{*}" and "a**" -> "{{a}^{*}}^{*}".
Definition at line 330 of file printer.hh.
|
private |
Left and right parentheses.
Definition at line 336 of file printer.hh.
|
private |
External product.
Definition at line 342 of file printer.hh.
|
private |
Definition at line 367 of file printer.hh.
|
private |
Output stream.
Definition at line 318 of file printer.hh.
Referenced by vcsn::rat::printer< ExpSet >::for(), vcsn::rat::printer< ExpSet >::visit_tuple< Dummy >::operator()(), vcsn::rat::printer< ExpSet >::print_(), and vcsn::rat::printer< ExpSet >::visit_tuple< Dummy >::print_().
|
private |
Definition at line 355 of file printer.hh.
|
private |
Definition at line 334 of file printer.hh.
|
private |
Definition at line 340 of file printer.hh.
|
private |
Definition at line 331 of file printer.hh.
|
private |
Definition at line 337 of file printer.hh.
|
private |
The expressionset.
Definition at line 322 of file printer.hh.
Referenced by vcsn::rat::printer< ExpSet >::for(), vcsn::rat::printer< ExpSet >::is_letter_(), vcsn::rat::printer< ExpSet >::is_word_(), vcsn::rat::printer< ExpSet >::letter_range(), vcsn::rat::printer< ExpSet >::print_(), and vcsn::rat::printer< ExpSet >::visit_tuple< Dummy >::print_().
|
private |
Definition at line 343 of file printer.hh.
|
private |
Definition at line 354 of file printer.hh.
Referenced by vcsn::rat::printer< ExpSet >::VCSN_RAT_VISIT().
|
private |
The expression operators.
Definition at line 347 of file printer.hh.
Referenced by vcsn::rat::printer< ExpSet >::VCSN_RAT_VISIT().
|
private |
Definition at line 351 of file printer.hh.
Referenced by vcsn::rat::printer< ExpSet >::VCSN_RAT_VISIT().
|
private |
Left tuple delimiter.
Definition at line 359 of file printer.hh.
Referenced by vcsn::rat::printer< ExpSet >::visit_tuple< Dummy >::operator()().
|
private |
Tuple tape separator.
Definition at line 361 of file printer.hh.
Referenced by vcsn::rat::printer< ExpSet >::visit_tuple< Dummy >::print_().
|
private |
Right tuple delimiter.
Definition at line 363 of file printer.hh.
Referenced by vcsn::rat::printer< ExpSet >::visit_tuple< Dummy >::operator()().
|
private |
Definition at line 277 of file printer.hh.
Referenced by vcsn::rat::printer< ExpSet >::visit_tuple< Dummy >::print_().
|
private |
The constants.
Definition at line 366 of file printer.hh.