From 8606b4f0f2a12e70af3da2564a83d8a86c03e5d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Cederberg?= Date: Mon, 22 Feb 2021 23:40:50 +0100 Subject: [PATCH] Fixed #116 Parsing would fail if a method contained `parfor`, as it wasn't in the `MatFunction::mat_kws` list. Thus, we ended into an infinite loop :( --- CHANGES.rst | 8 ++++++++ sphinxcontrib/mat_types.py | 4 ++-- tests/test_data/ClassContainingParfor.m | 16 ++++++++++++++++ tests/test_matlabify.py | 3 ++- tests/test_parse_mfile.py | 8 ++++++++ 5 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 tests/test_data/ClassContainingParfor.m diff --git a/CHANGES.rst b/CHANGES.rst index 2abf851..9f54912 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,11 @@ +sphinxcontrib-matlabdomain-0.11.6 (2021-02-23) +============================================== + +* Fixed `Issue 116 `_. + Failure on parfor statements in class methods. Fix `MatFunction` class to + also take `parfor` into account when counting `end`. + + sphinxcontrib-matlabdomain-0.11.5 (2021-01-05) ============================================== diff --git a/sphinxcontrib/mat_types.py b/sphinxcontrib/mat_types.py index 7216f21..2ee674f 100644 --- a/sphinxcontrib/mat_types.py +++ b/sphinxcontrib/mat_types.py @@ -515,8 +515,8 @@ class MatFunction(MatObject): :type tokens: list """ # MATLAB keywords that increment keyword-end pair count - mat_kws = list(zip((Token.Keyword,) * 6, - ('arguments', 'for', 'if', 'switch', 'try', 'while'))) + mat_kws = list(zip((Token.Keyword,) * 7, + ('arguments', 'for', 'if', 'switch', 'try', 'while', 'parfor'))) def __init__(self, name, modname, tokens): super(MatFunction, self).__init__(name) diff --git a/tests/test_data/ClassContainingParfor.m b/tests/test_data/ClassContainingParfor.m new file mode 100644 index 0000000..0bb0765 --- /dev/null +++ b/tests/test_data/ClassContainingParfor.m @@ -0,0 +1,16 @@ +classdef ClassContainingParfor + % Parfor is a keyword + + properties + Property1 + end + + methods + function obj = test(inputArg1,inputArg2) + % A method with parfor + obj.Property1 = inputArg1 + inputArg2; + parfor i = 1:10 + end + end + end +end \ No newline at end of file diff --git a/tests/test_matlabify.py b/tests/test_matlabify.py index 8ddddd7..6fe7407 100644 --- a/tests/test_matlabify.py +++ b/tests/test_matlabify.py @@ -69,7 +69,8 @@ def test_module(mod): 'ClassWithEnumMethod', 'ClassWithEventMethod', 'f_with_function_variable', 'ClassWithUndocumentedMembers', 'ClassWithGetterSetter', 'ClassWithDoubleQuotedString', 'ClassWithDummyArguments', - 'ClassWithStrings', 'ClassWithFunctionArguments', 'ClassWithMethodsWithSpaces'} + 'ClassWithStrings', 'ClassWithFunctionArguments', 'ClassWithMethodsWithSpaces', + 'ClassContainingParfor'} assert all_items == expected_items assert mod.getter('__name__') in modules diff --git a/tests/test_parse_mfile.py b/tests/test_parse_mfile.py index c792af8..d0729fd 100644 --- a/tests/test_parse_mfile.py +++ b/tests/test_parse_mfile.py @@ -532,6 +532,14 @@ def test_ClassWithMethodsWithSpaces(): assert obj.docstring == " Class with methods that have space after the function name.\n" assert obj.methods['static_method'].attrs == {'Static': True} +def test_ClassContainingParfor(): + mfile = os.path.join(DIRNAME, 'test_data', 'ClassContainingParfor.m') + obj = mat_types.MatObject.parse_mfile(mfile, 'ClassContainingParfor', 'test_data') + assert isinstance(obj, mat_types.MatClass) + assert obj.name == 'ClassContainingParfor' + assert set(obj.methods.keys()) == set(['test']) + assert obj.docstring == " Parfor is a keyword\n" +