diff options
author | Juergen Bocklage-Ryannel <juergen.bocklage-ryannel@pelagicore.com> | 2017-02-15 18:04:19 +0100 |
---|---|---|
committer | Juergen Bocklage-Ryannel <juergen.bocklage-ryannel@pelagicore.com> | 2017-02-15 18:04:19 +0100 |
commit | f505226745af1ab2057eb8d322a34c1246207b84 (patch) | |
tree | 010cbb678c5385d4eaeff058536ae65cfe15d2f0 | |
parent | dec3046824904714b896cc0da4f38a6a2e727343 (diff) | |
download | qtivi-qface-f505226745af1ab2057eb8d322a34c1246207b84.tar.gz |
Improvements on the doc parsing. Now uses a simple py script to gather the information. Now there needs to be a translation of the inner tags
-rw-r--r-- | qface/helper/doc.py | 43 | ||||
-rw-r--r-- | tests/test_comments.py | 7 |
2 files changed, 27 insertions, 23 deletions
diff --git a/qface/helper/doc.py b/qface/helper/doc.py index eff0852..34d97a9 100644 --- a/qface/helper/doc.py +++ b/qface/helper/doc.py @@ -1,32 +1,35 @@ -import re - - -class DocObject(object): - pass +from collections import OrderedDict def parse_doc(s): - o = DocObject() - print('parse_doc:', s) if not s: return + o = OrderedDict() tag = None + s = s[3:-2] # remove '/**' and '*/' for line in s.splitlines(): - if re.match(r'\/\*\*', line): - continue - if re.match(r'\s*\*/', line): - continue - res = re.match(r'^\s*\*?\s*@(\w+)\s*(.*$)', line) - if res: - tag = res.group(1) - value = res.group(2) if res.group(2) else None - setattr(o, tag, value) - continue - res = re.match(r'\s*\*\s*(.*$)', line) - if res and tag: - setattr(o, tag, '{0} {1}'.format(getattr(o, tag), res.group(1))) + line = line.lstrip(' *') # strip a ' ' and '*' from start + if not line: + tag = None # on empty line reset the tag information + elif line[0] == '@': + line = line[1:] + res = line.split(maxsplit=1) + if len(res) == 1: + tag = res[0] + o[tag] = True + elif len(res) == 2: + tag, value = res[0], res[1] + o[tag] = value + elif tag: # append to previous matched tag + if type(o[tag]) != list: + o[tag] = [o[tag]] + o[tag].append(line) return o + +def replace_tags(s): + pass + # {% with doc = parse_doc(symbol.commment) %} # \brief {{doc.brief}} # \description {{doc.description}} diff --git a/tests/test_comments.py b/tests/test_comments.py index 49b5587..d5234a8 100644 --- a/tests/test_comments.py +++ b/tests/test_comments.py @@ -26,7 +26,8 @@ def test_comment(): interface = system.lookup('org.example.echo.Echo') assert interface o = doc.parse_doc(interface.comment) - assert o.brief == 'the brief' - assert o.description == 'the description continues' - assert o.deprecated is None + # import pdb; pdb.set_trace() + assert o['brief'] == 'the brief' + assert o['description'] == ['the description', 'continues'] + assert o['deprecated'] is True |