#!/usr/bin/python


"""
This catches an opening brace that comes after a character that is not tab or
space. It detects code like "if (condition){", which should be "if (condition)
{". The @ is there because @{ seem to be used in doxygen comments. Characters
after // are ignored.
"""

error_msg = "Opening brace should be on the next line."

strip_comments_and_strings = True
regexp = r"""^([^/#"']|/([^/"']|"([^"]|\\")*"|'(\\[\'0nt]|[^\'])')|"([^"\]|\\"|\\[^"])*"|'(\\[\'0nt]|[^\'])')*(/[^	 /@]|[^	 "'@])\{"""

forbidden = [
    '/ /{',
    'if (condition){',

    # Eriks tests
    ## illegal_character_before_opening_brace.cc
    'struct A{};',
    'struct B{};',
    'struct C{};',
    'struct D{};',
    'struct E{};',
    'struct F{};',
    'struct G{};',
    'struct H{};',
    'struct I{};',
    'struct J{};',
    'struct K{};',
    'struct L{};',
    'struct M{};',
    'struct N{};',
    'struct O{};',
    'struct P{};',
    'struct Q{};',
    'struct R{};',
    'struct S{};',
    'struct T{};',
    'struct U{};',
    'struct V{};',
    'struct W{};',
    'struct X{};',
    'struct Y{};',
    'struct Z{};',
    'struct a{};',
    'struct b{};',
    'struct c{};',
    'struct d{};',
    'struct e{};',
    'struct f{};',
    'struct g{};',
    'struct h{};',
    'struct i{};',
    'struct j{};',
    'struct k{};',
    'struct l{};',
    'struct m{};',
    'struct n{};',
    'struct o{};',
    'struct p{};',
    'struct q{};',
    'struct r{};',
    'struct s{};',
    'struct t{};',
    'struct u{};',
    'struct v{};',
    'struct w{};',
    'struct x{};',
    'struct y{};',
    'struct z{};',
    'struct _{};',
    'struct _0{};',
    'struct _1{};',
    'struct _2{};',
    'struct _3{};',
    'struct _4{};',
    'struct _5{};',
    'struct _6{};',
    'struct _7{};',
    'struct _8{};',
    'struct _9{};',
]

allowed = [
    '//{',
    '// a{b|c}',
    'if (condition) {',
    ' * @{',
    'foo("{}")',
    "buffer[i] = '{';",
]
