diff options
author | Juergen Bocklage-Ryannel <juergen.bocklage-ryannel@pelagicore.com> | 2017-02-01 16:43:57 +0100 |
---|---|---|
committer | Juergen Bocklage-Ryannel <juergen.bocklage-ryannel@pelagicore.com> | 2017-02-01 16:43:57 +0100 |
commit | cbacb37421bc722b72db9cda824a4c7161902b0e (patch) | |
tree | 23897bf3b4a361904e54284bd6536f0560a46b19 | |
parent | 3a44ce6b3608132303cb3a7825e84e80df1d9284 (diff) | |
download | qtivi-qface-cbacb37421bc722b72db9cda824a4c7161902b0e.tar.gz |
WIP: Added initial support to parse documentation
-rwxr-xr-x | qface/builtin/qtcpp/qtcpp.py | 2 | ||||
-rw-r--r-- | qface/builtin/qtcpp/templates/abstractinterface.cpp | 9 | ||||
-rw-r--r-- | qface/helper/doc.py | 30 | ||||
-rw-r--r-- | tests/test_comments.py | 33 |
4 files changed, 74 insertions, 0 deletions
diff --git a/qface/builtin/qtcpp/qtcpp.py b/qface/builtin/qtcpp/qtcpp.py index 6a8917c..2e53edb 100755 --- a/qface/builtin/qtcpp/qtcpp.py +++ b/qface/builtin/qtcpp/qtcpp.py @@ -9,6 +9,7 @@ from path import Path from qface.generator import FileSystem, Generator from qface.helper.qtcpp import Filters +from qface.helper.doc import parse_doc here = Path(__file__).dirname() @@ -25,6 +26,7 @@ def run(src, dst): generator.register_filter('returnType', Filters.returnType) generator.register_filter('parameterType', Filters.parameterType) generator.register_filter('defaultValue', Filters.defaultValue) + generator.register_filter('parse_doc', parse_doc) ctx = {'dst': dst} for module in system.modules: log.debug('generate code for module %s', module) diff --git a/qface/builtin/qtcpp/templates/abstractinterface.cpp b/qface/builtin/qtcpp/templates/abstractinterface.cpp index ff1ef87..c42325c 100644 --- a/qface/builtin/qtcpp/templates/abstractinterface.cpp +++ b/qface/builtin/qtcpp/templates/abstractinterface.cpp @@ -18,6 +18,15 @@ { } +{% with doc = interface.comment|parse_doc %} +/** + * \class {{class}} + * \brief {{doc.brief}} + * + * {{doc.description|wordwrap(width=64, wrapstring='\n * ')}} + */ +{% endwith %} + {{class}}::~{{class}}() { } diff --git a/qface/helper/doc.py b/qface/helper/doc.py new file mode 100644 index 0000000..d8f05cf --- /dev/null +++ b/qface/helper/doc.py @@ -0,0 +1,30 @@ +import re + + +class DocObject(object): + pass + + +def parse_doc(s): + o = DocObject() + tag = None + 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))) + return o + +# {% with doc = parse_doc(symbol.commment) %} +# \brief {{doc.brief}} +# \description {{doc.description}} +# {% endwith %} diff --git a/tests/test_comments.py b/tests/test_comments.py new file mode 100644 index 0000000..73fd623 --- /dev/null +++ b/tests/test_comments.py @@ -0,0 +1,33 @@ +from qface.generator import FileSystem +from qface.helper import doc +import logging +import logging.config +from path import Path +import re + + +# logging.config.fileConfig('logging.ini') +logging.basicConfig() + +log = logging.getLogger(__name__) + +inputPath = Path('tests/in') + + +def loadEcho(): + path = inputPath / 'org.example.echo.qface' + return FileSystem.parse_document(path) + + +def test_comment(): + system = loadEcho() + module = system.lookup('org.example.echo') + assert module.comment == '/** module */' + assert module + 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\ncontinued' + assert o.deprecated is None + |