refactor(*): use + for concatenating format objects

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2014-08-24 09:35:25 -07:00
parent 7cb2ca62f4
commit fbf13994d8
12 changed files with 30 additions and 35 deletions

View file

@ -109,7 +109,7 @@ environment check_cmd(parser & p) {
formatter const & fmt = reg.get_formatter();
options opts = p.ios().get_options();
unsigned indent = get_pp_indent(opts);
format r = group(format{fmt(e), space(), colon(), nest(indent, compose(line(), fmt(type)))});
format r = group(fmt(e) + space() + colon() + nest(indent, line() + fmt(type)));
reg << mk_pair(r, opts) << endl;
return p.env();
}

View file

@ -607,7 +607,7 @@ public:
expr new_m = instantiate_meta(m, tmp);
expr new_type = type_checker(_env).infer(new_m).first;
proof_state ps(goals(goal(new_m, new_type)), substitution(), name_generator("dontcare"));
return format({format("failed to synthesize placeholder"), line(), ps.pp(fmt)});
return format("failed to synthesize placeholder") + line() + ps.pp(fmt);
});
}

View file

@ -172,7 +172,7 @@ auto pretty_fn::pp_sort(expr const & e) -> result {
if (m_env.impredicative() && e == Prop) {
return mk_result(format("Prop"));
} else if (m_universes) {
return mk_result(group(format({format("Type.{"), nest(6, pp_level(sort_level(e))), format("}")})));
return mk_result(group(format("Type.{") + nest(6, pp_level(sort_level(e))) + format("}")));
} else {
return mk_result(format("Type"));
}
@ -295,7 +295,7 @@ auto pretty_fn::pp_pi(expr const & e) -> result {
if (is_arrow(e)) {
result lhs = pp_child(binding_domain(e), get_arrow_prec());
result rhs = pp_child(lift_free_vars(binding_body(e), 1), get_arrow_prec()-1);
format r = group(format{lhs.first, space(), m_unicode ? g_arrow_n_fmt : g_arrow_fmt, line(), rhs.first});
format r = group(lhs.first + space() + (m_unicode ? g_arrow_n_fmt : g_arrow_fmt) + line() + rhs.first);
return mk_result(r, get_arrow_prec()-1);
} else {
expr b = e;
@ -346,12 +346,12 @@ auto pretty_fn::pp_let(expr e) -> result {
name const & n = local_pp_name(d.first);
format t = pp_child(mlocal_type(d.first), 0).first;
format v = pp_child(d.second, 0).first;
r += nest(3 + 1, compose(beg, group(format{format(n), space(),
colon(), nest(n.size() + 1 + 1 + 1, compose(space(), t)), space(), g_assign_fmt,
nest(m_indent, format{line(), v, sep})})));
r += nest(3 + 1, compose(beg, group(format(n) + space() + colon()
+ nest(n.size() + 1 + 1 + 1, space() + t) + space() + g_assign_fmt
+ nest(m_indent, line() + v + sep))));
}
format b = pp_child(e, 0).first;
r += format{line(), g_in_fmt, space(), nest(2 + 1, b)};
r += line() + g_in_fmt + space() + nest(2 + 1, b);
return mk_result(r, 0);
}
@ -365,14 +365,14 @@ auto pretty_fn::pp_have(expr const & e) -> result {
format type_fmt = pp_child(mlocal_type(local), 0).first;
format proof_fmt = pp_child(proof, 0).first;
format body_fmt = pp_child(body, 0).first;
format r = format{g_have_fmt, space(), format(n), space()};
format r = g_have_fmt + space() + format(n) + space();
if (binding_info(binding).is_contextual())
r += compose(g_fact_fmt, space());
r += format{colon(), nest(m_indent, format{line(), type_fmt, comma(), space(), g_from_fmt})};
r += colon() + nest(m_indent, line() + type_fmt + comma() + space() + g_from_fmt);
r = group(r);
r += nest(m_indent, compose(line(), compose(proof_fmt, comma())));
r += nest(m_indent, line() + proof_fmt + comma());
r = group(r);
r += compose(line(), body_fmt);
r += line() + body_fmt;
return mk_result(r, 0);
}
@ -381,7 +381,7 @@ auto pretty_fn::pp_show(expr const & e) -> result {
expr binding = get_annotation_arg(app_fn(e));
format type_fmt = pp_child(binding_domain(binding), 0).first;
format proof_fmt = pp_child(proof, 0).first;
format r = format{g_show_fmt, space(), nest(5, type_fmt), comma(), space(), g_from_fmt};
format r = g_show_fmt + space() + nest(5, type_fmt) + comma() + space() + g_from_fmt;
r = group(r);
r += nest(m_indent, compose(line(), proof_fmt));
return mk_result(group(r), 0);

View file

@ -521,7 +521,7 @@ format pp(level l, bool unicode, unsigned indent) {
case level_kind::Param: case level_kind::Global:
return format(to_param_core(l).m_id);
case level_kind::Meta:
return format{format("?"), format(meta_id(l))};
return format("?") + format(meta_id(l));
case level_kind::Succ:
return group(compose(format("succ"), nest(indent, compose(line(), pp_child(succ_of(l), unicode, indent)))));
case level_kind::Max: case level_kind::IMax: {
@ -545,7 +545,7 @@ format pp(level const & l, options const & opts) {
format pp(level const & lhs, level const & rhs, bool unicode, unsigned indent) {
format leq = unicode ? format("") : format("<=");
return group(format{pp(lhs, unicode, indent), space(), leq, line(), pp(rhs, unicode, indent)});
return group(pp(lhs, unicode, indent) + space() + leq + line() + pp(rhs, unicode, indent));
}
format pp(level const & lhs, level const & rhs, options const & opts) {

View file

@ -13,7 +13,7 @@ char const * pos_info_provider::get_file_name() const {
format pos_info_provider::pp(expr const & e) const {
try {
auto p = get_pos_info_or_some(e);
return format{format(get_file_name()), colon(), format(p.first), colon(), format(p.second), colon()};
return format(get_file_name()) + colon() + format(p.first) + colon() + format(p.second) + colon();
} catch (exception &) {
return format();
}

View file

@ -116,7 +116,7 @@ format rewrite_rule_set::pp(formatter const & fmt, options const & opts) const {
r += format(" [disabled]");
if (rule.must_check_types())
r += format(" [check]");
r += format{space(), colon(), space()};
r += space() + colon() + space();
r += nest(indent, fmt(rule.get_ceq(), opts));
});
return r;

View file

@ -29,10 +29,10 @@ format goal::pp(formatter const & fmt) const {
for (auto it = tmp.begin(); it != end; ++it) {
if (first) first = false; else r += compose(comma(), line());
expr l = *it;
r += format{fmt(l), space(), colon(), nest(indent, compose(line(), fmt(mlocal_type(l))))};
r += fmt(l) + space() + colon() + nest(indent, line() + fmt(mlocal_type(l)));
}
r = group(r);
r += format{line(), turnstile, space(), nest(indent, fmt(conclusion))};
r += line() + turnstile + space() + nest(indent, fmt(conclusion));
return group(r);
}

View file

@ -36,7 +36,7 @@ format proof_state::pp(formatter const & fmt) const {
for (auto const & g : get_goals()) {
if (first) first = false; else r += line();
if (show_goal_names) {
r += group(format{format(g.get_name()), colon(), nest(indent, compose(line(), g.pp(fmt)))});
r += group(format(g.get_name()) + colon() + nest(indent, line() + g.pp(fmt)));
} else {
r += g.pp(fmt);
}

View file

@ -628,7 +628,7 @@ struct unifier_fn {
r += pp_indent_expr(fmt, rhs);
buffer<expr> locals;
auto m = get_app_args(lhs, locals);
r += format({line(), format("containing '"), fmt(bad_local), format("', to placeholder '"), fmt(m), format("'")});
r += line() + format("containing '") + fmt(bad_local) + format("', to placeholder '") + fmt(m) + format("'");
if (locals.empty()) {
r += format(", in the empty local context");
} else {

View file

@ -30,16 +30,13 @@ static void tst1() {
format f4 = nest(3, f3);
format f5 = line();
format f6(f4, f5);
format f7 = nest(10, format{f6, f4, f6, f4});
format f7 = nest(10, f6 + f4 + f6 + f4);
format f8(f_atom1, nest(3, format(line(), f_atom1)));
format f9 = f7 + f8;
format f10;
f10 += f6 + f5 + f3;
format f11 = above(f1, above(above(f2, f3), f4));
format f12 = paren(format{format("a"),
format("b"),
format("c"),
format("d")});
format f12 = paren(format("a") + format("b") + format("c") + format("d"));
std::vector<pair<std::string, format>> v =
{{"f1", f1},

View file

@ -167,21 +167,19 @@ format group(format const & f) {
}
}
format above(format const & f1, format const & f2) {
return format{f1, line(), f2};
return f1 + line() + f2;
}
format bracket(std::string const & l, format const & x, std::string const & r) {
return group(nest(l.size(), format{format(l), x, format(r)}));
return group(nest(l.size(), format(l) + x + format(r)));
}
format paren(format const & x) {
return group(nest(1, format{lp(), x, rp()}));
return group(nest(1, lp() + x + rp()));
}
// wrap = <+/>
// wrap x y = x <> (text " " :<|> line) <> y
format wrap(format const & f1, format const & f2) {
return format{f1,
choice(format(" "), line()),
f2};
return f1 + choice(format(" "), line()) + f2;
}
/**
@ -391,7 +389,7 @@ struct sexpr_pp_fn {
if (is_nil(*curr)) {
return paren(r);
} else if (!is_cons(*curr)) {
return group(nest(1, format{lp(), r, space(), dot(), line(), apply(*curr), rp()}));
return group(nest(1, lp() + r + space() + dot() + line() + apply(*curr) + rp()));
} else {
r += line();
}

View file

@ -174,11 +174,11 @@ format pp(options const & o) {
name const & n = to_name(head(p));
unsigned sz = n.size();
unsigned indent = unicode ? sz+3 : sz+4;
r += group(nest(indent, format{pp(head(p)), space(), format(arrow), space(), pp(tail(p))}));
r += group(nest(indent, pp(head(p)) + space() + format(arrow) + space() + pp(tail(p))));
});
format open = unicode ? format(g_left_angle_bracket) : lp();
format close = unicode ? format(g_right_angle_bracket) : rp();
return group(nest(1, format{open, r, close}));
return group(nest(1, open + r + close));
}
std::ostream & operator<<(std::ostream & out, options const & o) {