Loading asn2md.py +22 −5 Original line number Diff line number Diff line Loading @@ -42,6 +42,9 @@ RE_DOXY_C_COMMENTS = re.compile(r'^\s*/\*\*\s(.*?)\*/', re.MULTILINE | re.DOTALL RE_DOXY_C_COMMENTS_I = re.compile(r'\s*\*+') RE_STRIPSTAR = re.compile(r'^\s*\*', re.MULTILINE) RE_POWER_SIGN = re.compile('\^(-?\w+|\(.*?\))') RE_GREATEQ_SIGN = re.compile(r'(?<=\s)>=(?=\s)') RE_LESSEQ_SIGN = re.compile(r'(?<=\s)<=(?=\s)') RE_REFERENCE_NUMBER = re.compile(r'\[(?:i\.)?\d+\]') RE_DOXY_REF = re.compile(r'@ref\s+([\w-]+)') Loading @@ -56,6 +59,7 @@ RE_DOXY_CATEGORY = re.compile(r'^\s*@category[\s:]+(.+)\n', re.MULTILINE) RE_DOXY_PARAM = re.compile(r'^\s*@(?:param|field):?\s+([\w-]+)\s*(.*?)\n\s*$', re.MULTILINE | re.DOTALL) RE_DOXY_SECTION = re.compile(r"^\s*@(brief|note|(class|struct|param|field|details)\s+([-\w]+)):?(.*?)(?=\n\s*@|\n\s*\n|\Z)", re.MULTILINE | re.DOTALL) RE_NOTE_SECTION = re.compile(r"^\s*@(note):?(.*?)(?=\n\s*@|\n\s*\n|\Z)", re.MULTILINE | re.DOTALL) # RE_TYPE = re.compile(r'(([A-Z][\w-]*)\s*::=[\w \t]+(?:{+(.*?)}+)?.*?)\n\s*\n', re.MULTILINE | re.DOTALL) RE_TYPE = re.compile(r'^\s*([A-Z][\w-]*)?\s*([{} \t:\w-]*?)?::=([\w \t]+.*?)\n\s*\n', re.MULTILINE | re.DOTALL) Loading Loading @@ -91,6 +95,12 @@ def parseText(content, indent=None): content = RE_POWER_SIGN.sub('<sup>\\1</sup>', content) content = RE_LESSEQ_SIGN.sub('≤', content) content = RE_GREATEQ_SIGN.sub('≥', content) content = RE_REFERENCE_NUMBER.sub('[\\g<0>](#references)', content) return indentLines(content, indent) def parseInlineComments(content:str, indent=None): Loading Loading @@ -188,7 +198,7 @@ def parseModule(mname, content): else: ret = parseText(l) elif m.group(1) == 'note': s_note = '\n>>>\n' + 'NOTE: ' + parseText(l).rstrip() + '\n>>>\n' s_note = '\n>>>\n' + 'NOTE: ' + parseText(l).rstrip() + '\n>>>\n' else: ret = m.string[m.start():m.end()] return ret Loading @@ -196,7 +206,7 @@ def parseModule(mname, content): def repl_category(m): nonlocal s_category s_category = '\n **Categories**: ' s_category = '\n **Categories:** ' for l in m.group(1).split(','): # s_category += '[{0}](#{1}) '.format(l.strip(), urlquote(l.strip())) s_category += parseText(l).strip() + ' ' Loading @@ -206,13 +216,13 @@ def parseModule(mname, content): def repl_unit(m): nonlocal s_unit s_unit = '\n **Unit**: _' + parseText(m.group(1)).strip() + '_\n' s_unit = '\n **Unit:** _' + parseText(m.group(1)).strip() + '_\n' return '' doc = RE_DOXY_UNIT.sub(repl_unit, doc) def repl_revision(m): nonlocal s_revision s_revision = '\n **Revision**: _' + parseText(m.group(1)).strip() + '_\n' s_revision = '\n **Revision:** _' + parseText(m.group(1)).strip() + '_\n' return '' doc = RE_DOXY_REVISION.sub(repl_revision, doc) else: Loading Loading @@ -297,6 +307,13 @@ def parseModule(mname, content): for m in RE_TYPE.finditer(content[cpos:]): ret += repl_type (m, m.string[pos:m.start()]) pos = m.end() v = parseText(parseOptions(parseDoxyComments(content[pos:]), m_options)) if len(v): def repl_note (m): return '\n>>>\n' + 'NOTE: ' + m.group(2).lstrip(":, \t").lstrip('\n').rstrip() + '\n>>>\n' ret += '\n\n' + RE_NOTE_SECTION.sub(repl_note, v).strip() +'\n' return ret Loading Loading @@ -336,7 +353,7 @@ def main(): cnt = 0 for a in o_args.modules: try: content = open(a, encoding='latin-1').read() content = open(a, mode="r", encoding='latin-1').read() cnt += parseAsn(o_args.out, content) except IOError as e: sys.stderr.write(e[1]+"\n") Loading cdd @ fad9ad63 Compare 65955d90 to fad9ad63 Original line number Diff line number Diff line Subproject commit 65955d90fbba94fe3d52538104e079de76e728e6 Subproject commit fad9ad63dce28ba316b468beed00c5678a4311e1 Loading
asn2md.py +22 −5 Original line number Diff line number Diff line Loading @@ -42,6 +42,9 @@ RE_DOXY_C_COMMENTS = re.compile(r'^\s*/\*\*\s(.*?)\*/', re.MULTILINE | re.DOTALL RE_DOXY_C_COMMENTS_I = re.compile(r'\s*\*+') RE_STRIPSTAR = re.compile(r'^\s*\*', re.MULTILINE) RE_POWER_SIGN = re.compile('\^(-?\w+|\(.*?\))') RE_GREATEQ_SIGN = re.compile(r'(?<=\s)>=(?=\s)') RE_LESSEQ_SIGN = re.compile(r'(?<=\s)<=(?=\s)') RE_REFERENCE_NUMBER = re.compile(r'\[(?:i\.)?\d+\]') RE_DOXY_REF = re.compile(r'@ref\s+([\w-]+)') Loading @@ -56,6 +59,7 @@ RE_DOXY_CATEGORY = re.compile(r'^\s*@category[\s:]+(.+)\n', re.MULTILINE) RE_DOXY_PARAM = re.compile(r'^\s*@(?:param|field):?\s+([\w-]+)\s*(.*?)\n\s*$', re.MULTILINE | re.DOTALL) RE_DOXY_SECTION = re.compile(r"^\s*@(brief|note|(class|struct|param|field|details)\s+([-\w]+)):?(.*?)(?=\n\s*@|\n\s*\n|\Z)", re.MULTILINE | re.DOTALL) RE_NOTE_SECTION = re.compile(r"^\s*@(note):?(.*?)(?=\n\s*@|\n\s*\n|\Z)", re.MULTILINE | re.DOTALL) # RE_TYPE = re.compile(r'(([A-Z][\w-]*)\s*::=[\w \t]+(?:{+(.*?)}+)?.*?)\n\s*\n', re.MULTILINE | re.DOTALL) RE_TYPE = re.compile(r'^\s*([A-Z][\w-]*)?\s*([{} \t:\w-]*?)?::=([\w \t]+.*?)\n\s*\n', re.MULTILINE | re.DOTALL) Loading Loading @@ -91,6 +95,12 @@ def parseText(content, indent=None): content = RE_POWER_SIGN.sub('<sup>\\1</sup>', content) content = RE_LESSEQ_SIGN.sub('≤', content) content = RE_GREATEQ_SIGN.sub('≥', content) content = RE_REFERENCE_NUMBER.sub('[\\g<0>](#references)', content) return indentLines(content, indent) def parseInlineComments(content:str, indent=None): Loading Loading @@ -188,7 +198,7 @@ def parseModule(mname, content): else: ret = parseText(l) elif m.group(1) == 'note': s_note = '\n>>>\n' + 'NOTE: ' + parseText(l).rstrip() + '\n>>>\n' s_note = '\n>>>\n' + 'NOTE: ' + parseText(l).rstrip() + '\n>>>\n' else: ret = m.string[m.start():m.end()] return ret Loading @@ -196,7 +206,7 @@ def parseModule(mname, content): def repl_category(m): nonlocal s_category s_category = '\n **Categories**: ' s_category = '\n **Categories:** ' for l in m.group(1).split(','): # s_category += '[{0}](#{1}) '.format(l.strip(), urlquote(l.strip())) s_category += parseText(l).strip() + ' ' Loading @@ -206,13 +216,13 @@ def parseModule(mname, content): def repl_unit(m): nonlocal s_unit s_unit = '\n **Unit**: _' + parseText(m.group(1)).strip() + '_\n' s_unit = '\n **Unit:** _' + parseText(m.group(1)).strip() + '_\n' return '' doc = RE_DOXY_UNIT.sub(repl_unit, doc) def repl_revision(m): nonlocal s_revision s_revision = '\n **Revision**: _' + parseText(m.group(1)).strip() + '_\n' s_revision = '\n **Revision:** _' + parseText(m.group(1)).strip() + '_\n' return '' doc = RE_DOXY_REVISION.sub(repl_revision, doc) else: Loading Loading @@ -297,6 +307,13 @@ def parseModule(mname, content): for m in RE_TYPE.finditer(content[cpos:]): ret += repl_type (m, m.string[pos:m.start()]) pos = m.end() v = parseText(parseOptions(parseDoxyComments(content[pos:]), m_options)) if len(v): def repl_note (m): return '\n>>>\n' + 'NOTE: ' + m.group(2).lstrip(":, \t").lstrip('\n').rstrip() + '\n>>>\n' ret += '\n\n' + RE_NOTE_SECTION.sub(repl_note, v).strip() +'\n' return ret Loading Loading @@ -336,7 +353,7 @@ def main(): cnt = 0 for a in o_args.modules: try: content = open(a, encoding='latin-1').read() content = open(a, mode="r", encoding='latin-1').read() cnt += parseAsn(o_args.out, content) except IOError as e: sys.stderr.write(e[1]+"\n") Loading
cdd @ fad9ad63 Compare 65955d90 to fad9ad63 Original line number Diff line number Diff line Subproject commit 65955d90fbba94fe3d52538104e079de76e728e6 Subproject commit fad9ad63dce28ba316b468beed00c5678a4311e1