davidvarga / MBeautifier

MBeautifier is a MATLAB source code formatter, beautifier. It can be used directly in the MATLAB Editor and it is configurable.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug when trying to append new entries to cell array

FENCor opened this issue · comments

Hi,
i recently experienced an issue in MBeautifier when I tried to append an entrie to a cell array:

% Minimal Example of Beautifier Error
% In this case MBeautifier destroys the script.

TestCell = {'Text1'};
TestCell = [TestCell {'Text2'}]; % The intention is to append the cell array with additional entries.

% Expected behaviour:
% TestCell = [TestCell, {'Text2'}];
%
% Actual behaviour:
% TestCell = [TestCell{'Text2'}];

After this the script does not work any more.

Best regards,
Frank.

P.S.: Beside the issue MBeautifier is an excellent tool.

Hi,

sorry for the late response - the problem should be fixed now.

Sorry, I had to revert the commit(s), it casues something else to break - this issue is much trickier than I thought.

Fixed the problem once again using a different solution.

Hi David,
Thanks for your answer. I modified my original test script:

TestArray = 1:10;
TestArray = [TestArray(5:10) TestArray (1:4)]; 

% Expected behaviour:
% TestArray = [TestArray(5:10) TestArray (1:4)];
%
% Actual behaviour:
% TestArray = [TestArray(5:10), TestArray(1:4)]; Commit c77308e
% TestArray = [TestArray, (5:10), TestArray, (1:4)]; Commit c792941

In case TestArray(5:10) it should be an index, in the second case TestArray (1:4) it should append TestArray and another array [1 2 3 4].

So far I found a workaround for myself. Before I ran the MBeautifier I searched for regular expressions and replaced them:

DangerousSequence = regexp(OrigContent, '\[*\w*[^,]\s[{(]', 'match');
if (~isempty(DangerousSequence))
    DisarmedSequence = replace(DangerousSequence, ' ', ', ');
    ChangedContent = regexprep(OrigContent, DangerousSequence, DisarmedSequence);
end

My workaround is not without errors since it modifies case {1 2} to case, {1, 2}.

I will also have a look at your second fix.

Best regards.

I just tried your second fix and it works great. :-)

@FENCor : Glad to hear :)