mfile2sci: The prettyprintoutput flag badly manages appended comments
Reported by Samuel GOUGEON (@sgougeon)
BUG DESCRIPTION:
----------------
When the prettyprintoutput option of mfile2sci() is set to
* %T : comments appended to a line of instructions are sent to the next line in their converted version.
This can easily make the converted code quite confuse, because then we no longer know if the comment
is related to the previous or the next instruction. Example:
b = b-a; % comment
disp('OK')
is converted into
b = b-a;
// comment
disp('OK')
and we no longer know if the comment is related to "b = b-a" (as it actually is) or to "disp('OK')"
=> Appended comments should stay appended when they are converted.
* %F : Then spaces between the last instruction and the comment are all removed. Example:
b = b-a; % comment
is converted into
b = b-a;// comment
Even if the initial space width is not kept, having 2 separating spaces would be better than none:
b = b-a; // comment
RESULTS of the HOW TO REPRODUCE section:
../..
Macro to tree conversion: Done
****** End of mfile2sci() session ******
a = 1;
// this is a test
../..
Macro to tree conversion: Done
****** End of mfile2sci() session ******
a = 1;// this is a test
ERROR LOG:
----------
None. Misleading or poor result.
HOW TO REPRODUCE THE BUG:
-------------------------
code = "a = 1; % this is a test";
mfile = TMPDIR + "/bug_16586";
mputl(code, mfile+".m");
// 1st run: prettify
mfile2sci(mfile+".m", TMPDIR,,,,%t);
mprintf("%s\n", mgetl(mfile+".sci"));
// 2nd run: do not prettify
mfile2sci(mfile+".m", TMPDIR,,,,%f);
mprintf("%s\n", mgetl(mfile+".sci"));
OTHER INFORMATION:
------------------
Already occurs with 5.5.2. Tested with 6.1.0