Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/python
import sys
import re
import os.path
def debug(msg):
sys.stderr.write(msg+"\n")
def write_out(*args):
print("@@@".join([str(a) for a in args]))
# capture #1 is the parameter path
comment = re.compile(r"^//! \\ogs_file_(param|attr)\{([A-Za-z_0-9]+)\}( \\todo .*)?$")
comment_special = re.compile(r"^//! \\ogs_file(_param|_attr)?_special(\{[A-Za-z_0-9]+\})?( \\todo .*)?$")
#comment_special = re.compile(r"^//! \\ogs_file_special$")
# capture #5 is the parameter name
getter = re.compile(r'^(get|check|ignore|peek)Conf(Param|Attribute|Subtree)(List|Optional|All)?'
+r'(<.*>)?'
+r'\("([a-zA-Z_0-9:]+)"[,)]')
getter_special = re.compile(r'^(get|check|ignore|peek)Conf(Param|Attribute|Subtree)(List|Optional|All)?'
+r'(<.*>)?\(')
state = "getter"
path = ""
lineno = 0
line = ""
tag_path_comment = ""
param_or_attr_comment = ""
for inline in sys.stdin:
oldpath = path; oldlineno = lineno; oldline = line
path, lineno, line = inline.split(":", 2)
if path != oldpath: debug(path)
line = line.strip()
lineno = int(lineno)
m = comment.fullmatch(line)
if m:
if state != "getter":
write_out("UNNEEDED", oldpath, oldlineno, oldline)
state = "comment"
param_or_attr_comment = m.group(1)
tag_path_comment = m.group(2).replace("__", ".")
debug(" {:>5} //! {}".format(lineno, tag_path_comment))
tag_name_comment = tag_path_comment.split(".")[-1]
continue
m = comment_special.fullmatch(line)
if m:
if state != "getter":
write_out("UNNEEDED", oldpath, oldlineno, oldline)
state = "comment"
param_or_attr_comment = "special"
if m.group(1): # param|attr matched
# second group must not be empty!
tag_path_comment = m.group(2).strip("{}").replace("__", ".")
param = tag_path_comment.split(".")[-1]
paramtype = ""
method = ""
write_out("OK", path, lineno, tag_path_comment, param, paramtype, method)
state = "getter" # reset state s.t. next time a comment is accepted
continue
m = getter.match(line)
if m:
param = m.group(5)
paramtype = m.group(4)[1:-1] if m.group(4) else ""
method = m.group(1) + "Conf" + m.group(2) + (m.group(3) or "")
if state != "comment" or oldpath != path:
write_out("NODOC", path, lineno, "NONE", param, paramtype, method)
else:
debug(" {:>5} {} {} ".format(lineno, param, paramtype))
if param != tag_name_comment:
debug("error: parameter name from comment and code do not match: "
+ tag_name_comment + " vs. " + param)
write_out("NODOC", path, lineno, tag_path_comment, param, paramtype, method)
elif lineno != oldlineno+1:
debug("error: the associated comment is not on the line preceding this one."
+ " line numbers {} vs. {}".format(oldlineno, lineno))
write_out("NODOC", path, lineno, tag_path_comment, param, paramtype, method)
elif param_or_attr_comment == "param" and m.group(2) != "Param" and m.group(2) != "Subtree":
debug("error: comment says param but code says different.")
write_out("NODOC", path, lineno, tag_path_comment, param, paramtype, method)
elif param_or_attr_comment == "attr" and m.group(2) != "Attribute":
debug("error: comment says attr but code says different.")
write_out("NODOC", path, lineno, tag_path_comment, param, paramtype, method)
elif param_or_attr_comment == "special":
debug("error: comment comments a special line.")
write_out("NODOC", path, lineno, "UNKNOWN", "UNKNOWN", paramtype, method)
else:
write_out("OK", path, lineno, tag_path_comment, param, paramtype, method)
state = "getter"
continue
m = getter_special.match(line)
if m:
paramtype = m.group(4)[1:-1] if m.group(4) else ""
method = m.group(1) + "Conf" + m.group(2) + (m.group(3) or "")
if state != "comment" or oldpath != path:
write_out("NODOC", path, lineno, "NONE", "UNKNOWN", paramtype, method)
else:
if lineno != oldlineno+1:
debug("error: the associated comment is not on the line preceding this one."
+ " line numbers {} vs. {}".format(oldlineno, lineno))
write_out("NODOC", path, lineno, "UNKNOWN", "UNKNOWN", paramtype, method)
elif param_or_attr_comment != "special":
debug("error: comment does not comment a special line.")
write_out("NODOC", path, lineno, "UNKNOWN", "UNKNOWN", paramtype, method)
else:
write_out("SPECIAL", path, lineno, paramtype, method)
state = "getter"
continue
write_out("WRONGIN", path, lineno, line.strip())
state = "getter" # reset state in order to avoid warnings