Angular analysis of B+->K*+(K+pi0)mumu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

217 lines
7.3 KiB

  1. import sys
  2. import re
  3. #First argument is the filename
  4. fileName = sys.argv[1]
  5. def stopLoopLinesClass(line):
  6. if ("public" in line): return True
  7. if ("private" in line): return True
  8. if ("(" in line): return True
  9. if (")" in line): return True
  10. if ("}" in line): return True
  11. return False
  12. def FormatClasses(class_full):
  13. class_full = re.split("\n",class_full)
  14. name = class_full[0].replace("class ","")[0:-1]
  15. public_vars = []
  16. private_vars = []
  17. functions = []
  18. for idx,line in enumerate(class_full[1:]):
  19. line = line[4:] #Remove the indent
  20. if (line.startswith(" ")): continue
  21. if (line.startswith("public:") or line.startswith("ic:")):
  22. idx = idx+1
  23. while (not stopLoopLinesClass(class_full[idx+1])):
  24. public_vars.append(class_full[idx+1].lstrip())
  25. idx = idx+1
  26. if (line.startswith("private:") or line.startswith("te:")):
  27. idx = idx+1
  28. while (not stopLoopLinesClass(class_full[idx+1])):
  29. private_vars.append(class_full[idx].lstrip())
  30. idx = idx+1
  31. if ("(" in line):
  32. tmp = line
  33. if (")" not in line):
  34. while (")" not in class_full[idx]):
  35. tmp = tmp + class_full[idx].strip()
  36. idx = idx+1
  37. tmp = tmp + class_full[idx].strip()
  38. functions.append(tmp)
  39. return name, public_vars, private_vars, functions
  40. def isPythonFile(fileName):
  41. if (fileName.endswith(".py")):
  42. return True
  43. else:
  44. return False
  45. def ReadFile(fileName): #Returns the read lines and an integer, that is true when the file if a python file
  46. with open(fileName) as f:
  47. lines = f.readlines()
  48. return lines
  49. def AddCommentWithLink(functionName, isPython):
  50. #Strip the data type from the title and add ()
  51. functionTitle = functionName
  52. if (not isPython): functionTitle = functionTitle[functionTitle.rfind(' '):]
  53. # Now parse the name to create the link
  54. functionLink = functionName
  55. for symbol in [" ","::"]:
  56. functionLink = functionLink.replace(symbol,"-")
  57. for symbol in ["(",")","\*","*"]:
  58. functionLink = functionLink.replace(symbol,"-")
  59. #Print the reference as it would be used in text
  60. return ("[comment]: # (["+functionTitle.strip()+"()](#" + functionLink.lower()+ "))")
  61. def ReadCpp(lines):
  62. globals_list = []
  63. function_list = []
  64. classes_list = []
  65. for idx,line in enumerate(lines):
  66. if (line.startswith(" ")): continue
  67. if (line.startswith("}")): continue
  68. if (line.startswith("//")): continue
  69. if (line.startswith("#")): continue
  70. if (line.startswith("using")): continue
  71. if (line.startswith("class")):
  72. tmp = ""
  73. while ("};" not in lines[idx]):
  74. tmp = tmp + lines[idx]
  75. idx = idx+1
  76. tmp = tmp + lines[idx].strip()
  77. classes_list.append(tmp)
  78. if (line.startswith("struct")):
  79. tmp = ""
  80. while ("}" not in lines[idx]):
  81. tmp = tmp + lines[idx]
  82. idx = idx+1
  83. tmp = tmp + lines[idx].strip()
  84. classes_list.append(tmp)
  85. if (line.isspace()): continue
  86. if ("(" not in line): globals_list.append(line.strip())
  87. elif (")" not in line):
  88. tmp = ""
  89. while (")" not in lines[idx]):
  90. tmp = tmp + lines[idx].strip()
  91. idx = idx+1
  92. tmp = tmp + lines[idx].strip()
  93. function_list.append(tmp)
  94. else: function_list.append(line.strip())
  95. for cl in classes_list: FormatClasses(cl)
  96. globals = []
  97. for glob in globals_list:
  98. glob = glob.replace(";","")
  99. for tmp in glob.split(','): globals.append(tmp.lstrip())
  100. print("\n\n## Global variables:\n")
  101. for tmp in globals: print("* "+tmp)
  102. print("\n\n# Classes")
  103. for cl in classes_list:
  104. name, pub, priv, funcs = FormatClasses(cl)
  105. print ("### "+name)
  106. print ("* **Private members:**")
  107. for p in priv:
  108. print(" * "+ p.replace(";",""))
  109. print ("* **Public members:**")
  110. for p in pub:
  111. print(" * "+ p.replace(";",""))
  112. print ("* **Functions:**")
  113. for f in funcs:
  114. f = f.replace("){","")
  115. f = f.replace(") {","")
  116. f = f.replace("*","\*")
  117. funcs = f.split("(")
  118. funcs[1] = funcs[1].split(',')
  119. if (len(funcs[1])>0) and (funcs[1][0].strip()!=""):
  120. print(" * **"+funcs[0]+"()**\n")
  121. print (AddCommentWithLink(funcs[0],False))
  122. print(" * **Parameters**")
  123. for params in funcs[1]:
  124. print(" * "+params.lstrip())
  125. print(" * **Return**")
  126. elif ("~" in funcs[0]): print(" * **"+funcs[0]+"()** // destructor")
  127. else: print(" * **"+funcs[0]+"()** // constructor")
  128. print("\n\n\n# Functions")
  129. functions = []
  130. for funcs in function_list:
  131. funcs = funcs.replace("){","")
  132. funcs = funcs.replace(") {","")
  133. funcs = funcs.replace("*","\*")
  134. functions = funcs.split("(")
  135. functions[1] = functions[1].split(',')
  136. print("### "+functions[0]+"()")
  137. print(AddCommentWithLink(functions[0],False)+"\n")
  138. print("* **Parameters**")
  139. for params in functions[1]:
  140. print(" * "+params.lstrip())
  141. if ("void " not in functions[0]): print("* **Return**\n")
  142. else: print("\n")
  143. return
  144. def ReadPython(lines):
  145. globals_list = []
  146. function_list = []
  147. classes_list = []
  148. for idx,line in enumerate(lines):
  149. if (line.startswith(" ")): continue
  150. if (line.startswith("#")): continue #Remove comments
  151. if (line.startswith("import")): continue
  152. if (line == "\n"): continue #Remove empty lines
  153. if (line.startswith("def")):
  154. line = line.replace(":","")
  155. if (")" not in line):
  156. tmp = ""
  157. while (")" not in lines[idx]):
  158. tmp = tmp + lines[idx].strip()
  159. idx = idx+1
  160. tmp = tmp + lines[idx].strip()
  161. function_list.append(tmp)
  162. else: function_list.append(line.strip())
  163. else:
  164. globals_list.append(line.strip())
  165. print("\n\n## Global variables:\n")
  166. for tmp in globals_list: print("* "+tmp)
  167. print("\n\n\n# Functions")
  168. functions = []
  169. for funcs in function_list:
  170. funcs = funcs.replace(")","")
  171. funcs = funcs.replace("def ","")
  172. funcs = funcs.replace("*","\*")
  173. functions = funcs.split("(")
  174. functions[1] = functions[1].split(',')
  175. print("### "+functions[0]+"()\n")
  176. print(AddCommentWithLink(functions[0],True)+"\n")
  177. print("* **Parameters**")
  178. for params in functions[1]:
  179. print(" * "+params.lstrip())
  180. print("* **Return**\n")
  181. return
  182. ##### The main run
  183. if (isPythonFile(fileName)):
  184. ReadPython(ReadFile(fileName))
  185. else :
  186. ReadCpp(ReadFile(fileName))