Lines Matching refs:self
32 def __init__ (self):
33 self.comment_nest = 0
34 self.leading_space_re = re.compile ('^(\t+| )')
35 self.trailing_space_re = re.compile ('(\t+| )$')
36 self.define_hack_re = re.compile ("(#\s*define\s+[a-zA-Z0-9_]+)\(")
38 def comment_nesting (self):
44 return self.comment_nest
46 def __call__ (self, line):
52 line = self.define_hack_re.sub (r'\1 (', line)
54 line = self.process_strings (line)
57 if self.comment_nest == 0:
64 if self.comment_nest > 0 and close_comment < 0:
70 self.comment_nest += 1
71 return self.trailing_space_re.sub ('', line [:open_comment])
75 self.comment_nest -= 1
76 return self.trailing_space_re.sub ('', line [close_comment + 2:])
78 if open_comment >= 0 and close_comment > 0 and self.comment_nest == 0:
83 return self.__call__ (newline)
87 def process_strings (self, line):
97 return line [:start + 1] + '"' + self.process_strings (line [k + 1:])
105 def __init__ (self, debug):
106 self.debug = debug
107 self.filename = None
108 self.error_count = 0
109 self.line_num = 1
110 self.orig_line = ''
111 self.trailing_newline_re = re.compile ('[\r\n]+$')
112 self.indent_re = re.compile ("^\s*")
113 self.last_line_indent = ""
114 self.last_line_indent_curly = False
115 self.re_checks = \
158 def get_error_count (self):
162 return self.error_count
164 def check_files (self, files):
169 self.check_file (filename)
171 def check_file (self, filename):
175 self.filename = filename
178 self.line_num = 1
186 line = self.trailing_newline_re.sub ('', line)
187 self.orig_line = line
189 self.line_checks (preprocess (line))
191 self.line_num += 1
194 self.filename = None
203 def line_checks (self, line):
209 indent = len (self.indent_re.search (line).group ())
211 if not self.last_line_indent_curly and indent != self.last_line_indent:
212 None # self.error ("bad indent on close curly brace")
213 self.last_line_indent_curly = True
215 self.last_line_indent_curly = False
218 for (check_re, msg) in self.re_checks:
220 self.error (msg)
224 self.error ("missing space around operator")
226 self.last_line_indent = indent
229 def error (self, msg):
233 print ("%s (%d) : %s" % (self.filename, self.line_num, msg))
234 if self.debug:
235 print ("'" + self.orig_line + "'")
236 self.error_count += 1