3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-06-03 04:41:22 +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-03-21 10:25:46 +13:00
parent 69fa0f9fef
commit 59bcd7ce14
No known key found for this signature in database

View file

@ -831,7 +831,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,
}; };
@ -851,6 +850,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");
@ -861,18 +861,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;
} }
@ -888,11 +886,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;
@ -903,6 +905,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
@ -910,6 +913,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 {
@ -927,12 +934,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;
} }
} }