@@ -17,19 +17,55 @@ def run_pipeline(self, config_file, name, lines):
17
17
output = ""
18
18
19
19
brace_prefix = "(?P<prefix>(extern|namespace)\s+[\w\" ]*)"
20
- brace_postfix = "\s */(/|\*)[^\r \n ]*"
20
+ brace_postfix = "[ \t ] */(/|\*)[^\r \n ]*"
21
21
22
22
brace_regex = regex .compile (
23
+ r"/\*|\*/|//|\\\\|\\\"|\"|\\'|'|" + linesep + "|" + \
23
24
"(" + brace_prefix + "\s*)?{|" # "{" with optional prefix
24
- "\ }(" + brace_postfix + ")?" ) # "}" with optional comment postfix
25
+ "}(" + brace_postfix + ")?" ) # "}" with optional comment postfix
25
26
26
27
name_stack = []
27
28
brace_count = 0
28
29
extract_location = 0
30
+ in_multicomment = False
31
+ in_singlecomment = False
32
+ in_string = False
33
+ in_char = False
29
34
for match in brace_regex .finditer (lines ):
30
35
token = match .group ()
31
36
32
- if match .group ("prefix" ):
37
+ if token == "/*" :
38
+ if not in_singlecomment and not in_string and not in_char :
39
+ in_multicomment = True
40
+ elif token == "*/" :
41
+ if not in_singlecomment and not in_string and not in_char :
42
+ in_multicomment = False
43
+ elif token == "//" :
44
+ if not in_multicomment and not in_string and not in_char :
45
+ in_singlecomment = True
46
+ elif in_singlecomment and linesep in token :
47
+ # Ignore token if it's in a singleline comment. Only check it
48
+ # for newlines to end the comment.
49
+ in_singlecomment = False
50
+ elif in_multicomment or in_singlecomment :
51
+ # Tokens processed after this branch are ignored if they are in
52
+ # comments
53
+ continue
54
+ elif token == "\\ \" " :
55
+ continue
56
+ elif token == "\" " :
57
+ if not in_char :
58
+ in_string = not in_string
59
+ elif token == "\\ '" :
60
+ continue
61
+ elif token == "'" :
62
+ if not in_string :
63
+ in_char = not in_char
64
+ elif in_string or in_char :
65
+ # Tokens processed after this branch are ignored if they are in
66
+ # double or single quotes
67
+ continue
68
+ elif match .group ("prefix" ):
33
69
brace_count += 1
34
70
name_stack .append ((brace_count , match .group ("prefix" ).rstrip ()))
35
71
elif "{" in token :
0 commit comments