summaryrefslogtreecommitdiff
path: root/doc/tools/makerst.py
diff options
context:
space:
mode:
Diffstat (limited to 'doc/tools/makerst.py')
-rwxr-xr-xdoc/tools/makerst.py58
1 files changed, 46 insertions, 12 deletions
diff --git a/doc/tools/makerst.py b/doc/tools/makerst.py
index 22c0b5d1fd..c3e15b2f9a 100755
--- a/doc/tools/makerst.py
+++ b/doc/tools/makerst.py
@@ -1,11 +1,10 @@
#!/usr/bin/env python3
import argparse
-import sys
import os
import re
import xml.etree.ElementTree as ET
-from collections import defaultdict, OrderedDict
+from collections import OrderedDict
# Uncomment to do type checks. I have it commented out so it works below Python 3.5
#from typing import List, Dict, TextIO, Tuple, Iterable, Optional, DefaultDict, Any, Union
@@ -684,10 +683,16 @@ def rstize_text(text, state): # type: (str, State) -> str
# Handle [tags]
inside_code = False
+ inside_url = False
+ url_has_name = False
+ url_link = ""
pos = 0
tag_depth = 0
+ previous_pos = 0
while True:
pos = text.find('[', pos)
+ if inside_url and (pos > previous_pos):
+ url_has_name = True
if pos == -1:
break
@@ -702,7 +707,11 @@ def rstize_text(text, state): # type: (str, State) -> str
escape_post = False
if tag_text in state.classes:
- tag_text = make_type(tag_text, state)
+ if tag_text == state.current_class:
+ # We don't want references to the same class
+ tag_text = '``{}``'.format(tag_text)
+ else:
+ tag_text = make_type(tag_text, state)
escape_post = True
else: # command
cmd = tag_text
@@ -757,14 +766,25 @@ def rstize_text(text, state): # type: (str, State) -> str
elif cmd.startswith("constant"):
found = False
- if method_param in class_def.constants:
- found = True
- else:
- for enum in class_def.enums.values():
- if method_param in enum.values:
- found = True
- break
+ # Search in the current class
+ search_class_defs = [class_def]
+
+ if param.find('.') == -1:
+ # Also search in @GlobalScope as a last resort if no class was specified
+ search_class_defs.append(state.classes["@GlobalScope"])
+
+ for search_class_def in search_class_defs:
+ if method_param in search_class_def.constants:
+ class_param = search_class_def.name
+ found = True
+
+ else:
+ for enum in search_class_def.enums.values():
+ if method_param in enum.values:
+ class_param = search_class_def.name
+ found = True
+ break
if not found:
print_error("Unresolved constant '{}', file: {}".format(param, state.current_class), state)
@@ -781,12 +801,16 @@ def rstize_text(text, state): # type: (str, State) -> str
elif cmd.find('image=') == 0:
tag_text = "" # '![](' + cmd[6:] + ')'
elif cmd.find('url=') == 0:
- tag_text = ':ref:`' + cmd[4:] + '<' + cmd[4:] + ">`"
+ url_link = cmd[4:]
+ tag_text = ':ref:`'
tag_depth += 1
+ url_has_name = False
+ inside_url = True
elif cmd == '/url':
- tag_text = ''
+ tag_text = ('' if url_has_name else url_link) + '<' + url_link + ">`"
tag_depth -= 1
escape_post = True
+ inside_url = False
elif cmd == 'center':
tag_depth += 1
tag_text = ''
@@ -857,6 +881,7 @@ def rstize_text(text, state): # type: (str, State) -> str
text = pre_text + tag_text + post_text
pos = len(pre_text) + len(tag_text)
+ previous_pos = pos
if tag_depth > 0:
print_error("Tag depth mismatch: too many/little open/close tags, file: {}".format(state.current_class), state)
@@ -917,6 +942,9 @@ def make_enum(t, state): # type: (str, State) -> str
if c in state.classes and e not in state.classes[c].enums:
c = "@GlobalScope"
+ if not c in state.classes and c.startswith("_"):
+ c = c[1:] # Remove the underscore prefix
+
if c in state.classes and e in state.classes[c].enums:
return ":ref:`{0}<enum_{1}_{0}>`".format(e, c)
print_error("Unresolved enum '{}', file: {}".format(t, state.current_class), state)
@@ -950,6 +978,12 @@ def make_method_signature(class_def, method_def, make_ref, state): # type: (Cla
if arg.default_value is not None:
out += '=' + arg.default_value
+ if isinstance(method_def, MethodDef) and method_def.qualifiers is not None and 'vararg' in method_def.qualifiers:
+ if len(method_def.parameters) > 0:
+ out += ', ...'
+ else:
+ out += ' ...'
+
out += ' **)**'
if isinstance(method_def, MethodDef) and method_def.qualifiers is not None: