void
TokenStream::visit_as_line (T &item, std::vector<TokenPtr> trailing)
{
+ indentation ();
visit (item);
for (auto &token : trailing)
tokens.push_back (token);
+ newline ();
}
template <typename T>
TokenId left_brace, TokenId right_brace)
{
tokens.push_back (Rust::Token::make (left_brace, Location ()));
- visit_items_as_lines (collection);
- tokens.push_back (Rust::Token::make (right_brace, Location ()));
+ if (collection.empty ())
+ {
+ tokens.push_back (Rust::Token::make (right_brace, Location ()));
+ newline ();
+ }
+ else
+ {
+ newline ();
+ increment_indentation ();
+ visit_items_as_lines (collection);
+ decrement_indentation ();
+ indentation ();
+ tokens.push_back (Rust::Token::make (right_brace, Location ()));
+ newline ();
+ }
}
void
}
}
+void
+TokenStream::newline ()
+{}
+
+void
+TokenStream::indentation ()
+{}
+
+void
+TokenStream::increment_indentation ()
+{}
+
+void
+TokenStream::decrement_indentation ()
+{}
+
void
TokenStream::visit (FunctionParam ¶m)
{
void
TokenStream::visit (DelimTokenTree &delim_tok_tree)
{
+ increment_indentation ();
+ newline ();
+ indentation ();
for (auto &token : delim_tok_tree.to_token_stream ())
{
visit (token);
}
+ decrement_indentation ();
+ newline ();
+ indentation ();
}
void
TokenStream::visit (BlockExpr &expr)
{
tokens.push_back (Rust::Token::make (LEFT_CURLY, expr.get_locus ()));
+ newline ();
+ increment_indentation ();
- visit_items_joined_by_separator (expr.get_statements (), SEMICOLON);
+ visit_items_as_lines (expr.get_statements (),
+ {Rust::Token::make (SEMICOLON, Location ())});
if (expr.has_tail_expr ())
- visit (expr.get_tail_expr ());
+ {
+ visit (expr.get_tail_expr ());
+ newline ();
+ }
+ decrement_indentation ();
tokens.push_back (Rust::Token::make (RIGHT_CURLY, expr.get_locus ()));
+ newline ();
}
void
TokenStream::visit (IfExprConseqElse &expr)
{
visit (static_cast<IfExpr &> (expr));
+ indentation ();
tokens.push_back (Rust::Token::make (ELSE, expr.get_locus ()));
visit (expr.get_else_block ());
}
TokenStream::visit (IfExprConseqIf &expr)
{
visit (static_cast<IfExpr &> (expr));
+ indentation ();
tokens.push_back (Rust::Token::make (ELSE, expr.get_locus ()));
// The "if" part of the "else if" is printed by the next visitor
visit (expr.get_conseq_if_expr ());
TokenStream::visit (IfExprConseqIfLet &expr)
{
visit (static_cast<IfExpr &> (expr));
+ indentation ();
tokens.push_back (Rust::Token::make (ELSE, expr.get_locus ()));
visit (expr.get_conseq_if_let_expr ());
}
TokenStream::visit (IfLetExprConseqElse &expr)
{
visit (static_cast<IfLetExpr &> (expr));
+ indentation ();
tokens.push_back (Rust::Token::make (ELSE, expr.get_locus ()));
visit (expr.get_else_block ());
}
TokenStream::visit (IfLetExprConseqIf &expr)
{
visit (static_cast<IfLetExpr &> (expr));
+ indentation ();
tokens.push_back (Rust::Token::make (ELSE, expr.get_locus ()));
visit (expr.get_conseq_if_expr ());
}
TokenStream::visit (IfLetExprConseqIfLet &expr)
{
visit (static_cast<IfLetExpr &> (expr));
+ indentation ();
tokens.push_back (Rust::Token::make (ELSE, expr.get_locus ()));
visit (expr.get_conseq_if_let_expr ());
}
// | TypeBoundWhereClauseItem
tokens.push_back (Rust::Token::make (WHERE, Location ()));
+ newline ();
+ increment_indentation ();
visit_items_joined_by_separator (rule.get_items (), COMMA);
+ decrement_indentation ();
}
void
tokens.push_back (Rust::Token::make (SEMICOLON, Location ()));
else
visit (block);
+ newline ();
}
void
if (module.get_kind () == Module::UNLOADED)
{
tokens.push_back (Rust::Token::make (SEMICOLON, Location ()));
+ newline ();
}
else /* Module::LOADED */
{
tokens.push_back (Rust::Token::make (LEFT_CURLY, Location ()));
+ newline ();
+ increment_indentation ();
visit_items_as_lines (module.get_inner_attrs ());
visit_items_as_lines (module.get_items ());
+ decrement_indentation ();
+
tokens.push_back (Rust::Token::make (RIGHT_CURLY, Location ()));
+ newline ();
}
}
Rust::Token::make_identifier (Location (), std::move (as_clause)));
}
tokens.push_back (Rust::Token::make (SEMICOLON, Location ()));
+ newline ();
}
void
tokens.push_back (Rust::Token::make (USE, decl.get_locus ()));
visit (*decl.get_tree ());
tokens.push_back (Rust::Token::make (SEMICOLON, Location ()));
+ newline ();
}
void
tokens.push_back (Rust::Token::make (SEMICOLON, Location ()));
else
visit (block);
+ newline ();
}
void
if (struct_item.has_where_clause ())
visit (struct_item.get_where_clause ());
if (struct_item.is_unit_struct ())
- tokens.push_back (Rust::Token::make (SEMICOLON, Location ()));
+ {
+ tokens.push_back (Rust::Token::make (SEMICOLON, Location ()));
+ newline ();
+ }
else
visit_items_as_block (struct_item.get_fields (),
{Rust::Token::make (COMMA, Location ())});
visit_items_joined_by_separator (tuple_struct.get_fields (), COMMA);
tokens.push_back (Rust::Token::make (RIGHT_PAREN, Location ()));
tokens.push_back (Rust::Token::make (SEMICOLON, Location ()));
+ newline ();
}
void
}
}
else
- tokens.push_back (Rust::Token::make (SEMICOLON, Location ()));
+ {
+ tokens.push_back (Rust::Token::make (SEMICOLON, Location ()));
+ newline ();
+ }
}
void
TokenStream::visit (TraitItemConst &item)
{
auto id = item.get_identifier ();
+ indentation ();
tokens.push_back (Rust::Token::make (CONST, item.get_locus ()));
tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id)));
tokens.push_back (Rust::Token::make (COLON, Location ()));
visit (item.get_type ());
tokens.push_back (Rust::Token::make (SEMICOLON, Location ()));
+ newline ();
}
void
TokenStream::visit (TraitItemType &item)
{
auto id = item.get_identifier ();
+ indentation ();
tokens.push_back (Rust::Token::make (TYPE, item.get_locus ()));
tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id)));
tokens.push_back (Rust::Token::make (SEMICOLON, Location ()));
+ newline ();
}
void
for (auto &attr : trait.get_outer_attrs ())
{
visit (attr);
+ newline ();
+ indentation ();
}
visit (trait.get_visibility ());
tokens.push_back (Rust::Token::make (FOR, Location ()));
visit (impl.get_type ());
tokens.push_back (Rust::Token::make (LEFT_CURLY, Location ()));
+ newline ();
+
+ increment_indentation ();
for (auto &item : impl.get_impl_items ())
{
+ indentation ();
visit (item);
}
+ decrement_indentation ();
+ newline ();
+
tokens.push_back (Rust::Token::make (RIGHT_CURLY, Location ()));
+ newline ();
}
void