Correct indentation bug when line contains "for" or "else".
Hi.
This commit replaces and extends 8a8c98ab.
Indeed, after further investigation, I finally found the root cause of the problem: in cstyle.js
there are some regex that are not finished by a \b
for for
and else
keywords.
I understand that this behavior seems needed for foreach
or elseif
keyword as cstyle.js
is used for different languages than C.
But, with this, the follwing snippet:
if(true)
fork();
printf("PID: %d\n", getpid());
Is indented as:
if(true)
fork();
printf("PID: %d\n", getpid());
Because fork()
contains for
and is then considered as a keyword.
So, in this patch I added \b
in the regex for else
and for
keyword.
I only added where they were needed so my tests succeeded maybe I can add them in every regex to be sure there will not be future trouble?
About other keywords like foreach
, I do not think this patch can cause trouble.
Indeed, for language with this keyword, like Perl, PHP or C#, you always need to put braces.
Thus, for these languages this snippet is wrong:
foreach(1, 2, 3, 4, 5)
print "$_\n";
So, I think cstyle.js
still works because the code called to handle such case is the one dealing with braces.
If you see any way to improve this patch, feel free to share.
Best regards.