Skip to content

Commit 81d6b20

Browse files
authored
[lldb] Add a simplified syntax for underlying command options (NFC) (llvm#155694)
This PR updates the tablegen emitter for command options to support a simplified syntax to underline the mnemonic. Previously, you had to write `${ansi.underline}<L>${ansi.normal}`, where `<L>` is the mnemonic. This really hurt the readability of the description. With this PR, you can write `${<L>}` instead.
1 parent 8f317c1 commit 81d6b20

File tree

2 files changed

+42
-18
lines changed

2 files changed

+42
-18
lines changed

lldb/source/Commands/Options.td

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -743,35 +743,32 @@ let Command = "process launch" in {
743743
}
744744

745745
let Command = "process attach" in {
746-
def process_attach_continue
747-
: Option<"continue", "c">,
748-
Desc<"Immediately ${ansi.underline}c${ansi.normal}ontinue the process "
749-
"once attached.">;
750-
def process_attach_plugin
751-
: Option<"plugin", "P">,
752-
Arg<"Plugin">,
753-
Desc<"Name of the process ${ansi.underline}p${ansi.normal}lugin you "
754-
"want to use.">;
746+
def process_attach_continue : Option<"continue", "c">,
747+
Desc<"Immediately ${c}ontinue the process "
748+
"once attached.">;
749+
def process_attach_plugin : Option<"plugin", "P">,
750+
Arg<"Plugin">,
751+
Desc<"Name of the process ${p}lugin you "
752+
"want to use.">;
755753
def process_attach_pid : Option<"pid", "p">,
756754
Group<1>,
757755
Arg<"Pid">,
758-
Desc<"The ${ansi.underline}p${ansi.normal}rocess ID "
756+
Desc<"The ${p}rocess ID "
759757
"of an existing process to attach to.">;
760758
def process_attach_name : Option<"name", "n">,
761759
Group<2>,
762760
Arg<"ProcessName">,
763-
Desc<"The ${ansi.underline}n${ansi.normal}ame of "
761+
Desc<"The ${n}ame of "
764762
"the process to attach to.">;
765763
def process_attach_include_existing
766764
: Option<"include-existing", "i">,
767765
Group<2>,
768-
Desc<"${ansi.underline}I${ansi.normal}nclude existing processes when "
766+
Desc<"${I}nclude existing processes when "
769767
"doing attach -w.">;
770-
def process_attach_waitfor
771-
: Option<"waitfor", "w">,
772-
Group<2>,
773-
Desc<"${ansi.underline}W${ansi.normal}ait for the process with "
774-
"<process-name> to launch.">;
768+
def process_attach_waitfor : Option<"waitfor", "w">,
769+
Group<2>,
770+
Desc<"${W}ait for the process with "
771+
"<process-name> to launch.">;
775772
}
776773

777774
let Command = "process continue" in {

lldb/utils/TableGen/LLDBOptionDefEmitter.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,33 @@ using namespace llvm;
2323
using namespace lldb_private;
2424

2525
namespace {
26+
/// Parses curly braces and replaces them with ANSI underline formatting.
27+
std::string underline(llvm::StringRef Str) {
28+
llvm::StringRef OpeningHead, OpeningTail, ClosingHead, ClosingTail;
29+
std::string Result;
30+
llvm::raw_string_ostream Stream(Result);
31+
while (!Str.empty()) {
32+
// Find the opening brace.
33+
std::tie(OpeningHead, OpeningTail) = Str.split("${");
34+
Stream << OpeningHead;
35+
36+
// No opening brace: we're done.
37+
if (OpeningHead == Str)
38+
break;
39+
40+
assert(!OpeningTail.empty());
41+
42+
// Find the closing brace.
43+
std::tie(ClosingHead, ClosingTail) = OpeningTail.split('}');
44+
assert(!ClosingTail.empty() &&
45+
"unmatched curly braces in command option description");
46+
47+
Stream << "${ansi.underline}" << ClosingHead << "${ansi.normal}";
48+
Str = ClosingTail;
49+
}
50+
return Result;
51+
}
52+
2653
struct CommandOption {
2754
std::vector<std::string> GroupsArg;
2855
bool Required = false;
@@ -68,7 +95,7 @@ struct CommandOption {
6895
Completions = Option->getValueAsListOfStrings("Completions");
6996

7097
if (auto D = Option->getValue("Description"))
71-
Description = D->getValue()->getAsUnquotedString();
98+
Description = underline(D->getValue()->getAsUnquotedString());
7299
}
73100
};
74101
} // namespace

0 commit comments

Comments
 (0)