mirror of
https://github.com/YosysHQ/yosys
synced 2025-06-03 04:41:22 +00:00
Docs: Fix dump_cmds_json for PrettyHelp
This commit is contained in:
parent
fd5e420edd
commit
0e1434ac0c
1 changed files with 55 additions and 37 deletions
|
@ -829,12 +829,16 @@ struct HelpPass : public Pass {
|
||||||
|
|
||||||
if (!has_pretty_help) {
|
if (!has_pretty_help) {
|
||||||
enum PassUsageState {
|
enum PassUsageState {
|
||||||
|
PUState_none,
|
||||||
PUState_signature,
|
PUState_signature,
|
||||||
PUState_description,
|
PUState_description,
|
||||||
PUState_options,
|
PUState_options,
|
||||||
PUState_postscript,
|
PUState_optionbody,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
source_location null_source;
|
||||||
|
string current_buffer = "";
|
||||||
|
|
||||||
// dump command help
|
// dump command help
|
||||||
std::ostringstream buf;
|
std::ostringstream buf;
|
||||||
log_streams.push_back(&buf);
|
log_streams.push_back(&buf);
|
||||||
|
@ -844,17 +848,31 @@ struct HelpPass : public Pass {
|
||||||
ss << buf.str();
|
ss << buf.str();
|
||||||
|
|
||||||
// parse command help
|
// parse command help
|
||||||
int blank_count = 0;
|
|
||||||
size_t def_strip_count = 0;
|
size_t def_strip_count = 0;
|
||||||
auto current_state = PUState_postscript;
|
auto current_state = PUState_none;
|
||||||
auto catch_verific = false;
|
auto catch_verific = false;
|
||||||
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");
|
||||||
std::size_t last_pos = line.find_last_not_of(" \t");
|
std::size_t last_pos = line.find_last_not_of(" \t");
|
||||||
if (first_pos == std::string::npos) {
|
if (first_pos == std::string::npos) {
|
||||||
|
switch (current_state)
|
||||||
|
{
|
||||||
|
case PUState_signature:
|
||||||
|
cmd_help.usage(current_buffer, null_source);
|
||||||
|
current_state = PUState_none;
|
||||||
|
break;
|
||||||
|
case PUState_none:
|
||||||
|
if (!current_buffer.empty()) cmd_help.codeblock(current_buffer, "none", null_source);
|
||||||
|
break;
|
||||||
|
case PUState_optionbody:
|
||||||
|
if (!current_buffer.empty()) cmd_help.codeblock(current_buffer, "none", null_source);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
// skip empty lines
|
// skip empty lines
|
||||||
blank_count += 1;
|
current_buffer = "";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -863,58 +881,58 @@ struct HelpPass : public Pass {
|
||||||
bool IsDefinition = stripped_line[0] == '-';
|
bool IsDefinition = stripped_line[0] == '-';
|
||||||
IsDefinition &= stripped_line[1] != ' ' && stripped_line[1] != '>';
|
IsDefinition &= stripped_line[1] != ' ' && stripped_line[1] != '>';
|
||||||
bool IsDedent = def_strip_count && first_pos < def_strip_count;
|
bool IsDedent = def_strip_count && first_pos < def_strip_count;
|
||||||
bool IsIndent = first_pos == 2 || first_pos == 4 || first_pos == 8;
|
bool IsIndent = def_strip_count < first_pos;
|
||||||
|
|
||||||
// line looks like a signature
|
// line looks like a signature
|
||||||
bool IsSignature = stripped_line.find(name) == 0;
|
bool IsSignature = stripped_line.find(name) == 0;
|
||||||
|
|
||||||
// start new usage block if it's a signature and we left the current signature
|
if (IsSignature) {
|
||||||
// or if we are adding new options after we left the options
|
if (current_state == PUState_options || current_state == PUState_optionbody) {
|
||||||
bool NewUsage = (IsSignature && current_state != PUState_signature)
|
cmd_help.close(2);
|
||||||
|| (IsDefinition && current_state == PUState_postscript);
|
}
|
||||||
|
if (current_state == PUState_signature) {
|
||||||
if (NewUsage) {
|
cmd_help.usage(current_buffer, null_source);
|
||||||
|
current_buffer = "";
|
||||||
|
}
|
||||||
current_state = PUState_signature;
|
current_state = PUState_signature;
|
||||||
// usages.push_back({});
|
|
||||||
def_strip_count = first_pos;
|
def_strip_count = first_pos;
|
||||||
catch_verific = false;
|
catch_verific = false;
|
||||||
} else if (IsDedent) {
|
} else if (IsDedent) {
|
||||||
def_strip_count = first_pos;
|
def_strip_count = first_pos;
|
||||||
if (current_state == PUState_signature)
|
if (current_state == PUState_optionbody) {
|
||||||
current_state = PUState_description;
|
current_state = PUState_options;
|
||||||
|
if (!current_buffer.empty()) {
|
||||||
|
cmd_help.codeblock(current_buffer, "none", null_source);
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
current_state = PUState_postscript;
|
current_state = PUState_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsDefinition && IsIndent && !catch_verific) {
|
if (IsDefinition && !catch_verific && current_state != PUState_signature) {
|
||||||
|
if (current_state == PUState_options || current_state == PUState_optionbody) {
|
||||||
|
cmd_help.close(1);
|
||||||
|
} else {
|
||||||
|
cmd_help.open_optiongroup("", null_source);
|
||||||
|
}
|
||||||
current_state = PUState_options;
|
current_state = PUState_options;
|
||||||
// usages.back().options.push_back(PassOption({stripped_line, ""}));
|
cmd_help.open_option(stripped_line, null_source);
|
||||||
def_strip_count = first_pos;
|
def_strip_count = first_pos;
|
||||||
} else {
|
} else {
|
||||||
string *desc_str;
|
if (current_state == PUState_options) {
|
||||||
if (current_state == PUState_signature) {
|
current_state = PUState_optionbody;
|
||||||
// desc_str = &(usages.back().signature);
|
|
||||||
blank_count += 1;
|
|
||||||
} else if (current_state == PUState_description) {
|
|
||||||
// desc_str = &(usages.back().description);
|
|
||||||
} else if (current_state == PUState_options) {
|
|
||||||
// desc_str = &(usages.back().options.back().description);
|
|
||||||
} else if (current_state == PUState_postscript) {
|
|
||||||
// desc_str = &(usages.back().postscript);
|
|
||||||
} else {
|
|
||||||
log_abort();
|
|
||||||
}
|
}
|
||||||
if (desc_str->empty())
|
if (current_buffer.empty())
|
||||||
*desc_str = stripped_line;
|
current_buffer = stripped_line;
|
||||||
else if (catch_verific)
|
else if (current_state == PUState_signature && IsIndent)
|
||||||
*desc_str += (IsIndent ? "\n" : " ") + stripped_line;
|
current_buffer += stripped_line;
|
||||||
else
|
else if (current_state == PUState_none) {
|
||||||
*desc_str += (blank_count > 0 ? "\n" : " ") + stripped_line;
|
current_buffer += "\n" + line;
|
||||||
|
} else
|
||||||
|
current_buffer += "\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_count = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue