mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-03-15 23:22:53 +08:00
create_manpage_completions.py: introduce TypeScdocManParser which is capable of parsing scdoc manpages
This greatly improves generated completions for scdoc man pages, see #7187.
This commit is contained in:
parent
d3661b3808
commit
aff2e76021
@ -502,6 +502,56 @@ class Type4ManParser(ManParser):
|
||||
options_section = options_section[options_matched.end() - 3 :]
|
||||
options_matched = re.search(options_parts_regex, options_section)
|
||||
|
||||
class TypeScdocManParser(ManParser):
|
||||
def is_my_type(self, manpage):
|
||||
return compile_and_search(r"\.(\\)(\") Generated by scdoc(.*?)\.SH OPTIONS(.*?)", manpage) != None
|
||||
|
||||
def parse_man_page(self, manpage):
|
||||
options_section_regex = re.compile("\.SH OPTIONS(.*?)\.SH", re.DOTALL)
|
||||
options_section_matched = re.search(options_section_regex, manpage)
|
||||
if options_section_matched == None:
|
||||
return False
|
||||
options_section = options_section_matched.group(1)
|
||||
|
||||
options_parts_regex = re.compile("(.*?).RE", re.DOTALL)
|
||||
options_matched = re.match(options_parts_regex, options_section)
|
||||
add_diagnostic("Command is %r" % CMDNAME)
|
||||
|
||||
if options_matched == None:
|
||||
add_diagnostic("%r: Unable to find options" % self)
|
||||
return False
|
||||
|
||||
while options_matched != None:
|
||||
# Get first option and move options_section
|
||||
option = options_matched.group(1)
|
||||
options_section = options_section[options_matched.end()::]
|
||||
options_matched = re.match(options_parts_regex, options_section)
|
||||
|
||||
option = remove_groff_formatting(option)
|
||||
option = option.split("\n")
|
||||
|
||||
# Crean option list
|
||||
option_clean = []
|
||||
for line in option:
|
||||
if line not in ["", ".P", ".RS 4"]:
|
||||
option_clean.append(line)
|
||||
|
||||
# Shold be at least two lines
|
||||
if len(option_clean) < 2:
|
||||
add_diagnostic("Unable to split option from description")
|
||||
continue
|
||||
|
||||
# Name and description, others lines are ignored
|
||||
option_name = option_clean[0]
|
||||
option_description = option_clean[1]
|
||||
|
||||
if "-" not in option_name:
|
||||
add_diagnostic("%r doesn't contain '-'" % option_name)
|
||||
|
||||
option_name = unquote_double_quotes(option_name)
|
||||
option_name = unquote_single_quotes(option_name)
|
||||
built_command(option_name, option_description)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@ -780,6 +830,7 @@ def parse_manpage_at_path(manpage_path, output_directory):
|
||||
parsers = [TypeDeroffManParser()]
|
||||
else:
|
||||
parsers = [
|
||||
TypeScdocManParser(),
|
||||
Type1ManParser(),
|
||||
Type2ManParser(),
|
||||
Type4ManParser(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user