Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/cxx-gen-ast/src/gen_ast_pretty_printer_cc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export function gen_ast_pretty_printer_cc({
emit(`}`);
emit(`void space() { accept.space(); }`);
emit(`void nospace() { accept.nospace(); }`);
emit(`void keepSpace() { accept.keepSpace(); }`);
emit(`void newline() { accept.newline(); }`);
emit(`void nonewline() { accept.nonewline(); }`);
emit(`void indent() { accept.indent(); }`);
Expand All @@ -99,6 +100,11 @@ export function gen_ast_pretty_printer_cc({
}
break;

case "opLoc":
emit(`space();`);
emit(`keepSpace();`);
break;

case "closeLoc":
case "colonLoc":
case "dotLoc":
Expand Down Expand Up @@ -149,6 +155,15 @@ export function gen_ast_pretty_printer_cc({
}
break;

case "equalLoc":
emit(`keepSpace();`);
break;

case "opLoc":
emit(`space();`);
emit(`keepSpace();`);
break;

case "closeLoc":
case "lbracketLoc":
case "lbracket2Loc":
Expand Down Expand Up @@ -379,11 +394,17 @@ void ASTPrettyPrinter::space() {
}

void ASTPrettyPrinter::nospace() {
if (keepSpace_) return;
space_ = false;
}

void ASTPrettyPrinter::keepSpace() {
keepSpace_ = true;
}

void ASTPrettyPrinter::newline() {
space_ = false;
keepSpace_ = false;
newline_ = true;
}

Expand Down
3 changes: 3 additions & 0 deletions packages/cxx-gen-ast/src/gen_ast_pretty_printer_h.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ ${code.join("\n")}
}
newline_ = false;
space_ = false;
keepSpace_ = false;
std::format_to(output_, fmt, std::forward<Args>(args)...);
space();
}
Expand All @@ -107,6 +108,7 @@ ${code.join("\n")}

void space();
void nospace();
void keepSpace();
void newline();
void nonewline();
void indent();
Expand All @@ -117,6 +119,7 @@ private:
std::ostream_iterator<char> output_;
int depth_ = 0;
bool space_ = false;
bool keepSpace_ = false;
bool newline_ = false;
};

Expand Down
Loading