#!/usr/bin/python


"""
This was added to find some of the stuff that annoys Nicolai, such as:
   if (a) throw wexception
      ("Message explaining what went wrong, using format "
       "argument such as %u, %ill and %s",
       7, -9380350846789, "hej");

He requires it to be formatted like this instead:
   if (a)
      throw wexception
         ...

So a line with "for (a)", "if (a)" or "while (a)" must end with one of the
characters in the string "){};\". Although a comment at the end is allowed
(therefore the complex regexp).

It would indeed be inconsistent to wrap within the controlled statement without
wrapping before it. A justification to do that would be to save vertical screen
space.

Do the same for do, else and return statements. Unfortunately it will miss
lines ending with do or else followed by something very short (a single letter,
                                                               like "do a" or
                                                               "else a")
because it has to allow "do if" and "else if".
"""

error_msg = """Multiline conditional should break after conditional. if (a) blah... -> if (a) \\n blah"""

regexp=r"""(?x)
^
(
    [^/\#"']|/([^/"']|"([^"\]|\\"|\\[^"])*"|'(\\[\'0nt]|[^\'])')|"([^"]|\\")*"|'(\\[\'0nt]|[^\'])'
)*
(
    (^|\t)((do|else)[ ]([^/i]|(i[^f]))|return[ ]+)|(for|if|while)[ ]*\((/[^/*]|[^/])*\)[ ]*
)
(/[^/*]|[^/])*
[^){};\\ \n]$"""

forbidden = [
    'do hl',
    '	do gam',
    'else hl',
    '	else gam',
    'return a ?',
    '	return hlj',
    'if (condition) do_something',
    'if (a) throw wexception',
]

allowed = [
    '	do if',
    '	do //  something',
    '	else if',
    '	else //  something',
    '	return a ? b : c;',
    '	return',
    '\return this is a doxygen comment',
    '\todo',
    'if (condition) do_something();',
    'if (c) throw wexception("Something went wrong.");',
    'if (c)',
    '	("calculated value for (%i, %i)",',
    '\t\treturn m_nb; ',
    '\t\treturn m_nb;\n',
]
