3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-07-28 23:17:57 +00:00

cmdref: Combine consecutive code blocks

Formatting is nicer when there is only one code block instead of multiple in a row, especially in pdf.
This commit is contained in:
Krystine Sherwin 2025-07-21 10:34:12 +12:00
parent a19f0103ff
commit cb502e7505
No known key found for this signature in database

View file

@ -829,7 +829,6 @@ struct HelpPass : public Pass {
enum PassUsageState { enum PassUsageState {
PUState_none, PUState_none,
PUState_signature, PUState_signature,
PUState_description,
PUState_options, PUState_options,
PUState_optionbody, PUState_optionbody,
}; };
@ -849,6 +848,7 @@ struct HelpPass : public Pass {
size_t def_strip_count = 0; size_t def_strip_count = 0;
auto current_state = PUState_none; auto current_state = PUState_none;
auto catch_verific = false; auto catch_verific = false;
auto blank_lines = 0;
for (string line; std::getline(ss, line, '\n');) { for (string line; std::getline(ss, line, '\n');) {
// find position of first non space character // find position of first non space character
std::size_t first_pos = line.find_first_not_of(" \t"); std::size_t first_pos = line.find_first_not_of(" \t");
@ -859,18 +859,16 @@ struct HelpPass : public Pass {
case PUState_signature: case PUState_signature:
cmd_help.usage(current_buffer, null_source); cmd_help.usage(current_buffer, null_source);
current_state = PUState_none; current_state = PUState_none;
current_buffer = "";
break; break;
case PUState_none: case PUState_none:
if (!current_buffer.empty()) cmd_help.codeblock(current_buffer, "none", null_source);
break;
case PUState_optionbody: case PUState_optionbody:
if (!current_buffer.empty()) cmd_help.codeblock(current_buffer, "none", null_source); blank_lines += 1;
break; break;
default: default:
break; break;
} }
// skip empty lines // skip empty lines
current_buffer = "";
continue; continue;
} }
@ -886,11 +884,15 @@ struct HelpPass : public Pass {
if (IsSignature) { if (IsSignature) {
if (current_state == PUState_options || current_state == PUState_optionbody) { if (current_state == PUState_options || current_state == PUState_optionbody) {
cmd_help.codeblock(current_buffer, "none", null_source);
current_buffer = "";
cmd_help.close(2); cmd_help.close(2);
} } else if (current_state == PUState_signature) {
if (current_state == PUState_signature) {
cmd_help.usage(current_buffer, null_source); cmd_help.usage(current_buffer, null_source);
current_buffer = ""; current_buffer = "";
} else if (current_state == PUState_none && !current_buffer.empty()) {
cmd_help.codeblock(current_buffer, "none", null_source);
current_buffer = "";
} }
current_state = PUState_signature; current_state = PUState_signature;
def_strip_count = first_pos; def_strip_count = first_pos;
@ -901,6 +903,7 @@ struct HelpPass : public Pass {
current_state = PUState_options; current_state = PUState_options;
if (!current_buffer.empty()) { if (!current_buffer.empty()) {
cmd_help.codeblock(current_buffer, "none", null_source); cmd_help.codeblock(current_buffer, "none", null_source);
current_buffer = "";
} }
} }
else else
@ -908,6 +911,10 @@ struct HelpPass : public Pass {
} }
if (IsDefinition && !catch_verific && current_state != PUState_signature) { if (IsDefinition && !catch_verific && current_state != PUState_signature) {
if (!current_buffer.empty()) {
cmd_help.codeblock(current_buffer, "none", null_source);
current_buffer = "";
}
if (current_state == PUState_options || current_state == PUState_optionbody) { if (current_state == PUState_options || current_state == PUState_optionbody) {
cmd_help.close(1); cmd_help.close(1);
} else { } else {
@ -925,12 +932,13 @@ struct HelpPass : public Pass {
else if (current_state == PUState_signature && IsIndent) else if (current_state == PUState_signature && IsIndent)
current_buffer += stripped_line; current_buffer += stripped_line;
else if (current_state == PUState_none) { else if (current_state == PUState_none) {
current_buffer += "\n" + line; current_buffer += (blank_lines > 0 ? "\n\n" : "\n") + line;
} else } else
current_buffer += "\n" + stripped_line; current_buffer += (blank_lines > 0 ? "\n\n" : "\n") + stripped_line;
if (stripped_line.compare("Command file parser supports following commands in file:") == 0) if (stripped_line.compare("Command file parser supports following commands in file:") == 0)
catch_verific = true; catch_verific = true;
} }
blank_lines = 0;
} }
} }