#!/usr/bin/env python -tt
# encoding: utf-8
#

"""
Catches something like
blah (kjhdsfjh +

which should be 
blah
    (jdhsf + 
"""

def check_function(lines,fn):
    errors = []
    for lineno,line in enumerate(lines):
        line = line.strip()
        lineno += 1
        opening_parens = line.count('(')
        closing_parens = line.count(')')
        if opening_parens > closing_parens and line[0] != '(':
            errors.append( (fn, lineno,
                "Parenthesis not closed before end of "
                "line must be at line begin")
            )

    return errors

strip_comments_and_strings = True
strip_macros = True

evaluate_matches = check_function

forbidden = [
"""float g(float, float) {
\treturn (0.0 +
\t\tg(1.1, 2.2));
}""",
]

allowed = [
"""float g(float, float) {
\treturn
\t\t(0.0 +
\t\t g(1.1, 2.2));
}""",

"""\tstd::string newvisi = s->get_string("newvisi", "");""",

# Ignore macros
"""#if (defined(WIN32) || defined (WINDOWS) || \\
\tdefined (_WINDOWS)) && defined(CALLBACK) && \\
\tdefined (USEWINDOWS_CALLBACK)""",
]
