Lines Matching refs:self
13 def __init__(self, filename): argument
14 self.filename = filename
15 self.line = None # most recently read line
16 self.lineno = -1 # zero-based
17 def finish(self): argument
21 def handle_line(self): argument
25 def read(self): argument
26 with open(self.filename) as f:
28 for self.lineno in range(len(lines)):
29 self.line = lines[self.lineno]
30 self.handle_line()
31 self.finish()
32 def context(self): argument
36 return "line " + str(self.lineno + 1) + " of " + self.filename
47 def __init__(self, filename, kind): argument
48 super(Specification, self).__init__(filename)
49 self.sections = dict() # key is section name, value is array of strings (lines) in the section
50 self.section = None # name of current %section
51 self.defmacro = dict() # key is macro name, value is string (body of macro)
52 …self.deflines = dict() # key is definition name, value is array of strings (lines) in the definiti…
53 self.deflines_key = None # name of current %define-lines
54 self.kind = kind
55 self.kinds = None # remember %define-kinds
56 self.conditional = self.UNCONDITIONAL
58 def finish(self): argument
59 assert self.section is None, "\"%section " + self.section + \
61 assert self.deflines_key is None, "\"%define-lines " + self.deflines_key + \
63 … assert self.conditional is self.UNCONDITIONAL, "%kind not terminated by end of specification file"
65 def macro_substitution(self): argument
71 orig = self.line
77 assert key in self.defmacro, "Missing definition of macro %{" + key + "} at " + self.context()
80 body_orig = self.defmacro[key]
88 assert argnum >= 0, "Macro argument number must be positive (at " + self.context() + ")"
90 str(len(args)) + " supplied arguments at " + self.context()
103 def match_kind(self, patterns_string): argument
111 if re.search("^" + re.escape(wildcard_match[1]), self.kind):
117 assert lowest_version_match[1] in self.kinds, (
118 "Kind \"" + pattern + "\" at " + self.context() +
121 lowest_pos = self.kinds.index(pattern[:-1])
122 return self.kind in self.kinds[lowest_pos:]
125 if not self.kinds is None and not pattern in self.kinds:
127 print("WARNING: kind \"" + pattern + "\" at " + self.context() +
129 if pattern == self.kind:
133 def handle_line(self): argument
144 matchbad = re.search("^[/\\\]%(\S*)", self.line)
146 print("WARNING: Probable misspelled directive at " + self.context())
149 if re.search("^%", self.line) and not re.search("^%{", self.line):
151 if re.search("^%%", self.line):
155 match = re.search("^(%\S*)", self.line);
158 assert False, "Unknown directive \"" + directive + "\" on " + self.context()
161 match = re.search("^%/define-lines\s*(\S*)", self.line)
163 assert match[1] == "", "Malformed directive \"%/define-lines\" on " + self.context()
164 … assert not self.deflines_key is None, "%/define-lines with no matching %define-lines on " + \
165 self.context()
166 self.deflines_key = None
170 assert self.deflines_key is None, "Directive is not permitted in definition of \"" + \
171 self.deflines_key + "\" at " + self.context()
174 match = re.search("^%define-lines\s+(\S+)\s*$", self.line)
177 if self.conditional is self.CONDITIONAL_OFF:
178 self.deflines_key = ""
180 … assert not key in self.deflines, "Duplicate definition of \"" + key + "\" on " + self.context()
181 self.deflines[key] = []
182 self.deflines_key = key
188 match = re.search("^%insert-lines\s+(\S+)\s*$", self.line)
190 assert not self.section is None, "%insert-lines outside %section at " + self.context()
192 … assert key in self.deflines, "Missing definition of lines \"" + key + "\" at " + self.context()
193 if self.conditional is self.CONDITIONAL_OFF:
195 self.sections[self.section].extend(self.deflines[key]);
199 match = re.search("^%section\s+(\S+)\s*$", self.line)
201 assert self.section is None, "Nested %section is forbidden at " + self.context()
202 …assert self.conditional is self.UNCONDITIONAL, "%section within %kind is forbidden at " + self.con…
204 … assert not key in self.sections, "Duplicate definition of \"" + key + "\" on " + self.context()
205 self.sections[key] = []
206 self.section = key
212 if re.search("^%/section\s*$", self.line):
213 assert not self.section is None, "%/section with no matching %section on " + self.context()
214 assert self.conditional is self.UNCONDITIONAL # can't actually happen
215 self.section = None
219 match = re.search("^%kind\s+((\S+)(\s+\S+)*)\s*$", self.line)
221 assert self.conditional is self.UNCONDITIONAL, "%kind is nested at " + self.context()
223 if self.match_kind(patterns):
224 self.conditional = self.CONDITIONAL_ON
226 self.conditional = self.CONDITIONAL_OFF
230 if re.search("^%else\s*$", self.line):
231 …assert not self.conditional is self.UNCONDITIONAL, "%else without matching %kind on " + self.conte…
232 if self.conditional == self.CONDITIONAL_ON:
233 self.conditional = self.CONDITIONAL_OFF
235 assert self.conditional == self.CONDITIONAL_OFF
236 self.conditional = self.CONDITIONAL_ON
256 if re.search("^%/kind\s*$", self.line):
257 …assert not self.conditional is self.UNCONDITIONAL, "%/kind without matching %kind on " + self.cont…
258 self.conditional = self.UNCONDITIONAL
262 match = re.search("^%define-kinds\s+(\S.*?)\s*$", self.line)
264 … assert self.conditional is self.UNCONDITIONAL, "%define-kinds within %kind is forbidden at " + \
265 self.context()
267 assert self.kind in kinds, "kind \"" + self.kind + "\" is not listed on " + self.context()
268 assert self.kinds is None, "Second %define-kinds directive at " + self.context()
269 self.kinds = kinds
273 match = re.search("^%define\s+(\S+)(.*)$", self.line)
275 if self.conditional is self.CONDITIONAL_OFF:
278 … assert not key in self.defmacro, "Duplicate definition of \"" + key + "\" on " + self.context()
282 self.defmacro[key] = match[1]
284 self.defmacro[key] = ""
288 assert False, "Malformed directive \"" + directive + "\" on " + self.context()
290 if self.conditional is self.CONDITIONAL_OFF:
292 elif not self.deflines_key is None:
293 self.deflines[self.deflines_key].append(self.macro_substitution())
294 elif self.section is None:
298 self.sections[self.section].append(self.macro_substitution())
304 def __init__(self, filename, specification): argument
305 super(Template, self).__init__(filename)
306 self.lines = []
307 self.specification = specification
309 def handle_line(self): argument
315 if re.search("^%", self.line):
317 if re.search("^%%", self.line):
321 match = re.search("^%insert\s+(\S+)\s*$", self.line)
324 assert key in specification.sections, "Unknown section \"" + key + "\" on " + self.context()
327 print("WARNING: \"TODO\" at " + self.context())
328 self.lines.append(line)
332 match = re.search("^(%\S*)", self.line)
333 assert False, "Unknown directive \"" + match[1] + "\" on " + self.context()
336 if re.search("TODO", self.line, re.IGNORECASE):
337 print("WARNING: \"TODO\" at " + self.context())
338 self.lines.append(self.line)