make_rst.py 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329
  1. #!/usr/bin/env python3
  2. # This script makes RST files from the XML class reference for use with the online docs.
  3. import argparse
  4. import os
  5. import re
  6. import xml.etree.ElementTree as ET
  7. from collections import OrderedDict
  8. # Uncomment to do type checks. I have it commented out so it works below Python 3.5
  9. # from typing import List, Dict, TextIO, Tuple, Iterable, Optional, DefaultDict, Any, Union
  10. # http(s)://docs.godotengine.org/<langcode>/<tag>/path/to/page.html(#fragment-tag)
  11. GODOT_DOCS_PATTERN = re.compile(
  12. r"^http(?:s)?://docs\.godotengine\.org/(?:[a-zA-Z0-9.\-_]*)/(?:[a-zA-Z0-9.\-_]*)/(.*)\.html(#.*)?$"
  13. )
  14. def print_error(error, state): # type: (str, State) -> None
  15. print("ERROR: {}".format(error))
  16. state.errored = True
  17. class TypeName:
  18. def __init__(self, type_name, enum=None): # type: (str, Optional[str]) -> None
  19. self.type_name = type_name
  20. self.enum = enum
  21. def to_rst(self, state): # type: ("State") -> str
  22. if self.enum is not None:
  23. return make_enum(self.enum, state)
  24. elif self.type_name == "void":
  25. return "void"
  26. else:
  27. return make_type(self.type_name, state)
  28. @classmethod
  29. def from_element(cls, element): # type: (ET.Element) -> "TypeName"
  30. return cls(element.attrib["type"], element.get("enum"))
  31. class PropertyDef:
  32. def __init__(
  33. self, name, type_name, setter, getter, text, default_value, overridden
  34. ): # type: (str, TypeName, Optional[str], Optional[str], Optional[str], Optional[str], Optional[bool]) -> None
  35. self.name = name
  36. self.type_name = type_name
  37. self.setter = setter
  38. self.getter = getter
  39. self.text = text
  40. self.default_value = default_value
  41. self.overridden = overridden
  42. class ParameterDef:
  43. def __init__(self, name, type_name, default_value): # type: (str, TypeName, Optional[str]) -> None
  44. self.name = name
  45. self.type_name = type_name
  46. self.default_value = default_value
  47. class SignalDef:
  48. def __init__(self, name, parameters, description): # type: (str, List[ParameterDef], Optional[str]) -> None
  49. self.name = name
  50. self.parameters = parameters
  51. self.description = description
  52. class MethodDef:
  53. def __init__(
  54. self, name, return_type, parameters, description, qualifiers
  55. ): # type: (str, TypeName, List[ParameterDef], Optional[str], Optional[str]) -> None
  56. self.name = name
  57. self.return_type = return_type
  58. self.parameters = parameters
  59. self.description = description
  60. self.qualifiers = qualifiers
  61. class ConstantDef:
  62. def __init__(self, name, value, text): # type: (str, str, Optional[str]) -> None
  63. self.name = name
  64. self.value = value
  65. self.text = text
  66. class EnumDef:
  67. def __init__(self, name): # type: (str) -> None
  68. self.name = name
  69. self.values = OrderedDict() # type: OrderedDict[str, ConstantDef]
  70. class ThemeItemDef:
  71. def __init__(
  72. self, name, type_name, data_name, text, default_value
  73. ): # type: (str, TypeName, str, Optional[str], Optional[str]) -> None
  74. self.name = name
  75. self.type_name = type_name
  76. self.data_name = data_name
  77. self.text = text
  78. self.default_value = default_value
  79. class ClassDef:
  80. def __init__(self, name): # type: (str) -> None
  81. self.name = name
  82. self.constants = OrderedDict() # type: OrderedDict[str, ConstantDef]
  83. self.enums = OrderedDict() # type: OrderedDict[str, EnumDef]
  84. self.properties = OrderedDict() # type: OrderedDict[str, PropertyDef]
  85. self.constructors = OrderedDict() # type: OrderedDict[str, List[MethodDef]]
  86. self.methods = OrderedDict() # type: OrderedDict[str, List[MethodDef]]
  87. self.operators = OrderedDict() # type: OrderedDict[str, List[MethodDef]]
  88. self.signals = OrderedDict() # type: OrderedDict[str, SignalDef]
  89. self.theme_items = OrderedDict() # type: OrderedDict[str, ThemeItemDef]
  90. self.inherits = None # type: Optional[str]
  91. self.brief_description = None # type: Optional[str]
  92. self.description = None # type: Optional[str]
  93. self.tutorials = [] # type: List[Tuple[str, str]]
  94. # Used to match the class with XML source for output filtering purposes.
  95. self.filepath = "" # type: str
  96. class State:
  97. def __init__(self): # type: () -> None
  98. # Has any error been reported?
  99. self.errored = False
  100. self.classes = OrderedDict() # type: OrderedDict[str, ClassDef]
  101. self.current_class = "" # type: str
  102. def parse_class(self, class_root, filepath): # type: (ET.Element, str) -> None
  103. class_name = class_root.attrib["name"]
  104. class_def = ClassDef(class_name)
  105. self.classes[class_name] = class_def
  106. class_def.filepath = filepath
  107. inherits = class_root.get("inherits")
  108. if inherits is not None:
  109. class_def.inherits = inherits
  110. brief_desc = class_root.find("brief_description")
  111. if brief_desc is not None and brief_desc.text:
  112. class_def.brief_description = brief_desc.text
  113. desc = class_root.find("description")
  114. if desc is not None and desc.text:
  115. class_def.description = desc.text
  116. properties = class_root.find("members")
  117. if properties is not None:
  118. for property in properties:
  119. assert property.tag == "member"
  120. property_name = property.attrib["name"]
  121. if property_name in class_def.properties:
  122. print_error("Duplicate property '{}', file: {}".format(property_name, class_name), self)
  123. continue
  124. type_name = TypeName.from_element(property)
  125. setter = property.get("setter") or None # Use or None so '' gets turned into None.
  126. getter = property.get("getter") or None
  127. default_value = property.get("default") or None
  128. if default_value is not None:
  129. default_value = "``{}``".format(default_value)
  130. overridden = property.get("override") or False
  131. property_def = PropertyDef(
  132. property_name, type_name, setter, getter, property.text, default_value, overridden
  133. )
  134. class_def.properties[property_name] = property_def
  135. constructors = class_root.find("constructors")
  136. if constructors is not None:
  137. for constructor in constructors:
  138. assert constructor.tag == "constructor"
  139. method_name = constructor.attrib["name"]
  140. qualifiers = constructor.get("qualifiers")
  141. return_element = constructor.find("return")
  142. if return_element is not None:
  143. return_type = TypeName.from_element(return_element)
  144. else:
  145. return_type = TypeName("void")
  146. params = parse_arguments(constructor)
  147. desc_element = constructor.find("description")
  148. method_desc = None
  149. if desc_element is not None:
  150. method_desc = desc_element.text
  151. method_def = MethodDef(method_name, return_type, params, method_desc, qualifiers)
  152. if method_name not in class_def.constructors:
  153. class_def.constructors[method_name] = []
  154. class_def.constructors[method_name].append(method_def)
  155. methods = class_root.find("methods")
  156. if methods is not None:
  157. for method in methods:
  158. assert method.tag == "method"
  159. method_name = method.attrib["name"]
  160. qualifiers = method.get("qualifiers")
  161. return_element = method.find("return")
  162. if return_element is not None:
  163. return_type = TypeName.from_element(return_element)
  164. else:
  165. return_type = TypeName("void")
  166. params = parse_arguments(method)
  167. desc_element = method.find("description")
  168. method_desc = None
  169. if desc_element is not None:
  170. method_desc = desc_element.text
  171. method_def = MethodDef(method_name, return_type, params, method_desc, qualifiers)
  172. if method_name not in class_def.methods:
  173. class_def.methods[method_name] = []
  174. class_def.methods[method_name].append(method_def)
  175. operators = class_root.find("operators")
  176. if operators is not None:
  177. for operator in operators:
  178. assert operator.tag == "operator"
  179. method_name = operator.attrib["name"]
  180. qualifiers = operator.get("qualifiers")
  181. return_element = operator.find("return")
  182. if return_element is not None:
  183. return_type = TypeName.from_element(return_element)
  184. else:
  185. return_type = TypeName("void")
  186. params = parse_arguments(operator)
  187. desc_element = operator.find("description")
  188. method_desc = None
  189. if desc_element is not None:
  190. method_desc = desc_element.text
  191. method_def = MethodDef(method_name, return_type, params, method_desc, qualifiers)
  192. if method_name not in class_def.operators:
  193. class_def.operators[method_name] = []
  194. class_def.operators[method_name].append(method_def)
  195. constants = class_root.find("constants")
  196. if constants is not None:
  197. for constant in constants:
  198. assert constant.tag == "constant"
  199. constant_name = constant.attrib["name"]
  200. value = constant.attrib["value"]
  201. enum = constant.get("enum")
  202. constant_def = ConstantDef(constant_name, value, constant.text)
  203. if enum is None:
  204. if constant_name in class_def.constants:
  205. print_error("Duplicate constant '{}', file: {}".format(constant_name, class_name), self)
  206. continue
  207. class_def.constants[constant_name] = constant_def
  208. else:
  209. if enum in class_def.enums:
  210. enum_def = class_def.enums[enum]
  211. else:
  212. enum_def = EnumDef(enum)
  213. class_def.enums[enum] = enum_def
  214. enum_def.values[constant_name] = constant_def
  215. signals = class_root.find("signals")
  216. if signals is not None:
  217. for signal in signals:
  218. assert signal.tag == "signal"
  219. signal_name = signal.attrib["name"]
  220. if signal_name in class_def.signals:
  221. print_error("Duplicate signal '{}', file: {}".format(signal_name, class_name), self)
  222. continue
  223. params = parse_arguments(signal)
  224. desc_element = signal.find("description")
  225. signal_desc = None
  226. if desc_element is not None:
  227. signal_desc = desc_element.text
  228. signal_def = SignalDef(signal_name, params, signal_desc)
  229. class_def.signals[signal_name] = signal_def
  230. theme_items = class_root.find("theme_items")
  231. if theme_items is not None:
  232. for theme_item in theme_items:
  233. assert theme_item.tag == "theme_item"
  234. theme_item_name = theme_item.attrib["name"]
  235. theme_item_data_name = theme_item.attrib["data_type"]
  236. theme_item_id = "{}_{}".format(theme_item_data_name, theme_item_name)
  237. if theme_item_id in class_def.theme_items:
  238. print_error(
  239. "Duplicate theme property '{}' of type '{}', file: {}".format(
  240. theme_item_name, theme_item_data_name, class_name
  241. ),
  242. self,
  243. )
  244. continue
  245. default_value = theme_item.get("default") or None
  246. if default_value is not None:
  247. default_value = "``{}``".format(default_value)
  248. theme_item_def = ThemeItemDef(
  249. theme_item_name,
  250. TypeName.from_element(theme_item),
  251. theme_item_data_name,
  252. theme_item.text,
  253. default_value,
  254. )
  255. class_def.theme_items[theme_item_id] = theme_item_def
  256. tutorials = class_root.find("tutorials")
  257. if tutorials is not None:
  258. for link in tutorials:
  259. assert link.tag == "link"
  260. if link.text is not None:
  261. class_def.tutorials.append((link.text.strip(), link.get("title", "")))
  262. def sort_classes(self): # type: () -> None
  263. self.classes = OrderedDict(sorted(self.classes.items(), key=lambda t: t[0]))
  264. def parse_arguments(root): # type: (ET.Element) -> List[ParameterDef]
  265. param_elements = root.findall("argument")
  266. params = [None] * len(param_elements) # type: Any
  267. for param_element in param_elements:
  268. param_name = param_element.attrib["name"]
  269. index = int(param_element.attrib["index"])
  270. type_name = TypeName.from_element(param_element)
  271. default = param_element.get("default")
  272. params[index] = ParameterDef(param_name, type_name, default)
  273. cast = params # type: List[ParameterDef]
  274. return cast
  275. def main(): # type: () -> None
  276. parser = argparse.ArgumentParser()
  277. parser.add_argument("path", nargs="+", help="A path to an XML file or a directory containing XML files to parse.")
  278. parser.add_argument("--filter", default="", help="The filepath pattern for XML files to filter.")
  279. group = parser.add_mutually_exclusive_group()
  280. group.add_argument("--output", "-o", default=".", help="The directory to save output .rst files in.")
  281. group.add_argument(
  282. "--dry-run",
  283. action="store_true",
  284. help="If passed, no output will be generated and XML files are only checked for errors.",
  285. )
  286. args = parser.parse_args()
  287. print("Checking for errors in the XML class reference...")
  288. file_list = [] # type: List[str]
  289. for path in args.path:
  290. # Cut off trailing slashes so os.path.basename doesn't choke.
  291. if path.endswith(os.sep):
  292. path = path[:-1]
  293. if os.path.basename(path) == "modules":
  294. for subdir, dirs, _ in os.walk(path):
  295. if "doc_classes" in dirs:
  296. doc_dir = os.path.join(subdir, "doc_classes")
  297. class_file_names = (f for f in os.listdir(doc_dir) if f.endswith(".xml"))
  298. file_list += (os.path.join(doc_dir, f) for f in class_file_names)
  299. elif os.path.isdir(path):
  300. file_list += (os.path.join(path, f) for f in os.listdir(path) if f.endswith(".xml"))
  301. elif os.path.isfile(path):
  302. if not path.endswith(".xml"):
  303. print("Got non-.xml file '{}' in input, skipping.".format(path))
  304. continue
  305. file_list.append(path)
  306. classes = {} # type: Dict[str, ET.Element]
  307. state = State()
  308. for cur_file in file_list:
  309. try:
  310. tree = ET.parse(cur_file)
  311. except ET.ParseError as e:
  312. print_error("Parse error reading file '{}': {}".format(cur_file, e), state)
  313. continue
  314. doc = tree.getroot()
  315. if "version" not in doc.attrib:
  316. print_error("Version missing from 'doc', file: {}".format(cur_file), state)
  317. continue
  318. name = doc.attrib["name"]
  319. if name in classes:
  320. print_error("Duplicate class '{}'".format(name), state)
  321. continue
  322. classes[name] = (doc, cur_file)
  323. for name, data in classes.items():
  324. try:
  325. state.parse_class(data[0], data[1])
  326. except Exception as e:
  327. print_error("Exception while parsing class '{}': {}".format(name, e), state)
  328. state.sort_classes()
  329. pattern = re.compile(args.filter)
  330. # Create the output folder recursively if it doesn't already exist.
  331. os.makedirs(args.output, exist_ok=True)
  332. for class_name, class_def in state.classes.items():
  333. if args.filter and not pattern.search(class_def.filepath):
  334. continue
  335. state.current_class = class_name
  336. make_rst_class(class_def, state, args.dry_run, args.output)
  337. if not state.errored:
  338. print("No errors found.")
  339. if not args.dry_run:
  340. print("Wrote reStructuredText files for each class to: %s" % args.output)
  341. else:
  342. print("Errors were found in the class reference XML. Please check the messages above.")
  343. exit(1)
  344. def make_rst_class(class_def, state, dry_run, output_dir): # type: (ClassDef, State, bool, str) -> None
  345. class_name = class_def.name
  346. if dry_run:
  347. f = open(os.devnull, "w", encoding="utf-8")
  348. else:
  349. f = open(os.path.join(output_dir, "class_" + class_name.lower() + ".rst"), "w", encoding="utf-8")
  350. # Warn contributors not to edit this file directly
  351. f.write(":github_url: hide\n\n")
  352. f.write(".. Generated automatically by doc/tools/make_rst.py in Godot's source tree.\n")
  353. f.write(".. DO NOT EDIT THIS FILE, but the " + class_name + ".xml source instead.\n")
  354. f.write(".. The source is found in doc/classes or modules/<name>/doc_classes.\n\n")
  355. f.write(".. _class_" + class_name + ":\n\n")
  356. f.write(make_heading(class_name, "="))
  357. # Inheritance tree
  358. # Ascendants
  359. if class_def.inherits:
  360. inh = class_def.inherits.strip()
  361. f.write("**Inherits:** ")
  362. first = True
  363. while inh in state.classes:
  364. if not first:
  365. f.write(" **<** ")
  366. else:
  367. first = False
  368. f.write(make_type(inh, state))
  369. inode = state.classes[inh].inherits
  370. if inode:
  371. inh = inode.strip()
  372. else:
  373. break
  374. f.write("\n\n")
  375. # Descendents
  376. inherited = []
  377. for c in state.classes.values():
  378. if c.inherits and c.inherits.strip() == class_name:
  379. inherited.append(c.name)
  380. if len(inherited):
  381. f.write("**Inherited By:** ")
  382. for i, child in enumerate(inherited):
  383. if i > 0:
  384. f.write(", ")
  385. f.write(make_type(child, state))
  386. f.write("\n\n")
  387. # Brief description
  388. if class_def.brief_description is not None:
  389. f.write(rstize_text(class_def.brief_description.strip(), state) + "\n\n")
  390. # Class description
  391. if class_def.description is not None and class_def.description.strip() != "":
  392. f.write(make_heading("Description", "-"))
  393. f.write(rstize_text(class_def.description.strip(), state) + "\n\n")
  394. # Online tutorials
  395. if len(class_def.tutorials) > 0:
  396. f.write(make_heading("Tutorials", "-"))
  397. for url, title in class_def.tutorials:
  398. f.write("- " + make_link(url, title) + "\n\n")
  399. # Properties overview
  400. if len(class_def.properties) > 0:
  401. f.write(make_heading("Properties", "-"))
  402. ml = [] # type: List[Tuple[str, str, str]]
  403. for property_def in class_def.properties.values():
  404. type_rst = property_def.type_name.to_rst(state)
  405. default = property_def.default_value
  406. if default is not None and property_def.overridden:
  407. ml.append((type_rst, property_def.name, default + " *(parent override)*"))
  408. else:
  409. ref = ":ref:`{0}<class_{1}_property_{0}>`".format(property_def.name, class_name)
  410. ml.append((type_rst, ref, default))
  411. format_table(f, ml, True)
  412. # Constructors, Methods, Operators overview
  413. if len(class_def.constructors) > 0:
  414. f.write(make_heading("Constructors", "-"))
  415. ml = []
  416. for method_list in class_def.constructors.values():
  417. for m in method_list:
  418. ml.append(make_method_signature(class_def, m, "constructor", state))
  419. format_table(f, ml)
  420. if len(class_def.methods) > 0:
  421. f.write(make_heading("Methods", "-"))
  422. ml = []
  423. for method_list in class_def.methods.values():
  424. for m in method_list:
  425. ml.append(make_method_signature(class_def, m, "method", state))
  426. format_table(f, ml)
  427. if len(class_def.operators) > 0:
  428. f.write(make_heading("Operators", "-"))
  429. ml = []
  430. for method_list in class_def.operators.values():
  431. for m in method_list:
  432. ml.append(make_method_signature(class_def, m, "operator", state))
  433. format_table(f, ml)
  434. # Theme properties
  435. if len(class_def.theme_items) > 0:
  436. f.write(make_heading("Theme Properties", "-"))
  437. pl = []
  438. for theme_item_def in class_def.theme_items.values():
  439. ref = ":ref:`{0}<class_{2}_theme_{1}_{0}>`".format(
  440. theme_item_def.name, theme_item_def.data_name, class_name
  441. )
  442. pl.append((theme_item_def.type_name.to_rst(state), ref, theme_item_def.default_value))
  443. format_table(f, pl, True)
  444. # Signals
  445. if len(class_def.signals) > 0:
  446. f.write(make_heading("Signals", "-"))
  447. index = 0
  448. for signal in class_def.signals.values():
  449. if index != 0:
  450. f.write("----\n\n")
  451. f.write(".. _class_{}_signal_{}:\n\n".format(class_name, signal.name))
  452. _, signature = make_method_signature(class_def, signal, "", state)
  453. f.write("- {}\n\n".format(signature))
  454. if signal.description is not None and signal.description.strip() != "":
  455. f.write(rstize_text(signal.description.strip(), state) + "\n\n")
  456. index += 1
  457. # Enums
  458. if len(class_def.enums) > 0:
  459. f.write(make_heading("Enumerations", "-"))
  460. index = 0
  461. for e in class_def.enums.values():
  462. if index != 0:
  463. f.write("----\n\n")
  464. f.write(".. _enum_{}_{}:\n\n".format(class_name, e.name))
  465. # Sphinx seems to divide the bullet list into individual <ul> tags if we weave the labels into it.
  466. # As such I'll put them all above the list. Won't be perfect but better than making the list visually broken.
  467. # As to why I'm not modifying the reference parser to directly link to the _enum label:
  468. # If somebody gets annoyed enough to fix it, all existing references will magically improve.
  469. for value in e.values.values():
  470. f.write(".. _class_{}_constant_{}:\n\n".format(class_name, value.name))
  471. f.write("enum **{}**:\n\n".format(e.name))
  472. for value in e.values.values():
  473. f.write("- **{}** = **{}**".format(value.name, value.value))
  474. if value.text is not None and value.text.strip() != "":
  475. f.write(" --- " + rstize_text(value.text.strip(), state))
  476. f.write("\n\n")
  477. index += 1
  478. # Constants
  479. if len(class_def.constants) > 0:
  480. f.write(make_heading("Constants", "-"))
  481. # Sphinx seems to divide the bullet list into individual <ul> tags if we weave the labels into it.
  482. # As such I'll put them all above the list. Won't be perfect but better than making the list visually broken.
  483. for constant in class_def.constants.values():
  484. f.write(".. _class_{}_constant_{}:\n\n".format(class_name, constant.name))
  485. for constant in class_def.constants.values():
  486. f.write("- **{}** = **{}**".format(constant.name, constant.value))
  487. if constant.text is not None and constant.text.strip() != "":
  488. f.write(" --- " + rstize_text(constant.text.strip(), state))
  489. f.write("\n\n")
  490. # Property descriptions
  491. if any(not p.overridden for p in class_def.properties.values()) > 0:
  492. f.write(make_heading("Property Descriptions", "-"))
  493. index = 0
  494. for property_def in class_def.properties.values():
  495. if property_def.overridden:
  496. continue
  497. if index != 0:
  498. f.write("----\n\n")
  499. f.write(".. _class_{}_property_{}:\n\n".format(class_name, property_def.name))
  500. f.write("- {} **{}**\n\n".format(property_def.type_name.to_rst(state), property_def.name))
  501. info = []
  502. if property_def.default_value is not None:
  503. info.append(("*Default*", property_def.default_value))
  504. if property_def.setter is not None and not property_def.setter.startswith("_"):
  505. info.append(("*Setter*", property_def.setter + "(value)"))
  506. if property_def.getter is not None and not property_def.getter.startswith("_"):
  507. info.append(("*Getter*", property_def.getter + "()"))
  508. if len(info) > 0:
  509. format_table(f, info)
  510. if property_def.text is not None and property_def.text.strip() != "":
  511. f.write(rstize_text(property_def.text.strip(), state) + "\n\n")
  512. index += 1
  513. # Constructor, Method, Operator descriptions
  514. if len(class_def.constructors) > 0:
  515. f.write(make_heading("Constructor Descriptions", "-"))
  516. index = 0
  517. for method_list in class_def.constructors.values():
  518. for i, m in enumerate(method_list):
  519. if index != 0:
  520. f.write("----\n\n")
  521. if i == 0:
  522. f.write(".. _class_{}_constructor_{}:\n\n".format(class_name, m.name))
  523. ret_type, signature = make_method_signature(class_def, m, "", state)
  524. f.write("- {} {}\n\n".format(ret_type, signature))
  525. if m.description is not None and m.description.strip() != "":
  526. f.write(rstize_text(m.description.strip(), state) + "\n\n")
  527. index += 1
  528. if len(class_def.methods) > 0:
  529. f.write(make_heading("Method Descriptions", "-"))
  530. index = 0
  531. for method_list in class_def.methods.values():
  532. for i, m in enumerate(method_list):
  533. if index != 0:
  534. f.write("----\n\n")
  535. if i == 0:
  536. f.write(".. _class_{}_method_{}:\n\n".format(class_name, m.name))
  537. ret_type, signature = make_method_signature(class_def, m, "", state)
  538. f.write("- {} {}\n\n".format(ret_type, signature))
  539. if m.description is not None and m.description.strip() != "":
  540. f.write(rstize_text(m.description.strip(), state) + "\n\n")
  541. index += 1
  542. if len(class_def.operators) > 0:
  543. f.write(make_heading("Operator Descriptions", "-"))
  544. index = 0
  545. for method_list in class_def.operators.values():
  546. for i, m in enumerate(method_list):
  547. if index != 0:
  548. f.write("----\n\n")
  549. if i == 0:
  550. f.write(
  551. ".. _class_{}_operator_{}_{}:\n\n".format(
  552. class_name, sanitize_operator_name(m.name, state), m.return_type.type_name
  553. )
  554. )
  555. ret_type, signature = make_method_signature(class_def, m, "", state)
  556. f.write("- {} {}\n\n".format(ret_type, signature))
  557. if m.description is not None and m.description.strip() != "":
  558. f.write(rstize_text(m.description.strip(), state) + "\n\n")
  559. index += 1
  560. # Theme property descriptions
  561. if len(class_def.theme_items) > 0:
  562. f.write(make_heading("Theme Property Descriptions", "-"))
  563. index = 0
  564. for theme_item_def in class_def.theme_items.values():
  565. if index != 0:
  566. f.write("----\n\n")
  567. f.write(".. _class_{}_theme_{}_{}:\n\n".format(class_name, theme_item_def.data_name, theme_item_def.name))
  568. f.write("- {} **{}**\n\n".format(theme_item_def.type_name.to_rst(state), theme_item_def.name))
  569. info = []
  570. if theme_item_def.default_value is not None:
  571. info.append(("*Default*", theme_item_def.default_value))
  572. if len(info) > 0:
  573. format_table(f, info)
  574. if theme_item_def.text is not None and theme_item_def.text.strip() != "":
  575. f.write(rstize_text(theme_item_def.text.strip(), state) + "\n\n")
  576. index += 1
  577. f.write(make_footer())
  578. def escape_rst(text, until_pos=-1): # type: (str) -> str
  579. # Escape \ character, otherwise it ends up as an escape character in rst
  580. pos = 0
  581. while True:
  582. pos = text.find("\\", pos, until_pos)
  583. if pos == -1:
  584. break
  585. text = text[:pos] + "\\\\" + text[pos + 1 :]
  586. pos += 2
  587. # Escape * character to avoid interpreting it as emphasis
  588. pos = 0
  589. while True:
  590. pos = text.find("*", pos, until_pos)
  591. if pos == -1:
  592. break
  593. text = text[:pos] + "\*" + text[pos + 1 :]
  594. pos += 2
  595. # Escape _ character at the end of a word to avoid interpreting it as an inline hyperlink
  596. pos = 0
  597. while True:
  598. pos = text.find("_", pos, until_pos)
  599. if pos == -1:
  600. break
  601. if not text[pos + 1].isalnum(): # don't escape within a snake_case word
  602. text = text[:pos] + "\_" + text[pos + 1 :]
  603. pos += 2
  604. else:
  605. pos += 1
  606. return text
  607. def format_codeblock(code_type, post_text, indent_level, state): # types: str, str, int, state
  608. end_pos = post_text.find("[/" + code_type + "]")
  609. if end_pos == -1:
  610. print_error("[" + code_type + "] without a closing tag, file: {}".format(state.current_class), state)
  611. return None
  612. code_text = post_text[len("[" + code_type + "]") : end_pos]
  613. post_text = post_text[end_pos:]
  614. # Remove extraneous tabs
  615. code_pos = 0
  616. while True:
  617. code_pos = code_text.find("\n", code_pos)
  618. if code_pos == -1:
  619. break
  620. to_skip = 0
  621. while code_pos + to_skip + 1 < len(code_text) and code_text[code_pos + to_skip + 1] == "\t":
  622. to_skip += 1
  623. if to_skip > indent_level:
  624. print_error(
  625. "Four spaces should be used for indentation within ["
  626. + code_type
  627. + "], file: {}".format(state.current_class),
  628. state,
  629. )
  630. if len(code_text[code_pos + to_skip + 1 :]) == 0:
  631. code_text = code_text[:code_pos] + "\n"
  632. code_pos += 1
  633. else:
  634. code_text = code_text[:code_pos] + "\n " + code_text[code_pos + to_skip + 1 :]
  635. code_pos += 5 - to_skip
  636. return ["\n[" + code_type + "]" + code_text + post_text, len("\n[" + code_type + "]" + code_text)]
  637. def rstize_text(text, state): # type: (str, State) -> str
  638. # Linebreak + tabs in the XML should become two line breaks unless in a "codeblock"
  639. pos = 0
  640. while True:
  641. pos = text.find("\n", pos)
  642. if pos == -1:
  643. break
  644. pre_text = text[:pos]
  645. indent_level = 0
  646. while text[pos + 1] == "\t":
  647. pos += 1
  648. indent_level += 1
  649. post_text = text[pos + 1 :]
  650. # Handle codeblocks
  651. if (
  652. post_text.startswith("[codeblock]")
  653. or post_text.startswith("[gdscript]")
  654. or post_text.startswith("[csharp]")
  655. ):
  656. block_type = post_text[1:].split("]")[0]
  657. result = format_codeblock(block_type, post_text, indent_level, state)
  658. if result is None:
  659. return ""
  660. text = pre_text + result[0]
  661. pos += result[1]
  662. # Handle normal text
  663. else:
  664. text = pre_text + "\n\n" + post_text
  665. pos += 2
  666. next_brac_pos = text.find("[")
  667. text = escape_rst(text, next_brac_pos)
  668. # Handle [tags]
  669. inside_code = False
  670. inside_url = False
  671. url_has_name = False
  672. url_link = ""
  673. pos = 0
  674. tag_depth = 0
  675. previous_pos = 0
  676. while True:
  677. pos = text.find("[", pos)
  678. if inside_url and (pos > previous_pos):
  679. url_has_name = True
  680. if pos == -1:
  681. break
  682. endq_pos = text.find("]", pos + 1)
  683. if endq_pos == -1:
  684. break
  685. pre_text = text[:pos]
  686. post_text = text[endq_pos + 1 :]
  687. tag_text = text[pos + 1 : endq_pos]
  688. escape_post = False
  689. if tag_text in state.classes:
  690. if tag_text == state.current_class:
  691. # We don't want references to the same class
  692. tag_text = "``{}``".format(tag_text)
  693. else:
  694. tag_text = make_type(tag_text, state)
  695. escape_post = True
  696. else: # command
  697. cmd = tag_text
  698. space_pos = tag_text.find(" ")
  699. if cmd == "/codeblock" or cmd == "/gdscript" or cmd == "/csharp":
  700. tag_text = ""
  701. tag_depth -= 1
  702. inside_code = False
  703. # Strip newline if the tag was alone on one
  704. if pre_text[-1] == "\n":
  705. pre_text = pre_text[:-1]
  706. elif cmd == "/code":
  707. tag_text = "``"
  708. tag_depth -= 1
  709. inside_code = False
  710. escape_post = True
  711. elif inside_code:
  712. tag_text = "[" + tag_text + "]"
  713. elif cmd.find("html") == 0:
  714. param = tag_text[space_pos + 1 :]
  715. tag_text = param
  716. elif (
  717. cmd.startswith("method")
  718. or cmd.startswith("member")
  719. or cmd.startswith("signal")
  720. or cmd.startswith("constant")
  721. ):
  722. param = tag_text[space_pos + 1 :]
  723. if param.find(".") != -1:
  724. ss = param.split(".")
  725. if len(ss) > 2:
  726. print_error("Bad reference: '{}', file: {}".format(param, state.current_class), state)
  727. class_param, method_param = ss
  728. else:
  729. class_param = state.current_class
  730. method_param = param
  731. ref_type = ""
  732. if class_param in state.classes:
  733. class_def = state.classes[class_param]
  734. if cmd.startswith("constructor"):
  735. if method_param not in class_def.constructors:
  736. print_error(
  737. "Unresolved constructor '{}', file: {}".format(param, state.current_class), state
  738. )
  739. ref_type = "_constructor"
  740. if cmd.startswith("method"):
  741. if method_param not in class_def.methods:
  742. print_error("Unresolved method '{}', file: {}".format(param, state.current_class), state)
  743. ref_type = "_method"
  744. if cmd.startswith("operator"):
  745. if method_param not in class_def.operators:
  746. print_error("Unresolved operator '{}', file: {}".format(param, state.current_class), state)
  747. ref_type = "_operator"
  748. elif cmd.startswith("member"):
  749. if method_param not in class_def.properties:
  750. print_error("Unresolved member '{}', file: {}".format(param, state.current_class), state)
  751. ref_type = "_property"
  752. elif cmd.startswith("signal"):
  753. if method_param not in class_def.signals:
  754. print_error("Unresolved signal '{}', file: {}".format(param, state.current_class), state)
  755. ref_type = "_signal"
  756. elif cmd.startswith("constant"):
  757. found = False
  758. # Search in the current class
  759. search_class_defs = [class_def]
  760. if param.find(".") == -1:
  761. # Also search in @GlobalScope as a last resort if no class was specified
  762. search_class_defs.append(state.classes["@GlobalScope"])
  763. for search_class_def in search_class_defs:
  764. if method_param in search_class_def.constants:
  765. class_param = search_class_def.name
  766. found = True
  767. else:
  768. for enum in search_class_def.enums.values():
  769. if method_param in enum.values:
  770. class_param = search_class_def.name
  771. found = True
  772. break
  773. if not found:
  774. print_error("Unresolved constant '{}', file: {}".format(param, state.current_class), state)
  775. ref_type = "_constant"
  776. else:
  777. print_error(
  778. "Unresolved type reference '{}' in method reference '{}', file: {}".format(
  779. class_param, param, state.current_class
  780. ),
  781. state,
  782. )
  783. repl_text = method_param
  784. if class_param != state.current_class:
  785. repl_text = "{}.{}".format(class_param, method_param)
  786. tag_text = ":ref:`{}<class_{}{}_{}>`".format(repl_text, class_param, ref_type, method_param)
  787. escape_post = True
  788. elif cmd.find("image=") == 0:
  789. tag_text = "" # '![](' + cmd[6:] + ')'
  790. elif cmd.find("url=") == 0:
  791. url_link = cmd[4:]
  792. tag_text = "`"
  793. tag_depth += 1
  794. inside_url = True
  795. url_has_name = False
  796. elif cmd == "/url":
  797. tag_text = ("" if url_has_name else url_link) + " <" + url_link + ">`__"
  798. tag_depth -= 1
  799. escape_post = True
  800. inside_url = False
  801. url_has_name = False
  802. elif cmd == "center":
  803. tag_depth += 1
  804. tag_text = ""
  805. elif cmd == "/center":
  806. tag_depth -= 1
  807. tag_text = ""
  808. elif cmd == "codeblock":
  809. tag_depth += 1
  810. tag_text = "\n::\n"
  811. inside_code = True
  812. elif cmd == "gdscript":
  813. tag_depth += 1
  814. tag_text = "\n .. code-tab:: gdscript\n"
  815. inside_code = True
  816. elif cmd == "csharp":
  817. tag_depth += 1
  818. tag_text = "\n .. code-tab:: csharp\n"
  819. inside_code = True
  820. elif cmd == "codeblocks":
  821. tag_depth += 1
  822. tag_text = "\n.. tabs::"
  823. elif cmd == "/codeblocks":
  824. tag_depth -= 1
  825. tag_text = ""
  826. elif cmd == "br":
  827. # Make a new paragraph instead of a linebreak, rst is not so linebreak friendly
  828. tag_text = "\n\n"
  829. # Strip potential leading spaces
  830. while post_text[0] == " ":
  831. post_text = post_text[1:]
  832. elif cmd == "i" or cmd == "/i":
  833. if cmd == "/i":
  834. tag_depth -= 1
  835. else:
  836. tag_depth += 1
  837. tag_text = "*"
  838. elif cmd == "b" or cmd == "/b":
  839. if cmd == "/b":
  840. tag_depth -= 1
  841. else:
  842. tag_depth += 1
  843. tag_text = "**"
  844. elif cmd == "u" or cmd == "/u":
  845. if cmd == "/u":
  846. tag_depth -= 1
  847. else:
  848. tag_depth += 1
  849. tag_text = ""
  850. elif cmd == "code":
  851. tag_text = "``"
  852. tag_depth += 1
  853. inside_code = True
  854. elif cmd == "kbd":
  855. tag_text = ":kbd:`"
  856. tag_depth += 1
  857. elif cmd == "/kbd":
  858. tag_text = "`"
  859. tag_depth -= 1
  860. elif cmd.startswith("enum "):
  861. tag_text = make_enum(cmd[5:], state)
  862. escape_post = True
  863. else:
  864. tag_text = make_type(tag_text, state)
  865. escape_post = True
  866. # Properly escape things like `[Node]s`
  867. if escape_post and post_text and (post_text[0].isalnum() or post_text[0] == "("): # not punctuation, escape
  868. post_text = "\ " + post_text
  869. next_brac_pos = post_text.find("[", 0)
  870. iter_pos = 0
  871. while not inside_code:
  872. iter_pos = post_text.find("*", iter_pos, next_brac_pos)
  873. if iter_pos == -1:
  874. break
  875. post_text = post_text[:iter_pos] + "\*" + post_text[iter_pos + 1 :]
  876. iter_pos += 2
  877. iter_pos = 0
  878. while not inside_code:
  879. iter_pos = post_text.find("_", iter_pos, next_brac_pos)
  880. if iter_pos == -1:
  881. break
  882. if not post_text[iter_pos + 1].isalnum(): # don't escape within a snake_case word
  883. post_text = post_text[:iter_pos] + "\_" + post_text[iter_pos + 1 :]
  884. iter_pos += 2
  885. else:
  886. iter_pos += 1
  887. text = pre_text + tag_text + post_text
  888. pos = len(pre_text) + len(tag_text)
  889. previous_pos = pos
  890. if tag_depth > 0:
  891. print_error("Tag depth mismatch: too many/little open/close tags, file: {}".format(state.current_class), state)
  892. return text
  893. def format_table(f, data, remove_empty_columns=False): # type: (TextIO, Iterable[Tuple[str, ...]]) -> None
  894. if len(data) == 0:
  895. return
  896. column_sizes = [0] * len(data[0])
  897. for row in data:
  898. for i, text in enumerate(row):
  899. text_length = len(text or "")
  900. if text_length > column_sizes[i]:
  901. column_sizes[i] = text_length
  902. sep = ""
  903. for size in column_sizes:
  904. if size == 0 and remove_empty_columns:
  905. continue
  906. sep += "+" + "-" * (size + 2)
  907. sep += "+\n"
  908. f.write(sep)
  909. for row in data:
  910. row_text = "|"
  911. for i, text in enumerate(row):
  912. if column_sizes[i] == 0 and remove_empty_columns:
  913. continue
  914. row_text += " " + (text or "").ljust(column_sizes[i]) + " |"
  915. row_text += "\n"
  916. f.write(row_text)
  917. f.write(sep)
  918. f.write("\n")
  919. def make_type(klass, state): # type: (str, State) -> str
  920. if klass.find("*") != -1: # Pointer, ignore
  921. return klass
  922. link_type = klass
  923. if link_type.endswith("[]"): # Typed array, strip [] to link to contained type.
  924. link_type = link_type[:-2]
  925. if link_type in state.classes:
  926. return ":ref:`{}<class_{}>`".format(klass, link_type)
  927. print_error("Unresolved type '{}', file: {}".format(klass, state.current_class), state)
  928. return klass
  929. def make_enum(t, state): # type: (str, State) -> str
  930. p = t.find(".")
  931. if p >= 0:
  932. c = t[0:p]
  933. e = t[p + 1 :]
  934. # Variant enums live in GlobalScope but still use periods.
  935. if c == "Variant":
  936. c = "@GlobalScope"
  937. e = "Variant." + e
  938. else:
  939. c = state.current_class
  940. e = t
  941. if c in state.classes and e not in state.classes[c].enums:
  942. c = "@GlobalScope"
  943. if c in state.classes and e in state.classes[c].enums:
  944. return ":ref:`{0}<enum_{1}_{0}>`".format(e, c)
  945. # Don't fail for `Vector3.Axis`, as this enum is a special case which is expected not to be resolved.
  946. if "{}.{}".format(c, e) != "Vector3.Axis":
  947. print_error("Unresolved enum '{}', file: {}".format(t, state.current_class), state)
  948. return t
  949. def make_method_signature(
  950. class_def, method_def, ref_type, state
  951. ): # type: (ClassDef, Union[MethodDef, SignalDef], str, State) -> Tuple[str, str]
  952. ret_type = " "
  953. if isinstance(method_def, MethodDef):
  954. ret_type = method_def.return_type.to_rst(state)
  955. out = ""
  956. if ref_type != "":
  957. if ref_type == "operator":
  958. out += ":ref:`{0}<class_{1}_{2}_{3}_{4}>` ".format(
  959. method_def.name,
  960. class_def.name,
  961. ref_type,
  962. sanitize_operator_name(method_def.name, state),
  963. method_def.return_type.type_name,
  964. )
  965. else:
  966. out += ":ref:`{0}<class_{1}_{2}_{0}>` ".format(method_def.name, class_def.name, ref_type)
  967. else:
  968. out += "**{}** ".format(method_def.name)
  969. out += "**(**"
  970. for i, arg in enumerate(method_def.parameters):
  971. if i > 0:
  972. out += ", "
  973. else:
  974. out += " "
  975. out += "{} {}".format(arg.type_name.to_rst(state), arg.name)
  976. if arg.default_value is not None:
  977. out += "=" + arg.default_value
  978. if isinstance(method_def, MethodDef) and method_def.qualifiers is not None and "vararg" in method_def.qualifiers:
  979. if len(method_def.parameters) > 0:
  980. out += ", ..."
  981. else:
  982. out += " ..."
  983. out += " **)**"
  984. if isinstance(method_def, MethodDef) and method_def.qualifiers is not None:
  985. # Use substitutions for abbreviations. This is used to display tooltips on hover.
  986. # See `make_footer()` for descriptions.
  987. for qualifier in method_def.qualifiers.split():
  988. out += " |" + qualifier + "|"
  989. return ret_type, out
  990. def make_heading(title, underline): # type: (str, str) -> str
  991. return title + "\n" + (underline * len(title)) + "\n\n"
  992. def make_footer(): # type: () -> str
  993. # Generate reusable abbreviation substitutions.
  994. # This way, we avoid bloating the generated rST with duplicate abbreviations.
  995. # fmt: off
  996. return (
  997. ".. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`\n"
  998. ".. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`\n"
  999. ".. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`\n"
  1000. ".. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`\n"
  1001. ".. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`\n"
  1002. ".. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`\n"
  1003. )
  1004. # fmt: on
  1005. def make_link(url, title): # type: (str, str) -> str
  1006. match = GODOT_DOCS_PATTERN.search(url)
  1007. if match:
  1008. groups = match.groups()
  1009. if match.lastindex == 2:
  1010. # Doc reference with fragment identifier: emit direct link to section with reference to page, for example:
  1011. # `#calling-javascript-from-script in Exporting For Web`
  1012. return "`" + groups[1] + " <../" + groups[0] + ".html" + groups[1] + ">`_ in :doc:`../" + groups[0] + "`"
  1013. # Commented out alternative: Instead just emit:
  1014. # `Subsection in Exporting For Web`
  1015. # return "`Subsection <../" + groups[0] + ".html" + groups[1] + ">`__ in :doc:`../" + groups[0] + "`"
  1016. elif match.lastindex == 1:
  1017. # Doc reference, for example:
  1018. # `Math`
  1019. return ":doc:`../" + groups[0] + "`"
  1020. else:
  1021. # External link, for example:
  1022. # `http://enet.bespin.org/usergroup0.html`
  1023. if title != "":
  1024. return "`" + title + " <" + url + ">`__"
  1025. else:
  1026. return "`" + url + " <" + url + ">`__"
  1027. def sanitize_operator_name(dirty_name, state): # type: (str, State) -> str
  1028. clear_name = dirty_name.replace("operator ", "")
  1029. if clear_name == "!=":
  1030. clear_name = "neq"
  1031. elif clear_name == "==":
  1032. clear_name = "eq"
  1033. elif clear_name == "<":
  1034. clear_name = "lt"
  1035. elif clear_name == "<=":
  1036. clear_name = "lte"
  1037. elif clear_name == ">":
  1038. clear_name = "gt"
  1039. elif clear_name == ">=":
  1040. clear_name = "gte"
  1041. elif clear_name == "+":
  1042. clear_name = "sum"
  1043. elif clear_name == "-":
  1044. clear_name = "dif"
  1045. elif clear_name == "*":
  1046. clear_name = "mul"
  1047. elif clear_name == "/":
  1048. clear_name = "div"
  1049. elif clear_name == "%":
  1050. clear_name = "mod"
  1051. elif clear_name == "unary+":
  1052. clear_name = "unplus"
  1053. elif clear_name == "unary-":
  1054. clear_name = "unminus"
  1055. elif clear_name == "<<":
  1056. clear_name = "bwsl"
  1057. elif clear_name == ">>":
  1058. clear_name = "bwsr"
  1059. elif clear_name == "&":
  1060. clear_name = "bwand"
  1061. elif clear_name == "|":
  1062. clear_name = "bwor"
  1063. elif clear_name == "^":
  1064. clear_name = "bwxor"
  1065. elif clear_name == "~":
  1066. clear_name = "bwnot"
  1067. elif clear_name == "[]":
  1068. clear_name = "idx"
  1069. else:
  1070. clear_name = "xxx"
  1071. print_error("Unsupported operator type '{}', please add the missing rule.".format(dirty_name), state)
  1072. return clear_name
  1073. if __name__ == "__main__":
  1074. main()